Skip to content

fix: skip const-fold for arange for attention mask - #4452

Open
fs-eire wants to merge 2 commits into
pytorch:mainfrom
fs-eire:sdpa-constant-fold-fix
Open

fix: skip const-fold for arange for attention mask#4452
fs-eire wants to merge 2 commits into
pytorch:mainfrom
fs-eire:sdpa-constant-fold-fix

Conversation

@fs-eire

@fs-eire fs-eire commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Description

This change introduced a const-fold exclusion rule "attention_mask_arange". With this rule, generated causal mask will be preserved as operations so that later TRT/Myelin can correctly generate optimized layer.

#4450 is required as prerequisite for this PR.

Fixes # (issue)

Type of change

  • 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 30, 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 labels Jul 30, 2026
@github-actions
github-actions Bot requested a review from narendasan July 30, 2026 22:43
def test_decomposed_attention_mask_aranges_are_not_folded(self):
self._assert_only_attention_aranges_survive(decompose_attention=True)

def test_ia_attention_mask_aranges_are_not_folded(self):

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.

What is "ia"? Is this a typo?

from typing import Any, Optional

import torch
from torch_tensorrt.dynamo.lowering.constant_fold_exclusions._core import (

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.

Shouldnt we eagerly import attention_mask here, or via the package init, so the rule is always registered when this pass runs?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants