Skip to content

fix(inference): skip empty KV pulls for fully cached handoffs - #7838

Closed
adenzhou1350 wants to merge 1 commit into
NVIDIA:mainfrom
adenzhou1350:codex/fix-empty-ssm-kv-pull
Closed

adenzhou1350 wants to merge 1 commit into
NVIDIA:mainfrom
adenzhou1350:codex/fix-empty-ssm-kv-pull

Conversation

@adenzhou1350

Copy link
Copy Markdown
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

Skip an empty KV pull when decode reuses every prompt KV block, while still starting the independent SSM import.

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share a design doc with the team. If you're unsure what's the best way to do so, contact @NVIDIA/mcore-oncall.

_try_start_kv_handoff_import() currently submits begin_pull_blocks() even when the uncached KV suffix is empty. For the PP-metadata path reported in #7837, this can fail before _start_ssm_handoff_import() runs. Guarding the KV submission with imported_blocks leaves its handle as None; existing pending-handle collection already filters None, and SSM transfer startup is unchanged.

The regression covers no/partial/full prefix hits, with and without SSM, and flat/PP metadata. It checks continuation-block ownership and that nonempty suffix transfers still happen.

Issue tracking

For PRs from open-source community contributors:

  • New features: a linked issue is required. Please open a feature request and reference it here before submitting the PR.
  • Small updates (bug fixes, minor improvements): a linked issue is recommended and will accelerate the PR review process.

Linked issue: Fixes #7837

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • If this PR adds or changes a GPU kernel (Triton, jit_fuser/torch.compile, CUDA extension, TE or external-library dispatch, or a scatter/index accumulation), I have added or updated its bit-exact determinism test and registered it in tests/unit_tests/determinism/kernels/manifest.py (guide)
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Verification scope

AI-assisted implementation. CPU source-component checks using the actual method/helper bodies and regression test pass all 12 combinations after the change; the baseline fails the four full-cache combinations. Transfer agents are mocked, and the component loader substitutes the unused SamplingParams constructor. This is not a native NIXL or distributed-suite pass.

Full test collection with CUDA hidden is blocked by the existing import chain reaching ssm/ops/gdp/common.py, which queries device 0. No GB200/NIXL model run or performance result is claimed. Python syntax and git diff --check pass. The Linux autoformatter and official distributed test remain pending.

Suggested targeted CI command:

uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q \
  tests/unit_tests/inference/test_disagg_handoff_lifecycle.py

Kept as Draft pending author review and CI, as required by this repository. This changes handoff control flow, not a numerical kernel.

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"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
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, the Final Review label 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 Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 2, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@adenzhou1350

Copy link
Copy Markdown
Author

Current main already resolves this through the disaggregated-inference update in #6675 (09462ef). The pull path now calls begin_pull_blocks only when imported_blocks is nonempty, independently starts SSM imports, and the new push path similarly prepares KV transfers only for nonempty imports.

Main also includes test_fully_cached_handoff_skips_kv_but_imports_ssm, covering pull/push and hybrid/non-hybrid modes with PP metadata. It asserts no KV transfer call for a fully cached prefix and verifies the independent SSM transfer. The regression and production behavior this PR aimed to add are therefore covered by current main. Closing as superseded, retaining the original branch/history; no new NIXL or distributed/GPU validation is claimed.

Upstream: #6675
Commit: 09462ef

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(inference): handle SSM-only handoff when all KV blocks are cached

1 participant