Skip to content
Merged
Changes from 2 commits
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
32 changes: 31 additions & 1 deletion onnxscript/function_libs/torch_lib/ops/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7657,7 +7657,7 @@
raise NotImplementedError()


@torch_op(("aten::remainder.Tensor", "aten::remainder.Scalar"), trace_only=True)
@torch_op("aten::remainder.Tensor", trace_only=True)
def aten_remainder(self: TTensor, other: TTensor) -> TTensor:
"""remainder.Tensor(Tensor self, Tensor other) -> Tensor"""

Expand All @@ -7673,6 +7673,36 @@
return op.Sub(self, op.Mul(rounded_quotient, other))


@torch_op("aten::remainder.Scalar", trace_only=True)
def aten_remainder(self: TTensor, other: float) -> TTensor:
Comment thread Fixed
Comment thread Fixed
Comment thread
justinchuby marked this conversation as resolved.
Outdated
"""remainder.Scalar(Tensor self, Scalar other) -> Tensor"""

other_tensor = ir.tensor(other, dtype=self.dtype)

if self.dtype.is_integer():
Comment thread
justinchuby marked this conversation as resolved.
Outdated
return op.Mod(self, other_tensor)

# a - a.div(b, rounding_mode="floor") * b
rounded_quotient = op.Floor(op.Div(self, other_tensor))

return op.Sub(self, op.Mul(rounded_quotient, other_tensor))


@torch_op("aten::remainder.Scalar_Tensor", trace_only=True)
def aten_remainder_scalar_tensor(self: float, other: TTensor) -> TTensor:
"""remainder.Scalar_Tensor(Scalar self, Tensor other) -> Tensor"""

self_tensor = ir.tensor(self, dtype=other.dtype)

if other.dtype.is_integer():
return op.Mod(self_tensor, other)

# a - a.div(b, rounding_mode="floor") * b
rounded_quotient = op.Floor(op.Div(self_tensor, other))

return op.Sub(self_tensor, op.Mul(rounded_quotient, other))
Comment thread
justinchuby marked this conversation as resolved.
Outdated


@torch_op("_operator::mod", trace_only=True)
def operator_mod(self: TTensor, other: TTensor) -> TTensor:
# Modulus operator % on SymInt
Expand Down
Loading