Skip to content

Add aten_maximum_real #2371

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

Closed
wants to merge 1 commit into from
Closed

Add aten_maximum_real #2371

wants to merge 1 commit into from

Conversation

xadupre
Copy link
Member

@xadupre xadupre commented Jun 10, 2025

No description provided.

Copy link

codecov bot commented Jun 10, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 70.14%. Comparing base (51ecf47) to head (2c7908a).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
onnxscript/function_libs/torch_lib/ops/core.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2371      +/-   ##
==========================================
- Coverage   70.14%   70.14%   -0.01%     
==========================================
  Files         197      197              
  Lines       24983    24986       +3     
  Branches     2667     2667              
==========================================
+ Hits        17525    17526       +1     
- Misses       6531     6533       +2     
  Partials      927      927              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@justinchuby
Copy link
Collaborator

The types should be promoted already when the op is being translated and should be handled by

def aten_maximum(self: TReal, other: TReal) -> TReal:
. Was there a case when this isn't true? ONNX max requires all inputs to be the same type https://onnx.ai/onnx/operators/onnx__Max.html but this change allows the two inputs to take different types, which would allow an invalid model

Copy link
Collaborator

@justinchuby justinchuby left a comment

Choose a reason for hiding this comment

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

Explained above and for further discussions

@github-project-automation github-project-automation bot moved this from Todo to In Progress in ONNX Script Review Board Jun 10, 2025
@xadupre
Copy link
Member Author

xadupre commented Jun 10, 2025

There is a regression for the model XGLMForCausalLM. I tried this change based on the error message I got (missing signature for aten::max.other). But type promotion fails as you mentioned. Error: Type parameter (T) of Optype (Max) bound to different types (tensor(float16) and tensor(float) in node (n0).

@justinchuby
Copy link
Collaborator

Looks like max.other is an alias of maximum (https://github.com/pytorch/pytorch/blob/b44306d3681d5b248e6b439d293ea0d5a8903a61/aten/src/ATen/native/native_functions.yaml#L10064-L10069). I think we can do one of two things:

  1. Unregister max.other and hope that it gets decomposed to maximum, which we have a type promotion rule for.
  2. Add max.other to entries in https://github.com/pytorch/pytorch/blob/b44306d3681d5b248e6b439d293ea0d5a8903a61/torch/onnx/_internal/fx/passes/type_promotion.py#L828-L833

@titaiwangms
Copy link
Contributor

Looks like max.other is an alias of maximum (https://github.com/pytorch/pytorch/blob/b44306d3681d5b248e6b439d293ea0d5a8903a61/aten/src/ATen/native/native_functions.yaml#L10064-L10069). I think we can do one of two things:

  1. Unregister max.other and hope that it gets decomposed to maximum, which we have a type promotion rule for.
  2. Add max.other to entries in https://github.com/pytorch/pytorch/blob/b44306d3681d5b248e6b439d293ea0d5a8903a61/torch/onnx/_internal/fx/passes/type_promotion.py#L828-L833

I will take a look and update it here.

@titaiwangms
Copy link
Contributor

#2377 should fix what this PR tried to fix.

@github-project-automation github-project-automation bot moved this from In Progress to Done in ONNX Script Review Board Jun 12, 2025
titaiwangms added a commit that referenced this pull request Jun 13, 2025
Issue revealed by #2371,
which aten.max.other is lack of matching overload. It's caused by
missing type promotion. The reason is that aten::max.other (binary max)
is an alias of aten::maimum.default. Thus, iwhen type promotion pass
dispatches torch.max through `__torch__dispatch__`, it does not find
aten::max.other (However, I am not sure how `make_fx` dispatches
torch.max to aten::max.other).

The existence of aten::max.other looks like a legacy code:
pytorch/pytorch#42579.
@justinchuby justinchuby linked an issue Jun 14, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants