| import os |
| import sys |
| import subprocess |
| from pathlib import Path |
|
|
| def run_notebook(): |
| print("============================================================") |
| print(" QuantHive β Notebook-based GRPO Training (HF Jobs)") |
| print("============================================================") |
|
|
| |
| print("π¦ Installing notebook execution tools...") |
| subprocess.run([sys.executable, "-m", "pip", "install", "-q", "nbconvert", "nbformat", "ipykernel", "huggingface_hub"], check=True) |
|
|
| |
| print("π Executing mate_training.ipynb (mimicking Colab flow)...") |
| try: |
| |
| 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}") |
| |
| |
| |
| |
| 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" |
| |
| |
| 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() |
|
|