@@ -213,25 +213,31 @@ def run_mega_sweep(binp, quick, prefix="mega_sweep", sched=None):
213213 leg times per-launch with restores, so its reps budget is much smaller)."""
214214 if sched is None :
215215 sched = _QUICK_SCHED if quick else _FULL_SCHED
216- out = [f"# { prefix } { time .strftime ('%c' )} (bench/tune.py)" ]
216+ # INCREMENTAL PERSIST: the file is created up front and appended after
217+ # EVERY section, so a killed run (power cut, reboot, orchestrator bail)
218+ # keeps all completed sections — hours of Orin data died to the old
219+ # write-at-the-end behavior (2026-07-31).
220+ path = BENCH_DIR / f"{ prefix } _{ time .strftime ('%Y%m%d_%H%M' )} .txt"
221+ hdr = [f"# { prefix } { time .strftime ('%c' )} (bench/tune.py)" ]
217222 try :
218223 smi = subprocess .check_output (
219224 ["nvidia-smi" , "--query-gpu=name,clocks.max.sm,clocks.sm,temperature.gpu" ,
220225 "--format=csv,noheader" ], text = True ).strip ()
221- out .append (smi )
226+ hdr .append (smi )
222227 except Exception :
223228 pass
224- out .append ("" )
229+ hdr .append ("" )
230+ path .write_text ("\n " .join (hdr ) + "\n " )
225231 for nprob , reps in sched :
226232 for dt in ("f32" , "f64" ):
227233 print (f" -> { prefix } NPROB={ nprob } reps={ reps } { dt } " )
228- out .append (f"################ NPROB={ nprob } reps={ reps } dtype={ dt } ################" )
229234 r = subprocess .run ([str (binp ), nprob , reps , dt ], text = True ,
230235 capture_output = True , cwd = BENCH_DIR )
231- out .append (r .stdout )
232- out .append ("" )
233- path = BENCH_DIR / f"{ prefix } _{ time .strftime ('%Y%m%d_%H%M' )} .txt"
234- path .write_text ("\n " .join (out ))
236+ with open (path , "a" ) as f :
237+ f .write (f"################ NPROB={ nprob } reps={ reps } dtype={ dt } ################\n " )
238+ f .write (r .stdout )
239+ f .write ("\n " )
240+ print (f" section saved -> { path .name } " )
235241 print (f"==> wrote { path .relative_to (GLASS_DIR )} " )
236242 return path
237243
0 commit comments