[torchlib] Add missing dtype parameter to aten_mean_dim#2885
Merged
justinchuby merged 2 commits intomicrosoft:mainfrom Apr 10, 2026
Merged
[torchlib] Add missing dtype parameter to aten_mean_dim#2885justinchuby merged 2 commits intomicrosoft:mainfrom
justinchuby merged 2 commits intomicrosoft:mainfrom
Conversation
The ATen schema for mean.dim documents dtype as an optional parameter, but aten_mean_dim and aten_mean_dim_complex did not accept it. This causes a TypeError when PyTorch lowers mean.dim with an explicit dtype (e.g. from GlobalAveragePooling2D in Keras). Add dtype: int = -1 to both functions, following the same pattern used by aten_sum_dim_IntList. Fixes microsoft#2884
Contributor
Author
|
Hey! This is my first contribution to onnxscript. We ran into this while exporting Keras models to ONNX at work - GlobalAveragePooling2D lowers through aten::mean.dim with an explicit dtype, which hits the missing parameter. Happy to adjust anything if needed😄 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2885 +/- ##
==========================================
- Coverage 72.04% 72.03% -0.01%
==========================================
Files 239 239
Lines 29305 29309 +4
Branches 2880 2882 +2
==========================================
Hits 21112 21112
- Misses 7216 7218 +2
- Partials 977 979 +2 ☔ View full report in Codecov by Sentry. |
Collaborator
|
@linusjuni could you fix lint? |
Contributor
Author
|
@microsoft-github-policy-service agree |
justinchuby
approved these changes
Apr 10, 2026
justinchuby
pushed a commit
that referenced
this pull request
Apr 17, 2026
Fixes #2884 `aten_mean_dim` and `aten_mean_dim_complex` are missing the `dtype` keyword argument from their signatures, even though the ATen schema documents it (`ScalarType? dtype=None`). This causes a `TypeError` when PyTorch lowers `aten::mean.dim` with an explicit `dtype` - which happens for any model using `GlobalAveragePooling2D` (Keras/PyTorch). - Add `dtype: int = -1` to `aten_mean_dim`, with `op.Cast` when dtype is specified - Add `dtype: int = -1` to `aten_mean_dim_complex`, raising `NotImplementedError` for complex tensors Follows the same pattern used by `aten_sum_dim_IntList` and `aten_sum_dim_IntList_complex`.
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.
Fixes #2884
aten_mean_dimandaten_mean_dim_complexare missing thedtypekeyword argument from their signatures, even though the ATen schema documents it (ScalarType? dtype=None). This causes aTypeErrorwhen PyTorch lowersaten::mean.dimwith an explicitdtype- which happens for any model usingGlobalAveragePooling2D(Keras/PyTorch).dtype: int = -1toaten_mean_dim, withop.Castwhen dtype is specifieddtype: int = -1toaten_mean_dim_complex, raisingNotImplementedErrorfor complex tensorsFollows the same pattern used by
aten_sum_dim_IntListandaten_sum_dim_IntList_complex.