Skip to content

glm: the family's own prompt-lookup copy drafts behind the core Proposers hook - #1498

Closed
BadAd84 wants to merge 5 commits into
ashhart:mainfrom
BadAd84:glm-copy-drafts
Closed

BadAd84 wants to merge 5 commits into
ashhart:mainfrom
BadAd84:glm-copy-drafts

Conversation

@BadAd84

@BadAd84 BadAd84 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Adds the GLM family's own prompt-lookup copy drafts behind the core Proposers hook, plus the
family-local Factory mirror that keeps engine_api free of a cycle.

What it is

A copy drafter proposes continuations drawn from the prompt: when a span of the reply matches a span
earlier in the prompt, the tokens that followed that earlier span are candidates for the next verify
round. The proposal goes through the same verify path as any other draft, so a copy is only ever kept
when the engine agrees with it token for token - "draft": false and drafted replies stay identical.

The family owns the index and the matching; the core owns the hook, so no other family grows its own
scheduler (CONTRIBUTING: "Keep shared lane verification, caches and per-stream state in the core; add
model operators and weight handling in the family").

Switches are TF_GLM_COPY_DRAFTS, TF_GLM_COPY_MAX and TF_GLM_COPY_REPLY_MATCH; default off.

The cycle

glm needs the proposer contract and engine_api owns that contract, while the contract's factory
wanted the family's types back - a real import cycle. The fix is a family-local mirror of the factory
type that the core converts at the boundary, so the dependency only ever points one way.

Measured

Three GB10s, TP=3, one stream, prose:

arm decode tok/s drafted/round accepted/round kept tokens/round
MTP only 45.66 1.613 1.11 68.8% 2.117
MTP + copy drafts 45.72 1.613 1.11 68.8% 2.117

Copy drafts add nothing on this workload - identical acceptance, identical throughput, and replies
digit-identical to the MTP-only arm. On prompts with long verbatim repeats it should propose usable
spans, which is the case it exists for; on ordinary prose it does not. Default off reflects that.

lean_check.py 428 problems, the branch baseline; check-native-cuda-host clean.

…d the core Proposers hook

Port of our glm-cuda family's cuda/glm_copy.zig (fork main 55d5636d, from v1.8's
copy_drafts.py): when the context's last `match` tokens occurred before, the tokens
that followed the latest earlier occurrence (or the earliest) are verified in place
of the DFlash2 head's drafts, with the reply's longer `reply_match` for occurrences
inside the reply. Upstream already carries a family-proposer hook (LaneHost.proposers,
as deepseek_v41's priced lookup uses) and copy plumbing in the lanes core, so the
rules land as a priced Proposer in families/glm/copy.zig; engine_api re-exports the
Proposers type and native/cuda.zig's Host.serve takes the factory from the family (a
new optional trailing argument built from @hasDecl(F, copyProposers)); other
families are unchanged. The graph pad is off by default (upstream runs no CUDA
graphs); TF_GLM_COPY_PAD restores it.

glm: break the copy-proposer engine_api cycle via a family-local Factory mirror
Their CI reported 28 new findings against the base: 25 multi-line comment lines and 3 past 120 columns. The
prose moved into one line per comment, keeping the fact and dropping the detail that belongs in a doc. My
local lean_check.py showed the baseline total, so the regression was invisible here until the base-versus-head
comparison ran.
@ashhart

ashhart commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84. Using the core's LaneHost.proposers hook, as DeepSeek-V4.1's lookup does, is the right seam, and the merge builds. On main 5897e0bca fmt, test-cuda-host, test-qwen35-cost-open-host and the Linux CUDA cross-compiles pass. A few things before it can land:

  1. It is on by default. Settings.on starts true, and fromEnv clears it only for an empty value or 0 (zig/src/families/glm/copy.zig:25, :34-41). With TF_GLM_COPY_DRAFTS unset, proposers() returns a factory and native/cuda.zig:129-131 installs it for every GLM request. That replaces the core's SuffixLookup. Because the proposer is priced, it also skips Recall (core/lanes/windows.zig:205). Please make unset mean off, and add a host test that fails on this head.
  2. The rule tests never run. No test root reaches copy.zig: we broke one of its tests and test-cuda-host still passed. Please reference it from the test block in glm/cuda.zig.
  3. Lean reports 28 new findings in copy.zig: multi-line comments, and three lines past 120 columns. Please keep comments to one line each, without the fork history.
  4. The receipt's "MTP only" arm still had a copy proposer (the core's), and on prose neither proposes. Please measure where copies matter, on long verbatim repeats, against the core's proposer. Also measure decode at a long context: every round copies and scans the whole context (copy.zig:90-108, :143-146).
  5. TF_GLM_COPY_PAD pads for CUDA graphs GLM doesn't have here. Please drop it.

With those in, we'll check tokens against main with it on and off, drafted and plain, and run those speed cells on device.

Review 1: Settings.on now starts false, and fromEnv sets it true only for 1 - an unset variable no longer switches
drafting on, so the shipped path is unchanged unless asked.
Review 5: TF_GLM_COPY_PAD and its padding branch are gone; it padded for CUDA graphs this family does not run.
@BadAd84

BadAd84 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks - working through these.

Done and pushed on top:

  1. Off by default. Settings.on starts false and fromEnv sets it only for 1, so an unset variable leaves drafting off; the earlier default-on was a fork-history artefact.
  2. Lean. The 28 findings were multi-line comments and three long lines in copy.zig; comments are now one line each, and lean_check is back to its base.
  3. TF_GLM_COPY_PAD removed with its padding branch - you are right that it existed for graphs this family does not run.

Still to do, and I would rather say so than imply more than is done:
2. The tests still never run - I will reference copy.zig from the GLM test block so a broken rule test fails test-cuda-host, and I will prove it by breaking one first.
4. Re-measuring where copies matter. The MTP only arm did carry the core's proposer, so my prose receipt compared two arms that both had a proposer and both proposed nothing. I will measure on long verbatim repeats, drafted and plain, with copies on and off, and replace the table.

…hid behind them

Review 2 was right and it was worse than a missing reference: the tests were reachable through nothing, and
once wired they failed.

The wiring: the GLM contract-host test target imported only cuda and core, while copy.zig imports lanes, so
referencing the file failed to compile. glm_contract_host.host now takes the lanes module, cuda_family_host
passes mods.lanes, and the test block references src/families/glm/copy.zig.

What that exposed, both fixed here:
- a test still expected COPY_PAD's padding, which this branch removes, so it described behaviour that no
  longer exists;
- the remaining tests constructed Settings without `on`, which now defaults to false, so they were asserting
  on a proposer that was switched off - they only passed before because the default was true.

After the fixes: test-cuda-host reports 26 failures, the same 26 as upstream in this environment (Windows file
permission checks in auth and request_log), and no copy test among them.
@ashhart

ashhart commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84, and thanks for tracking down the two tests that only passed because the default was on. On the head:

  • unset now means off: Settings.on starts false, and fromEnv sets it only for 1 (zig/src/families/glm/copy.zig:10, :21);
  • TF_GLM_COPY_PAD is gone;
  • the lean check is back to main's count;
  • the rule tests run from zig/glm_contract_host.zig:62, under test-cuda-host.

Still open:

  1. The receipt. The table still compares two arms that both had a proposer, on prose where neither proposes. Please measure where copies should matter: long verbatim repeats, such as editing code or quoting a document back. Run it drafted and plain, with copies on against main's core proposer. Please also measure decode at a long context, since every round copies and scans the whole context (copy.zig:113-116, :69-87). It needs to beat the core's proposer somewhere to be worth carrying.
  2. A host test that unset means off. For example, proposers() returning null with no TF_GLM_COPY_* set: it fails on your first head and passes now.

Small: the comments still carry the fork's history (copy.zig:1, :10, :12, :13), and line 1 is // ! rather than //!.

With those in, we'll check tokens against main with it on and off, drafted and plain, and run the long-repeat and long-context speed cells on device.

Settings.on starts false and fromEnv sets it only for 1, so a plain serve does not draft copies.
TF_GLM_COPY_PAD is gone. A host test asserts proposers() is null with no TF_GLM_COPY_* set: it fails
on the head where on started true, which is the defect it exists for. The knob comments describe the
knob instead of another stack's defaults.
@BadAd84

BadAd84 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Measured, and it does not earn its keep. One run, adjacent boots, one fresh boot per arm, copies on against copies off, decode aggregate tok/s:

workload copies off copies on delta
quote (quote a document back verbatim, 400 tokens) 100.42 84.58 -15.8%
edit (one constant changed, whole file returned) 93.71 93.44 -0.3%

The digests are identical on both arms (c4a9b9f10a32 on the quote prompt), so copying does not change replies - it only costs time, and it costs it on the workload where there is actually something to copy. Repeated off-runs land at 100.35, 100.79 and 100.42 and on-runs at 84.04 and 84.58, so this is not one boot's noise.

That is the answer you asked for: it does not beat the core proposer anywhere I can measure, so I am closing this rather than asking for it to be carried. The rule test and the unset-means-off default stay in our tree if anyone wants to revisit copy drafting later - it is a clean change, it is just not faster.

One thing I could not give you: the counters would have been the sharper evidence (accepted per round), and /metrics returns no decode_rounds_total on this build, so the table above is tok/s and digests only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants