Skip to content

Perf: early-resolve the DeepSeek-V4 Flash CSA decode producers - #915

Merged
zhangqi-chen merged 1 commit into
hw-native-sys:mainfrom
Hzfengsy:perf/dsv4-flash-csa-early-resolve
Aug 7, 2026
Merged

zhangqi-chen merged 1 commit into
hw-native-sys:mainfrom
Hzfengsy:perf/dsv4-flash-csa-early-resolve

Conversation

@Hzfengsy

@Hzfengsy Hzfengsy commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Mark six CSA decode producers allow_early_resolve=True so the scheduler
    may stage them speculatively: rmsnorm_rope_cache_write
    (decode_compressor_ratio4), weights_proj_reduce (decode_indexer),
    kv_and_cache_write (decode_indexer_compressor), and kv_touch,
    qk_pv, and rope_cs (decode_sparse_attn_csa).
  • Apply the same set to both the deepseek_v4_flash_dspark and
    deepseek_v4_flash_mtp trees. Scheduling hints only; no kernel math,
    tiling, or dependency edge changes.

Every touched scope is reached only through the CSA decode path. The shared
qkv_proj_rope inline kernel is deliberately left alone: decode_swa,
decode_hca, prefill_csa, prefill_swa, prefill_hca, and the
prefill_cp_* flows all call it, and none of them receive these CSA hints,
so changing its early-resolve state would alter unbenchmarked callers.

Benchmark setup

Measured with PYPTO_BENCH=1 (the repository default 100 measured rounds
after 5 warmup launches) on one a2a3 card, physical device 0, via
python models/deepseek_v4_flash_<tree>/decode_csa.py -p a2a3 -d 0.

The two trees run different token counts at their defaults (dspark T=32,
mtp T=8), so the trees are not comparable to one another -- only each tree
against itself. All twelve runs below passed golden validation for both
kv_cache and x_out.

Three independent before/after launch pairs were run per tree, alternating
the patch in and out, because a single pair cannot separate the shift from
the within-run spread (roughly 45us peak-to-peak on dspark).

Results: median effective_us

deepseek_v4_flash_dspark (T=32):

Pair Before After Delta
1 654.6 646.9 -7.7
2 652.2 637.1 -15.1
3 646.6 636.8 -9.8
mean 651.1 640.3 -10.9 (-1.7%)

deepseek_v4_flash_mtp (T=8):

Pair Before After Delta
1 365.3 358.5 -6.8
2 369.6 355.6 -14.0
3 365.9 356.0 -9.9
mean 366.9 356.7 -10.2 (-2.8%)

All six paired deltas are negative, and the per-run minima separate
cleanly in both trees (dspark after 606.7-628.3 against before
630.3-634.9; mtp after 346.0-349.7 against before 355.0-358.3). The
dspark medians do overlap in one pair (after 646.9 against before 646.6),
so the dspark result rests on the paired comparison rather than on
disjoint median ranges.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c5517b9b-86c8-4043-9383-9a37ab6b18ab

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR adjusts allow_early_resolve across DeepSeek V4 dspark and MTP decode scopes. It enables early resolution for decode, cache-write, and sparse-attention stages, while removing it from the qr_rms_norm_quant loop.

Changes

DeepSeek early-resolution scope tuning

Layer / File(s) Summary
Decode and cache-write scope updates
models/deepseek_v4_flash_dspark/decode_compressor_ratio4.py, models/deepseek_v4_flash_dspark/decode_indexer.py, models/deepseek_v4_flash_dspark/decode_indexer_compressor.py, models/deepseek_v4_flash_mtp/...
Decode compressor, indexer reduction, and KV cache-write scopes now enable allow_early_resolve=True.
Sparse-attention scope updates
models/deepseek_v4_flash_dspark/decode_sparse_attn_csa.py, models/deepseek_v4_flash_mtp/decode_sparse_attn_csa.py
The kv_touch, qk_pv, and rope_cs scopes now enable early dependency resolution.
QKV projection resolution adjustment
models/deepseek_v4_flash_dspark/qkv_proj_rope.py, models/deepseek_v4_flash_mtp/qkv_proj_rope.py
The qr_rms_norm_quant loops no longer enable early resolution.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Poem

A bunny checks each task in line,
Early resolve makes timing fine.
Cache writes hop, sparse paths flow,
QKV waits where defaults say so.
Carrots cheer the scopes tonight! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main scheduling optimization for DeepSeek-V4 Flash CSA decode producers.
Description check ✅ Passed The description accurately explains the scheduling hint changes, affected trees, benchmark results, and validation status.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e5f11c1e6e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread models/deepseek_v4_flash_mtp/qkv_proj_rope.py Outdated
## Summary

- Mark six CSA decode producers `allow_early_resolve=True` so the scheduler
  may stage them speculatively: `rmsnorm_rope_cache_write`
  (`decode_compressor_ratio4`), `weights_proj_reduce` (`decode_indexer`),
  `kv_and_cache_write` (`decode_indexer_compressor`), and `kv_touch`,
  `qk_pv`, and `rope_cs` (`decode_sparse_attn_csa`).
- Apply the same set to both the `deepseek_v4_flash_dspark` and
  `deepseek_v4_flash_mtp` trees. Scheduling hints only; no kernel math,
  tiling, or dependency edge changes.

Every touched scope is reached only through the CSA decode path. The shared
`qkv_proj_rope` inline kernel is deliberately left alone: `decode_swa`,
`decode_hca`, `prefill_csa`, `prefill_swa`, `prefill_hca`, and the
`prefill_cp_*` flows all call it, and none of them receive these CSA hints,
so changing its early-resolve state would alter unbenchmarked callers.

## Benchmark setup

Measured with `PYPTO_BENCH=1` (the repository default 100 measured rounds
after 5 warmup launches) on one a2a3 card, physical device 0, via
`python models/deepseek_v4_flash_<tree>/decode_csa.py -p a2a3 -d 0`.

The two trees run different token counts at their defaults (dspark T=32,
mtp T=8), so the trees are not comparable to one another -- only each tree
against itself. All twelve runs below passed golden validation for both
`kv_cache` and `x_out`.

Three independent before/after launch pairs were run per tree, alternating
the patch in and out, because a single pair cannot separate the shift from
the within-run spread (roughly 45us peak-to-peak on dspark).

## Results: median effective_us

deepseek_v4_flash_dspark (T=32):

| Pair | Before | After | Delta |
| ---: | ---: | ---: | ---: |
| 1 | 654.6 | 646.9 | -7.7 |
| 2 | 652.2 | 637.1 | -15.1 |
| 3 | 646.6 | 636.8 | -9.8 |
| mean | 651.1 | 640.3 | -10.9 (-1.7%) |

deepseek_v4_flash_mtp (T=8):

| Pair | Before | After | Delta |
| ---: | ---: | ---: | ---: |
| 1 | 365.3 | 358.5 | -6.8 |
| 2 | 369.6 | 355.6 | -14.0 |
| 3 | 365.9 | 356.0 | -9.9 |
| mean | 366.9 | 356.7 | -10.2 (-2.8%) |

All six paired deltas are negative, and the per-run minima separate
cleanly in both trees (dspark after 606.7-628.3 against before
630.3-634.9; mtp after 346.0-349.7 against before 355.0-358.3). The
dspark medians do overlap in one pair (after 646.9 against before 646.6),
so the dspark result rests on the paired comparison rather than on
disjoint median ranges.
@Hzfengsy
Hzfengsy force-pushed the perf/dsv4-flash-csa-early-resolve branch from e5f11c1 to 3b3fe13 Compare August 7, 2026 07:01
@zhangqi-chen
zhangqi-chen merged commit d5e3995 into hw-native-sys:main Aug 7, 2026
9 of 11 checks passed
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