Skip to content

Conversation

@Itssshikhar
Copy link

Resolves #934

Used a zero-nonzero specialization in which 0 is kept distinct while 1 just goes >= 2 similar to already present '_tensor_key' logic & this can be turned on with an environment variable 'HELION_SHAPE_BUCKETING' that defaults to 'min2' (current behavior: bucket dims are 0, 1, >=2), and disables 0/1 when using 'zero_nonzero'. Kept 0 as a separate bucket to deal with zero-numel edge cases. Added test for the same as well.

…th in a diff way while 1 just goes >= 2 similar to already present '_tensor_key' logic & this can be turned on with an environment variable 'HELION_SHAPE_BUCKETING' that default to 'min2', and disables 0/1 when using 'zero_nonzero'.
@meta-cla
Copy link

meta-cla bot commented Oct 30, 2025

Hi @Itssshikhar!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 30, 2025
@meta-cla
Copy link

meta-cla bot commented Oct 30, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@oulgen
Copy link
Contributor

oulgen commented Oct 31, 2025

please rebase to main and make sure the lint is passing, and move your PR from draft to ready for review when you're ready

@Itssshikhar Itssshikhar marked this pull request as ready for review October 31, 2025 17:18
@Itssshikhar
Copy link
Author

Appreciate the comments. I've rebase the main to this branch and lint seems to be passing. Let me know if there is anything else.

Copy link
Contributor

@jansel jansel left a comment

Choose a reason for hiding this comment

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

This fixes the bucketing that happens inside the kernel.py specialization key, but I think it may have some correctness issues because there is still similar shape bucketing coming from ShapeEnv/FakeTensors (which are part of PyTorch). So the code the is generated may not be shape agnostic, but this will cause it to be used as if it is.

You should be able to surface this issue by adding tests that:

  1. Run the full kernel with varying 1-ness of shapes
  2. Inspect the generated output code (via assertExpectedJournal) so you can see if shape specialization is happening.

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.

Setting to disable 0/1 specialization

3 participants