Skip to content

[torchlib] Implement type promotion #2010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TensorType
  • Loading branch information
justinchuby committed Jan 15, 2025
commit c6e300c00f943b71cae5f64e0878941bb9fecff9
4 changes: 3 additions & 1 deletion onnxscript/function_libs/torch_lib/ops/core.py
Original file line number Diff line number Diff line change
@@ -214,19 +214,21 @@
by the scalar value and adds it to self.
"""
# FIXME: Int to float
self, tensor1, tensor2 = _type_promotion.promote_types(op, [self, tensor1, tensor2])

Check warning on line 217 in onnxscript/function_libs/torch_lib/ops/core.py

Codecov / codecov/patch

onnxscript/function_libs/torch_lib/ops/core.py#L217

Added line #L217 was not covered by tests

return op.Add(self, op.Mul(op.Div(tensor1, tensor2), value))


@torch_op("aten::addcmul", trace_only=True)
def aten_addcmul(self: TReal, tensor1: TReal, tensor2: TReal, value: float = 1.0) -> TReal:
def aten_addcmul(
self: TensorType, tensor1: TensorType, tensor2: TensorType, value: float = 1.0
) -> TensorType:
"""addcmul(Tensor self, Tensor tensor1, Tensor tensor2, *, Scalar value=1) -> Tensor

Performs the element-wise multiplication of tensor1 by tensor2, multiplies the
result by the scalar value and adds it to self.
"""
self, tensor1, tensor2 = _type_promotion.promote_types(op, [self, tensor1, tensor2])

Check warning on line 231 in onnxscript/function_libs/torch_lib/ops/core.py

Codecov / codecov/patch

onnxscript/function_libs/torch_lib/ops/core.py#L231

Added line #L231 was not covered by tests

# Follow the order in https://github.com/pytorch/pytorch/blob/29e3fddb082b5a14262a7246bc62381a55199d45/aten/src/ATen/native/cpu/PointwiseOpsKernel.cpp#L47
# TODO(#811): Understand fp16 accuracy issue
@@ -266,7 +268,7 @@

Performs the outer-product of vectors vec1 and vec2 and adds it to the matrix input.
"""
self, vec1, vec2 = _type_promotion.promote_types(op, [self, vec1, vec2])

Check warning on line 271 in onnxscript/function_libs/torch_lib/ops/core.py

Codecov / codecov/patch

onnxscript/function_libs/torch_lib/ops/core.py#L271

Added line #L271 was not covered by tests
vec1_shape = op.Constant(value_ints=[-1, 1])
vec2_shape = op.Constant(value_ints=[1, -1])
vec1_reshaped = op.Reshape(vec1, vec1_shape)
Loading
Oops, something went wrong.