Skip to content

flashnext cuda: hold two graphs per window graph cache slot - #2815

Closed
ashhart wants to merge 1 commit into
mainfrom
lead/fn-window-graph-ways
Closed

ashhart wants to merge 1 commit into
mainfrom
lead/fn-window-graph-ways

Conversation

@ashhart

@ashhart ashhart commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

A Flash Next window pass on CUDA alternates between a stream's state and its spare from round to round, and the head's inputs alternate too, so the one-graph-per-slot window_graph.Cache re-recorded a slot's graph on 57% of window passes: a recent device log showed 283 graph updates against 212 replays.

What changes (zig/src/families/flashnext/cuda_window_graph.zig): each slot holds two graphs with least-recently-used eviction.

  • A round replays a graph only when its whole key matches (pointers, sizes and shapes), as before.
  • Otherwise the slot's second way is captured, or, with both ways full, the older one is re-recorded in place.
  • The total stays capped at 128 held graphs, and the capture-failure fallback to eager launches is unchanged.
  • The way choice sits inline in run() rather than in a separate function; the tests drive it through a fake driver.
  • The capture log now also prints when clear() drops held graphs, and its every-64 interval counts updates as well as captures.

Kernels, arguments and replies are unchanged. Only how often a graph is captured changes.

Checks: zig build test-flashnext-window-graph-host passes, 31/31. The tests cover a two-state ping-pong that hits after the first two captures, a third key evicting the least recently used one, replays only on an exactly matching key, the 128-graph cap, and capture counts before and after. zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu passes, zig fmt --check is clean, and the lean count is unchanged.

Still to run before landing: Qwen3.8-Flash-Next (MLX 4-bit or FP4-Local) on one GB10, where window graphs are on (they're off at TP=2, so the two-GB10 NVFP4 setup can't exercise this). Main against this branch, base-new-new-base with run 1 dropped, MTP drafting on, 1 and 4 streams, chat and code, greedy and seeded. Tokens must be equal on every request, decode at least level, a cold 4K first token level, and graph records per 100 verify rounds down.

  • Synthena (Ash's Agent)

A Flash Next window pass alternates between a stream's state and its
spare from round to round, and its head inputs alternate too, so the
one-graph-per-slot cache re-recorded the slot's graph almost every
round. Each slot now holds two graphs with least-recently-used
eviction: a round replays a graph only when its whole key (pointers,
sizes and shapes) matches, otherwise the second way is captured or the
older one is re-recorded in place. The total stays capped at 128 held
graphs. Kernels, arguments and replies are unchanged; only how often a
graph is captured changes.
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner Author

Device result on one GB10 (Qwen3.8-Flash-Next MLX 4-bit, MTP on, main against this head, base-new-new-base, run 1 dropped): replies identical (0 of 20 prompt rows differ) and decode level. Code and chat at 1, 2, 4 and 8 streams, greedy and sampled, all moved between -0.3% and +0.2%. Holding two graphs per slot doesn't change throughput on this setup, so this stays a draft rather than landing.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Closing: holding two graphs per slot came out level on a GB10 (-0.3% to +0.2%, replies identical), so it doesn't earn its place. The measurement stays here for reference.

  • Synthena (Ash's Agent)

@ashhart ashhart closed this Nov 14, 2026
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.

1 participant