Skip to content

Fix fbcode CI torch.compile fusion with newer PyTorch#2567

Open
choijon5 wants to merge 1 commit into
mainfrom
fix-fbcode-torch-compile-fusion
Open

Fix fbcode CI torch.compile fusion with newer PyTorch#2567
choijon5 wants to merge 1 commit into
mainfrom
fix-fbcode-torch-compile-fusion

Conversation

@choijon5
Copy link
Copy Markdown
Contributor

@choijon5 choijon5 commented May 23, 2026

Fix Helion torch.compile fusion failures seen in fbcode CI with a newer PyTorch/Inductor version.

Newer Inductor rejects template prologue fusion when the template scheduler node reports mutation. PyTorch PR pytorch/pytorch#185317 adds a template hook for that gate, and this Helion change implements the hook instead of monkey patching SchedulerNode.

Helion allows independent non-mutated prologue producers while still blocking aliases, real mutations, direct mutation inputs, and producers that read mutated inputs through allowed_prologue_inps.

Also refreshes Inductor range-tree symbol mappings after fusion hook setup to fix Unregistered range symbol failures from renamed prologue/epilogue range variables.

Adds a regression test for the allowed and blocked prologue-fusion cases.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 23, 2026
@choijon5 choijon5 force-pushed the fix-fbcode-torch-compile-fusion branch 2 times, most recently from eb5d719 to 91be000 Compare May 23, 2026 03:55
@choijon5 choijon5 requested a review from jansel May 23, 2026 04:26
Comment on lines +849 to +865
_scheduler_node_has_aliasing_or_mutation = SchedulerNode.has_aliasing_or_mutation


def _helion_scheduler_node_has_aliasing_or_mutation(
self: SchedulerNode,
) -> bool:
if isinstance(self.node, HelionTemplateBuffer):
return False
return _scheduler_node_has_aliasing_or_mutation(self)


# Inductor's generic template prologue check rejects any template with mutation
# outputs. Helion already limits prologue fusion to non-mutated inputs via
# allowed_prologue_inps, so non-mutated pointwise producers can still fuse safely.
SchedulerNode.has_aliasing_or_mutation = ( # pyrefly: ignore[bad-assignment]
_helion_scheduler_node_has_aliasing_or_mutation
)
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.

what's going on here? this code looks very suspicious

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep it was too broad. Addressed now.

@choijon5 choijon5 force-pushed the fix-fbcode-torch-compile-fusion branch 4 times, most recently from 1025482 to 575afbd Compare May 23, 2026 17:14
# Inductor has no template hook for the prologue-fusion mutation gate. Route
# Helion templates through the narrower check above while leaving every other
# SchedulerNode on Inductor's implementation.
SchedulerNode.has_aliasing_or_mutation = ( # pyrefly: ignore[bad-assignment]
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.

Can we fix this on the PyTorch side rather than monkey patching?

@choijon5 choijon5 force-pushed the fix-fbcode-torch-compile-fusion branch from 575afbd to 4c442a1 Compare May 27, 2026 04:06
@choijon5 choijon5 force-pushed the fix-fbcode-torch-compile-fusion branch from 4c442a1 to 5db18b9 Compare May 27, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants