Repository navigation
Conversation
…g window; its context in a ring of that window Every DFlash2 layer is sliding_attention with sliding_window 2048: a context key at distance > 2047 from the query is masked. _dattn_kernel nevertheless looped over every context tile from position 0, and the drafter kept `capacity` rows of keys and values, so a block pass cost grew with the context and the drafter's buffer (and its estimate, which counted two copies) with the window. - _dattn_kernel starts at the 64-row tile holding s - window. The skipped tiles are masked for every query and leave the running max, sum and accumulator bit for bit as they were (max(-1e30, -inf) = -1e30, alpha = 1, p = 0); the tiles run are the same tiles at the same offsets, so the output is the same bits. - Drafter(ring=True), TF_GLM_DRAFT_RING (default 1): keys and values in a ring of draft_ring_rows(2047, 8) = 2,176 rows (window + block + a tile, whole tiles) addressed modulo the ring; the same drafts. TF_GLM_DRAFT_RING=0 keeps the flat buffer; both ranks compare it with their other settings. - decode: take_snapshot copies a ring drafter's window (drafter_rows, 20 MiB a rank at GLM-5.3-Flash-DFlash2's sizes) since the reply overwrites it in the ring; restore puts it back; save_rows drops it with drafter_end; snapshot_bytes counts it against TF_GLM_CACHE_GIB. - geometry.dflash2_geometry: the one context copy the engine allocates, a constant 21.25 MiB ring (was 20,480 B a slot: 20 GiB estimated at a 1,048,576 window). geometry.dflash2_weights / admit(draft_weights=): the drafter as held (4-bit copies, BF16 norms and selector projection, float32 codebooks): 0.63 GiB a rank instead of 4.36 GiB (the checkpoint at 4 bytes a value). One DGX Spark (GB10), kernel only, all 5 layers at one rank's dims: block attention 16.2 -> 0.20 ms at 196k context, 43 -> 0.20 ms at 524k. Tests: tests/cuda/test_glm_draft_ring.py (the window loop and the ring equal the loop from tile 0 bitwise up to 12,345 rows, stale ring rows included; the synthetic drafter's candidates, logits and selector rows bitwise equal flat vs ring over 3.5k-9k contexts, with a kept state restored after the ring wrapped, eager and CUDA graphs); tests/test_glm_draft_ring.py (ring size, estimates, kept-state plumbing on CPU). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014wCj5zx4NuKdUNWUeJi3X1
ashhart
added a commit
that referenced
this pull request
Sep 30, 2026
…keeps DFlash2's ring window (#134) - The lane and prompt matmuls build for Ada (sm_89); sm_90 and newer compile the same kernels as before - CUDA serves on 8.9, NVFP4 and FP8 checkpoints keep a 9.0 floor, and a GPU below its floor is refused at startup - The 27B's startup estimate counts what it loads, and its verify scratch the rows a round takes - The 27B's prompt chunk comes from the GPU's memory: the most rows, up to 4,096, whose arrays fit a 32nd of it - Clones of a 27B state share one attention list, so a grow frees the buffers it replaces - On one GPU the 27B's kept prompt states give way, oldest first, so admission counts one live window - GLM-5.3 on CUDA: a prompt kept one token early keeps DFlash2's ring window, so resends resume with it on (#134) - The Nemotron resume test expects prompts kept one token early (#98) - The vision clone test expects the shared attention list and the carried byte budget
Owner
|
Thanks for this. DFlash2's block attention on GLM now reads only its sliding window, with the context kept in a ring. At 52k tokens that DFlash2 decode went from 37.1 tok/s to 40.1, and the startup estimate from 96.91 GiB to 93.11 GiB a rank. Every reply matched, a resend and the next turn included, and a dip on a 7k prompt did not reproduce. This is in 0.6.0, out tonight. |
ThinkOffApp
added a commit
to ThinkOffApp/TensorFold
that referenced
this pull request
Oct 2, 2026
…ROCm) It came in with ashhart#134 after this PR's ROCm skips; it calls qmm.matmul, which raises on HIP by design. On the Strix it was the only failing GPU-side test file (2 failed), on 0.6.0 and on 0.6.1 alike. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ThinkOffApp
added a commit
to ThinkOffApp/TensorFold
that referenced
this pull request
Oct 2, 2026
…ROCm) It came in with ashhart#134 after this PR's ROCm skips; it calls qmm.matmul, which raises on HIP by design. On the Strix it was the only failing GPU-side test file (2 failed), on 0.6.0 and on 0.6.1 alike. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ThinkOffApp
added a commit
to ThinkOffApp/TensorFold
that referenced
this pull request
Oct 3, 2026
…ROCm) It came in with ashhart#134 after this PR's ROCm skips; it calls qmm.matmul, which raises on HIP by design. On the Strix it was the only failing GPU-side test file (2 failed), on 0.6.0 and on 0.6.1 alike. Co-Authored-By: Claude Opus 5.5 <[email protected]>
BlivionIaG
pushed a commit
to BlivionIaG/TensorFold
that referenced
this pull request
Oct 20, 2026
…keeps DFlash2's ring window (ashhart#134) - The lane and prompt matmuls build for Ada (sm_89); sm_90 and newer compile the same kernels as before - CUDA serves on 8.9, NVFP4 and FP8 checkpoints keep a 9.0 floor, and a GPU below its floor is refused at startup - The 27B's startup estimate counts what it loads, and its verify scratch the rows a round takes - The 27B's prompt chunk comes from the GPU's memory: the most rows, up to 4,096, whose arrays fit a 32nd of it - Clones of a 27B state share one attention list, so a grow frees the buffers it replaces - On one GPU the 27B's kept prompt states give way, oldest first, so admission counts one live window - GLM-5.3 on CUDA: a prompt kept one token early keeps DFlash2's ring window, so resends resume with it on (ashhart#134) - The Nemotron resume test expects prompts kept one token early (#98) - The vision clone test expects the shared attention list and the carried byte budget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR: every layer of GLM-5.3-Flash's DFlash2 drafter is
sliding_attentionwith a 2,048-row window, but_dattn_kernelread every context row from position 0 and masked all but the window, and the drafter keptcapacityrows of keys and values. The block attention now starts at the window's first tile, and the context lives in a ring of window + block + a tile (2,176 rows). Same draft bits; at 196k context the block attention goes from 16.2 ms to 0.20 ms, and the drafter's context memory no longer grows with the window.The problem
_dattn_kernelloopedfor start in range(0, klen, BK): at context endsit loaded every key and value from 0 tos + block, then masked everything older thans - window. A block pass cost grew linearly with the context although only ~2,048 rows can contribute.Drafterallocatedcapacity + blockrows of K/V for each of its 5 layers: 10 KiB a token on each rank, 10 GiB at a 1,048,576-token window. The startup estimate (draft_geometry, shared with the 27B's drafter) counted two copies of it, 20 GiB.The change
dflash2._dattn_kernel): the loop starts at the 64-row tile holdings - window. Every skipped tile is masked for every query, and a fully masked tile leaves the running max, sum and accumulator bit for bit unchanged (max(-1e30, -inf) = -1e30,alpha = exp(0) = 1,p = 0). The tiles that still run are the same tiles at the same offsets, so the output has the same bits.SKIP=Falsekeeps the old loop as the reference the tests compare against.Drafter(ring=True),TF_GLM_DRAFT_RING, default on): keys and values go in a ring ofgeometry.draft_ring_rows(window, block)= 2,176 rows, addressed modulo the ring (RINGin the kernel,Drafter._slotsfor writes). The drafts are unchanged. When the window already exceedscapacity + block, the flat buffer is kept.TF_GLM_DRAFT_RING=0keeps the flat buffer, and it joins the two ranks' settings check.decode): a flat buffer still holds a kept prompt's drafter rows after the reply, but a ring overwrites them. Sotake_snapshotcopies the window (Snapshot.drafter_rows, 20 MiB a rank at DFlash2's sizes),restoreputs it back and refuses a ring restore without one,save_rowsdrops it along withdrafter_end, andsnapshot_bytescounts it withinTF_GLM_CACHE_GIB.geometry.dflash2_geometry,geometry.dflash2_weights,capacity.admit(draft_weights=)): one context copy, the one the engine allocates. With the ring it is a constant 21.25 MiB; flat, it is 10,240 B a slot, where it used to be 20,480. The weights are counted as held: 4-bit copies (k and v twice, as inqkvandkv), BF16 norms and selector projection, and the selector's float32 codebooks. The 27B'sdraft_geometryis untouched.docs/recipes/glm-5.3-flash.md: one paragraph.Measurements
One DGX Spark (GB10), one rank's dimensions of GLM-5.3-Flash-DFlash2 (16 query heads, 4 KV heads, head_dim 128, block 8). These are kernel-only timings of the block attention, not end-to-end decode:
A re-run of the same kernel on this branch, on the same Spark while another model server was resident (one layer, fastest of 7): old loop 0.51 / 6.40 / 17.8 ms at 16k / 196k / 524k, window loop 0.037 ms and ring 0.039 ms at all three. The old loop's absolute times vary with what else holds the memory bus. The new loop's time doesn't depend on the context.
Memory, per rank, at a 1,048,576-token window: the drafter's context is 21 MiB (was 10 GiB allocated and 20 GiB in the estimate). The drafter's weights are estimated at 0.63 GiB (was 4.36 GiB).
Tests
tests/cuda/test_glm_draft_ring.py(new, small, no engine): 8 passed on the Spark.test_glm_enginegives the same candidates, logits and selector rows with the ring as with the flat buffer, bit for bit, over 160 rounds. The contexts run from 3.5k to 9k rows, and a kept state is taken, the ring overwritten by 3,000 rows and the state restored. This runs both eager and with CUDA graphs.tests/test_glm_draft_ring.py(new, CPU): the ring size, both estimates (checked against GLM-5.3-Flash-DFlash2's shapes), and the kept-state plumbing. The plumbing check: after a reply has wrapped the ring three times, a restored state reads the same window as a flat drafter and a cold start, a saved state drops the window, and a ring restore without a window is refused.tensorfoldCUDA image:test_glm_draft_ring,test_glm_cuda_kept,test_cuda_geometry,test_cuda_capacity,test_cuda_admission,test_cuda_failed_admission,test_cuda_parallel_admission,test_flash_capacity_dispatch,test_glm_drafter_choice,test_glm5_memory,test_glm5_next_familyandtest_glm_tool_calls: 188 passed, 2 skipped. The wholetests/directory was not run to completion here: in this image two MLX-only modules fail to collect, and the run was stopped for time.tests/cuda/test_glm_engine.py: 14 passed, 5 errors. The passing tests include DFlash2 replies equal to serial, the drafter choice, and resumed prompts equal to fresh prefills; the ring is on by default there, since 2,176 < 2,560 + 8. The 5 errors are theengine_n(no MTP head, DFlash2 only) andengine_long(past the dense limit) fixtures. Admission refused them ("startup memory budget cannot fit requested context 2600") because another model server was holding that Spark's memory. They didn't run; they did not fail on the change.