Skip to content

Fix the Qwen GQA test failure.#4385

Merged
SandSnip3r merged 2 commits into
pytorch:mainfrom
SandSnip3r:dev-fix-gqa-bug
Jul 10, 2026
Merged

Fix the Qwen GQA test failure.#4385
SandSnip3r merged 2 commits into
pytorch:mainfrom
SandSnip3r:dev-fix-gqa-bug

Conversation

@SandSnip3r

Copy link
Copy Markdown
Collaborator

Description

Fix the Qwen GQA test failure.

The Qwen GQA test failed in the decomposed variant due to the intemediate between the matmuls being downcast to fp16. Plumb use_fp32_acc through the dynamo backend.
Pick a specific seed for the GQA test.
Reenable GQA test for fp16.

Type of change

Please delete options that are not relevant and/or add your own.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@meta-cla meta-cla Bot added the cla signed label Jul 6, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: lowering Issues re: The lowering / preprocessing passes component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: torch_compile labels Jul 6, 2026
@github-actions github-actions Bot requested a review from narendasan July 6, 2026 22:20
@narendasan narendasan requested a review from zewenli98 July 6, 2026 22:25

@zewenli98 zewenli98 left a comment

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.

@SandSnip3r The idea looks good! The decomposed attention path needs the entire computation in FP32, not just matmul.

My only concern is that the definition of use_fp32_acc currently suggests FP32 applies only to matmul, whereas this implementation extends it to the whole attention path. It may help to clarify that in the definition, for example by noting that [op1, op2, ...] will use FP32 for the full computation rather than matmul alone for accuracy.

@SandSnip3r

Copy link
Copy Markdown
Collaborator Author

My only concern is that the definition of use_fp32_acc currently suggests FP32 applies only to matmul, whereas this implementation extends it to the whole attention path. It may help to clarify that in the definition, for example by noting that [op1, op2, ...] will use FP32 for the full computation rather than matmul alone for accuracy.

Yeah, I understand that. I don't necessarily love my overloading of the fp32 accumulation flag for this exact reason.

I have a comment inside scaled_dot_product_attention_decomposition specifically for this, as it's a behavior that's specific to this decomposition.

Are you proposing something different? Possibly commenting about the option's behavior with regard to sdpa in CompilationSettings?

@zewenli98

Copy link
Copy Markdown
Collaborator

My only concern is that the definition of use_fp32_acc currently suggests FP32 applies only to matmul, whereas this implementation extends it to the whole attention path. It may help to clarify that in the definition, for example by noting that [op1, op2, ...] will use FP32 for the full computation rather than matmul alone for accuracy.

Yeah, I understand that. I don't necessarily love my overloading of the fp32 accumulation flag for this exact reason.

I have a comment inside scaled_dot_product_attention_decomposition specifically for this, as it's a behavior that's specific to this decomposition.

Are you proposing something different? Possibly commenting about the option's behavior with regard to sdpa in CompilationSettings?

Yeah it's very clear for developers to see your comments inside scaled_dot_product_attention_decomposition. For users, I think it would be clear if we add the op-specific explanations in public API docs like CompilationSettings, compile(), cross_compile_for_windows(), convert_exported_program_to_serialized_trt_engine() and anywhere it's documented. Eventually they will be shown in the doc.

The Qwen GQA test failed in the decomposed variant due to the intemediate between the matmuls being downcast to fp16.
Plumb use_fp32_acc through the dynamo backend.
Pick a specific seed for the GQA test.
Reenable GQA test for fp16.
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 10, 2026
@SandSnip3r

Copy link
Copy Markdown
Collaborator Author

Ok, I've gone through and added comments about attention, on the fp32_acc flag, when decompose_attention is also set

@zewenli98 zewenli98 left a comment

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.

LGTM

@SandSnip3r SandSnip3r merged commit 6998ab5 into pytorch:main Jul 10, 2026
113 of 127 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: tests Issues re: Tests component: torch_compile documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants