Repository navigation
fix: enhance attention module with query observation and legacy support - #2466
Merged
Merged
Conversation
Signed-off-by: Xin He <xin3.he@intel.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Direct FlashAttention calls remain unobserved, cleanup can remove existing overrides, and legacy paths lack tests.
1 open finding
What changed in this PR
Adds query calibration for legacy attention modules that bypass Transformers’ AttentionInterface.
Changes:
- Extracts query observation into
observe. - Patches legacy eager and FlashAttention methods.
- Warns when calibration never observes a module.
| File | Description |
|---|---|
auto_round/experimental/attention.py |
Adds legacy attention observation, patching, and cleanup. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Collaborator
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines successfully started running 1 pipeline(s). |
chensuyue
approved these changes
Oct 14, 2026
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.

Description
This pull request adds support for observing and calibrating legacy attention modules that do not use the standard
AttentionInterface. The changes introduce mechanisms to patch such modules, ensuring query statistics are collected correctly during calibration. Additionally, cleanup logic is improved to handle unobserved modules.Legacy attention module support:
_patch_legacy_attentionand related helpers to dynamically patch attention modules that bypass the standard interface, enabling observation of query tensors at the kernel boundary. (auto_round/experimental/attention.py, auto_round/experimental/attention.pyL112-R186)init_hooked_attentionto detect and patch legacy modules, logging a message when this occurs. (auto_round/experimental/attention.py, auto_round/experimental/attention.pyR219-R226)_unpatch_legacy_attentionto remove dynamic patches during cleanup. (auto_round/experimental/attention.py, [1] [2]Query observation and calibration improvements:
observemethod, and ensured it is called in both standard and legacy paths. (auto_round/experimental/attention.py, auto_round/experimental/attention.pyR101-R113)clean_up_hooked_attentionto warn if a module was never observed during calibration, preventing silent failures. (auto_round/experimental/attention.py, auto_round/experimental/attention.pyR249-R254)Type of Change
Bug fix
Related Issues
Fixes or relates to #
Checklist Before Submitting
/azp run Unit-Test-CUDA-AutoRound.