Skip to content

Conversation

karthickai
Copy link
Contributor

@karthickai karthickai commented Sep 22, 2025

Stacked PRs:


Add hl.rand op with seed arg lowering to tl.rand

karthickai added a commit that referenced this pull request Sep 22, 2025
stack-info: PR: #652, branch: karthickai/stack/2
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 22, 2025
seed: int,
dtype: torch.dtype = torch.float32,
device: torch.device | None = None,
) -> torch.Tensor:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to comment more on when user should use hl.rand vs. torch.rand_like (#530)? IMO ideally we should minimize the hl.* API surface and encourage reuse of existing torch.* APIs. But if there are cases where torch API would not work, then it makes sense to add hl.rand API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I'll add the comment clarifying the intent hl.rand exists to explicitly pass a seed arg for deterministic randomness in helion kernels, whereas torch.rand_like doesn't take seed arg.

karthickai added a commit that referenced this pull request Sep 22, 2025
stack-info: PR: #652, branch: karthickai/stack/2
karthickai added a commit that referenced this pull request Sep 22, 2025
stack-info: PR: #652, branch: karthickai/stack/2
@karthickai karthickai requested a review from jansel September 22, 2025 03:18
test/test_rng.py Outdated
def test_hl_rand_3d(self):
import helion

@helion.kernel(ref_mode=helion.RefMode.EAGER)
Copy link
Contributor

@yf225 yf225 Sep 22, 2025

Choose a reason for hiding this comment

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

Maybe remove the ref_mode setting? The code as-is will explicitly test ref eager mode instead of normal Helion compile mode, but here I believe the intent is to test compile mode. (We have other harness to run tests in ref eager mode automatically so usually we don't need to worry about it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the catch! I added that line for debugging to check the ref implementation and forgot to remove it. I’ve updated it now.

test/test_rng.py Outdated
self.assertTrue(torch.all(output < 1.0), "All values should be < 1")

def test_hl_rand_3d(self):
import helion
Copy link
Contributor

Choose a reason for hiding this comment

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

Can likely remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed that line.

stack-info: PR: #652, branch: karthickai/stack/2
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.

2 participants