Skip to content

Commit

Permalink
Trace convert_element_type | fix(torchlib) (#1129)
Browse files Browse the repository at this point in the history
Set convert_element_type to trace_only because different branches return
different dtype values.

Fixes #1128
  • Loading branch information
justinchuby authored Nov 6, 2023
1 parent 8eec5ae commit 0f6f0fe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion onnxscript/function_libs/torch_lib/ops/prims.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ def prims_conj_physical(self: TensorType) -> TensorType:
raise NotImplementedError()


@torch_op("prims::convert_element_type")
@torch_op("prims::convert_element_type", trace_only=True)
def prims_convert_element_type(a: RealType, dtype: int) -> RealType:
"""convert_element_type(Tensor a, ScalarType dtype) -> Tensor"""

# Set trace_only=True because different if branches return different dtypes
# which is not supported in an ONNX function
if dtype == COMPLEX128_TYPE:
# Cast to the real representation of the complex type
casted = op.Cast(a, to=DOUBLE.dtype)
Expand Down

0 comments on commit 0f6f0fe

Please sign in to comment.