Skip to content

Perf: skip redundant CSA scoring and fuse gather unpack - #1195

Merged
zhangqi-chen merged 6 commits into
hw-native-sys:mainfrom
Little-oil:perf/dspark-csa-opt
Sep 11, 2026
Merged

zhangqi-chen merged 6 commits into
hw-native-sys:mainfrom
Little-oil:perf/dspark-csa-opt

Conversation

@Little-oil

@Little-oil Little-oil commented Sep 10, 2026

Copy link
Copy Markdown
Contributor
  • Bypass query scoring and sorting when the ratio-4 cache fits Top-K
    in distributed CSA, retaining causal visibility, cache updates and
    the long-cache path.
  • Read CSA gather payloads directly into typed consumers before epoch
    retirement, removing full packed buffers and separate unpack waves.
    Distributed CSA calls both typed gathers directly; TP1 uses its
    separate decode_csa_tp1 entry. Standalone transport fixtures exercise
    the same typed gathers, replacing their legacy packed implementations.

TP4 CSA at 16x256 on a2a3: minimum per-rank median latency falls from
1010.05 µs to 880.500 µs (12.83%). Measured with PYPTO_BENCH=1,
swimlane0, 100 timed rounds and 5 warmups, with all 400 timed samples
retained.

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Review Change StackReview 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: Advanced

Run ID: b5d50e66-7f11-49e8-92e1-8cab2420681d

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 7fa23168-b998-419d-bf38-013d2aeeb961

📥 Commits

Reviewing files that changed from the base of the PR and between c80a7e3 and 3daaee2.

📒 Files selected for processing (3)
  • models/deepseek_v4_flash_dspark/decode_cp_allgather.py
  • models/deepseek_v4_flash_dspark/decode_csa.py
  • models/deepseek_v4_flash_dspark/decode_indexer.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds typed CSA all-gather pipelines and a TP_SIZE==4 decode fast path. Cache-fitting requests bypass redundant indexer scoring and projection stages. Indexer helper annotations now expose task dependencies required by the new orchestration.

Changes

CSA TP4 decode path

Layer / File(s) Summary
Typed CSA all-gather pipelines
models/deepseek_v4_flash_dspark/decode_cp_allgather.py
Adds main and auxiliary typed all-gather steps. The steps decode gathered payload segments, synchronize workers, retire signals, and return completion dependencies.
TP4 dependency and projection bypasses
models/deepseek_v4_flash_dspark/decode_csa.py, models/deepseek_v4_flash_dspark/decode_indexer.py
For TP_SIZE==4 requests whose compressed cache fits within IDX_TOPK, the orchestration uses typed gathers, skips selected indexer stages, computes bounded indices, and propagates task dependencies through updated return annotations. Existing paths remain for other cases.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant decode_csa
  participant typed_allgather
  participant indexer
  participant outputs
  decode_csa->>typed_allgather: gather typed CSA payloads
  typed_allgather->>outputs: write projection and cache tensors
  decode_csa->>indexer: propagate task dependencies
  indexer->>outputs: write bounded Top-K indices
Loading

Merge Risk: ⚪ Minimal · up to 3daae

The TP4 decode optimization preserves fallback behavior, and no merge-blocking correctness or runtime risk is currently identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files.
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.
Title check ✅ Passed The title clearly summarizes the two main changes: skipping redundant CSA scoring and fusing gather unpacking for performance.
Description check ✅ Passed The description is directly related to the changeset. It explains the TP4 fast path, typed gather integration, retained fallback behavior, and measured performance impact.

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

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

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

Youhezhen added 2 commits September 10, 2026 01:22
- Bypass query scoring and sorting when the ratio-4 cache fits Top-K,
  retaining causal visibility, cache updates and the long-cache path.
- Read CSA gather payloads directly into typed consumers before epoch
  retirement, removing full packed buffers and separate unpack waves.
TP4 CSA at 16x256 on a2a3: average minimum-rank median latency falls
1016.850 -> 880.275 us (13.43%). Average minimum-rank mean latency falls
1027.507 -> 923.736 us (10.10%). Use PYPTO_BENCH=1, swimlane0, 100 timed
rounds and 5 warmups, with all samples retained across AB/BA runs.
@Little-oil Little-oil changed the title Perf: skip redundant TP4 CSA scoring and fuse gather unpack Perf: skip redundant CSA scoring and fuse gather unpack Sep 10, 2026
Youhezhen added 4 commits September 10, 2026 02:27
Call typed allgathers directly and remove the packed gather/unpack
branch, its imports and task-ID array. TP1 is dispatched to its
separate kernel before reaching distributed CSA.

Retain the cache-length conditions without redundant TP guards.
Route the CSA main and aux transport fixtures through the production
typed allgathers. Repack their outputs without numerical conversion
to retain the existing raw-bit and retained-window epoch checks.

Remove both packed allgather implementations now that no callers remain.
- Derive CSA arrival and retirement counts from push/readback workers.
- Share named projection widths and wire offsets across CSA packing,
  typed gathers and their transport fixtures.
- Name indexer dependency slots and CSA pack/visible-index worker sizes.
@zhangqi-chen
zhangqi-chen merged commit 4a49d76 into hw-native-sys:main Sep 11, 2026
11 of 12 checks passed
@Little-oil
Little-oil deleted the perf/dspark-csa-opt branch September 11, 2026 07:54
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