Skip to content

[BugFix][xlite] Fix index_full_mask type checking in extract_kv_cache - #16879

Closed
Cancan0320 wants to merge 1 commit into
vllm-project:mainfrom
Cancan0320:fix/xlite-index-full-mask-mypy-16658
Closed

Cancan0320 wants to merge 1 commit into
vllm-project:mainfrom
Cancan0320:fix/xlite-index-full-mask-mypy-16658

Conversation

@Cancan0320

@Cancan0320 Cancan0320 commented Sep 18, 2026 •

Copy link
Copy Markdown

What this PR does / why we need it?

DeepseekV32XliteModel.extract_kv_cache() directly accesses
self.xlite_config.index_full_mask. However, XModelConfig does not
statically declare this attribute; it is assigned dynamically in
_build_model_config().

As a result, mypy reports:

vllm_ascend/xlite/xlite.py:
error: "XModelConfig" has no attribute "index_full_mask" [attr-defined]

This type-checking error can cause the repository-wide pre-commit/mypy
job to fail, including for PRs unrelated to xlite.

This PR uses the same safe access pattern already used in
_build_model():

getattr(self.xlite_config, "index_full_mask", None)

If the attribute is unavailable or empty, it falls back to an all-True
mask, preserving the existing fallback behavior.

Fixes #16658

Does this PR introduce any user-facing change?

No API or configuration changes.

For normally initialized xlite configurations, runtime behavior remains
unchanged. If index_full_mask is unavailable, the code now safely uses
the existing all-True fallback instead of directly accessing a missing
attribute.

How was this patch tested?

No new runtime test was added because this is a static type-checking fix
and does not change the normal KV-cache extraction behavior.

The following checks passed:

mypy --follow-imports skip \
  --check-untyped-defs \
  --python-version 3.12 \
  vllm_ascend

ruff check vllm_ascend/xlite/xlite.py
ruff format --check vllm_ascend/xlite/xlite.py
git diff --check

The original index_full_mask [attr-defined] mypy error is no longer
reported.

extract_kv_cache() read self.xlite_config.index_full_mask directly, but XModelConfig does not statically declare that attribute (it is set dynamically in _build_model_config). mypy reports "XModelConfig" has no attribute "index_full_mask" [attr-defined], which blocks the repository-wide pre-commit/mypy job for unrelated PRs.

Use the same safe getattr(self.xlite_config, "index_full_mask", None) access already used in _build_model(), falling back to a full-True mask. Runtime behavior is unchanged for all cases where the attribute is set.

Fixes vllm-project#16658

Signed-off-by: cancan <luckycan@foxmail.com>
@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 static type-checking failure in the 'DeepseekV32XliteModel' class. By using 'getattr' to safely access 'index_full_mask', the code avoids triggering mypy errors caused by dynamically assigned attributes, ensuring that repository-wide type checks pass successfully without altering runtime logic.

Highlights

  • Type Safety Improvement: Replaced direct attribute access of 'index_full_mask' with 'getattr' to resolve mypy 'attr-defined' errors.
  • Fallback Logic Preservation: Maintained the existing fallback behavior, ensuring an all-True mask is used if the attribute is missing or empty.
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. ↩

@github-actions

Copy link
Copy Markdown
Contributor

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

@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][BugFix] Safely retrieve index_full_mask from xlite_config

Suggested PR Summary:

### What this PR does / why we need it?
This PR updates the retrieval of `index_full_mask` from `self.xlite_config` to use `getattr(self.xlite_config, 'index_full_mask', None)` instead of direct attribute access. This prevents potential `AttributeError` exceptions if the attribute is missing from the configuration. It also adds a type annotation `list[bool]` to `index_mask`.

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

### How was this patch tested?
No tests were provided in this PR.

There are no review comments to address.

@github-actions

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!

@Cancan0320

Copy link
Copy Markdown
Author

Thanks for the review.

After checking the latest main, I found that #16626 had already introduced
the same safe getattr() access before this PR was opened.

Therefore, this PR is now redundant and conflicts with the latest main.
Closing it as superseded by #16626.

@Cancan0320 Cancan0320 closed this Sep 18, 2026
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.

[CI][xlite] Fix repository-wide mypy failure for index_full_mask

1 participant