Repository navigation
Conversation
|
At I repeated the call to A trial merge with Igor Lessio - AIFLOW LABS |
|
Thanks @gilby. Building the draft head once at load is a neat idea, and target verification still reads the 8-bit
We'll handle the rebase onto current main (a conflict in
|
d6fb847 to
97c77cd
Compare
|
Thanks @ashhart (and @AIFlowML for the allocation-reuse check). Addressed all three items and rebased onto current
Verification on
|
|
I checked revised head
The full-checkpoint memory and timing figures remain the author’s measurements. Igor Lessio - AIFLOW LABS |
|
Thanks @gilby. The revised switch is off by default, skips synthesis with DFlash2, and documents both the sampled slowdowns and the changed draft precision. That addresses all three earlier requests, and the posted checks support the default and skip behavior. The 4-bit head built from the loaded 8-bit head only proposes drafts: the target still verifies every drafted token, so replies stay equal to plain decoding and only acceptance and speed change. That fits our rule. What remains is the device comparison on a GLM checkpoint: drafted replies equal to plain ones with the switch on, greedy and seeded, and the speed effect at one and several streams.
|
Quantizes an 8-bit/64 GLM lm_head into an in-memory 4-bit/64 MTP draft head at load only when GLM_DRAFT_HEAD_Q4=1, --drafter is not set, tp == 1, and memory budget allows; unset, blank or 0 stays off and malformed values fail closed. Refs ashhart#3152
97c77cd to
adcc166
Compare
|
Rebased cleanly onto 1. Rebase & checks on
|
| Cell | main (r1, r4) |
main mean |
Q4=1 (r2, r3) |
Q4=1 mean |
Diff | main steady |
Q4=1 steady |
Steady diff |
|---|---|---|---|---|---|---|---|---|
code T=0.0 N=1 |
86.7, 86.2 |
86.45 |
83.0, 83.2 |
83.10 |
-3.88% | — | — | — |
code T=0.0 N=3 |
148.8, 148.8 |
148.80 |
151.3, 153.2 |
152.25 |
+2.32% | 151.70 |
155.30 |
+2.37% |
chat T=0.0 N=1 |
71.3, 71.2 |
71.25 |
72.2, 72.3 |
72.25 |
+1.40% | — | — | — |
chat T=0.0 N=3 |
132.2, 133.0 |
132.60 |
135.8, 136.0 |
135.90 |
+2.49% | 138.50 |
142.10 |
+2.60% |
code T=1.0 N=1 |
81.0, 80.5 |
80.75 |
81.2, 81.4 |
81.30 |
+0.68% | — | — | — |
code T=1.0 N=3 |
102.6, 103.9 |
103.25 |
104.5, 105.8 |
105.15 |
+1.84% | 107.10 |
109.35 |
+2.10% |
chat T=1.0 N=1 |
68.0, 67.9 |
67.95 |
69.9, 70.1 |
70.00 |
+3.02% | — | — | — |
chat T=1.0 N=3 |
100.4, 99.7 |
100.05 |
101.0, 99.8 |
100.40 |
+0.35% | 104.45 |
105.15 |
+0.67% |
- Note on
code T=0.0 N=1(-3.88%): underGLM_DRAFT_HEAD_Q4=1, the 4-bit draft head shifted proposals so requests drafted more tokens (accepted=152/206in104rounds vsmain's149/166in107rounds;r3_q4rep 1 drafted149/173at86.47 tok/s), widening verify rounds enough to offset the faster draft projection. Across the remaining7/8cells (N=1andN=3),GLM_DRAFT_HEAD_Q4=1measured+0.35%to+3.02%(+0.67%to+2.60%steady), consistent with keepingGLM_DRAFT_HEAD_Q4off by default (0). - Uniform
4-bit/64checkpoint no-op (GLM-5.3-Flash-MLX-4bit-MTP,--tokens 64 --reps 1 --levels 1):GLM_DRAFT_HEAD_Q4unset vsGLM_DRAFT_HEAD_Q4=1both loaded180.6 GBweights (187,392,032,768 Bvs187,390,459,904 BMaxRSS;187,734,791,248 Bvs187,733,218,432 Bpeak footprint;+0synthesized bytes),4/4--aloneand4/4--serialequal,0failed, bit-identicaltoken_sha256across unset,Q4=1, and"draft": false.
|
Thanks @gilby. The default-off switch, DFlash2 skip and precision disclosure address the earlier requests. Target verification still uses the loaded head, so the changed draft proposals fit the verified-draft rule. The new greedy and seeded M5 comparison is useful evidence, including the slower cell and memory cost. This is suitable for final integration checks; the merge is clean. Please retain the full checkpoint pins and raw receipts with those results.
|
What this changes
Gates in-memory
4-bit/64MTP draft-head synthesis (zig/src/families/glm/draft_head_q4.zig, called fromzig/src/families/glm/engine.zig) behind an opt-in environment switch,GLM_DRAFT_HEAD_Q4(default0/ unset / blank off; malformed values fail closed namingGLM_DRAFT_HEAD_Q4), and skips synthesis whenever--drafter(DFlash2) is set (zig/src/native/glm_host.zig).Default (
GLM_DRAFT_HEAD_Q4unset, blank, or0, or whenever--drafteris set): No draft head is synthesized (+0bytes, zero extra load time, identical weights, drafts, and replies tomain).Opt-in (
GLM_DRAFT_HEAD_Q4=1without--drafter,tp == 1,w.mtp != null,w.draft_head == null, andused + need <= limit): Quantizes an8-bit/64lm_headonce at load into an in-memory4-bit/64w.draft_head(356,843,520 Bshared buffer at[154880, 4096]).Precision & exactness: Target verification continues to read the unmodified
8-bit/64lm_head, so verified replies keepmain's exact tokens ("draft": false, greedy and seeded); however, underGLM_DRAFT_HEAD_Q4=1, the MTPdraft_headitself is re-quantized from8to4bits, so draft logits and draft proposals change (moving MTP acceptance and drafted token counts).Which workloads
GLM_DRAFT_HEAD_Q4=1helps (and where to leave it off):8-bit/64lm_headand no storeddraft_head(such asGLM-5.3-Flash-oQ4e-mtp-oq071) where the 4-bit draft head shortens draft projection without increasing rejected drafts: on Apple M5 Ultra (512 GiB,--parallel 3 --context 131072), 7 of 8bench_concurrent.pycells speed up (+0.35%to+3.02%aggregate,+0.67%to+2.60%steady, includingcode T=0 N=3+2.32%,chat T=0 N=1+1.40%,chat T=0 N=3+2.49%,chat T=1.0 N=1+3.02%), and earlier single-streambench_openai.pyruns speed up+1.94%to+3.52%.0): Prompts/workloads where 4-bit draft logits shift MTP/copy proposals toward lower acceptance or wider verify rounds (code T=0 N=1on the 512 GiB M5 Ultra--context 131072run shifted from149/166to152/206accepted/drafted tokens,-3.88%, and earlier M5 Ultra 256 GiBbench_concurrent.pyT=1.0sampled cells moved-1.25%to-2.95%), as well as--drafter(DFlash2) runs (automatically skipped) and uniform4-bit/64checkpoints (GLM-5.3-Flash-MLX-4bit-MTP, already a no-op).Issue: Refs GLM-5.3-Flash on Metal: decode and prompt speed on M5 Ultra, token-exact (baseline, items and gate) #3152
Stacked on:
main(0652b7907b847786c53bc44b04a43c16a8dcf547)Checks on this head
adcc166af2a073385ecc83a04121dd3627387e3d(rebased ontomain0652b7907b847786c53bc44b04a43c16a8dcf547)python3 tools/zig/lean_check.py/tools/zig/lean_new.py):165on base (0652b7907b),165on head (adcc166af2),0new findings (python3 tools/pr_check.py --pr 4253 --base origin/mainexits0with0errors; every touched.zigfile <= 600 lines:draft_head_q4.zig239,engine.zig586,glm.zig99,glm_host.zig289,environment.zig596,environment_test.zig585).atc overlap --json(7changed files).adcc166af2(Zig 0.17.0,-Dcpu=apple_m1):zig fmt --check build.zig zig— passed (0exit)git diff --check origin/main..HEAD— passed (0exit)zig build test-glm-disk-charge-host test-drafter-skip-metal-host test-glm-metal-dflash-host test-environment-host test-env-defaults-host test-shared-head-cost-metal-host -Dcpu=apple_m1 --summary all—69/69steps succeeded;396/399tests passed (3skipped) (test-glm-disk-charge-host64/64,test-drafter-skip-metal-host71/71,test-glm-metal-dflash-host15/15,test-environment-host32/32,test-env-defaults-host43 pass / 3 skip+102/102,test-shared-head-cost-metal-host69/69)zig build test-native -Dcpu=apple_m1 --summary all—68/68steps succeeded;183/186tests passed (3skipped; includesdraft_head_q4.zigunit tests)zig build test-golden -Dcpu=apple_m1 --summary all—5/5steps succeeded (69/69+327/340equal,0unexpected differences)97c77cd6e2live--draftersmoke checks onGLM-5.3-Flash-oQ4e-mtp-oq071+--drafter GLM-5.3-Flash-DFlash2(--context 4096 --prompt-cache-gib 0):GLM_DRAFT_HEAD_Q4=0vsGLM_DRAFT_HEAD_Q4=1both loaded184.7 GBtarget weights (192,776,757,016 Bvs192,775,233,424 Bfootprint;draft_head_q4skipped), identical 64-token greedy replysha256.draft_head_q4load path).Receipt
Rebased head (
adcc166af2) on Apple M5 Ultra (512 GiB, macOS 27.2.1, Zig0.17.0,ReleaseFast)GLM-5.3-Flash-oQ4e-mtp-oq071(8-bit/64lm_head+ native MTP, without--drafter),--parallel 3 --context 131072 --prompt-cache-gib 0 --profile stable --no-update-check --port 18091;tools/bench_concurrent.py --alone --serial --tokens 256 --reps 3 --temperatures 0,1.0 --levels 1,3 --seed 1234, alternating A-B-B-A (r1_base->r2_q4->r3_q4->r4_base),pmset -g thermclean (No thermal warning/No performance warning) before and after every run.GLM_DRAFT_HEAD_Q4=yes): exits1withtensorfold: GLM_DRAFT_HEAD_Q4="yes": expected 0 or 1 (1 quantizes an 8-bit/64 GLM lm_head into an in-memory 4-bit/64 MTP draft head at load)./usr/bin/time -l) & default parity:r1_base/r4_base(origin/main0652b7907b):184.7 GBweights; MaxRSS191,478,136,832 B/191,473,451,008 B(mean191,475,793,920 B), peak footprint191,869,788,240 B/191,865,053,096 B(mean191,867,420,668 B).r5_cand_unset(adcc166af2,GLM_DRAFT_HEAD_Q4unset):184.7 GBweights; MaxRSS191,473,680,384 B, peak footprint191,865,282,376 B(+0weight bytes vsmain).r2_q4/r3_q4(adcc166af2,GLM_DRAFT_HEAD_Q4=1):185.1 GBweights; MaxRSS191,831,703,552 B/191,831,539,712 B(mean191,831,621,632 B, +355,827,712 B /+355.8 MB), peak footprint192,223,502,392 B/192,223,404,232 B(mean192,223,453,312 B, +356,032,644 B /+356.0 MB).drafted == plain == main, greedy & seeded):0failed,0unmeasured,timing_valid=True,48/48--aloneequal (0unequal,0failed, non-vacuous atN=3) and16/16--serial("draft": false) equal (0unequal,0failed,plain_drafted=0, non-vacuous MTP drafts accepted on every cell) per run.r5_cand_unset(1rep):16/16--aloneequal,16/16--serialequal,0failed.token_sha256parity:100%bit-identical acrossr1_base(origin/main),r4_base(origin/main),r5_cand_unset(adcc166af2unset),r2_q4(Q4=1),r3_q4(Q4=1),--alone, and--serial("draft": false) at bothT=0(code7cd4ab7084c3...,chat20acae32b5d8...) andT=1.0seeds1234..1236(code378ce72fdd3b...,5f649fe4146c...,9c2be42968b6...;chat1fd198720049...,346536bbcc9a...,99673f09fb34...).aggregate_tps/steady_tps, A-B-B-A means of 3-rep cell medians):main(r1, r4)mainmeanQ4=1(r2, r3)Q4=1meanmainsteadyQ4=1steadycode T=0.0 N=186.7, 86.286.4583.0, 83.283.10code T=0.0 N=3148.8, 148.8148.80151.3, 153.2152.25151.70155.30chat T=0.0 N=171.3, 71.271.2572.2, 72.372.25chat T=0.0 N=3132.2, 133.0132.60135.8, 136.0135.90138.50142.10code T=1.0 N=181.0, 80.580.7581.2, 81.481.30code T=1.0 N=3102.6, 103.9103.25104.5, 105.8105.15107.10109.35chat T=1.0 N=168.0, 67.967.9569.9, 70.170.00chat T=1.0 N=3100.4, 99.7100.05101.0, 99.8100.40104.45105.154-bit/64checkpoint no-op (GLM-5.3-Flash-MLX-4bit-MTP,--tokens 64 --reps 1 --levels 1):GLM_DRAFT_HEAD_Q4unset vsGLM_DRAFT_HEAD_Q4=1both loaded180.6 GBweights (MaxRSS187,392,032,768 Bvs187,390,459,904 B, peak footprint187,734,791,248 Bvs187,733,218,432 B),4/4--aloneand4/4--serialequal,0failed, bit-identicaltoken_sha256across unset,Q4=1, and"draft": false.(Earlier
d6fb847706/97c77cd6e2Apple M5 Ultra 256 GiB receipts: https://gist.github.com/gilby/eb56bbd461a97cd6f4293cd56062004f)glm5_nexton Metal whenGLM_DRAFT_HEAD_Q4=1is set,--drafteris not set, an8/64lm_headand MTP layer are present,tp == 1, no storeddraft_headexists, and memory budget fits (~0.36 GBshared buffer); complete no-op by default (GLM_DRAFT_HEAD_Q4unset/blank/0), with--drafter, on4/64checkpoints (GLM-5.3-Flash-MLX-4bit-MTP), or when tight againstlimit.GLM_DRAFT_HEAD_Q4(.scope = .metal,.kind = .flaginzig/src/platform/environment.zig, documented indocs/environment.md); accepted values0or1(unset or blank is0, malformed values refused by name); no profile row change (stays0across profiles).adcc166af2a073385ecc83a04121dd3627387e3datopmain0652b7907b847786c53bc44b04a43c16a8dcf5470.17.0(-Dcpu=apple_m1 -Doptimize=ReleaseFast), macOS Metal (macOS 27.2.1)512 GiB,applegpu_g17, unified memory, tensor units true)GLM-5.3-Flash-oQ4e-mtp-oq071(8/64lm_head+ MTP),TensorFold/GLM-5.3-Flash-MLX-4bit-MTP(uniform4/64)512 GiB) single-Macoq071(origin/main,GLM_DRAFT_HEAD_Q4unset,GLM_DRAFT_HEAD_Q4=1,GLM_DRAFT_HEAD_Q4=yesrefusal),GLM-5.3-Flash-MLX-4bit-MTP(4/64no-op), host/native/golden tests; earlier97c77cd6e2--drafterskip check onGLM-5.3-Flash-DFlash2.cuda_mtp_load.zig).tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:GLM_DRAFT_HEAD_Q4=0/unset changes no weights or sums (r5_cand_unsetmatchesorigin/mainin weights andtoken_sha256).GLM_DRAFT_HEAD_Q4=1, the MTPdraft_headis re-quantized from8-bit/64to4-bit/64(so draft logits and draft proposals change), while target verification still reads the8-bit/64lm_head:bench_concurrent.py --alone --serialrecorded0unequal and0failed across allalone(48/48per run) andserial(16/16per run) checks, with100%cross-binarytoken_sha256match againstorigin/mainand"draft": falseat bothT=0andT=1.0.0/unset is identical tomain; opt-inGLM_DRAFT_HEAD_Q4=1onGLM-5.3-Flash-oQ4e-mtp-oq071(--parallel 3 --context 131072) speeds up7of8cells (+0.35%to+3.02%, steady+0.67%to+2.60%) while shiftingcode T=0.0 N=1by-3.88%(152/206vs149/166accepted/drafted tokens).prompt_ttft_tps~164.4–165.4oncode,258.8–260.4onchat; draft LM head runs only during MTP drafting).Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.GLM_DRAFT_HEAD_Q4=0changes no bits. When opted intoGLM_DRAFT_HEAD_Q4=1, the MTPdraft_headitself is re-quantized in memory from 8-bit/64 to 4-bit/64, so MTP draft logits and draft proposals change while target verification keeps the 8-bit/64lm_headand verified replies stay exact.)--drafter, no slower than without it, greedy and sampled (DefaultGLM_DRAFT_HEAD_Q4=0and--drafterruns matchmain; opt-inGLM_DRAFT_HEAD_Q4=1shifts draft proposals and can slow specific cells such ascode T=0.0 N=1-3.88%or earlierT=1.0sampled cells, which is why the switch stays off by default.)