fix(inference): preserve valid rows, cached KV, and greedy semantics - #7061
Draft
wdykas wants to merge 3 commits into
Draft
fix(inference): preserve valid rows, cached KV, and greedy semantics#7061wdykas wants to merge 3 commits into
wdykas wants to merge 3 commits into
Conversation
Bind the context real-token scalar whenever the NVLS dispatcher is selected, including EP=1, and use it to gate fused-MoE work and mask CUDA-graph padding rows. Preserve the global-to-local count conversion for sequence-parallel shards. Signed-off-by: William Dykas <wdykas@nvidia.com>
Continue redirecting writes into an inherited hash-matched partial block even when a continuation chunk finds no additional complete blocks. Otherwise recomputation can mutate KV shared with another request. Signed-off-by: William Dykas <wdykas@nvidia.com>
Honor the torch backend contract that top_k=1 is greedy. Use first-argmax tie breaking for all-greedy batches, repair greedy rows in mixed batches, and report a one-hot processed distribution for greedy log probabilities. Signed-off-by: William Dykas <wdykas@nvidia.com>
Contributor
Author
|
/claude strict-review |
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 does this PR do?
Fixes three independently reproduced dynamic-inference correctness edge cases that remain on current
main:DynamicInferenceContext._nvls_dispatcheris false at EP=1, although the model still constructsNVLSAllGatherVDispatcher. Consequently, its GPU real-token-count tensor was never bound, andtoken_dispatch()reported the graph-padded local tensor height as valid. This change binds the scalar whenever NVLS is selected, masks routing padding, and converts the global count to an SP-local valid-row count.The write-redirection guard checked only
num_matched_blocksfrom the current chunk. A short, unaligned continuation within a partial block inherited from an earlier prefix match has zero newly matched blocks, so its recomputed KV was written into the shared cached block. This change also checksreq.num_matched_prefix_blocksbefore redirecting those writes to the dummy block.top_k=1is not reliably greedy when maximum logits tie.FlashInfer's threshold-based top-k kernel retains equal logits at the cutoff and can sample among them, whereas
SamplingParamsand the Torch backend definetop_k=1as first-argmax. This change usesargmaxfor all-greedy batches, repairs greedy rows in mixed batches, and returns the corresponding one-hot processed log-probability distribution. The common unfiltered path still returns before the greedy checks.Each issue has a focused regression test that failed on untouched
mainat06a1d8e6fand passes with this branch.Upstream audit
Related candidates were excluded because current
mainalready contains their fixes:f76d34522)6e5a8c11f)d0612089d)487bb3948)Validation
06a1d8e6f: 6 failed and 1 passed across the new focused reproducers.{1: 2087, 3: 2009}; Torch first-argmaxreturned ID1.ruff checkon all changed files: passed.git diff --check: passed.This remains a draft because the complete repository autoformatter is not available in the supplied runtime image.
Issue tracking
Linked issue: N/A
Contribution process
Pre-checks
Code review
Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge this PR.