Skip to content

[Ref Mode] PyTorch reference mode (eager only) #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: yf225/stack/39
Choose a base branch
from

Conversation

yf225
Copy link
Contributor

@yf225 yf225 commented Jul 20, 2025

yf225 added a commit that referenced this pull request Jul 20, 2025
stack-info: PR: #339, branch: yf225/stack/34
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 20, 2025
yf225 added a commit that referenced this pull request Jul 20, 2025
Fixes #77.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 20, 2025
Fixes #77.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 20, 2025
Fixes #77.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 20, 2025
Fixes #77.

stack-info: PR: #339, branch: yf225/stack/34
)

# Step 3: Handle block_size (in ref mode, full dim size is always used as block_size)
block_size_list = [None] * len(end_list)
Copy link
Contributor Author

@yf225 yf225 Jul 20, 2025

Choose a reason for hiding this comment

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

Always use full dim size in ref modes regardless of block_size value

x_part = hl.load(
x, [tile0, tile1], extra_mask=(tile1.index < x.size(1))[None, :]
Copy link
Contributor Author

@yf225 yf225 Jul 20, 2025

Choose a reason for hiding this comment

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

Since we are treating tile as a Python slice object in ref mode, tile.index no longer works and we have to use hl.tile_index().

To make the UX better, in a follow-up PR I am thinking of adding a RefTile class that Dynamo can understand, and support tile APIs like .index / .begin / .end in that class.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should make tile.index work. Maybe rather than changing the examples we should skip tests in reference mode.

@yf225 yf225 requested review from jansel, oulgen, drisspg and joydddd July 20, 2025 23:50
class TestExamplesRefCompile(test_examples.TestExamples):
"""Run all TestExamples tests in reference torch.compile mode via HELION_REF_COMPILE=1."""

# NOTE: All tests in TestExamples are run in ref torch.compile(fullgraph=True) mode by default in this test file.
Copy link
Contributor Author

@yf225 yf225 Jul 20, 2025

Choose a reason for hiding this comment

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

Currently all examples in TestExamples pass with ref eager mode and ref compile mode.

Planning to add more ref mode unit tests to cover test_reduce.py, test_associative_scan.py etc. in the next PR.

yf225 added a commit that referenced this pull request Jul 20, 2025
Fixes #77.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 20, 2025
Fixes #77. Please see
inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 20, 2025
Fixes #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 21, 2025
Fixes #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 21, 2025
Fixes #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 21, 2025
Fixes #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 21, 2025
Fixes #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
yf225 added a commit that referenced this pull request Jul 24, 2025
Fixes #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
@yf225 yf225 changed the base branch from main to yf225/stack/39 July 24, 2025 23:57
@yf225 yf225 changed the base branch from yf225/stack/39 to main July 25, 2025 02:26
yf225 added a commit that referenced this pull request Jul 25, 2025
Fixes #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
@yf225 yf225 changed the base branch from main to yf225/stack/39 July 25, 2025 02:27
@yf225 yf225 changed the base branch from yf225/stack/39 to main July 25, 2025 04:12
yf225 added a commit that referenced this pull request Jul 25, 2025
Fixes #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
@yf225 yf225 changed the base branch from main to yf225/stack/39 July 25, 2025 04:12
@yf225 yf225 changed the base branch from yf225/stack/39 to main July 25, 2025 04:14
yf225 added a commit that referenced this pull request Jul 25, 2025
Part of #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
@yf225 yf225 changed the base branch from main to yf225/stack/39 July 25, 2025 04:14
@yf225 yf225 changed the base branch from yf225/stack/39 to main July 25, 2025 04:17
yf225 added a commit that referenced this pull request Jul 25, 2025
Part of #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
@yf225 yf225 changed the base branch from main to yf225/stack/39 July 25, 2025 04:17
@yf225 yf225 changed the base branch from yf225/stack/39 to main July 25, 2025 04:18
yf225 added a commit that referenced this pull request Jul 25, 2025
Part of #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
@yf225 yf225 changed the base branch from main to yf225/stack/39 July 25, 2025 04:18
@yf225 yf225 changed the title PyTorch reference mode (both eager and torch.compile) PyTorch reference mode (eager only) Jul 25, 2025
Part of #77.
Please see inline code comments on the PR.

stack-info: PR: #339, branch: yf225/stack/34
@yf225 yf225 changed the base branch from yf225/stack/39 to main July 25, 2025 05:43
@yf225 yf225 changed the title PyTorch reference mode (eager only) [Ref Mode] PyTorch reference mode (eager only) Jul 25, 2025
@yf225 yf225 changed the base branch from main to yf225/stack/39 July 25, 2025 05:43
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.

4 participants