Skip to content

[BugFix] Fix replicated SFA indexer cache metadata under DCP - #16174

Open
Ruiqiu-Zheng wants to merge 5 commits into
vllm-project:mainfrom
Ruiqiu-Zheng:fix/sfa-replicated-indexer-dcp-metadata-b9f77
Open

Ruiqiu-Zheng wants to merge 5 commits into
vllm-project:mainfrom
Ruiqiu-Zheng:fix/sfa-replicated-indexer-dcp-metadata-b9f77

Conversation

@Ruiqiu-Zheng

@Ruiqiu-Zheng Ruiqiu-Zheng commented Sep 9, 2026 •

Copy link
Copy Markdown

What this PR does

#15669 split the SFA indexer into an independent AscendSFAIndexerBackend with its own physical cache and metadata builder. Under replicated SFA DCP, the common attention metadata is restored to the local SFA KV view before the independent indexer metadata is built, while the indexer cache remains physically replicated. That can make the indexer's block table / slot mapping address a different physical layout than its own cache.

This patch keeps ownership at the independent indexer boundary and composes the retained SFA DCP cache addresses before the indexer forward:

  • plain DCP / DSA-DCP reuse SFA's retained replicated (or DSA-padded) slot_mapping and replicated block table;
  • PCP+DCP reuses the pcp_slot_mapping produced by [Feature][MRV2] sfa support dcp +pcp #15809, without adding another PCP reorder or collective;
  • LI C8 under replicated DCP does not reuse reshape groups derived from the restored local slots; it falls back to the normal k/scale scatter path with the composed replicated slots;
  • geometry mismatches fail closed, and shared metadata is not mutated.

No key-domain sharding, GlobalTopK, score-publication ABI, or new collective is introduced.

Validation

  • dependency-light host oracle: 35 cases passed;
  • real 2-NPU defect reproduction: for logical target 16384, the pre-fix path mapped to 8192 while the candidate returned 16384;
  • production-shaped correctness coverage included B2/B4 at 128K and 256K plus mixed B4 64K/128K/256K/312K;
  • PCP2+DCP2 real-NPU HCCL canary: candidate used 4 slots versus the pre-fix local 2-slot view; all four Native LI targets hit the expected 16384/16512 addresses; an intentionally wrong unreordered-slot sensitivity control removed all four targets.

Current upstream already provides dependency-complete CI surfaces for MRV2 PCP+DCP graph execution (#15809) and for replicated DSA-DCP + LI C8 + MTP3 full-decode graph accuracy. Candidate-specific CI is intentionally left to the PR CI rather than a separate overlay environment.

Current PR-head validation

Current PR head: 24f178d7d06439a19f53c69e728e951a30b1303f.

  • PR E2E #29228: pre-commit and dependency-complete CPU UT passed. The run-level ci-gate is still blocked because the PR does not yet have the maintainer-only ready-precise label, so its selected NPU matrix was not triggered.
  • Author-triggered targeted A3 four-card /e2e run #220 passed on the current PR code for both vLLM refs (v0.28.0 and b2f685834a6456197e7033966fdef52a23f1abcd). It covered:
    • replicated DSA-DCP + LI C8 + MTP3 + FULL_DECODE_ONLY graph accuracy;
    • MRV2 PCP2 + DCP4 replicated-indexer + FULL_DECODE_ONLY graph accuracy.

These results support candidate-specific upstream CPU and targeted A3 NPU correctness only. Formal PR selected-test/ci-gate closure still requires ready-precise, and merge still requires the repository's human approval policy.

This is a correctness fix; no performance or production-gain claim is made.

Signed-off-by: Ruiqiu Zheng 191817791+Ruiqiu-Zheng@users.noreply.github.com

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-09T14:56:07.108730Z 24f178d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.


Tip

💡 Consider Linking a Related Issue or RFC

Your PR title contains the [BugFix] tag, indicating a bug fix or new feature.

Linking a related issue or RFC in the PR description is strongly encouraged — it gives reviewers helpful context and speeds up the review. You can use any of these keywords:

  • Fixes #<issue_number>
  • Closes #<issue_number>
  • Resolves #<issue_number>
  • Refs #<rfc_or_issue_number> (for RFCs)

🙏 Thanks for helping us keep the project well-organized!

Copy link
Copy Markdown
Author

CI trigger note: this PR changes vllm_ascend/** / unit-test source paths. In current pr_test.yaml, select-tests and the selected NPU jobs require a run-enabling label; ready-precise is the minimal appropriate mode for this scoped correctness fix. Could a maintainer add ready-precise? ready-all is not necessary.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical metadata alignment issue between the independent SFA indexer and the replicated DCP cache layout. By ensuring the indexer consumes the correct replicated cache addresses, it prevents physical layout mismatches that previously led to incorrect address mapping. The changes introduce a composition layer at the SFA boundary to maintain ownership and integrity of the cache metadata during forward passes.

Highlights

  • Metadata Composition: Introduced compose_indexer_cache_metadata to correctly align the independent SFA indexer's cache addresses with the replicated DCP (Decode Context Parallel) layout.
  • Reshape Optimization: Disabled LI C8 reshape optimizations when DCP is active to prevent geometry mismatches and ensure correct cache mapping.
  • Correctness Fix: Ensured that the indexer's block table and slot mapping are derived from the SFA's retained replicated view rather than local restored slots, preventing address layout conflicts.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Suggested PR Title:

[Attention][Feature] Support replicated DCP indexer handoff and compose indexer cache metadata

Suggested PR Summary:

### What this PR does / why we need it?
This PR introduces support for replicated Decode Context Parallel (DCP) indexer handoff in the SFA attention backend. It adds the `compose_indexer_cache_metadata` function to use SFA's retained replicated DCP addresses for the independent cache, bypassing local-slot C8 reshape optimizations when DCP is active. This ensures proper metadata composition at the SFA boundary.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Added unit tests in `tests/ut/attention/test_indexer.py` to verify that the metadata builder skips local reshape groups under DCP and that `compose_indexer_cache_metadata` correctly uses the pre-gather replicated DCP view.

I have no further feedback as there are no review comments to address.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b9f77ccd76

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vllm_ascend/attention/indexer.py Outdated
def _use_c8_reshape_optim(self) -> bool:
"""Whether this indexer can use the LI C8 cache-write operator."""
return self.enable_sparse_li_c8 and get_ascend_config().c8_reshape_optim_enabled
return self.enable_sparse_li_c8 and not self._dcp_active and get_ascend_config().c8_reshape_optim_enabled

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Initialize _dcp_active in direct-construction fixtures

When the existing LI-C8 tests construct AscendSFAIndexerBackend via __new__ (tests/ut/ops/test_mla.py in test_write_cache_scatter_path and test_write_cache_reshape_optim_path), they set enable_sparse_li_c8 but not the newly required _dcp_active. Both tests now raise AttributeError here before reaching their cache-write assertions; either make this lookup tolerate legacy/direct construction or initialize the field in those fixtures so the existing unit suite remains green.

AGENTS.md reference: AGENTS.md:L362-L364

Useful? React with 👍 / 👎.

@Ruiqiu-Zheng

Ruiqiu-Zheng commented Sep 9, 2026 •

Copy link
Copy Markdown
Author

/e2e tests/e2e/pull_request/four_card/context_parallel/test_accuracy.py::test_models_dcp_full_feature_accuracy[dsv3_2_sfa_dcp_replicated_indexer] tests/e2e/pull_request/four_card/context_parallel/test_accuracy_v2.py::test_dsv3_2_sfa_pcp_dcp_model_runner_v2_graph_accuracy
[Bot]: e2e command triggered. See workflow run for details.
[Bot]: e2e command completed successfully.

@Ruiqiu-Zheng

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 24f178d7d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vllm_ascend/attention/sfa_v1.py Outdated
slot_mapping_sfa = self._get_sfa_kv_slot_mapping(attn_metadata)
indexer_attn_metadata = self._get_indexer_attn_metadata()
if indexer_attn_metadata is not None:
indexer_attn_metadata = compose_indexer_cache_metadata(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indexer_attn_metadata 不应该依赖sfa的metadata,要解耦

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已按建议解耦,更新在 d96bbe229e1dcf5c1dd77b26ed9a346680ad3b03。现在 replicated-DCP 的 block table / slot mapping 由 AscendSFAIndexerMetadataBuilder 在 indexer 侧构造和持有,SFA forward 不再通过 SFA attention metadata 去 compose indexer_attn_metadata。PCP ordered slots、DSA-CP padding 以及 LI-C8 + DCP 兼容行为都保留,并补了 focused UT。当前 pre-commit 正在新 HEAD 上重跑。

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Signed-off-by: Ruiqiu Zheng <191817791+Ruiqiu-Zheng@users.noreply.github.com>
Signed-off-by: Ruiqiu Zheng <191817791+Ruiqiu-Zheng@users.noreply.github.com>
Signed-off-by: Ruiqiu Zheng <191817791+Ruiqiu-Zheng@users.noreply.github.com>
Signed-off-by: Ruiqiu Zheng <191817791+Ruiqiu-Zheng@users.noreply.github.com>
Signed-off-by: Ruiqiu Zheng <191817791+Ruiqiu-Zheng@users.noreply.github.com>
@Ruiqiu-Zheng
Ruiqiu-Zheng force-pushed the fix/sfa-replicated-indexer-dcp-metadata-b9f77 branch from 403e555 to 0d4bd0c Compare September 12, 2026 03:25
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

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.

2 participants