[RFC] Add WEAKORDER to ComparisonType and Deprecate SIGNED/UNSIGNED - #3003
Open
akuegel wants to merge 7 commits into
Open
[RFC] Add WEAKORDER to ComparisonType and Deprecate SIGNED/UNSIGNED#3003akuegel wants to merge 7 commits into
akuegel wants to merge 7 commits into
Conversation
This PR adds an RFC proposing to extend `ComparisonType` in StableHLO with `NUMPY` comparison ordering and deprecate the redundant `SIGNED` and `UNSIGNED` attributes. ### Summary 1. **Add `NUMPY` to `ComparisonType`**: Supports NumPy/Python total ordering semantics (-0.0 == +0.0, NaNs sorted to the end). This eliminates the 7+ op canonicalization boilerplate in frontend sort comparators (such as JAX) and avoids fragile compiler AST pattern matching for GPU/TPU radix sort (b/376918731). 2. **Deprecate `SIGNED` and `UNSIGNED`**: In StableHLO, operand types explicitly encode signedness (`si32`, `ui32`, `i1`), and integer comparisons are inherently total order. `SIGNED` and `UNSIGNED` are legacy artifacts of XLA internals and should be deprecated in favor of `NOTYPE` (or omitting the attribute). 3. **Alternatives Considered**: Evaluates replacing `compare_type` with `comparison_order` (PARTIAL, TOTAL, NUMPY) to align with XLA's internal migration (cl/974361549), but chooses in-place `ComparisonType` extension to avoid syntax/API churn for existing StableHLO users. This PR introduces the RFC markdown document in `rfcs/` for community review and feedback prior to implementation. CC @GleasonK @phawkins
Adjust link to pull request
Address linter warnings
Member
|
Thank you for the RFC. Motivation and Overall LGTM. Do we have a better name for enum value and avoid using |
abhigunj
approved these changes
Sep 2, 2026
Member
|
cc @hawkinsp for visibility. Somehow I can't add as a reviewer. LGTM comment will work! |
hawkinsp
suggested changes
Sep 2, 2026
hawkinsp
left a comment
Contributor
There was a problem hiding this comment.
The change itself seems like a fine idea. Just a naming nit...
|
|
||
| ## Motivation & Background | ||
|
|
||
| ### 1. The Need for NUMPY Comparison Order |
Contributor
There was a problem hiding this comment.
One suggestion: don't call this "numpy" comparison, because that will get confusing if NumPy ever changes it...
Member
Author
There was a problem hiding this comment.
Thanks, that makes sense. I changed it to WEAKORDER now. Is that ok?
Like suggested in the reviews, NUMPY is not a great name as it ties to a library that might change its implementation. Now I am using WEAKORDER instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds an RFC proposing to extend
ComparisonTypein StableHLO withWEAKORDERcomparison ordering and deprecate the redundantSIGNEDandUNSIGNEDattributes.Summary
WEAKORDERtoComparisonType: Supports NumPy/Python total ordering semantics (-0.0 == +0.0, NaNs sorted to the end). This eliminates the 7+ op canonicalization boilerplate in frontend sort comparators (such as JAX) and avoids fragile compiler AST pattern matching.SIGNEDandUNSIGNED: In StableHLO, operand types explicitly encode signedness (si32,ui32,i1), and integer comparisons are inherently total order.SIGNEDandUNSIGNEDare legacy artifacts of XLA internals and should be deprecated in favor ofNOTYPE(or omitting the attribute).compare_typewithcomparison_order(PARTIAL, TOTAL, WEAK) to align with XLA's internal migration, but chooses in-placeComparisonTypeextension to avoid syntax/API churn for existing StableHLO users. This PR introduces the RFC markdown document inrfcs/for community review and feedback prior to implementation.CC @GleasonK @phawkins