dspark perf optimization#1698
Merged
Merged
Conversation
Contributor
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the DSpark speculative-decode hot path by removing per-decode-step GPU→CPU synchronization points and rebuilding parts of the ragged-input assembly to avoid host round-trips.
Changes:
- Replaces a DSpark-only
aten::itemscalar read inEagleProposer.prepare_inputs()with an on-device clamp. - Reworks
_ragged_fill_deferred_all_same()to assemble ragged deferredinput_idsdirectly on the GPU buffer and zero-fill graph tail padding on-device.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
atom/spec_decode/eagle.py |
Removes a per-step GPU scalar read by clamping token indices fully on-device for DSpark. |
atom/model_engine/model_runner.py |
Replaces CPU scatter + D2H/H2D rebuild of ragged deferred input_ids with a GPU-side gather/select write into the flat buffer, plus GPU tail zeroing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+628
to
+633
| seq_of_pos = np.repeat(np.arange(bs, dtype=np.int64), lens) # [total] | ||
| local_of_pos = np.arange(total, dtype=np.int64) - cu[seq_of_pos] | ||
| dev = self.prev_token_ids.device | ||
| seq_t = torch.as_tensor(seq_of_pos, device=dev) | ||
| local_t = torch.as_tensor(local_of_pos, device=dev) | ||
| anchor_vals = self.prev_token_ids[seq_t] # [total] |
valarLip
approved these changes
Jul 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Remove two DSpark-only per-decode-step host syncs from the spec-decode hot path (both gated on
use_dspark/ the ragged path; plain V4 never hits them).before

after

eagle.pyprepare_inputs—int(cu_seqlens_q[-1])read a GPU scalar back to the host every decode step (aten::item→_local_scalar_dense→hipMemcpyWithStream). The copy is stream-ordered after the whole decode kernel, so the CPU blocked until the GPU queue drained, collapsing CPU/GPU overlap into a ping-pong. Replaced with an on-device clamp (torch.minimumagainst a 0-dim device scalar);clamp_(min=0)on the bound preserves the oldtotal_tokens > 0guard.model_runner_ragged_fill_deferred_all_same— assembled ragged decodeinput_idsvia 2× D2H (prev/draft ids) + a Python per-seq scatter loop + a full H2D each step (the two D2H also forced a sync on the sampler/draft kernels). Rebuilt entirely on-device (gather anchors/drafts + masked select), mirroring the rectangular all-same path.Impact
Restores CPU/GPU overlap on the DSpark ragged + PIECEWISE + DP-attention decode path. The large
aten::itemspan disappears from the profiler trace and decode throughput improves.Validation
--ignore-eos; MTP acceptance rate unchanged. Change Update logo #2 altersinput_idsassembly — please confirm before merge.