Skip to content

fix: enhance attention module with query observation and legacy support - #2466

Merged
xin3he merged 2 commits into
mainfrom
xinhe/10-10
Oct 14, 2026
Merged

xin3he merged 2 commits into
mainfrom
xinhe/10-10

Conversation

@xin3he

@xin3he xin3he commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Description

  • tiny 模型 (tiny-random/kimi-k2.6 fixed in enhance attention module with original implementation retrieval… #2408):attention 统一调用 ALL_ATTENTION_FUNCTIONS[...],所以会进入 QuantizedAttentionImpl.forward() 并更新 q_scale。
  • 真实模型 (fixed here):模型仓库自带的 attention 直接调用 torch.matmul 或 flash_attn_func,完全绕过这个入口。模块被识别出来并注册了 q_scale,但统计代码一次都没执行,所以 q_scale 一直是初始值 0。

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:

  • Added _patch_legacy_attention and 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)
  • Updated init_hooked_attention to detect and patch legacy modules, logging a message when this occurs. (auto_round/experimental/attention.py, auto_round/experimental/attention.pyR219-R226)
  • Introduced _unpatch_legacy_attention to remove dynamic patches during cleanup. (auto_round/experimental/attention.py, [1] [2]

Query observation and calibration improvements:

Type of Change

Bug fix

Related Issues

Fixes or relates to #

Checklist Before Submitting

  • My code has been tested locally.
  • Documentation has been updated as needed.
  • New or updated tests are included where applicable.
  • The CUDA CI has passed. You can trigger it by commenting /azp run Unit-Test-CUDA-AutoRound.

Copilot AI balanced review requested due to automatic review settings October 10, 2026 03:00

Copilot AI 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.

🟡 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.

Comment thread auto_round/experimental/attention.py
Signed-off-by: Xin He <xin3.he@intel.com>
@AutoRoundBot

Copy link
Copy Markdown
Collaborator

/azp run Unit-Test-CUDA-AutoRound

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@xin3he
xin3he merged commit 376fdc0 into main Oct 14, 2026
54 checks passed
@xin3he
xin3he deleted the xinhe/10-10 branch October 14, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants