@@ -25,7 +25,6 @@ import (
2525 "context"
2626 "crypto/sha256"
2727 "encoding/json"
28- "errors"
2928 "fmt"
3029 "math"
3130 "os"
@@ -37,7 +36,6 @@ import (
3736
3837 "github.com/anthony-chaudhary/fak/internal/appversion"
3938 "github.com/anthony-chaudhary/fak/internal/benchckpt"
40- "github.com/anthony-chaudhary/fak/internal/benchcli"
4139 "github.com/anthony-chaudhary/fak/internal/compute"
4240 "github.com/anthony-chaudhary/fak/internal/ggufload"
4341 "github.com/anthony-chaudhary/fak/internal/mathx"
@@ -47,32 +45,6 @@ import (
4745 "github.com/anthony-chaudhary/fak/internal/nativeperf"
4846)
4947
50- // newGGUFLoadProfiler enables default progress for lean and resident/streamed Q4_K
51- // GGUF loads. Only lean and streamed paths support detailed phase profiles.
52- // Resident Q4_K progress counts collected tensors, before packing and finalization.
53- // Returns nil when neither progress nor a supported detailed profile is requested.
54- func newGGUFLoadProfiler (f * benchFlags ) * ggufload.LoadProfiler {
55- profiledGGUF := * f .gguf != "" && (* f .lean || streamQ4KEnabled (f ))
56- wantLoadProfile := (* f .loadProfile || * f .loadProfileTrace || * f .phaseProfile ) && profiledGGUF
57- progressGGUF := * f .gguf != "" && (* f .lean || * f .q4k )
58- wantProgress := * f .loadProgress && progressGGUF
59- if ! wantLoadProfile && ! wantProgress {
60- return nil
61- }
62- lp := ggufload .NewLoadProfiler ()
63- if wantProgress {
64- lp .Progress = os .Stderr // stream load % to stderr so a large multi-minute load is not silent
65- if * f .q4k && ! streamQ4KEnabled (f ) {
66- fmt .Fprintln (lp .Progress , "fak: resident Q4_K progress counts collected GGUF tensors; Q8 packing and model finalization may continue after 100%" )
67- }
68- }
69- if * f .loadProfileTrace {
70- lp .Trace = os .Stderr
71- lp .Every = * f .loadProfileTraceEvery
72- }
73- return lp
74- }
75-
7648// loadModel selects the load path from the flags (lean GGUF/HF, plain GGUF/HF, or fak
7749// dir format) and returns the model plus its report label. May set *f.quant for -lean.
7850func loadModel (f * benchFlags , lp * ggufload.LoadProfiler ) (* model.Model , string , error ) {
@@ -186,21 +158,6 @@ func currentLoadWorkerControl() loadWorkerControl {
186158 return readLoadWorkerControl (os .LookupEnv , runtime .GOMAXPROCS (0 ))
187159}
188160
189- func loadReportIdentity (f * benchFlags ) map [string ]any {
190- return map [string ]any {
191- "source" : loadSource (* f .hf , * f .gguf , * f .dir , * f .lean , * f .q4k , streamQ4KEnabled (f )),
192- "stream_q4k" : streamQ4KEnabled (f ),
193- "load_worker_control" : currentLoadWorkerControl (),
194- }
195- }
196-
197- func ggufLoadProfileIdentity (f * benchFlags ) (mode , source string ) {
198- if streamQ4KEnabled (f ) {
199- return "gguf-streamed-dense-q4k" , loadSource (* f .hf , * f .gguf , * f .dir , * f .lean , * f .q4k , true )
200- }
201- return "gguf-lean-q8" , * f .gguf
202- }
203-
204161// runLoadOnly emits the load-time + peak-RSS report and is the whole job for -load-only.
205162func runLoadOnly (f * benchFlags , modelName string , loadMS float64 , ggufLoadProfile * ggufload.LoadProfile ) {
206163 peakRSS , rssErr := peakRSSBytes ()
@@ -1413,107 +1370,6 @@ func runFitGate(f *benchFlags) {
14131370 }
14141371}
14151372
1416- // Closed-vocabulary -smoke statuses.
1417- const (
1418- smokeStatusLoaded = "SMOKE_LOADED" // load finished within the deadline
1419- smokeStatusTimeout = "SMOKE_LOAD_TIMEOUT" // load exceeded -smoke-deadline (aborted)
1420- smokeStatusOK = "SMOKE_OK" // forward ran and produced finite logits
1421- smokeStatusForwardFailed = "SMOKE_FORWARD_FAILED" // forward panicked or produced NaN/Inf
1422- )
1423-
1424- // smokeOutcome is the PURE deadline decision for the -smoke load: given whether the load finished
1425- // and how long it took against the deadline, it returns the closed status. Factored out so the
1426- // timeout logic is unit-testable without a real multi-minute load.
1427- func smokeOutcome (done bool , elapsed , deadline time.Duration ) string {
1428- if ! done {
1429- return smokeStatusTimeout
1430- }
1431- if deadline > 0 && elapsed > deadline {
1432- return smokeStatusTimeout
1433- }
1434- return smokeStatusLoaded
1435- }
1436-
1437- // loadModelMaybeDeadline bounds smoke loads. Q4_K loaders cooperate with cancellation and
1438- // return only after their workers and checkpoint reader are drained; other loaders retain the
1439- // historical race-and-exit behavior.
1440- func loadModelMaybeDeadline (f * benchFlags , lp * ggufload.LoadProfiler ) (* model.Model , string , error ) {
1441- if ! * f .smoke || * f .smokeDeadline <= 0 {
1442- return loadModel (f , lp )
1443- }
1444- if * f .q4k {
1445- start := time .Now ()
1446- ctx , cancel := context .WithTimeout (context .Background (), * f .smokeDeadline )
1447- defer cancel ()
1448- m , name , err := loadModelContext (ctx , f , lp )
1449- elapsed := time .Since (start )
1450- if errors .Is (err , context .DeadlineExceeded ) {
1451- smokeTimeoutReporter (f , elapsed )
1452- return nil , "" , nil // unreachable in production: reportSmokeTimeout exits
1453- }
1454- return m , name , err
1455- }
1456- type loadRes struct {
1457- m * model.Model
1458- name string
1459- err error
1460- }
1461- ch := make (chan loadRes , 1 )
1462- start := time .Now ()
1463- go func () {
1464- m , name , err := loadModel (f , lp )
1465- ch <- loadRes {m , name , err }
1466- }()
1467- select {
1468- case r := <- ch :
1469- // Won the race within the deadline window.
1470- return r .m , r .name , r .err
1471- case <- time .After (* f .smokeDeadline ):
1472- // The deadline fired first. smokeOutcome (the pure, tested classifier) names this
1473- // SMOKE_LOAD_TIMEOUT; report it and exit. The load goroutine is abandoned (the process
1474- // exits), so a load that would have run for an hour is bounded by -smoke-deadline.
1475- elapsed := time .Since (start )
1476- if smokeOutcome (false , elapsed , * f .smokeDeadline ) == smokeStatusTimeout {
1477- reportSmokeTimeout (f , elapsed )
1478- }
1479- return nil , "" , nil // unreachable: reportSmokeTimeout exits
1480- }
1481- }
1482-
1483- // reportSmokeTimeout emits the SMOKE_LOAD_TIMEOUT artifact (with the last progress visible on
1484- // stderr from the load profiler) and exits non-zero.
1485- var smokeTimeoutReporter = reportSmokeTimeout
1486-
1487- func reportSmokeTimeout (f * benchFlags , elapsed time.Duration ) {
1488- fmt .Fprintf (os .Stderr , "fak: -smoke load exceeded -smoke-deadline %s (%.0fs elapsed) — aborting\n " , * f .smokeDeadline , elapsed .Seconds ())
1489- report := map [string ]any {
1490- "app_version" : appversion .Current (),
1491- "engine" : "fak modelbench smoke" ,
1492- "smoke_status" : smokeStatusTimeout ,
1493- "elapsed_seconds" : elapsed .Seconds (),
1494- "deadline" : f .smokeDeadline .String (),
1495- }
1496- for key , value := range loadReportIdentity (f ) {
1497- report [key ] = value
1498- }
1499- writeReport (f , report )
1500- os .Exit (1 )
1501- }
1502-
1503- // allFinite reports whether every logit is a finite number — the cheapest proof a forward pass
1504- // produced real output rather than NaN/Inf (a broken kernel or a config mismatch).
1505- func allFinite (logits []float32 ) bool {
1506- if len (logits ) == 0 {
1507- return false
1508- }
1509- for _ , v := range logits {
1510- if math .IsNaN (float64 (v )) || math .IsInf (float64 (v ), 0 ) {
1511- return false
1512- }
1513- }
1514- return true
1515- }
1516-
15171373// runSmoke is the -smoke entry after a successful (deadline-bounded) load: it decodes multiple tokens
15181374// (controlled by -smoke-decode-steps, defaulting to 16) and asserts the logits are finite, emitting SMOKE_OK
15191375// or SMOKE_FORWARD_FAILED and exiting. This proves the forward and autoregressive decode loop run before committing
@@ -1589,25 +1445,6 @@ func runSmoke(f *benchFlags, m *model.Model, modelName string, loadMS float64, v
15891445 }
15901446}
15911447
1592- func loadSource (hf , gguf , dir string , lean , q4k , streamQ4K bool ) string {
1593- if gguf != "" {
1594- if q4k {
1595- if streamQ4K {
1596- return gguf + " (streamed dense Q4_K)"
1597- }
1598- return gguf + " (resident Q4_K)"
1599- }
1600- return gguf
1601- }
1602- if hf == "" {
1603- return dir
1604- }
1605- if lean {
1606- return filepath .Join (hf , "model.safetensors" ) + " (quantize-at-load)"
1607- }
1608- return filepath .Join (hf , "model.safetensors" )
1609- }
1610-
16111448func parseTokenSize (s string ) (int , error ) {
16121449 s = strings .TrimSpace (s )
16131450 if s == "" {
@@ -1650,33 +1487,3 @@ func parsePositiveInts(csv string) ([]int, error) {
16501487 }
16511488 return out , nil
16521489}
1653-
1654- func writeReport (f * benchFlags , report map [string ]any ) {
1655- b , _ := benchcli .MarshalReport (report )
1656- if * f .out != "" {
1657- if err := os .WriteFile (* f .out , b , 0o644 ); err != nil {
1658- fmt .Fprintln (os .Stderr , "write:" , err )
1659- f .exit (1 )
1660- }
1661- fmt .Fprintln (os .Stderr , "wrote" , * f .out )
1662- return
1663- }
1664- fmt .Println (string (b ))
1665- }
1666-
1667- func phaseTable (p * model.PhaseProfile ) string {
1668- if p == nil {
1669- return ""
1670- }
1671- n := 8
1672- if len (p .Phases ) < n {
1673- n = len (p .Phases )
1674- }
1675- s := fmt .Sprintf ("[fak phase] %s tokens=%d steps=%d total=%.1f ms bottleneck=%s\n " ,
1676- p .Mode , p .Tokens , p .Steps , p .TotalMS , p .Bottleneck )
1677- for i := 0 ; i < n ; i ++ {
1678- ph := p .Phases [i ]
1679- s += fmt .Sprintf (" %-28s %7.1f ms %5.1f%% calls=%d\n " , ph .Phase , ph .MS , ph .TimePct , ph .Calls )
1680- }
1681- return s
1682- }
0 commit comments