Skip to content

Conversation

@Sibylau
Copy link
Contributor

@Sibylau Sibylau commented Aug 29, 2025

This pull request fixes #447: HELION_INTERPRET=1 silently hides HELION_PRINT_OUTPUT_CODE=1

When both HELION_INTERPRET and HELION_PRINT_OUTPUT_CODE are enabled, it will throw out an EagerCodePrintError.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 29, 2025
@Sibylau Sibylau requested review from oulgen and yf225 August 29, 2025 20:14
from typing import Protocol
from typing import Sequence
from typing import cast
from typing import cast, Literal, Protocol, Sequence, TYPE_CHECKING
Copy link
Contributor

Choose a reason for hiding this comment

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

please install and run pre-commit on your PR, our linter requires imports on different lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

used pre-commit in my updated PR.

Check if eager mode is enabled before printing output code. If eager mode is enabled, raise an error.
"""
if self.ref_mode == RefMode.EAGER and self.print_output_code:
self.print_output_code = False
Copy link
Contributor

Choose a reason for hiding this comment

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

if we are throwing an exception, is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted this line.

Copy link
Contributor

@oulgen oulgen left a comment

Choose a reason for hiding this comment

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

please add a test, you can use mock.patch to deal with env vars or mock the settings

torch.testing.assert_close(add(x, y), torch.add(x, y))

def test_normal_code_print(self):
"""Test that EagerCodePrintError is raised when using @helion.kernel with both settings"""
Copy link
Contributor

Choose a reason for hiding this comment

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

fix the comment here

@Sibylau
Copy link
Contributor Author

Sibylau commented Aug 30, 2025

Added unittest to check output print when ref_mode is either eager or normal.
I set print_output_code and ref_mode in kernel decorators.
Using mock.patch.dict to set env vars for each unittest is not working, as class _Settings reads env vars when helion is imported before running unittests.


x = torch.randn([512, 512], device="cuda", dtype=torch.float16)
y = torch.randn([512, 512], device="cuda", dtype=torch.float16)
torch.testing.assert_close(add(x, y), torch.add(x, y))
Copy link
Contributor

Choose a reason for hiding this comment

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

with pytest.raises(exc.EagerCodePrintError):

should be over this one line only


@helion.kernel(
use_default_config=True,
print_output_code=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

The CI for ref mode passes the env variable to turn on ref mode, so you need to either mock the env var or disable the ref mode for this test

Copy link
Contributor

@yf225 yf225 left a comment

Choose a reason for hiding this comment

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

thanks! some nits on the "ref eager mode" naming to make future lookups easier, otherwise it looks great!

Sibylau and others added 13 commits August 30, 2025 22:35
Co-authored-by: Will Feng <yfeng.us@gmail.com>
Co-authored-by: Will Feng <yfeng.us@gmail.com>
Co-authored-by: Will Feng <yfeng.us@gmail.com>
Co-authored-by: Will Feng <yfeng.us@gmail.com>
Co-authored-by: Will Feng <yfeng.us@gmail.com>
Co-authored-by: Will Feng <yfeng.us@gmail.com>
Co-authored-by: Will Feng <yfeng.us@gmail.com>
Co-authored-by: Will Feng <yfeng.us@gmail.com>
Co-authored-by: Will Feng <yfeng.us@gmail.com>
@Sibylau Sibylau merged commit d2bf84d into main Sep 2, 2025
13 checks passed
@Sibylau Sibylau deleted the jieeliu-patch-1 branch September 2, 2025 17:50
lolpack pushed a commit to lolpack/helion that referenced this pull request Oct 13, 2025
…mode (pytorch#528)

Co-authored-by: Will Feng <yfeng.us@gmail.com>
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.

HELION_INTERPRET=1 silently hides HELION_PRINT_OUTPUT_CODE=1

4 participants