Spaces:
Runtime error
Runtime error
tc043 commited on
Commit ·
5a8eee8
1
Parent(s): 66b1bc1
feat: update training pipeline to use full-precision merge and add volume verification test
Browse files- app.py +1 -1
- modal_train.py +33 -12
- test_modal_ls.py +16 -0
app.py
CHANGED
|
@@ -16,7 +16,7 @@ GRAMMAR_PATH = ROOT / "grammar.gbnf"
|
|
| 16 |
|
| 17 |
# Keep the demo runnable while the GGUF files are still being prepared.
|
| 18 |
MOCK_MODE = os.getenv("STEP_ZERO_MOCK", "1") != "0"
|
| 19 |
-
NEMOTRON_MODEL_PATH = os.getenv("NEMOTRON_MODEL_PATH", "./models/
|
| 20 |
MINICPM_MODEL_PATH = os.getenv("MINICPM_MODEL_PATH", "./models/minicpm-3-4b.gguf")
|
| 21 |
|
| 22 |
app = FastAPI(title="Step-Zero")
|
|
|
|
| 16 |
|
| 17 |
# Keep the demo runnable while the GGUF files are still being prepared.
|
| 18 |
MOCK_MODE = os.getenv("STEP_ZERO_MOCK", "1") != "0"
|
| 19 |
+
NEMOTRON_MODEL_PATH = os.getenv("NEMOTRON_MODEL_PATH", "./models/step-zero-nemotron-finetuned.gguf")
|
| 20 |
MINICPM_MODEL_PATH = os.getenv("MINICPM_MODEL_PATH", "./models/minicpm-3-4b.gguf")
|
| 21 |
|
| 22 |
app = FastAPI(title="Step-Zero")
|
modal_train.py
CHANGED
|
@@ -38,7 +38,7 @@ def train_model():
|
|
| 38 |
model_name = "nvidia/Nemotron-Mini-4B-Instruct",
|
| 39 |
max_seq_length = max_seq_length,
|
| 40 |
dtype = None,
|
| 41 |
-
load_in_4bit =
|
| 42 |
)
|
| 43 |
|
| 44 |
model = FastLanguageModel.get_peft_model(
|
|
@@ -106,21 +106,42 @@ def train_model():
|
|
| 106 |
)
|
| 107 |
trainer.train()
|
| 108 |
|
| 109 |
-
print("
|
| 110 |
-
|
|
|
|
|
|
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
|
| 117 |
-
print("
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
"--outfile", "/vol/step-zero-nemotron-finetuned.gguf",
|
| 122 |
"--outtype", "q8_0"
|
| 123 |
-
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
try:
|
| 126 |
vol.commit()
|
|
|
|
| 38 |
model_name = "nvidia/Nemotron-Mini-4B-Instruct",
|
| 39 |
max_seq_length = max_seq_length,
|
| 40 |
dtype = None,
|
| 41 |
+
load_in_4bit = False,
|
| 42 |
)
|
| 43 |
|
| 44 |
model = FastLanguageModel.get_peft_model(
|
|
|
|
| 106 |
)
|
| 107 |
trainer.train()
|
| 108 |
|
| 109 |
+
print("Merging LoRA adapter into base model...")
|
| 110 |
+
import os, subprocess
|
| 111 |
+
hf_dir = "/root/step-zero-nemotron-hf"
|
| 112 |
+
os.makedirs(hf_dir, exist_ok=True)
|
| 113 |
|
| 114 |
+
# Merge the LoRA weights into the base model using PEFT directly
|
| 115 |
+
merged_model = model.merge_and_unload()
|
| 116 |
+
merged_model.save_pretrained(hf_dir)
|
| 117 |
+
tokenizer.save_pretrained(hf_dir)
|
| 118 |
|
| 119 |
+
print(f"HF export contents: {os.listdir(hf_dir)}")
|
| 120 |
+
|
| 121 |
+
print("Cloning llama.cpp for manual GGUF conversion...")
|
| 122 |
+
subprocess.run(["git", "clone", "--depth", "1", "https://github.com/ggerganov/llama.cpp.git", "/root/llama.cpp"], check=True)
|
| 123 |
+
subprocess.run(["pip", "install", "-r", "/root/llama.cpp/requirements.txt"], check=True)
|
| 124 |
+
|
| 125 |
+
print("Converting HF model to GGUF...")
|
| 126 |
+
result = subprocess.run([
|
| 127 |
+
"python3", "/root/llama.cpp/convert_hf_to_gguf.py",
|
| 128 |
+
hf_dir,
|
| 129 |
"--outfile", "/vol/step-zero-nemotron-finetuned.gguf",
|
| 130 |
"--outtype", "q8_0"
|
| 131 |
+
], capture_output=True, text=True)
|
| 132 |
+
print("STDOUT:", result.stdout[-2000:] if result.stdout else "")
|
| 133 |
+
print("STDERR:", result.stderr[-2000:] if result.stderr else "")
|
| 134 |
+
if result.returncode != 0:
|
| 135 |
+
print(f"convert_hf_to_gguf.py failed with code {result.returncode}")
|
| 136 |
+
print("Trying f16 fallback...")
|
| 137 |
+
result2 = subprocess.run([
|
| 138 |
+
"python3", "/root/llama.cpp/convert_hf_to_gguf.py",
|
| 139 |
+
hf_dir,
|
| 140 |
+
"--outfile", "/vol/step-zero-nemotron-finetuned.gguf",
|
| 141 |
+
"--outtype", "f16"
|
| 142 |
+
], capture_output=True, text=True)
|
| 143 |
+
print("STDOUT:", result2.stdout[-2000:] if result2.stdout else "")
|
| 144 |
+
print("STDERR:", result2.stderr[-2000:] if result2.stderr else "")
|
| 145 |
|
| 146 |
try:
|
| 147 |
vol.commit()
|
test_modal_ls.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import modal
|
| 2 |
+
|
| 3 |
+
image = modal.Image.from_registry("ubuntu:22.04")
|
| 4 |
+
|
| 5 |
+
app = modal.App("step-zero-test-ls")
|
| 6 |
+
vol = modal.Volume.from_name("step-zero-volume")
|
| 7 |
+
|
| 8 |
+
@app.function(image=image, volumes={"/vol": vol})
|
| 9 |
+
def check_vol():
|
| 10 |
+
import os
|
| 11 |
+
print("Files in /vol:")
|
| 12 |
+
os.system("ls -la /vol")
|
| 13 |
+
|
| 14 |
+
@app.local_entrypoint()
|
| 15 |
+
def main():
|
| 16 |
+
check_vol.remote()
|