Skip to content

Fix aten::mean dtype handling - #3010

Closed
Promise Emmanuel Oluwadare (promiseeuler) wants to merge 1 commit into
microsoft:mainfrom
promiseeuler:codex/fix-mean-dtype
Closed

Fix aten::mean dtype handling#3010
Promise Emmanuel Oluwadare (promiseeuler) wants to merge 1 commit into
microsoft:mainfrom
promiseeuler:codex/fix-mean-dtype

Conversation

@promiseeuler

Copy link
Copy Markdown

Summary

While testing ONNXScript's TorchLib lowering for torch.mean(..., dtype=...), I found that the aten::mean overload ignored its schema's dtype argument and silently exported the wrong output type.

This change:

  • accepts the optional dtype argument
  • casts the input before ReduceMean, preserving the requested accumulation precision
  • adds a precision-sensitive end-to-end regression

Fixes #3008.

Validation

  • Exported torch.mean([1e8, 1, -1e8], dtype=torch.float64)
  • Verified graph order: Cast -> ReduceMean -> Squeeze
  • Verified ONNX reference output matches PyTorch in value and float64 dtype
  • ruff check passed
  • ruff format --check passed

The focused e2e test file cannot collect on this local Python 3.14 build because torchvision imports the unavailable stdlib _lzma extension; the same test logic was executed directly and passed.

@promiseeuler

Copy link
Copy Markdown
Author

Thanks om singhal (@Om-singhaI) — I found #3009 after opening this PR. I compared the two changes, and #3009 covers the same cast-before-reduction fix with broader OpInfo coverage and consistent handling of the complex overload. To keep maintainer review focused and avoid duplicate work, I’m closing this one in favor of #3009. The precision-sensitive reproduction from #3008 agrees with its approach.

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.

aten::mean silently ignores dtype and exports the wrong output type

1 participant