Skip to content

Flash Next CUDA (0.6.1 port): the lone stream's graph slot keeps its rows, so its graphs are captured once - #180

Closed
jschmied wants to merge 4 commits into
ashhart:pr-141-0.6.1from
jschmied:solo-graph-keep
Closed

jschmied wants to merge 4 commits into
ashhart:pr-141-0.6.1from
jschmied:solo-graph-keep

Conversation

@jschmied

@jschmied jschmied commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

On the 0.6.1 port, every resize of the lone stream's graph slot drops its graphs: _grow and _shrink call
_state_changed. The slot starts at 256 rows, grows to 8,192 once a reply's context passes them, and shrinks back when
the request ends. So every lone request recaptures its graphs mid-reply: 23 captures, 3.0 s of a 512-token reply on a
GB10. Two and four streams lose 8–11 % the same way, because the first stream starts alone in the slot.

  • The slot keeps its rows when idle. It gives them back only when memory is short: an evicted kept end, the newest
    stream ending, or an idle slot freed for another stream's growth.
  • It grows by doubling (at least STEP rows), so a long session recaptures a handful of times rather than every request.
  • warm() captures its graphs last. Before, the warm request grew the slot after the captures, which discarded them.
  • A different lone request takes the slot without dropping its graphs. A finished request's prompt end is kept in the
    slot it ran in, so the next lone request with another prompt landed elsewhere, and _move_to_solo made that slot the
    graph slot (_state_changed, a full recapture each request). Now the kept prompt end moves to a free slot of the same
    rows (copy_from; its snapshot is unchanged). With no free slot that fits without evicting, the old swap stays.
  • copy_from takes a source with fewer rows into its first rows, because the graph slot now keeps more rows than a
    stream moving in may have. Rows past pos are written before they are read. A larger source is refused.

Two ranks: rank 0 plans on Shadows of the slots, dec.solo.st included, so _is_solo compares the slots the
Shadows stand for. Keeping the rows records only a reset for rank 1, and a release records the resize like any other.
(The first commit compared a Shadow with the real slot and never matched while planning, so it did nothing on two ranks.
BHCC2025's two-rank run showed it. Fixed in the second commit.) Two ranks keep the slot swap for kept prompt ends,
because the plan names kept ends by slot.

Measured

One GB10, Flash Next EXL3 3.05bpw, greedy, 512 tokens of code per stream, two starts each:

0.6.0 cb5101d this PR
--parallel 4, one request (ms/token) 13.63 / 13.52 18.41 / 18.56 12.18 / 12.20
--parallel 1 (ms/token) 12.09 / 12.19 12.33 / 12.15 12.18 / 12.19
two streams (tok/s) 111.9 / 111.5 99.8 / 99.1 111.7 / 110.8
four streams (tok/s) 158.4 / 157.9 146.8 / 145.1 157.6 / 157.8
graph captures inside the reply (one / two streams) — 23 / 8 0 / 0

Every reply is byte-identical in all three columns.

Lone requests one after another with different prompts (--parallel 4, 256 tokens each; the last request resumes the
first one's kept prompt end):

cb5101d this PR
graph captures per request 33 / 32 / 30 / 19 0 / 0 / 0 / 0
ms/token 31.6 / 29.4 / 27.3 / 23.0 14.0 / 12.7 / 11.7 / 12.1

The replies are byte-identical, including the resumed one.

Tests

tests/test_cuda_growing_caches.py:

  • The new test checks that the slot keeps its rows across a request's end and gives them to another stream when the
    gate is short. It also checks that the slot grows 8,192 → 16,384 → 32,768 → the window.
  • A second test drives the slot through a Shadow while planning: it is recognised, keeping its rows records only a
    reset, and a release records the resize. It fails on the first commit.
  • The file's decoder helper now sets the port's new attributes (solo, solo_on, planning). Its three existing
    decoder tests failed on cb5101d with AttributeError: ... 'solo' and pass again.
  • Two more tests (third commit): a lone stream moves into a graph slot with more rows (no resize, rows and positions
    carried), and a different lone request takes the graph slot while the kept prompt end moves to a free slot with its
    rows. Both fail on the second commit (a size mismatch in copy_from; the slot swapped).
  • The file passes 10 of 10. Fourth commit (by @plotarmordev): tests/cuda/test_flashnext_tp_multi.py's lone-stream test
    asserts the new behaviour (the graph slot and its graphs kept, the first prompt's kept end moved, not evicted).
    With it, test_cuda_growing_caches.py and tests/cuda/test_flashnext_{tp_multi,multi,tp,prompt_cache,kvquant}.py
    give 180 passed, 1 skipped on one GB10 here (178 / 3 on theirs). tests/cuda/test_flashnext_multi.py passes 27 of 27 on this PR and on cb5101d.

I ran the 14 multi-decoder host test files on both commits. This PR fails 29, cb5101d fails 32, and the 29 are a
subset of the 32 (211 pass here). The remainder fail on this machine for other reasons (mostly mlx not installed).

Not covered: int8/int4 KV, a two-rank run of the second and third commits (one GPU here), and a server under memory pressure with
the slot holding its rows.

Written with AI assistance (Claude Code); the author reviewed every change.

…its graphs are captured once

On the 0.6.1 port every resize of the solo slot (`_grow`, `_shrink`) drops its graphs through `_state_changed`, and
a slot starts at 256 rows and shrinks back after each request. A lone request therefore recaptured its graphs
mid-decode whenever its context passed the slot's rows: 23 captures, 3.0 s of a 512-token reply on a GB10.

- The solo slot keeps its rows when idle; it gives them back only when memory is short (an evicted kept end,
  the newest stream ending, or an idle solo slot freed for another stream's growth).
- It grows by doubling (at least STEP rows), so a long session recaptures a handful of times, not every request.
- `warm()` captures its graphs last, at the rows requests will find (the warm request had grown the slot after
  the captures, which discarded them).

tests/test_cuda_growing_caches.py: the slot keeps its rows across a request's end, gives them to another stream when
the gate is short, and grows 8192 -> 16384 -> 32768 -> the window; its decoder helper sets the port's new attributes
(`solo`, `solo_on`, `planning`), so the file's three existing decoder tests run again on the port.

GB10, EXL3 3.05bpw, greedy, 512 tokens, two starts: a streams=4 engine serving one request 18.41/18.56 ->
12.18/12.20 ms/token (= streams=1's 12.18/12.19); two streams 99.8/99.1 -> 111.7/110.8 tok/s and four
146.8/145.1 -> 157.6/157.8 (0.6.0: 111.9/111.5 and 158.4/157.9). No captures during any measured reply; every
reply byte-identical to its solo run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011SuBgdp87NbfLbiigmzn1z
Jürgen Schmied and others added 2 commits October 1, 2026 14:47
…an Shadows too

On two ranks, rank 0 plans on Shadows of the slots, and `dec.solo.st` is itself a Shadow there. `_is_solo` unwrapped
only its argument, so it was never true while planning: the two-rank path kept resizing the graph slot (and
recapturing its graphs) as before ashhart#180. It now compares the slots the Shadows stand for, and an idle graph slot can be
released under memory pressure while planning too (its resize is recorded for rank 1 like any other).

tests/test_cuda_growing_caches.py: through a Shadow, the graph slot is recognised, keeping its rows records only a
reset, and a release records the resize. The test fails on 6a3a8b1 (`_is_solo(Shadow)` is False).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011SuBgdp87NbfLbiigmzn1z
…thout dropping its graphs

Two paths still dropped or broke the graph slot after the first request:

- A lone request's prompt end is kept in the slot it finished in, the graph slot. The next lone request with another
  prompt landed elsewhere and `_move_to_solo` made that slot the graph slot instead (`_state_changed`, a full
  recapture). On one GB10, Flash Next EXL3, a --parallel 4 engine, four 256-token requests with three prompts:
  32 / 30 / 19 graph captures (3.8 / 3.6 / 2.3 s) on every request after the first. Now the kept prompt end moves
  to a free slot of the same rows (`copy_from`, its snapshot unchanged) and the request takes the graph slot. If no
  free slot fits without evicting, the old swap stays. On two ranks the kept ends are named by slot in the plan, so
  they keep the swap too.
- With the graph slot keeping its rows, a lone stream from a smaller slot no longer has the same geometry, and
  `copy_from` failed on the cache tensors' sizes. `copy_from` now takes a source with fewer rows into its first rows
  (rows past `pos` are written before they are read) and refuses a larger one.

The same four requests: 0 captures each, 14.0 / 12.7 / 11.7 / 12.1 ms/token (0.6.1 port: 31.6 / 29.4 / 27.3 / 23.0),
every reply byte-identical to the port's, including the one that resumes the moved prompt end.

tests/test_cuda_growing_caches.py: a lone stream moves into a graph slot with more rows (no resize, rows and positions
carried); a different lone request takes the graph slot while the kept prompt end moves to a free slot with its
rows. Both fail on 6ada832 (a size mismatch in copy_from; the graph slot swapped).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011SuBgdp87NbfLbiigmzn1z
@jschmied

jschmied commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

A third commit, 5824347, fixes two paths the first two missed. Each new lone request with a different prompt still recaptured every graph, because the previous request's kept prompt end held the slot. copy_from could also fail on sizes once the slot kept its rows. With four lone requests on --parallel 4 there are now 0 captures each (was 33/32/30/19), and every reply is byte-identical. Details are in the description.

Written with AI assistance (Claude Code).

@plotarmordev

Copy link
Copy Markdown
Contributor

Ran #180 at 5824347 on two DGX Sparks (same setup as my #141 run: 2x GB10, direct 200G RoCE, NGC pytorch:26.07-py3, Vontra/Qwen3.8-Flash-Next-MLX-4bit-MTP @ dadefa80, --tp 2 --context 65536 --parallel 8), against pr-141-0.6.1 at cb5101db in the same session.

Tests. One GPU test fails on #180, both cases: tests/cuda/test_flashnext_tp_multi.py::test_a_lone_stream_retargets_the_graphs_without_discarding_kept_prefixes[bf16|int8]. It still asserts the old slot swap (start is not first_slot, the first prompt's kept end left in that slot), which the third commit intentionally replaces. I updated it to assert the new behaviour: the second lone request ends in the graph slot, the slot's graphs are not dropped (_state_changed not called on it), the first prompt's kept end is moved rather than evicted, replies equal fresh runs and the resume still hits. It fails on cb5101db and passes on #180:
plotarmordev@4a5385d (branch pr180-gpu-test-update, one file on top of 5824347).
With it, test_cuda_growing_caches.py and tests/cuda/test_flashnext_{tp_multi,multi,tp,prompt_cache,kvquant}.py give 178 passed, 3 skipped on a GB10.

Exactness on two ranks (by token_sha), int8 and bf16 KV: tools/bench_concurrent.py --levels 1,2,4,8 --alone --serial --reps 3 had every concurrent reply equal to its solo run and every solo run equal to "draft": false (180 and 72 checks per run, 0 unequal), and my extra checks passed 13/13 on each dtype (alone → mixed → alone with joins at token 1/8/22, hang-ups in prefill and decode, resumed turns, structured-output refusals). No errors on either rank.

Speed, aggregate tok/s, medians of 3, int8 (baseline without --parallel at e5f50dd / cb5101db / #180):

Users code greedy code sampled chat greedy chat sampled
1 112.1 / 105.6 / 110.5 124.0 / 115.8 / 116.8 94.0 / 84.4 / 87.9 82.8 / 76.8 / 77.9
2 111.8 / 193.8 / 195.6 112.0 / 142.4 / 134.0 92.4 / 160.3 / 162.9 85.6 / 109.9 / 119.3
4 111.6 / 336.5 / 341.9 106.3 / 171.6 / 202.4 91.3 / 276.2 / 287.8 83.8 / 160.7 / 167.9
8 110.4 / 532.5 / 554.0 107.7 / 260.6 / 282.1 93.1 / 458.5 / 471.9 83.0 / 230.0 / 237.0

Lone requests one after another (512 tokens, greedy, six different prompts then the first again): the first after startup went from 67.0 to 108.7 tok/s (the warm captures are no longer thrown away), the others gained 3-5%. On two ranks a different prompt still takes the slot swap, as the code says (_relocate_kept is one GPU only), so the remaining single-request gap there is that path.

In my opinion #180 is merge ready, with the test update above.

…nd its graphs

ashhart#180's third commit moves a kept prompt end out of the graph slot (one GPU) so a different
lone request takes the slot without dropping its graphs. The GPU test still asserted the old
swap (the request in another slot), so it failed on ashhart#180 (bf16 and int8). It now asserts the
new behaviour: the request ends in the graph slot, the slot's graphs are not dropped, the first
prompt's kept end is moved rather than evicted, replies equal fresh runs and the resume still
hits. Fails without ashhart#180, passes with it.
@jschmied

jschmied commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the run and the test fix. I hadn't run test_flashnext_tp_multi.py, and you're right that it still
asserted the old swap. Your commit is on #180 now as yours (d2e651a).
On one GB10 the set you listed passes: 180 passed, 1 skipped (test_cuda_growing_caches.py and tests/cuda/test_flashnext_{tp_multi,multi,tp,prompt_cache,kvquant}.py).

The single-request gap left on two ranks is the swap: rank 0's plan names kept prompt ends by slot, so
_relocate_kept only runs on one GPU. Carrying "move this kept end to that slot" in the plan, for rank 1 to replay
like a resize, would close it. That's a separate change, if wanted.

Written with AI assistance (Claude Code).

@SvangenStudios

Copy link
Copy Markdown

Ran d2e651a on one DGX Spark (GB10, NGC pytorch:26.07-py3, one rank) with the NVFP4 export local-inference-lab/Qwen3.8-Flash-Next-NVFP4 @ 7c4f1bc1, against its base cb5101d, as a data point beside the EXL3 runs.

tests/test_cuda_growing_caches.py and tests/cuda/test_flashnext_tp_multi.py: 45 passed. Greedy replies on 6 fixed prompts are byte-identical between cb5101d and this PR, also identical to v0.6.1, and identical between --parallel 4 and --parallel 1 on this PR.

I could not reproduce the speed regression on this NVFP4 checkpoint, so these runs don't show a speedup either. That says nothing about the EXL3 numbers in the description, which used a different checkpoint. Median of two runs, 512 greedy tokens per stream:

cb5101d --parallel 4 #180 --parallel 4 #180 --parallel 1
one request (tok/s) 36.0 34.4 36.9
two streams (aggregate tok/s) 56.6 58.3 —
four streams (aggregate tok/s) 85.8 87.8 —
four different lone requests in a row (mean tok/s) 39.9 40.2 46.0

The one-request differences are within run-to-run spread (cb5101d 37.3/34.8, #180 33.3/35.5). Unlike the EXL3 table (18.41 ms/token for cb5101d at --parallel 4), cb5101d one request at --parallel 4 is level with v0.6.1 here (36.3 tok/s). I did not count graph captures, so I can't say whether the recaptures happened here and cost little, or didn't happen. One thing that may or may not be noise: four short lone requests in a row ran about 15 % faster at --parallel 1 than at --parallel 4, with and without this PR (only four requests, wide spread).

@jschmied

jschmied commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@SvangenStudios thanks for the NVFP4 run. On our NVFP4 export (ModelOpt, NVFP4 experts, block-FP8 dense; one GB10) the
recaptures do happen on cb5101d and #180 removes them, two rounds, greedy replies identical:

ms/token cb5101d #180
--parallel 1 engine, one request 15.93 / 15.90 16.05 / 15.87
--parallel 4 engine, one request 21.29 / 20.86, 21 captures 15.95 / 15.95, 0
four different lone requests in a row 20.9–31.1, 26–29 captures each 13.8–18.5, 0

Our one-request speed is 63 tok/s against your 36, at every setting, so something else may bound your decode. Your
startup lines would tell: "N decode graphs captured" and whether the mapped n-gram tables fit ("do not fit ... page them
from disk").

Written with AI assistance (Claude Code).

@SvangenStudios

Copy link
Copy Markdown

Thanks, that pointed the right way. The startup lines speak against n-gram paging as the cause: the tables fit ("n-gram tables read in 0.6s", no "do not fit" line). --parallel 1 reports "21 decode graphs captured" and --parallel 4 "0" at startup, which says nothing about captures later in a reply. Most of the gap was my prompts. I reran #180 (d2e651a) on the same NVFP4 export with server-side numbers, one request at a time, greedy, 512 tokens, each prompt twice:

prompt --parallel 1 decode_tps accepted / drafted tokens per round --parallel 4 (wall clock)
long story (2 prompts) 35.7–36.8 229/375, 230/379 (61 %) 1.81 35.7–36.7
code, LRU cache class 45.0–46.3 298/405 (74 %) 2.40 45.1–46.2
code, CSV parser 60.0–61.7 371/454 (82 %) 3.63 43.2 then 61.3

A round takes about 50–60 ms whatever the prompt, so the drafts decide the speed. On code that drafts well this export reaches ~61 tok/s, close to your 63; my earlier 36 was the story prompts, at 1.8 tokens a round. At --parallel 4 the server doesn't report decode_tps, so that column is wall clock, a different measure from the --parallel 1 column. The two are close on every prompt except the first CSV request (43.2, rerun 61.3), with the same round counts and accepted counts within one. On these prompts, I found no large single-request penalty from --parallel 4 on this export with #180. I didn't rerun these prompts on cb5101d, so this isn't a measured gain from the PR.

@grearjake-star

Copy link
Copy Markdown
Contributor

Data point from a single-GPU port of this (GB10, Flash Next EXL3 4.05 bpw, our fork on 0.6.x, --parallel 4 --decode-share 0.25 --context 262144), in case it helps:

  • Lone stream under --parallel: household median 47.8 → 60.85 tok/s with the graph slot (the single-stream server does ~60–64 on the same box). Aggregate also up: 2 streams 74.6 → 78.0, 4 streams 96.7 → 101.3 tok/s.
  • Exactness: lone jobs equal the single-stream server's household hashes 12/12; every stream equals its solo run 12/12 at 2 and at 4 streams.

One case we hit that may also apply here: once every pool slot held a kept prompt end, the slot logic moved the graphs to the newly admitted request's slot and recaptured them on every request — lone speed fell to 39.6 tok/s. What fixed it for us: a new prompt takes the graph slot at admission (the kept end there moves out), and a resumed request that needs a slot evicts the oldest other kept end instead of the graphs. With that, captures stay at one set across requests. We also found waiting streams' pending DeltaNet rows needed folding before other rounds reuse the scratch (latent on our base, not specific to this PR).

Still eager in our port: lone streams with a grammar constraint and requests with drafts off. Happy to share the port/regression test if useful.

Written with AI assistance (Claude Code).

ashhart pushed a commit that referenced this pull request Oct 3, 2026
…its graphs are captured once

On the 0.6.1 port every resize of the solo slot (`_grow`, `_shrink`) drops its graphs through `_state_changed`, and
a slot starts at 256 rows and shrinks back after each request. A lone request therefore recaptured its graphs
mid-decode whenever its context passed the slot's rows: 23 captures, 3.0 s of a 512-token reply on a GB10.

- The solo slot keeps its rows when idle; it gives them back only when memory is short (an evicted kept end,
  the newest stream ending, or an idle solo slot freed for another stream's growth).
- It grows by doubling (at least STEP rows), so a long session recaptures a handful of times, not every request.
- `warm()` captures its graphs last, at the rows requests will find (the warm request had grown the slot after
  the captures, which discarded them).

tests/test_cuda_growing_caches.py: the slot keeps its rows across a request's end, gives them to another stream when
the gate is short, and grows 8192 -> 16384 -> 32768 -> the window; its decoder helper sets the port's new attributes
(`solo`, `solo_on`, `planning`), so the file's three existing decoder tests run again on the port.

GB10, EXL3 3.05bpw, greedy, 512 tokens, two starts: a streams=4 engine serving one request 18.41/18.56 ->
12.18/12.20 ms/token (= streams=1's 12.18/12.19); two streams 99.8/99.1 -> 111.7/110.8 tok/s and four
146.8/145.1 -> 157.6/157.8 (0.6.0: 111.9/111.5 and 158.4/157.9). No captures during any measured reply; every
reply byte-identical to its solo run.

fix(qwen4_exp cuda): the graph slot is recognised through rank 0's plan Shadows too

On two ranks, rank 0 plans on Shadows of the slots, and `dec.solo.st` is itself a Shadow there. `_is_solo` unwrapped
only its argument, so it was never true while planning: the two-rank path kept resizing the graph slot (and
recapturing its graphs) as before #180. It now compares the slots the Shadows stand for, and an idle graph slot can be
released under memory pressure while planning too (its resize is recorded for rank 1 like any other).

tests/test_cuda_growing_caches.py: through a Shadow, the graph slot is recognised, keeping its rows records only a
reset, and a release records the resize. The test fails on 6a3a8b1 (`_is_solo(Shadow)` is False).

fix(qwen4_exp cuda): a different lone request takes the graph slot without dropping its graphs

Two paths still dropped or broke the graph slot after the first request:

- A lone request's prompt end is kept in the slot it finished in, the graph slot. The next lone request with another
  prompt landed elsewhere and `_move_to_solo` made that slot the graph slot instead (`_state_changed`, a full
  recapture). On one GB10, Flash Next EXL3, a --parallel 4 engine, four 256-token requests with three prompts:
  32 / 30 / 19 graph captures (3.8 / 3.6 / 2.3 s) on every request after the first. Now the kept prompt end moves
  to a free slot of the same rows (`copy_from`, its snapshot unchanged) and the request takes the graph slot. If no
  free slot fits without evicting, the old swap stays. On two ranks the kept ends are named by slot in the plan, so
  they keep the swap too.
- With the graph slot keeping its rows, a lone stream from a smaller slot no longer has the same geometry, and
  `copy_from` failed on the cache tensors' sizes. `copy_from` now takes a source with fewer rows into its first rows
  (rows past `pos` are written before they are read) and refuses a larger one.

The same four requests: 0 captures each, 14.0 / 12.7 / 11.7 / 12.1 ms/token (0.6.1 port: 31.6 / 29.4 / 27.3 / 23.0),
every reply byte-identical to the port's, including the one that resumes the moved prompt end.

tests/test_cuda_growing_caches.py: a lone stream moves into a graph slot with more rows (no resize, rows and positions
carried); a different lone request takes the graph slot while the kept prompt end moves to a free slot with its
rows. Both fail on 6ada832 (a size mismatch in copy_from; the graph slot swapped).
ashhart pushed a commit that referenced this pull request Oct 3, 2026
…nd its graphs

#180's third commit moves a kept prompt end out of the graph slot (one GPU) so a different
lone request takes the slot without dropping its graphs. The GPU test still asserted the old
swap (the request in another slot), so it failed on #180 (bf16 and int8). It now asserts the
new behaviour: the request ends in the graph slot, the slot's graphs are not dropped, the first
prompt's kept end is moved rather than evicted, replies equal fresh runs and the resume still
hits. Fails without #180, passes with it.
@ashhart

ashhart commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied. The lone stream's graph slot now keeps its rows and its captured graphs, in TensorFold 0.6.4: https://github.com/ashhart/TensorFold/releases/tag/v0.6.4

Your first fix is in under your name. Your two follow-ups (the slot recognised through rank 0's plan, and a different lone request keeping the graphs) are in too, but they were folded into our commit fdf456f, so the history does not show your name on them. Sorry about that; the release notes credit you, and we have changed how we land follow-ups so it does not happen again. It passed the same two-Spark exactness run as #141. Great find.

@ashhart ashhart closed this Oct 3, 2026
@jschmied
jschmied deleted the solo-graph-keep branch October 11, 2026 17:36
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…its graphs are captured once

On the 0.6.1 port every resize of the solo slot (`_grow`, `_shrink`) drops its graphs through `_state_changed`, and
a slot starts at 256 rows and shrinks back after each request. A lone request therefore recaptured its graphs
mid-decode whenever its context passed the slot's rows: 23 captures, 3.0 s of a 512-token reply on a GB10.

- The solo slot keeps its rows when idle; it gives them back only when memory is short (an evicted kept end,
  the newest stream ending, or an idle solo slot freed for another stream's growth).
- It grows by doubling (at least STEP rows), so a long session recaptures a handful of times, not every request.
- `warm()` captures its graphs last, at the rows requests will find (the warm request had grown the slot after
  the captures, which discarded them).

tests/test_cuda_growing_caches.py: the slot keeps its rows across a request's end, gives them to another stream when
the gate is short, and grows 8192 -> 16384 -> 32768 -> the window; its decoder helper sets the port's new attributes
(`solo`, `solo_on`, `planning`), so the file's three existing decoder tests run again on the port.

GB10, EXL3 3.05bpw, greedy, 512 tokens, two starts: a streams=4 engine serving one request 18.41/18.56 ->
12.18/12.20 ms/token (= streams=1's 12.18/12.19); two streams 99.8/99.1 -> 111.7/110.8 tok/s and four
146.8/145.1 -> 157.6/157.8 (0.6.0: 111.9/111.5 and 158.4/157.9). No captures during any measured reply; every
reply byte-identical to its solo run.

fix(qwen4_exp cuda): the graph slot is recognised through rank 0's plan Shadows too

On two ranks, rank 0 plans on Shadows of the slots, and `dec.solo.st` is itself a Shadow there. `_is_solo` unwrapped
only its argument, so it was never true while planning: the two-rank path kept resizing the graph slot (and
recapturing its graphs) as before ashhart#180. It now compares the slots the Shadows stand for, and an idle graph slot can be
released under memory pressure while planning too (its resize is recorded for rank 1 like any other).

tests/test_cuda_growing_caches.py: through a Shadow, the graph slot is recognised, keeping its rows records only a
reset, and a release records the resize. The test fails on 6a3a8b1 (`_is_solo(Shadow)` is False).

fix(qwen4_exp cuda): a different lone request takes the graph slot without dropping its graphs

Two paths still dropped or broke the graph slot after the first request:

- A lone request's prompt end is kept in the slot it finished in, the graph slot. The next lone request with another
  prompt landed elsewhere and `_move_to_solo` made that slot the graph slot instead (`_state_changed`, a full
  recapture). On one GB10, Flash Next EXL3, a --parallel 4 engine, four 256-token requests with three prompts:
  32 / 30 / 19 graph captures (3.8 / 3.6 / 2.3 s) on every request after the first. Now the kept prompt end moves
  to a free slot of the same rows (`copy_from`, its snapshot unchanged) and the request takes the graph slot. If no
  free slot fits without evicting, the old swap stays. On two ranks the kept ends are named by slot in the plan, so
  they keep the swap too.
- With the graph slot keeping its rows, a lone stream from a smaller slot no longer has the same geometry, and
  `copy_from` failed on the cache tensors' sizes. `copy_from` now takes a source with fewer rows into its first rows
  (rows past `pos` are written before they are read) and refuses a larger one.

The same four requests: 0 captures each, 14.0 / 12.7 / 11.7 / 12.1 ms/token (0.6.1 port: 31.6 / 29.4 / 27.3 / 23.0),
every reply byte-identical to the port's, including the one that resumes the moved prompt end.

tests/test_cuda_growing_caches.py: a lone stream moves into a graph slot with more rows (no resize, rows and positions
carried); a different lone request takes the graph slot while the kept prompt end moves to a free slot with its
rows. Both fail on 6ada832 (a size mismatch in copy_from; the graph slot swapped).
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…nd its graphs

ashhart#180's third commit moves a kept prompt end out of the graph slot (one GPU) so a different
lone request takes the slot without dropping its graphs. The GPU test still asserted the old
swap (the request in another slot), so it failed on ashhart#180 (bf16 and int8). It now asserts the
new behaviour: the request ends in the graph slot, the slot's graphs are not dropped, the first
prompt's kept end is moved rather than evicted, replies equal fresh runs and the resume still
hits. Fails without ashhart#180, passes with it.
kelchm pushed a commit to kelchm/TensorFold that referenced this pull request Nov 7, 2026
…model wrote (2x DGX Sparks recipe issue ashhart#180)

A tool parameter whose schema names no type - `{}`, a description alone, or a reference that resolves nowhere (a
missing definition, a cycle, a bad pointer) - came back to the client as a JSON string holding the object the model
wrote: `"payload":"{\"id\": 7, \"tags\": [\"alpha\", \"beta\"]}"`. Reproduced on this pair 2026-11-04 with an
agent-style tool whose `payload` carried only a description. Upstream keeps an untyped value as text (v1.1.2's rule);
this recipe follows the maintainer's decision on MiaAI-Lab/GLM-5.3-Flash-EXL3-2x-DGX-Sparks-TensorFold#180 (reported
by jsfs11, traced by SvangenStudios): decode when the schema admits an object or array or is untyped and the text
parses as a JSON object or array; scalars, plain words and JSON-quoted strings stay the text the model wrote. A union
that admits an object already decoded one here.

- tool_params.decode: an untyped schema goes through `untyped`, which parses the text (whole, or left open and closed
  as a typed object is) and keeps an object or array; `schemaUntyped` names the condition. Tests: `{}` and a
  description-only schema with an object, an array, an open object, and seven texts that stay text.
- tool_stream: an untyped parameter's key is held until its value's first non-blank byte: `{` or `[` buffers the
  value and decodes it at the close, as a typed value is; anything else streams as text exactly as before (a tool
  declared without a parameter schema keeps streaming its arguments). A value closed before any byte is the empty
  string; a value the reply's end cut short is sent whole as a string.
- tool_union_witness: the six cases where a kind-less reference carried an object (cycle, missing definition, bad
  pointer, type-free definition) now expect the object, with the divergence from upstream noted at the gate.

Host tests: test-tool-parse-host (43), test-tool-visibility-http-host, test-json-answer-host, check-native-cuda-host
pass; the cold host suites give the base tree's failure set (tool_stream_test's cut and witness cases included).

Origin: MiaAI-Lab/GLM-5.3-Flash-DGX-Sparks-1104@13f2464 patches/engine 0105-server-an-untyped-tool-parameter-takes-the-JSON-object-or-array-the-model-wrote.patch sha256:28729a0cbb6cb39d07f3f5d07ac1ab1868814b62c5da7ad0c679a1595b9df8f9
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.

5 participants