File size: 2,389 Bytes
213c699
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
import subprocess
from pathlib import Path

def run_notebook():
    print("============================================================")
    print("  QuantHive β€” Notebook-based GRPO Training (HF Jobs)")
    print("============================================================")

    # 1. Install necessary execution dependencies
    print("πŸ“¦ Installing notebook execution tools...")
    subprocess.run([sys.executable, "-m", "pip", "install", "-q", "nbconvert", "nbformat", "ipykernel", "huggingface_hub"], check=True)

    # 2. Execute the notebook
    print("πŸš€ Executing mate_training.ipynb (mimicking Colab flow)...")
    try:
        # We run it with --to notebook --execute --inplace
        subprocess.run([
            "jupyter", "nbconvert", 
            "--to", "notebook", 
            "--execute", 
            "--inplace", 
            "mate_training.ipynb"
        ], check=True)
        print("βœ… Notebook execution successful!")
    except subprocess.CalledProcessError as e:
        print(f"❌ Notebook execution failed: {e}")
        # We don't exit here because the notebook might have saved partial results
    
    # 3. Model Storage to HF Hub
    # The notebook saves to ./quanthive-trader-grpo-lora
    model_path = Path("quanthive-trader-grpo-lora")
    if model_path.exists():
        print(f"πŸ“‘ Found trained model at {model_path}. Pusing to HF Hub...")
        try:
            from huggingface_hub import HfApi
            api = HfApi()
            repo_id = "ARKAISW/quanthive-trader-grpo-lora"
            
            # Use HF_TOKEN if available in environment
            token = os.environ.get("HF_TOKEN")
            
            api.upload_folder(
                folder_path=str(model_path),
                repo_id=repo_id,
                repo_type="model",
                token=token
            )
            print(f"βœ… Model successfully pushed to https://huggingface.co/{repo_id}")
        except Exception as e:
            print(f"⚠️ Model push failed: {e}")
            print("You can manually push the 'quanthive-trader-grpo-lora' folder later.")
    else:
        print("❌ Trained model folder not found. Check notebook output for errors.")

    print("============================================================")
    print("🏁 Processing Finished.")

if __name__ == "__main__":
    run_notebook()