Skip to content

perf(deepseek-v4): capture DSA projections and cache writes into the prefill graph - #714

Open
dongjiyingdjy wants to merge 2 commits into
mainfrom
perf/deepseek-v4-prefill-graph-dsa-writes
Open

perf(deepseek-v4): capture DSA projections and cache writes into the prefill graph#714
dongjiyingdjy wants to merge 2 commits into
mainfrom
perf/deepseek-v4-prefill-graph-dsa-writes

Conversation

@dongjiyingdjy

Copy link
Copy Markdown
Contributor

Summary

Narrow the DeepSeek-V4 attention break to the request-dependent DSA core and move the surrounding token-shaped work into the captured prefill-graph segments, removing kernel launches from the eager critical path.

  • E1 — phase-1 Q/KV/QR projections and the compressor-score GEMMs run in the pre-break segment, overlapped on an aux stream.
  • E2 — the attention output projection joins the post-break segment.
  • E3 — the CSA indexer query packing (wq_b / weights_proj / mxfp4) runs pre-break.
  • E4a — per-forward memoization of compressed/state slot mappings, shared across the CSA indexer, the 30 CSA layers, and the C4 compressor.
  • E4b/E4c — the CSA indexer and main C4 compressor state-save + cache-insert writes are captured in the pre-break segment, fed by persistent staging buffers refreshed by prepare/finish_prefill_graph_replay model hooks, with a -1 fail-open contract and a single ctx.dsa_pregraph_writes arm flag so the eager break skips exactly what the captured segment wrote (exactly-once across capture / replay / eager / mixed / decode / MTP-draft).

Structure is unchanged: 61 eager attention breaks / 62 graph segments / 123 callables.

Verification

Verified on top of current origin/main (rebuilt matching tokenspeed-kernel objs + tokenspeed-scheduler 0.1.2 exposing flat_block_tables_arrays):

  • GSM8K (V4-Flash, TP4, 5-shot first-50, greedy): strict 0.98 / flexible 0.98 (gate ≥ 0.92), 0 fatal server lines.
  • Prefill breakable graph engaged on all TP ranks (87 segments, buckets 16–8192), no eager-prefill fallback.
  • CPU unit tests: 65 passed / 5 skipped — pin the control-flow invariants (arm/disarm matrix, skip gates, hook seam, staging bind). Numerical byte-equality is covered by the GPU gates.

🤖 Generated with Claude Code

…prefill graph

Narrow the attention break to the request-dependent DSA core and move the
surrounding token-shaped work into the captured prefill-graph segments:

- E1: phase-1 Q/KV/QR projections and the compressor-score GEMMs run in the
  pre-break segment, overlapped on an aux stream.
- E2: the attention output projection joins the post-break segment.
- E3: the CSA indexer query packing (wq_b/weights_proj/mxfp4) runs pre-break.
- E4a: per-forward memoization of compressed/state slot mappings, shared
  across the CSA indexer, the 30 CSA layers, and the C4 compressor.
- E4b/E4c: the CSA indexer and main C4 compressor state-save + cache-insert
  writes are captured in the pre-break segment, fed by persistent staging
  buffers refreshed by prepare/finish_prefill_graph_replay model hooks, with
  a -1 fail-open contract and a single ctx.dsa_pregraph_writes arm flag so the
  eager break skips exactly what the captured segment wrote (exactly-once
  across capture/replay/eager/mixed/decode/MTP-draft).

Structure stays 61 eager breaks / 62 graph segments / 123 callables. GSM8K
0.96 (strict/flexible) unchanged; TP8 capture smoke clean. New CPU unit tests
pin the control-flow invariants (arm/disarm matrix, skip gates, hook seam,
staging bind); numerical byte-equality is covered by the GPU gates.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: jiyingd <87510204+dongjiyingdjy@users.noreply.github.com>
@dongjiyingdjy
dongjiyingdjy requested a review from a team as a code owner July 17, 2026 15:02
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