Fix dynamo export for scalar mul on converted real tensors - #3005
Fix dynamo export for scalar mul on converted real tensors#3005Justin Chu (justinchuby) with Copilot wants to merge 3 commits into
Conversation
|
Copilot also fix pytorch/pytorch#194381 and errors of this class |
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
This class of issue is covered by the missing scalar-multiply registrations in the torch-lib export mapping: |
|
Copilot can you add the same support for other arithmetic op scalar overloads |
The other scalar arithmetic overloads are already covered by the same torch-lib pattern in |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3005 +/- ##
==========================================
- Coverage 72.63% 72.63% -0.01%
==========================================
Files 265 265
Lines 32208 32212 +4
Branches 3042 3042
==========================================
+ Hits 23395 23397 +2
- Misses 7779 7781 +2
Partials 1034 1034 ☔ View full report in Codecov by Harness. |
|
Copilot fix lint |
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Fixed the lint issue in the regression test and re-ran the repo lint checks. The targeted export regression also passes: |
Promise Emmanuel Oluwadare (promiseeuler)
left a comment
There was a problem hiding this comment.
While validating the new Scalar overload, I exported and executed four focused cases against this branch: float16 tensor × 1.5, float32 × integer 2, int64 × -3, and bool × true. All four ONNX programs passed onnx.checker and runtime outputs matched PyTorch exactly, including output element types. This gives useful coverage beyond the added float16-to-float32 regression and confirms that materializing the scalar with self.dtype preserves aten::mul.Scalar semantics for the tested real/bool domains. The repository e2e test module itself could not collect in my Python 3.14 environment because that interpreter lacks the optional _lzma module required while importing torchvision; the standalone export/runtime checks avoid that unrelated environment failure.
torch.onnx.export(..., dynamo=True)could fail when a real-valued tensor produced byconvert_element_typewas multiplied by a scalar literal (aten.mul.Scalar/aten.multiply.Scalar). In the 2.13+ export path, that overload was missing from the torch-lib registrations, so FX translation raised a dispatch error even though the lowering is a standard scalar multiply.Summary
convert_element_type+* 1.0pattern with a regression case.Change
onnxscript/function_libs/torch_lib/ops/core.py, registered:aten::mul.Scalaraten::multiply.Scalaraten::muland preserve the expected scalar-to-tensor promotion behavior.Example
This is the same shape as the failing export pattern: a scalar multiply applied to a
convert_element_typeresult, which previously hit a missing ONNX function registration during translation.