diff --git a/docs/MAC.md b/docs/MAC.md index 100c0d90e5..e7342ade9e 100644 --- a/docs/MAC.md +++ b/docs/MAC.md @@ -130,8 +130,9 @@ The ready-made Mac engine is in the app and in the Terminal's engine component, ## Defaults and options The config uses the Mac defaults: `--spec 2` with MTP (best on mixed text; an explicit `--spec N` in the config's `args` is kept), -or `--spec 3 --spec-min-p 0.5` for the IQ3_S and Q2_0 sets (M5 Max, 5 interleaved pairs, same tokens, over `--spec 2`: IQ3_S story -0.9%, -code +2.5%, JSON +16.7%, agent turn +4.9%; Q2_0 story +0.4%, code +11.5%, JSON +6.3%, agent turn +1.9%; the other sets are not measured), +or `--spec 3 --spec-min-p 0.5` for the IQ3_S, Q2_0 and Coder sets (M5 Max, 5 interleaved pairs, same tokens, over `--spec 2`: IQ3_S story -0.9%, +code +2.5%, JSON +16.7%, agent turn +4.9%; Q2_0 story +0.4%, code +11.5%, JSON +6.3%, agent turn +1.9%; Coder story -2.5%, code +7.1%, +JSON +9.3%, agent turn +12.5%; the other sets are not measured), and the Q8_0 hyper-connection read. `STRATA_HC_Q8=0` in the config's `env` gives the exact BF16 read. The Mac engine is deterministic: two runs give identical numbers. @@ -263,7 +264,7 @@ For testing. All are off unless set; the defaults are described above. | `STRATA_METAL_WIRE_ARENA=0` | Streaming, 64 GB or more: leave the filled arena pageable (default: wired) | | `STRATA_METAL_IGNORE_REPACK=1` | Start although a model repack or setup's preparation is running (the engine refuses by default) | | `STRATA_METAL_KEEP_HOST_WEIGHTS=1` | Streaming: keep the host code's own copies of the weights (2 to 3 GB) | -| `STRATA_METAL_F16=1` | Decode windows of a resident model: the GEMVs of Q2_0, Q3_K-Q6_K and IQ4_XS and the Q2_0 routed experts in fp16. Measured on an M1 Max only: a 2-token window's GPU time 56-60 -> 40-41 ms, mean KL 0.009 against fp32 | +| `STRATA_METAL_F16=1` / `=0` | Decode windows of a resident model: the GEMVs of Q2_0, Q3_K-Q6_K and IQ4_XS and the Q2_0 routed experts in fp16. On in the config setup writes for a resident IQ3_S or Q2_0 pack (M5 Max: decode +9 to +15%, top-1 96-97% and mean KL 0.009-0.016 against fp32; the 61-task quality suite passes the same tasks as with it off); `=0` in the config's `env` turns it off. Other sets: off unless set. M1 Max: a 2-token window's GPU time 56-60 -> 40-41 ms, mean KL 0.009 against fp32 | | `STRATA_METAL_TRACE=1`, `STRATA_METAL_PROFILE=1`, `STRATA_METAL_KPROF=T` | Per-window traces, a time breakdown, per-kernel GPU times | ## How it works diff --git a/metal/setup_mac.py b/metal/setup_mac.py index b17cdc1087..0eb49c2646 100644 --- a/metal/setup_mac.py +++ b/metal/setup_mac.py @@ -544,7 +544,8 @@ def main(argv=None) -> int: S.step(7, "writing the start script") port = a.port or 8080 cfg = mac_config(exe, engine_args(pack, shards, rt, ctx, stream, info["ram_gb"], model), pack, f"{fam['name']}-{model.lower()}", tag, port) - cfg["env"] = {"STRATA_METAL_STREAM": "1" if stream else "0"} # the engine follows setup's measured choice + cfg["env"] = {"STRATA_METAL_STREAM": "1" if stream else "0", # the engine follows setup's measured choice + **_fit.engine_env(model, stream)} # STRATA_METAL_F16=1 for a resident IQ3_S / Q2_0 (mac_fit.F16_MODELS) if vision == "yes": cfg["args"] += ["--vision"] cfg["vision"] = {"exe": str(vexe), "mmproj": str(mmproj), "model": str(files[0]), "gpu": vision_gpu, diff --git a/strata_control/mac_fit.py b/strata_control/mac_fit.py index d92fd91ae2..6b9699ba27 100644 --- a/strata_control/mac_fit.py +++ b/strata_control/mac_fit.py @@ -47,8 +47,23 @@ STREAM_SPEC = 3 # A resident IQ3_S or Q2_0 pack runs a 3-token window with --spec-min-p 0.5 (the draft layer extends the window only when sure): # M5 Max, MTP, 5 interleaved pairs, identical tokens, over --spec 2: IQ3_S story / code / JSON / agent turn -0.9% / +2.5% / +16.7% / # +4.9%; Q2_0 +0.4% / +11.5% / +6.3% / +1.9% (phaseA-tests/mac-q/RESULTS.md sections 14 and 15). Other sets are not measured: --spec 2. -SPEC3_MODELS = ("IQ3_S", "Q2_0") +# The expert-pruned Coder (256 experts, IQ1_M) story / code / JSON / agent turn -2.5% / +7.1% / +9.3% / +12.5%, 5 pairs, identical tokens +# (section 31.1 of the same file; it has no Mac setup entry yet, the name is what a config for it would pass). +SPEC3_MODELS = ("IQ3_S", "Q2_0", "CODER") SPEC3_MIN_P = "0.5" +# STRATA_METAL_F16=1 (the fp16 decode windows, PR 4807) is the default of a resident IQ3_S or Q2_0 pack. M5 Max: decode +9 to +15% (Q2_0) +# and +9 to +12% (IQ3_S); top-1 agreement against the fp32 path 97.1% (Q2_0) / 96.2% (IQ3_S), mean KL 0.009 / 0.016 (sections 20, 22); +# the 61-task quality suite (section 30): same tasks passed with it on and off, no family drop, no new hallucination flag, 0 pass/fail +# changes between two runs of the same arm. The owner's rule was an option unless it passes that suite. STRATA_METAL_F16=0 in the config's +# env turns it off. Other sets (and a streaming pack, where the windows are not fp16) are not set. +F16_MODELS = ("IQ3_S", "Q2_0") + + +def engine_env(model: str, stream: bool) -> dict[str, str]: + """The engine variables a Mac config carries besides STRATA_METAL_STREAM: STRATA_METAL_F16=1 for a resident IQ3_S or Q2_0 pack.""" + if not stream and (model or "").upper() in F16_MODELS: + return {"STRATA_METAL_F16": "1"} + return {} def spec_args(model: str, stream: bool, mtp: bool) -> list[str]: diff --git a/tools/test_setup_mac.py b/tools/test_setup_mac.py index f905952bfe..9e549bcdad 100644 --- a/tools/test_setup_mac.py +++ b/tools/test_setup_mac.py @@ -129,6 +129,9 @@ class Config(unittest.TestCase): q2 = M.engine_args(Path("/p/packs/q2_0"), shards, Path("/d/mtp/rt"), 32768, model="Q2_0") self.assertEqual(q2[q2.index("--spec") + 1], "3") self.assertEqual(q2[q2.index("--spec-min-p") + 1], "0.5") + coder = M.engine_args(Path("/p/packs/coder"), shards, Path("/d/mtp/rt"), 32768, model="Coder") # 5 pairs: story -2.5%, code +7.1%, JSON +9.3%, agent +12.5% + self.assertEqual(coder[coder.index("--spec") + 1], "3") + self.assertEqual(coder[coder.index("--spec-min-p") + 1], "0.5") other = M.engine_args(Path("/p/packs/iq3_xxs"), shards, Path("/d/mtp/rt"), 32768, model="IQ3_XXS") # not measured: the old default self.assertEqual(other[other.index("--spec") + 1], "2") self.assertNotIn("--spec-min-p", other) @@ -143,6 +146,16 @@ class Config(unittest.TestCase): self.assertEqual(big[big.index("--spec") + 1], "3") self.assertNotIn("--spec-min-p", big) + def test_fp16_decode_is_set_for_a_resident_iq3_s_or_q2_0_only(self): + # the 61-task suite (phaseA-tests/mac-q/RESULTS.md section 30) passed the same tasks with STRATA_METAL_F16=1 as with =0 + self.assertEqual(M._fit.engine_env("IQ3_S", False), {"STRATA_METAL_F16": "1"}) + self.assertEqual(M._fit.engine_env("Q2_0", False), {"STRATA_METAL_F16": "1"}) + self.assertEqual(M._fit.engine_env("iq3_s", False), {"STRATA_METAL_F16": "1"}) + self.assertEqual(M._fit.engine_env("IQ3_S", True), {}) # streaming: the windows are not fp16 + self.assertEqual(M._fit.engine_env("UD-Q4_K_XL", False), {}) # not measured + self.assertEqual(M._fit.engine_env("IQ3_XXS", False), {}) + self.assertEqual(M._fit.engine_env("", False), {}) + def test_config_is_a_model_config_with_the_metal_backend(self): cfg = M.mac_config(Path("/r/build-metal/strata"), ["--pack", "x"], Path("/p"), "qwen3.8-flash-next-q2_0", "Q2_0", 8080)