Skip to content

Commit

Permalink
[torchlib] Fix aten_mean_dim (#1962)
Browse files Browse the repository at this point in the history
Fix when the rank of `dim` is not known, the conditional will pick the
wrong branch because the truthiness of a value is always True.
  • Loading branch information
justinchuby authored Nov 22, 2024
1 parent 5a4d22e commit 99b3d26
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions onnxscript/function_libs/torch_lib/ops/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5225,9 +5225,8 @@ def aten_mean_dim(self: TReal, dim: INT64, keepdim: bool = False) -> TReal:
if IsScalar(self):
result = self
else:
if IsScalar(dim):
dim = op.Unsqueeze(dim, axes=0)
result = op.ReduceMean(self, dim, keepdims=keepdim)
dims = op.Reshape(dim, op.Constant(value_ints=[-1]))
result = op.ReduceMean(self, dims, keepdims=keepdim)
return result


Expand Down

0 comments on commit 99b3d26

Please sign in to comment.