[Fix] Avoid CUDA sync in DeepSeek-V4 prefill token metadata - #5016
Open
adenzhou1350 wants to merge 1 commit into
Open
adenzhou1350 wants to merge 1 commit into
adenzhou1350 wants to merge 1 commit into
Conversation
Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
This branch has not been deployed
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.
Motivation
build_prefill_token_metatakes itsarangesize fromcu_q_seqlens[-1]. The CUDA prefill caller builds these cumulative lengths on the device, so that scalar conversion synchronizes even though the helper claims not to. The flattened input's token count is already available from its shape.Modification
Pass
step_ctx.input_ids.numel()through_precompute_prefillto an optional keyword-onlytotal_tokensargument. Calls that omit it retain the existing behavior. Token mappings and dtypes are unchanged; the docstring now describes the fallback accurately.Validation
called a synchronizing CUDA operationin sync-debug mode, both with and without supplied cumulative lengths. The host-count path passes that check.pytest tests/pytorch/kernel/test_v4_utils.py -q: 26 passed, covering CPU/CUDA, empty/mixed sequence lengths, optional cumulative lengths/count, output dtype/device, and the sync regression.git diff --checkpass.The tests directly load the actual standalone helper with real Torch operations, not mocked tensor behavior. This is component validation, not a full DeepSeek-V4 model benchmark or a whole-model speedup claim. Full package import was blocked by missing
mmenginelocally; pre-commit environment bootstrap was blocked by Windows application control. Upstream package/CI coverage is still needed.