Fuse DeepSeek MTP verification into decode dispatch - #133
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughChangesDeepSeek V4 fused MTP decode
Sequence Diagram(s)sequenceDiagram
participant DeepSeekV4ModelRunner
participant fused_decode_callable
participant device_buffers
DeepSeekV4ModelRunner->>device_buffers: stage tail tokens, positions, and slots
DeepSeekV4ModelRunner->>fused_decode_callable: dispatch combined main and MTP arguments
fused_decode_callable->>device_buffers: write acceptance counts and sampled IDs
DeepSeekV4ModelRunner->>device_buffers: read outputs and update request state
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
fd69bec to
0a24f3a
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_deepseek_v4.py (1)
1354-1449: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd direct unit coverage for
_stage_fused_mtp_metadata.This test exercises the fused decode dispatch end-to-end, but it stubs
_stage_fused_mtp_metadata(runner._stage_fused_mtp_metadata = lambda _inputs: layout.decode_seq). Its staging logic — writingdecode_tail_token_ids/decode_tail_positions/decode_tail_slot_ids, computingdecode_logit_row_indices, and raisingRuntimeErrorwhen committed tail state is missing — is not directly verified anywhere in this diff.Add a focused unit test for
_stage_fused_mtp_metadata, similar totest_deepseek_stage_mtp_decode_inputs_updates_only_active_prefix_after_first_stepfor the legacy_stage_mtp_decode_inputs.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_deepseek_v4.py` around lines 1354 - 1449, Add a focused unit test for runner._stage_fused_mtp_metadata, modeled on test_deepseek_stage_mtp_decode_inputs_updates_only_active_prefix_after_first_step. Verify it writes decode_tail_token_ids, decode_tail_positions, and decode_tail_slot_ids, computes decode_logit_row_indices correctly, and raises RuntimeError when committed tail state is missing; keep the existing fused-dispatch test unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.agents/skills/profile-dsv4-serving-strace/scripts/analyze_profile.py:
- Around line 339-361: Update the device-effective decode report and table
generation to use the existing main_phase_label variable from the decode-layout
branch instead of hardcoded “main” or “Main Effective” labels. This ensures
two_l2 traces with device STRACE display “Main+verify” consistently while
preserving “Main” for other layouts.
---
Nitpick comments:
In `@tests/test_deepseek_v4.py`:
- Around line 1354-1449: Add a focused unit test for
runner._stage_fused_mtp_metadata, modeled on
test_deepseek_stage_mtp_decode_inputs_updates_only_active_prefix_after_first_step.
Verify it writes decode_tail_token_ids, decode_tail_positions, and
decode_tail_slot_ids, computes decode_logit_row_indices correctly, and raises
RuntimeError when committed tail state is missing; keep the existing
fused-dispatch test unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e1118d41-ae95-4b06-a77e-9bde172ac3e4
📒 Files selected for processing (7)
.agents/skills/profile-dsv4-serving-strace/SKILL.md.agents/skills/profile-dsv4-serving-strace/scripts/analyze_profile.py.agents/skills/profile-dsv4-serving-strace/scripts/render_8lane.pypypto-libpypto_serving/model/deepseek/npu_executor.pypypto_serving/model/deepseek/npu_runner.pytests/test_deepseek_v4.py
c9017fb to
5a01e36
Compare
- Compile a combined main-decode and device-side MTP verification L3. - Keep MTP decode as the second internal L2 submission. - Preserve the non-MTP autoregressive decode path and cover both modes. - Detect legacy four-L2 and current two-L2 layouts in the DSV4 profiling skill. - Update pypto-lib to the fused decode implementation.
Summary
decode_fwd_mtpkernel moduleorigin/maincommitfd91568Why
DeepSeek V4 previously submitted main decode, MTP verification, and MTP draft decode as three L2 callables. The extra verification submission increased host dispatch overhead and heap-ring pressure. The final library layout keeps standalone JIT entrypoints independent from the inline fused implementation.
Impact
The fused path reduces decode L2 submissions from three to two. In the 8-card DP/EP=8 MTP profile with 20 output tokens on a2a3 and PTOAS 0.54, steady critical-rank host decode time decreased from 45.159 ms to 42.980 ms. The same workload completed with a 2 GiB ring heap.
Validation
decode_fwdanddecode_mtppassed on real a2a3 devices_jit_l3_decode_fwd_mtpand returned the expected 10-token completionUses merged hw-native-sys/pypto-lib#884.