From 6ec4d68ab2c126f58be2300a301ae31c78934629 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sun, 8 Nov 2026 20:04:02 +0100 Subject: [PATCH] DFlash2 per-device defaults (11-08 CONF-SWEEP): Strix Halo window 5 -> 8; Blackwell cc 12.0 with >= 48 GB conf 0.35 -> 0.55 and window 6 -> 8 Strix Halo (gfx1151): engine cap 5 -> 8 and the Terminal writes --spec 8; conf stays 0.35. Measured (5 interleaved pairs, 5/5 faster): UD-Q4_K_XL +5.3%, UD-IQ4_XS-v31 +2.1%. UD-Q4_K_XL greedy output differs from the old width's (deterministic run to run); v31 is identical. Blackwell sm_120 (cc 12.0) with at least 48 GB: cap 6 -> 8, --draft-conf 0.55 (RTX PRO 5000 72 GB, IQ3_S +2.4%, 5/5 pairs, output identical). The DGX Spark (cc 12.1) and consumer cards under 48 GB keep conf 0.35 and cap 6. dflash2_auto_cap now takes the compute minor and the card's memory; drafting.py writes --spec 8 only on these two classes (window_for), so no other card's effective window changes. draft_cap_test, tests/terminal drafting tests (new test_drafting_card_window.py) and the snapshot goldens (nv_resident and strix_halo_win only) are updated. --- include/strata/core/draft_cap.hpp | 23 ++-- src/core/draft_cap_test.cpp | 23 +++- src/program/generate.cpp | 15 ++- strata_control/drafting.py | 31 ++++- tests/snapshot/golden/nv_resident/iq3_s.json | 18 +-- .../golden/nv_resident/ud_iq4_xs_v31.json | 18 +-- .../golden/nv_resident/ud_q4_k_xl.json | 18 +-- .../snapshot/golden/strix_halo_win/iq3_s.json | 6 +- .../golden/strix_halo_win/ud_iq4_xs_v31.json | 6 +- .../golden/strix_halo_win/ud_q4_k_xl.json | 6 +- tests/terminal/test_drafting.py | 2 +- tests/terminal/test_drafting_card_window.py | 119 ++++++++++++++++++ tests/terminal/test_drafting_hardware.py | 4 +- .../terminal/test_drafting_streaming_class.py | 2 +- tests/terminal/test_drafting_tuned.py | 4 +- 15 files changed, 236 insertions(+), 59 deletions(-) create mode 100644 tests/terminal/test_drafting_card_window.py diff --git a/include/strata/core/draft_cap.hpp b/include/strata/core/draft_cap.hpp index 42d2038d64..f1bef9fe0b 100644 --- a/include/strata/core/draft_cap.hpp +++ b/include/strata/core/draft_cap.hpp @@ -1,17 +1,26 @@ -// include/strata/core/draft_cap.hpp - the widest verify window --draft dflash2 uses on each card class (measured A/Bs, notes-dflash2-p1.md; recommend, never force). +// include/strata/core/draft_cap.hpp - the widest verify window --draft dflash2 uses on each card class (measured A/Bs, notes-dflash2-p1.md, RESULTS-CONF.md; recommend, never force). #pragma once #include namespace strata::core { -/// 0 = no cap (the --spec given stays). `uma`: Strix Halo / iGPU (gfx1151); `cc_major`: the CUDA compute capability's major (0 on HIP). -/// - Strix Halo / UMA: 5 (agent-safe; 6 ties on agent prompts) -/// - Blackwell (sm_120, cc 12): 6 (+1.9% at 6 on an RTX PRO 5000, 8 was worse) +/// 48 GB of video memory, counted the way cards are sold (a 48 GB card reports about 47.5 GiB). The large-Blackwell class below starts here. +inline constexpr size_t kDflash2BigCardBytes = (size_t) 48'000'000'000ull; + +/// The large-VRAM Blackwell class the 11-08 sweep measured (RTX PRO 5000 72 GB, sm_120 = cc 12.0): cc 12.0 exactly (not the DGX Spark, cc 12.1) and at least 48 GB. +/// A consumer RTX 50 card with less memory was not measured and keeps the older values. +inline bool dflash2_big_blackwell(int cc_major, int cc_minor, size_t vram_bytes) { return cc_major == 12 && cc_minor == 0 && vram_bytes >= kDflash2BigCardBytes; } + +/// 0 = no cap (the --spec given stays). `uma`: Strix Halo / iGPU (gfx1151); `cc_major` / `cc_minor`: the CUDA compute capability (0 on HIP); `vram_bytes`: the card's memory (CUDA). +/// Measured 11-08 (RESULTS-CONF.md; 36 requests, 300 greedy tokens, 5 interleaved pairs against the old values, all pairs faster): +/// - Strix Halo / UMA: 8, conf 0.35. UD-Q4_K_XL +5.3% (5 -> 8; 7: +5.1%), UD-IQ4_XS-v31 +2.1%. Greedy output on UD-Q4_K_XL differs from the old width's (deterministic run to run), v31's is identical +/// - Blackwell cc 12.0 with >= 48 GB (RTX PRO 5000 72 GB): 8 with conf 0.55: IQ3_S +2.4% (6 -> 8 and 0.35 -> 0.55; conf alone +1.1%, cap alone +0.5%), output identical +/// - other Blackwell (cc 12.1 DGX Spark, a card under 48 GB): 6 (nothing beat 0.35 / 6 on the Spark's IQ3_S; the small cards were not measured) /// - everything else: unmeasured, --spec as given -inline int dflash2_auto_cap(bool uma, int cc_major) { - if (uma) return 5; - if (cc_major == 12) return 6; +inline int dflash2_auto_cap(bool uma, int cc_major, int cc_minor, size_t vram_bytes) { + if (uma) return 8; + if (cc_major == 12) return dflash2_big_blackwell(cc_major, cc_minor, vram_bytes) ? 8 : 6; return 0; } diff --git a/src/core/draft_cap_test.cpp b/src/core/draft_cap_test.cpp index 7137a9239a..9529fdea21 100644 --- a/src/core/draft_cap_test.cpp +++ b/src/core/draft_cap_test.cpp @@ -8,11 +8,26 @@ using namespace strata::core; static int fails = 0; #define CHECK(c) do { if (!(c)) { std::fprintf(stderr, "FAIL %s:%d %s\n", __FILE__, __LINE__, #c); ++fails; } } while (0) +static constexpr size_t GiB = (size_t) 1 << 30; + int main() { - CHECK(dflash2_auto_cap(true, 0) == 5); // Strix Halo - CHECK(dflash2_auto_cap(false, 12) == 6); // Blackwell (sm_120) - CHECK(dflash2_auto_cap(false, 8) == 0); // Ampere / Ada: --spec as given - CHECK(dflash2_auto_cap(false, 0) == 0); // another AMD card + CHECK(dflash2_auto_cap(true, 0, 0, 0) == 8); // Strix Halo (gfx1151) + CHECK(dflash2_auto_cap(false, 12, 0, 72 * GiB) == 8); // Blackwell cc 12.0, RTX PRO 5000 72 GB + CHECK(dflash2_auto_cap(false, 12, 0, 96 * GiB) == 8); // Blackwell cc 12.0, 96 GB + CHECK(dflash2_auto_cap(false, 12, 0, 48000000000ull) == 8);// exactly 48 GB + CHECK(dflash2_auto_cap(false, 12, 0, 48000000000ull - 1) == 6); + CHECK(dflash2_auto_cap(false, 12, 0, 51033931776ull) == 8);// a 48 GB card reports about 47.5 GiB + CHECK(dflash2_auto_cap(false, 12, 0, 32 * GiB) == 6); // RTX 5090: cc 12.0 under 48 GB keeps 6 + CHECK(dflash2_auto_cap(false, 12, 0, 12 * GiB) == 6); // RTX 5070 + CHECK(dflash2_auto_cap(false, 12, 0, 0) == 6); // memory unknown keeps 6 + CHECK(dflash2_auto_cap(false, 12, 1, 128 * GiB) == 6); // DGX Spark (cc 12.1): unchanged whatever the memory it reports + CHECK(dflash2_auto_cap(false, 12, 1, 24 * GiB) == 6); + CHECK(dflash2_auto_cap(false, 8, 0, 80 * GiB) == 0); // Ampere / Hopper: --spec as given + CHECK(dflash2_auto_cap(false, 8, 9, 48 * GiB) == 0); // Ada + CHECK(dflash2_auto_cap(false, 0, 0, 0) == 0); // another AMD card + CHECK(dflash2_big_blackwell(12, 0, 72 * GiB)); + CHECK(!dflash2_big_blackwell(12, 1, 72 * GiB)); + CHECK(!dflash2_big_blackwell(9, 0, 72 * GiB)); CHECK(dflash2_small_nvidia(true, (size_t) 12 << 30)); CHECK(!dflash2_small_nvidia(true, (size_t) 16 << 30)); CHECK(!dflash2_small_nvidia(false, (size_t) 8 << 30)); diff --git a/src/program/generate.cpp b/src/program/generate.cpp index b0d053b157..bb6e338112 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -1174,7 +1174,7 @@ void usage() { " --draft-conf P with --draft dflash2: end the window where the product of the selector's probabilities falls below P (default 0 = --spec-min-p)\n" " --draft auto (serve) both drafters stay current; a request picks one: draft=mtp|dflash2, else --draft-rule df2|mtp|learn;\n" " MTP requests use --draft-mtp-spec N (default 4) and --draft-mtp-min-p P\n" - " --draft-cap N the widest verify window with --draft dflash2 (default by card: 5 on Strix Halo / iGPU, --spec as given elsewhere)\n" + " --draft-cap N the widest verify window with --draft dflash2 (default by card: 8 on Strix Halo / iGPU and on Blackwell cc 12.0 with 48 GB or more, 6 on other Blackwell, --spec as given elsewhere)\n" " --control-vector-scaled FILE:SCALE[,...] a control vector GGUF on the residual stream (llama.cpp's\n" " format; --control-vector FILE = scale 1). --serve: requests switch it (cvec=0|1)\n" " --control-vector-layer-range A B the layers it follows (inclusive; default 1 .. the last)\n" @@ -7189,8 +7189,8 @@ int main(int argc, char** argv) { if (why == nullptr) { if (df2.load(o.draft_model, multi_gpu && last_st != nullptr && !df2_first ? last_st->dev : 0, err)) { use_df2 = true; - // Per card class, from the measured A/Bs (notes-dflash2-p1.md): on Strix Halo a window of 5 is the agent-safe pick (cap 6 ties on - // agent prompts); a 12 GB NVIDIA card is slower with DFlash2 than with the MTP at every cap but code, which only the user can know. + // Per card class, from the measured A/Bs (notes-dflash2-p1.md, RESULTS-CONF.md 11-08; the numbers are in core/draft_cap.hpp): Strix Halo 8, Blackwell cc 12.0 with + // at least 48 GB 8, other Blackwell 6; a 12 GB NVIDIA card is slower with DFlash2 than with the MTP at every cap but code, which only the user can know. // Recommend, never force: the window is capped for the card unless --draft-cap says otherwise, and a small NVIDIA card gets one plain line. cudaDeviceProp dp{}; if (cudaGetDeviceProperties(&dp, df2.device()) == cudaSuccess) { @@ -7204,7 +7204,14 @@ int main(int argc, char** argv) { #else const int cc_major = dp.major; #endif - const int cap = o.draft_cap > 0 ? o.draft_cap : strata::core::dflash2_auto_cap(uma, cc_major); +#if defined(STRATA_USE_HIP) + const int cc_minor = 0; + const size_t card_bytes = 0; +#else + const int cc_minor = dp.minor; + const size_t card_bytes = dp.totalGlobalMem; +#endif + const int cap = o.draft_cap > 0 ? o.draft_cap : strata::core::dflash2_auto_cap(uma, cc_major, cc_minor, card_bytes); if (cap > 0 && o.spec > cap) { std::fprintf(stderr, "strata generate: --draft dflash2: windows capped at %d tokens (%s; --draft-cap N changes it)\n", cap, o.draft_cap > 0 ? "as asked" : "the width measured best on this card"); diff --git a/strata_control/drafting.py b/strata_control/drafting.py index e675cc52ff..014ec5eee4 100644 --- a/strata_control/drafting.py +++ b/strata_control/drafting.py @@ -8,7 +8,7 @@ The choice is the person's, and it is saved in the model's run config as ``"draf strata_control/draft_layer.py), so a setup run that rewrites the engine arguments cannot undo it. An older config that names both drafters (``--mtp`` and ``--draft dflash2``) starts with the one chosen. - dflash2 ``--draft dflash2 --draft-model --draft-fallback none --mtp-draft-vocab --spec 6 --draft-conf 0.35`` and no ``--mtp``: the DFlash2 + dflash2 ``--draft dflash2 --draft-model --draft-fallback none --mtp-draft-vocab --spec 6 --draft-conf 0.35`` (``--spec 8`` on Strix Halo and on Blackwell cc 12.0 with >= 48 GB, whose conf is 0.55: window_for / big_blackwell) and no ``--mtp``: the DFlash2 block drafter (incoai/Qwen3.8-Flash-Next-DFlash2, Q4_0 pack) for Qwen3.8-Flash-Next, Gyro and Unsloth's quantizations, with the window and confidence that measured best (RESULTS-DRAFT.md section 4); a ``--spec`` or ``--draft-conf`` the person set by hand (``user_args``) stays mtp the model's own draft layer (``--mtp ``) and none of the DFlash2 flags @@ -252,6 +252,7 @@ LEGACY_PACK_NAME = "qwen3.8-flash-next-dflash2.q8.pack" # what Strata 0.2.9 VRAM_GB = DRAFTER_GB["dflash2"] # graphics memory with the MTP layer not loaded and the bf16-selector pack: 890 MiB (RESULTS-DF2MEM.md); vram_gb() has the true figure for this computer FOLDER = "dflash2" # under the model data folder, next to ``mtp`` SPEC_WINDOW = 6 # --spec with DFlash2: the widest window of drafted words per round (measured best on Blackwell; the engine caps it per card) +WIDE_WINDOW = 8 # --spec on the two card classes whose engine cap (include/strata/core/draft_cap.hpp dflash2_auto_cap) is 8: Strix Halo and Blackwell cc 12.0 with >= 48 GB (window_for). The engine only ever lowers --spec to its cap, so every other card keeps SPEC_WINDOW MTP_WINDOW = 4 # the MTP's usual --spec: the window it runs when DFlash2 falls back to it, unless the config names another DRAFT_CONF = 0.35 # --draft-conf with DFlash2: the window ends where the chance that every draft so far holds falls below this (the card holds most experts) @@ -275,6 +276,11 @@ MAX_SLOTS = 24576 # every (layer, expert) pair of Qwen3.8-Flash-Next # DFlash2 --spec 6 against MTP --spec 2, 3 interleaved rounds x 2 reps, six request kinds (phaseA-tests/round0215/RESULTS-MAC-OUT.md): conf 0.35 / 0.5 / 0.6 = +10.0 / +14.3 / +12.4% over all # six kinds (0.5 faster than MTP on every kind in 3 of 3 rounds; the slot rule would have written 0.8 for the Mac's --expert-cache 64). BACKEND_CONF = {"sycl": 0.6, "metal": 0.5} +# Large-VRAM Blackwell (cc 12.0 = sm_120, at least 48 GB: l620's RTX PRO 5000 72 GB; NOT the DGX Spark, sm_121, and not a consumer card under 48 GB, which were not measured): conf 0.55 and a window +# of 8 (the engine cap is 8 there too). 11-08 sweep (phaseA-tests/df2r2/RESULTS-CONF.md), IQ3_S, 36 requests, 300 greedy tokens, 5 interleaved pairs against conf 0.35 / window 6: +2.4%, 5 of 5 pairs +# faster, output identical (conf 0.55 alone +1.1%, window 8 alone +0.5%). Only where every expert is resident (the first CONF_STEPS step), the case that was measured. +BIG_BLACKWELL_CONF = 0.55 +BIG_CARD_BYTES = 48_000_000_000 # "48 GB" the way cards are sold (a 48 GB card reports about 47.5 GiB); the engine's kDflash2BigCardBytes is the same number @dataclass(frozen=True) @@ -749,6 +755,22 @@ def engine_flags(pack: str | Path, vocab: str | Path | None = None, form: str | return ("--draft", "dflash2", "--draft-model", str(pack), "--draft-fallback", "none", *where, "--spec", str(SPEC_WINDOW), "--draft-conf", f"{DRAFT_CONF:g}") +def big_blackwell(backend: str | None, archs: Any = None, vram_mib: float | None = None, slots: int | float | None = None) -> bool: + """Is this start on the large-VRAM Blackwell class (BIG_BLACKWELL_CONF): CUDA, the first card's architecture sm_120 (cc 12.0; the Spark is sm_121), the one card's memory ``vram_mib`` + at least BIG_CARD_BYTES (None = several cards or unknown: no), and ``slots`` in the all-resident step (None counts as unknown: no)? Mirrors the engine's dflash2_big_blackwell.""" + if str(backend or "").strip().lower() != "cuda" or first_arch(archs) != "sm_120" or not vram_mib or slots is None: + return False + return vram_mib * 1048576 >= BIG_CARD_BYTES and slots >= CONF_STEPS[0][0] + + +def window_for(backend: str | None, archs: Any = None, vram_mib: float | None = None, slots: int | float | None = None) -> int: + """The ``--spec`` of a DFlash2 start: WIDE_WINDOW (8) on Strix Halo (HIP gfx1151, engine cap 8) and on the large-VRAM Blackwell class (big_blackwell), SPEC_WINDOW (6) everywhere else, so no other + card's effective window changes (the engine caps 6 on the Spark and the smaller Blackwell cards, and does not cap the rest).""" + if str(backend or "").strip().lower() == "hip" and first_arch(archs) == "gfx1151": + return WIDE_WINDOW + return WIDE_WINDOW if big_blackwell(backend, archs, vram_mib, slots) else SPEC_WINDOW + + def conf_for(backend: str | None, slots: int | float | None) -> float: """The ``--draft-conf`` for this engine family and a card that holds ``slots`` experts: the backend's own value (BACKEND_CONF) when it has one, else the slot steps.""" own = BACKEND_CONF.get(str(backend or "").strip().lower()) @@ -1076,7 +1098,7 @@ def apply(cfg: dict[str, Any], *, klass: str = "other", data_dir: str | Path | N backend: str | None = None, archs: Any = None, vram_mib: float | None = None, split: bool = False, slots: int = 0, engine: str | os.PathLike[str] | None = None) -> Decision: """Put the config's ``"drafting"`` choice on its engine arguments (in place): ONE drafter's options and none of the other's. DFlash2: no ``--mtp``, no MTP option, - ``--draft dflash2 --draft-model --draft-fallback none --mtp-draft-vocab --spec 6 --draft-conf C``; the person's own ``--spec`` or ``--draft-conf`` + ``--draft dflash2 --draft-model --draft-fallback none --mtp-draft-vocab --spec W --draft-conf C`` (W = window_for: 8 on Strix Halo and on cc 12.0 with >= 48 GB, else 6); the person's own ``--spec`` or ``--draft-conf`` in ``user_args`` stays. C is 0.35 where the card holds most experts and higher where fewer slots fit (conf_for_slots): from the person's own ``--expert-cache N``, else from ``vram_mib``, the memory of the one card (None: several cards, a shared-memory chip, unknown: 0.35). MTP: the arguments without any DFlash2 option. ``off``: neither (the draft layer's own switch, ``"mtp": false``). ``slots`` says that this start serves several requests at @@ -1123,7 +1145,10 @@ def apply(cfg: dict[str, Any], *, klass: str = "other", data_dir: str | Path | N flags = list(engine_flags(pack, vocab, form)) kept_conf = _flag_value(mine, "--draft-conf") tuned_conf = tuned_conf_for(backend, cfg.get("model_name")) if Path(pack) == tuned_path(data_dir, tuned_variant(backend, cfg.get("model_name"))) else None # Metal: the conf the tuned pack was measured with; CUDA / HIP: None, the backend's own conf stays - flags[flags.index("--draft-conf") + 1] = kept_conf if kept_conf is not None else f"{tuned_conf if tuned_conf is not None else conf_for(backend, slots_of(base, vram_mib)):g}" + held = slots_of(base, vram_mib) + wide = big_blackwell(backend, archs, vram_mib, held) # large-VRAM Blackwell: its own measured conf (BIG_BLACKWELL_CONF); Strix keeps 0.35 and widens only the window + flags[flags.index("--draft-conf") + 1] = kept_conf if kept_conf is not None else f"{tuned_conf if tuned_conf is not None else BIG_BLACKWELL_CONF if wide else conf_for(backend, held):g}" + flags[flags.index("--spec") + 1] = str(window_for(backend, archs, vram_mib, held)) if _flag_value(mine, "--spec") is None: base = _without_flag(base, "--spec") # the DFlash2 window; the person's own --spec stays else: diff --git a/tests/snapshot/golden/nv_resident/iq3_s.json b/tests/snapshot/golden/nv_resident/iq3_s.json index 12e773077b..3c45bd3ba4 100644 --- a/tests/snapshot/golden/nv_resident/iq3_s.json +++ b/tests/snapshot/golden/nv_resident/iq3_s.json @@ -211,13 +211,13 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", - "0.35" + "0.55" ], "env_set": {}, "notes": [ - "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.35)" + "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.55)" ] } }, @@ -348,13 +348,13 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", - "0.35" + "0.55" ], "env_set": {}, "notes": [ - "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.35)" + "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.55)" ] } }, @@ -470,13 +470,13 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", - "0.35" + "0.55" ], "env_set": {}, "notes": [ - "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.35)" + "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.55)" ] } } diff --git a/tests/snapshot/golden/nv_resident/ud_iq4_xs_v31.json b/tests/snapshot/golden/nv_resident/ud_iq4_xs_v31.json index e314a15bc2..ba83a1d753 100644 --- a/tests/snapshot/golden/nv_resident/ud_iq4_xs_v31.json +++ b/tests/snapshot/golden/nv_resident/ud_iq4_xs_v31.json @@ -210,13 +210,13 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", - "0.35" + "0.55" ], "env_set": {}, "notes": [ - "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.35)" + "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.55)" ] } }, @@ -347,13 +347,13 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", - "0.35" + "0.55" ], "env_set": {}, "notes": [ - "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.35)" + "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.55)" ] } }, @@ -469,13 +469,13 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", - "0.35" + "0.55" ], "env_set": {}, "notes": [ - "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.35)" + "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.55)" ] } } diff --git a/tests/snapshot/golden/nv_resident/ud_q4_k_xl.json b/tests/snapshot/golden/nv_resident/ud_q4_k_xl.json index 38f130a045..98546430d8 100644 --- a/tests/snapshot/golden/nv_resident/ud_q4_k_xl.json +++ b/tests/snapshot/golden/nv_resident/ud_q4_k_xl.json @@ -208,13 +208,13 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", - "0.35" + "0.55" ], "env_set": {}, "notes": [ - "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.35)" + "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.55)" ] } }, @@ -343,13 +343,13 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", - "0.35" + "0.55" ], "env_set": {}, "notes": [ - "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.35)" + "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.55)" ] } }, @@ -463,13 +463,13 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", - "0.35" + "0.55" ], "env_set": {}, "notes": [ - "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.35)" + "[strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.55)" ] } } diff --git a/tests/snapshot/golden/strix_halo_win/iq3_s.json b/tests/snapshot/golden/strix_halo_win/iq3_s.json index 66a804b421..e39c35b174 100644 --- a/tests/snapshot/golden/strix_halo_win/iq3_s.json +++ b/tests/snapshot/golden/strix_halo_win/iq3_s.json @@ -199,7 +199,7 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", "0.35" ], @@ -337,7 +337,7 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", "0.35" ], @@ -460,7 +460,7 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", "0.35" ], diff --git a/tests/snapshot/golden/strix_halo_win/ud_iq4_xs_v31.json b/tests/snapshot/golden/strix_halo_win/ud_iq4_xs_v31.json index c76e805e27..7927939daf 100644 --- a/tests/snapshot/golden/strix_halo_win/ud_iq4_xs_v31.json +++ b/tests/snapshot/golden/strix_halo_win/ud_iq4_xs_v31.json @@ -200,7 +200,7 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", "0.35" ], @@ -338,7 +338,7 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", "0.35" ], @@ -461,7 +461,7 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", "0.35" ], diff --git a/tests/snapshot/golden/strix_halo_win/ud_q4_k_xl.json b/tests/snapshot/golden/strix_halo_win/ud_q4_k_xl.json index 4ccb79bd0e..8253f72d32 100644 --- a/tests/snapshot/golden/strix_halo_win/ud_q4_k_xl.json +++ b/tests/snapshot/golden/strix_halo_win/ud_q4_k_xl.json @@ -200,7 +200,7 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", "0.35" ], @@ -338,7 +338,7 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", "0.35" ], @@ -461,7 +461,7 @@ "--mtp-draft-vocab", "/data/mtp/rt/draft_vocab.bin", "--spec", - "6", + "8", "--draft-conf", "0.35" ], diff --git a/tests/terminal/test_drafting.py b/tests/terminal/test_drafting.py index 612aded29f..129a226013 100644 --- a/tests/terminal/test_drafting.py +++ b/tests/terminal/test_drafting.py @@ -494,7 +494,7 @@ class UnslothAndTheOtherFlashNextFiles(unittest.TestCase): self.assertEqual(args[args.index("--mtp-draft-vocab") + 1], str(mtp / "draft_vocab.bin"), "the vocabulary the engine needs") for flag in ("--mtp", "--spec-min-p"): self.assertNotIn(flag, args, (backend, name, flag)) - self.assertEqual(args[args.index("--spec") + 1], "6") + self.assertEqual(args[args.index("--spec") + 1], "8" if (backend, archs) == ("hip", ["gfx1151"]) else "6", "Strix Halo 8 (RESULTS-CONF.md 11-08), every other card 6") def test_swift_coder_and_nvfp4_stay_on_the_mtp(self): for backend, archs in self.HARDWARE: diff --git a/tests/terminal/test_drafting_card_window.py b/tests/terminal/test_drafting_card_window.py new file mode 100644 index 0000000000..0a18d65ef3 --- /dev/null +++ b/tests/terminal/test_drafting_card_window.py @@ -0,0 +1,119 @@ +"""The per-card DFlash2 window and confidence of 0.2.13 (owner 11-08, RESULTS-CONF.md): Strix Halo window 8 (conf 0.35), Blackwell cc 12.0 with >= 48 GB window 8 and conf 0.55. + +Every other card keeps conf and --spec 6, so its EFFECTIVE window (--spec lowered to the engine's cap, include/strata/core/draft_cap.hpp) is what it was. +""" + +from __future__ import annotations + +import tempfile +import unittest +from pathlib import Path +from unittest import mock + +from strata_control import drafting + +IQ3S = "qwen3.8-flash-next-iq3_s" +Q4 = "qwen3.8-flash-next-unsloth-ud-q4_k_xl" +V31 = "qwen3.8-flash-next-unsloth-ud-iq4_xs-v31" + +GIB = 1 << 30 + + +def old_cap(uma, major): # include/strata/core/draft_cap.hpp before 11-08 + return 5 if uma else 6 if major == 12 else 0 + + +def new_cap(uma, major, minor, vram_bytes): # the same file after (mirrored here; src/core/draft_cap_test.cpp tests the C++) + if uma: + return 8 + if major == 12: + return 8 if (minor == 0 and vram_bytes >= 48_000_000_000) else 6 + return 0 + + +def effective(spec, cap): + return min(spec, cap) if cap > 0 else spec + + +class CardWindow(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + self.data = Path(self.tmp.name) + (self.data / "dflash2").mkdir() + (self.data / "dflash2" / drafting.PACK_NAME).write_bytes(b"s" * (2 << 20)) + (self.data / "dflash2" / drafting.VOCAB_NAME).write_bytes(b"v" * 100) + self.exe = self.data / "strata" + self.exe.write_bytes(b"--mtp-draft-vocab FILE (or --mtp DIR ... --draft-fallback ... selector codebooks: Q4_0 rows") + patcher = mock.patch.object(drafting, "ENGINE_SERVES_DFLASH2", True) + patcher.start() + self.addCleanup(patcher.stop) + + def flags(self, name, backend, archs, vram, extra=(), user_args=None): + cfg = {"model_name": name, "args": ["--native", "m.gguf", *extra], "drafting": "dflash2"} + if user_args: + cfg["user_args"] = list(user_args) + with mock.patch.object(drafting, "detect_hardware", return_value=(backend, list(archs))): + d = drafting.apply(cfg, data_dir=self.data, backend=backend, archs=list(archs), engine=self.exe, vram_mib=vram) + self.assertEqual(d.drafter, "dflash2") + a = cfg["args"] + return a[a.index("--spec") + 1], a[a.index("--draft-conf") + 1] + + def test_the_constants(self): + self.assertEqual((drafting.SPEC_WINDOW, drafting.WIDE_WINDOW, drafting.DRAFT_CONF, drafting.BIG_BLACKWELL_CONF), (6, 8, 0.35, 0.55)) + self.assertEqual(drafting.BIG_CARD_BYTES, 48_000_000_000) + + def test_strix_halo_window_8_conf_unchanged(self): + for name in (IQ3S, Q4, V31): + self.assertEqual(self.flags(name, "hip", ["gfx1151"], None), ("8", "0.35"), name) + + def test_blackwell_cc_12_0_with_48_gb_or_more(self): + for mib in (73728, 73415, 49152, 49140, 98304, 45777): # 72 GB, the l620 reading, 48 GiB, an RTX A6000-class 48 GB, 96 GB, the 48e9 byte line + for name in (IQ3S, V31): + self.assertEqual(self.flags(name, "cuda", ["sm_120"], mib), ("8", "0.55"), (name, mib)) + + def test_blackwell_cc_12_0_under_48_gb_keeps_today(self): + for mib in (32768, 24576, 16384, 12288, 45776, None): # RTX 5090 32 GB .. 5070 12 GB, just under the line, memory unknown (several cards) + self.assertEqual(self.flags(IQ3S, "cuda", ["sm_120"], mib), ("6", f"{drafting.conf_for('cuda', drafting.slots_of([], mib)):g}"), mib) # the slot rule, as before + self.assertEqual(self.flags(IQ3S, "cuda", ["sm_120"], 32768)[1], "0.35") + + def test_the_spark_is_unchanged(self): + self.assertEqual(self.flags(IQ3S, "cuda", ["sm_121"], None), ("6", "0.35")) + self.assertEqual(self.flags(V31, "cuda", ["sm_121"], None), ("6", "0.35")) + self.assertEqual(self.flags(IQ3S, "cuda", ["sm_121"], 131072), ("6", "0.35"), "even when a reading of its pool is passed") + + def test_the_big_card_with_a_small_expert_cache_keeps_the_slot_rule(self): + self.assertEqual(self.flags(IQ3S, "cuda", ["sm_120"], 73728, extra=["--expert-cache", "1000"]), ("6", "0.8")) + + def test_other_cards_are_unchanged(self): + for backend, archs, mib in (("cuda", ["sm_86"], 12288), ("cuda", ["sm_89"], 24576), ("cuda", ["sm_90"], 81920), ("cuda", ["sm_86"], 49152), ("hip", ["gfx1201"], 32768), + ("hip", ["gfx1100"], 24576), ("hip", ["gfx1103"], None), ("sycl", ["arc_a"], None), ("metal", [], None)): + spec, conf = self.flags(Q4 if backend == "hip" else V31, backend, archs, mib) + self.assertEqual(spec, "6", (backend, archs)) + self.assertEqual(conf, f"{drafting.conf_for(backend, drafting.slots_of([], mib)):g}", (backend, archs)) # the stock pack here: the backend's own rule + + def test_the_persons_own_flags_win(self): + self.assertEqual(self.flags(IQ3S, "cuda", ["sm_120"], 73728, user_args=["--draft-conf", "0.4", "--spec", "5"], extra=["--draft-conf", "0.4", "--spec", "5"])[1], "0.4") + cfg = {"model_name": IQ3S, "args": ["--native", "m.gguf", "--spec", "5"], "user_args": ["--spec", "5"], "drafting": "dflash2"} + with mock.patch.object(drafting, "detect_hardware", return_value=("hip", ["gfx1151"])): + drafting.apply(cfg, data_dir=self.data, backend="hip", archs=["gfx1151"], engine=self.exe) + self.assertEqual(cfg["args"].count("--spec"), 1) + self.assertEqual(cfg["args"][cfg["args"].index("--spec") + 1], "5") + + def test_no_card_but_the_two_classes_changes_its_effective_window(self): + """--spec as written, lowered to the engine's cap: the same number as before for every card but Strix Halo (5 -> 8) and the large Blackwell class (6 -> 8).""" + cards = [("hip", ["gfx1151"], None, True, 0, 0, 0)] + for mib, major, minor in ((73728, 12, 0), (98304, 12, 0), (49152, 12, 0), (32768, 12, 0), (16384, 12, 0), (12288, 12, 0), (None, 12, 0), (131072, 12, 1), (None, 12, 1), + (12288, 8, 6), (24576, 8, 9), (81920, 9, 0), (49152, 8, 6), (73728, 10, 0)): + cards.append(("cuda", [f"sm_{major}{minor}"], mib, False, major, minor, (mib or 0) * (1 << 20))) + for backend, archs, mib, uma, major, minor, vram in (*cards, ("hip", ["gfx1201"], 32768, False, 0, 0, 0), ("hip", ["gfx1100"], 24576, False, 0, 0, 0), ("sycl", ["arc_a"], None, False, 0, 0, 0), ("metal", [], None, False, 0, 0, 0)): + spec = int(self.flags(IQ3S if backend != "hip" else Q4, backend, archs, mib)[0]) + old = effective(6, old_cap(uma, major)) + new = effective(spec, new_cap(uma, major, minor, vram)) + big = backend == "cuda" and major == 12 and minor == 0 and vram >= 48_000_000_000 + want = 8 if (uma or big) else old + self.assertEqual(new, want, (backend, archs, mib, "old", old)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/terminal/test_drafting_hardware.py b/tests/terminal/test_drafting_hardware.py index 2f08e33bc8..e8de066e5c 100644 --- a/tests/terminal/test_drafting_hardware.py +++ b/tests/terminal/test_drafting_hardware.py @@ -181,9 +181,11 @@ class ConfidenceFollowsTheSlots(unittest.TestCase): def test_the_card_decides_when_the_cache_is_auto(self): args = ["--expert-cache", "auto", "--max-context", "131072", "--kv", "int8"] - for vram, want in ((8192, "0.8"), (12288, "0.8"), (16384, "0.7"), (20480, "0.7"), (24564, "0.5"), (32768, "0.35"), (49152, "0.35"), (73415, "0.35")): + for vram, want in ((8192, "0.8"), (12288, "0.8"), (16384, "0.7"), (20480, "0.7"), (24564, "0.5"), (32768, "0.35"), (45000, "0.35"), (49152, "0.55"), (73415, "0.55")): self.assertEqual(self.conf(args, vram_mib=vram), want, vram) self.assertEqual(self.conf(args, vram_mib=32768, backend="hip", archs=("gfx1201",)), "0.35", "the R9700 (12,570 slots measured) keeps 0.35") + for archs in (("sm_121",), ("sm_89",), ("sm_86",)): + self.assertEqual(self.conf(args, vram_mib=73415, archs=archs), "0.35", f"{archs}: only cc 12.0 with 48 GB or more has 0.55") def test_the_estimate_matches_the_two_measured_starts(self): n = drafting.expected_slots(32768, ["--max-context", "131072", "--kv", "int8"]) diff --git a/tests/terminal/test_drafting_streaming_class.py b/tests/terminal/test_drafting_streaming_class.py index 71cae58605..083dbd7b95 100644 --- a/tests/terminal/test_drafting_streaming_class.py +++ b/tests/terminal/test_drafting_streaming_class.py @@ -204,7 +204,7 @@ class OtherSetsAndEntriesAreUnchanged(Base): def test_the_resident_strix_arc_and_metal_starts_are_what_they_were(self): self.put_tuned() - for hardware, name, conf in ((L620, IQ3S, "0.35"), (SPARK, V31, "0.35"), (STRIX, IQ3S, "0.35")): + for hardware, name, conf in ((L620, IQ3S, "0.55"), (SPARK, V31, "0.35"), (STRIX, IQ3S, "0.35")): # l620: 0.55 since 11-08 d, args = self.apply(name, hardware) self.assertEqual((d.drafter, flag(args, "--draft-model"), flag(args, "--draft-conf")), ("dflash2", str(drafting.tuned_path(self.data)), conf), (hardware, name)) d, args = self.apply(Q4, ("metal", [], None)) diff --git a/tests/terminal/test_drafting_tuned.py b/tests/terminal/test_drafting_tuned.py index b303ecfe25..471da48ba9 100644 --- a/tests/terminal/test_drafting_tuned.py +++ b/tests/terminal/test_drafting_tuned.py @@ -476,7 +476,7 @@ class CudaAndHip(Fetch): self.assertEqual(flag(args2, "--draft-model"), str(drafting.pack_path(self.data, self.exe)), where) self.assertNotEqual(flag(args2, "--draft-model"), flag(args, "--draft-model"), where) self.assertEqual(flag(args, "--draft-conf"), flag(args2, "--draft-conf"), f"only the pack changes, not the conf {where}") - self.assertEqual(flag(args, "--draft-conf"), "0.35", where) + self.assertEqual(flag(args, "--draft-conf"), "0.55" if hardware is L620 else "0.35", where) # l620 0.55, 11-08 self.assertEqual(flag(args, "--spec"), flag(args2, "--spec"), where) strip = lambda a: [x for i, x in enumerate(a) if not (i and a[i - 1] == "--draft-model")] # noqa: E731 self.assertEqual(strip(args), strip(args2), where) @@ -530,7 +530,7 @@ class CudaAndHip(Fetch): self.assertEqual(drafting.BACKEND_CONF, {"sycl": 0.6, "metal": 0.5}) self.assertEqual((drafting.DRAFT_CONF, drafting.SPEC_WINDOW), (0.35, 6)) self.put_stock() - want = {L620[0]: "0.35", SPARK[0]: "0.35", STRIX[0]: "0.35", P2003[0]: "0.8", ARC[0]: "0.6"} + want = {L620[0]: "0.55", SPARK[0]: "0.35", STRIX[0]: "0.35", P2003[0]: "0.8", ARC[0]: "0.6"} for hardware in (L620, SPARK, STRIX, P2003, ARC): name = V31 if hardware is P2003 else IQ3S # (IQ3S on the 12 GB class is the MTP now: no DFlash2 conf to compare) before = flag(self.apply_on(hardware, name)[1], "--draft-conf")