[AMD] Fix aiter backend missing ENCODER_ONLY attention support#20102
[AMD] Fix aiter backend missing ENCODER_ONLY attention support#20102nathanrchn wants to merge 6 commits intosgl-project:mainfrom
Conversation
The aiter attention backend hardcoded `causal=True` in forward_extend, unlike other backends (flashinfer, triton, torch_native) which set `causal=False` and `save_kv_cache=False` for ENCODER_ONLY attention. This caused bidirectional embedding models (e.g. pplx-embed-v1) to produce NaN hidden states when batching multiple requests, as the causal mask prevented proper bidirectional attention computation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello, 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 issue in the aiter attention backend on AMD GPUs where bidirectional embedding models produced NaN hidden states due to an incorrectly hardcoded causal mask. The changes introduce dynamic handling of causal attention and KV cache saving based on the attention type, ensuring compatibility and correct behavior for encoder-only models and aligning the aiter backend with other existing attention backends. Highlights
🧠 New Feature in Public Preview: You can now enable Memory 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. Changelog
Activity
Using Gemini Code AssistThe 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
Customization To customize 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a bug in the aiter attention backend where causal=True was hardcoded, leading to incorrect behavior for bidirectional models on AMD GPUs. The fix correctly sets causal=False and disables KV cache saving for ENCODER_ONLY attention, aligning its behavior with other backends. The implementation is sound, and I've offered a minor suggestion to simplify the conditional logic for improved readability and efficiency.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ites Remove `save_kv_cache = False` for ENCODER_ONLY attention. The non-MLA prefill path reads K/V from the cache buffer via kv_indices, so skipping the cache write causes attention to read uninitialized GPU memory, producing NaN hidden states that nan_to_num silently converts to zeros. With disable_radix_cache=True, cache entries are freed after each request anyway, so there is no memory waste from writing them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Motivation
The aiter attention backend hardcoded
causal=Trueinforward_extend, unlike other backends (flashinfer, triton, torch_native) which check forAttentionType.ENCODER_ONLYand setcausal=False+save_kv_cache=False.This caused bidirectional embedding models (e.g.
perplexity-ai/pplx-embed-v1) to produce NaN hidden states when batching multiple requests on AMD GPUs, as the causal mask prevented proper bidirectional attention computation.Modifications
AttentionTypeat runtime (was only underTYPE_CHECKING)ENCODER_ONLYcheck at the start offorward_extendto setcausal=Falseandsave_kv_cache=False, matching the flashinfer backend behaviorcausal=Truewith the computedcausalvariable in both the MLA and non-MLA prefill pathsChecklist
pre-commit run --all-files