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
Files changed (3) hide show
  1. app.py +1 -1
  2. modal_train.py +33 -12
  3. 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/nemotron-mini-4b.gguf")
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 = True,
42
  )
43
 
44
  model = FastLanguageModel.get_peft_model(
@@ -106,21 +106,42 @@ def train_model():
106
  )
107
  trainer.train()
108
 
109
- print("Exporting HuggingFace 16-bit Model...")
110
- model.save_pretrained_merged("step-zero-nemotron-hf", tokenizer, save_method="merged_16bit")
 
 
111
 
112
- import subprocess
113
- print("Cloning llama.cpp to run conversion manually...")
114
- subprocess.run(["git", "clone", "https://github.com/ggerganov/llama.cpp.git"])
115
- subprocess.run(["pip", "install", "-r", "llama.cpp/requirements.txt"])
116
 
117
- print("Converting to GGUF using llama.cpp...")
118
- subprocess.run([
119
- "python3", "llama.cpp/convert_hf_to_gguf.py",
120
- "step-zero-nemotron-hf",
 
 
 
 
 
 
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()