Spaces:
Running on Zero
Running on Zero
dexifried commited on
Commit ·
7f0f034
1
Parent(s): f57d914
Push checkpoint to HF Hub instead of download (Dexifried/tiny-router-checkpoint)
Browse files- app.py +20 -14
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -84,7 +84,7 @@ def train_and_export(encoder: str, epochs: int, batch_size: int, lr: float, max_
|
|
| 84 |
logs.append(proc.stdout[-3000:] if proc.stdout else "")
|
| 85 |
if proc.returncode != 0:
|
| 86 |
logs.append(f"❌ Training failed:\n{proc.stderr[-2000:]}")
|
| 87 |
-
return "\n".join(logs), None
|
| 88 |
|
| 89 |
logs.append("✅ Training complete!")
|
| 90 |
|
|
@@ -102,18 +102,25 @@ def train_and_export(encoder: str, epochs: int, batch_size: int, lr: float, max_
|
|
| 102 |
eval_results = json.load(f)
|
| 103 |
logs.append(f"\n📈 Results: {json.dumps(eval_results, indent=2)}")
|
| 104 |
|
| 105 |
-
# ──
|
| 106 |
-
logs.append("\n
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
summary = json.dumps(eval_results, indent=2) if eval_results else "No eval results"
|
| 116 |
-
return "\n".join(logs),
|
| 117 |
|
| 118 |
|
| 119 |
def quick_predict(text: str):
|
|
@@ -151,15 +158,14 @@ with gr.Blocks(title="⚡ Dex Neural Bake — Tiny-Router Trainer", theme=gr.the
|
|
| 151 |
lr = gr.Number(label="Learning rate", value=DEFAULT_LR)
|
| 152 |
max_length = gr.Slider(64, 512, value=DEFAULT_MAX_LENGTH, step=32, label="Max token length")
|
| 153 |
|
| 154 |
-
train_btn = gr.Button("🚀 Train
|
| 155 |
train_log = gr.Textbox(label="Training log", lines=25, max_lines=50, interactive=False)
|
| 156 |
eval_summary = gr.JSON(label="Evaluation results")
|
| 157 |
-
model_file = gr.File(label="Download ONNX model")
|
| 158 |
|
| 159 |
train_btn.click(
|
| 160 |
fn=train_and_export,
|
| 161 |
inputs=[encoder, epochs, batch_size, lr, max_length],
|
| 162 |
-
outputs=[train_log,
|
| 163 |
)
|
| 164 |
|
| 165 |
with gr.Tab("📋 Dataset Info"):
|
|
|
|
| 84 |
logs.append(proc.stdout[-3000:] if proc.stdout else "")
|
| 85 |
if proc.returncode != 0:
|
| 86 |
logs.append(f"❌ Training failed:\n{proc.stderr[-2000:]}")
|
| 87 |
+
return "\n".join(logs), None
|
| 88 |
|
| 89 |
logs.append("✅ Training complete!")
|
| 90 |
|
|
|
|
| 102 |
eval_results = json.load(f)
|
| 103 |
logs.append(f"\n📈 Results: {json.dumps(eval_results, indent=2)}")
|
| 104 |
|
| 105 |
+
# ── Push checkpoint to HF Hub ──────────────────────────────────────
|
| 106 |
+
logs.append("\n📤 Pushing checkpoint to HF Hub...")
|
| 107 |
+
try:
|
| 108 |
+
from huggingface_hub import HfApi
|
| 109 |
+
api = HfApi()
|
| 110 |
+
repo_id = "Dexifried/tiny-router-checkpoint"
|
| 111 |
+
api.create_repo(repo_id=repo_id, repo_type="model", exist_ok=True)
|
| 112 |
+
api.upload_folder(
|
| 113 |
+
folder_path=model_dir,
|
| 114 |
+
repo_id=repo_id,
|
| 115 |
+
repo_type="model",
|
| 116 |
+
commit_message=f"Tiny-router checkpoint (encoder={encoder}, epochs={epochs})",
|
| 117 |
+
)
|
| 118 |
+
logs.append(f"✅ Pushed to https://huggingface.co/{repo_id}")
|
| 119 |
+
except Exception as e:
|
| 120 |
+
logs.append(f"⚠️ Push failed: {e}")
|
| 121 |
|
| 122 |
summary = json.dumps(eval_results, indent=2) if eval_results else "No eval results"
|
| 123 |
+
return "\n".join(logs), summary
|
| 124 |
|
| 125 |
|
| 126 |
def quick_predict(text: str):
|
|
|
|
| 158 |
lr = gr.Number(label="Learning rate", value=DEFAULT_LR)
|
| 159 |
max_length = gr.Slider(64, 512, value=DEFAULT_MAX_LENGTH, step=32, label="Max token length")
|
| 160 |
|
| 161 |
+
train_btn = gr.Button("🚀 Train & Push to HF", variant="primary")
|
| 162 |
train_log = gr.Textbox(label="Training log", lines=25, max_lines=50, interactive=False)
|
| 163 |
eval_summary = gr.JSON(label="Evaluation results")
|
|
|
|
| 164 |
|
| 165 |
train_btn.click(
|
| 166 |
fn=train_and_export,
|
| 167 |
inputs=[encoder, epochs, batch_size, lr, max_length],
|
| 168 |
+
outputs=[train_log, eval_summary],
|
| 169 |
)
|
| 170 |
|
| 171 |
with gr.Tab("📋 Dataset Info"):
|
requirements.txt
CHANGED
|
@@ -9,3 +9,4 @@ torch>=2.2.0
|
|
| 9 |
transformers>=4.40,<5
|
| 10 |
tqdm>=4.66.0
|
| 11 |
tiktoken>=0.12.0
|
|
|
|
|
|
| 9 |
transformers>=4.40,<5
|
| 10 |
tqdm>=4.66.0
|
| 11 |
tiktoken>=0.12.0
|
| 12 |
+
huggingface_hub>=0.22.0
|