tc043 commited on
Commit
66b1bc1
·
1 Parent(s): 3c194fb

refactor: remove post-processing constraints in app.py and update model training to export HF merged format via llama.cpp conversion

Browse files
Files changed (2) hide show
  1. app.py +2 -8
  2. modal_train.py +13 -14
app.py CHANGED
@@ -64,6 +64,8 @@ async def run_blocking(func, *args, **kwargs):
64
  async def generate_atomic_task(goal: str, previous_failures: int, history: list = None) -> str:
65
  if history is None:
66
  history = []
 
 
67
  if MOCK_MODE:
68
  await asyncio.sleep(1) # Simulate inference latency
69
  demo_steps = [
@@ -108,14 +110,6 @@ async def generate_atomic_task(goal: str, previous_failures: int, history: list
108
 
109
  content = content.strip('"\' ,.-1234567890)')
110
 
111
- # POST-PROCESSING: 4B models often ignore constraints and try to output lists.
112
- # Force it to be atomic by taking the first item before a comma or " and ".
113
- if "," in content:
114
- content = content.split(",")[0].strip()
115
- if " and " in content.lower():
116
- content = content.split(" and ")[0].strip()
117
-
118
- content = content.strip('"\' ,.-1234567890)')
119
 
120
  print(f"NEMOTRON RAW OUT: {content}", flush=True)
121
  return content or "Focus on the screen."
 
64
  async def generate_atomic_task(goal: str, previous_failures: int, history: list = None) -> str:
65
  if history is None:
66
  history = []
67
+ history_str = "\n".join([f"- {t}" for t in history]) if history else "None"
68
+
69
  if MOCK_MODE:
70
  await asyncio.sleep(1) # Simulate inference latency
71
  demo_steps = [
 
110
 
111
  content = content.strip('"\' ,.-1234567890)')
112
 
 
 
 
 
 
 
 
 
113
 
114
  print(f"NEMOTRON RAW OUT: {content}", flush=True)
115
  return content or "Focus on the screen."
modal_train.py CHANGED
@@ -106,27 +106,26 @@ def train_model():
106
  )
107
  trainer.train()
108
 
109
- print("Exporting to GGUF...")
110
- import os
111
- os.makedirs("export_dir", exist_ok=True)
112
- model.save_pretrained_gguf("export_dir", tokenizer, quantization_method = "q4_k_m")
113
 
114
- import shutil
115
- import glob
116
- import os
 
117
 
118
- print("Files in export_dir:", os.listdir("export_dir"))
 
 
 
 
 
 
119
 
120
- gguf_files = glob.glob("export_dir/*.gguf") + glob.glob("*.gguf")
121
- for file in gguf_files:
122
- print(f"Copying {file} to /vol...")
123
- shutil.copy(file, "/vol/step-zero-nemotron.gguf")
124
-
125
  try:
126
  vol.commit()
127
  except Exception as e:
128
  print("vol.commit() skipped:", e)
129
-
130
  print("Training complete. GGUF artifact generated in /vol.")
131
 
132
  @app.local_entrypoint()
 
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()
127
  except Exception as e:
128
  print("vol.commit() skipped:", e)
 
129
  print("Training complete. GGUF artifact generated in /vol.")
130
 
131
  @app.local_entrypoint()