[torchlib] Float remainder is off by the divisor when the quotient rounds up, and nan for an infinite divisor
维护者通常 3 天内回复
评估
调研方向
Start with _aten_remainder, whose TODO points to the PyTorch kernel; compare its remainder behavior with the examples in the issue, including quotient rounding and infinite divisors. Check the relevant tests for exported torch.remainder behavior. Done when exported results match PyTorch for the reported cases, including large quotients and both divisor signs.
由索引模型根据 Issue 内容生成。
描述
Float remainder (a % b, torch.remainder) is exported as a - Floor(a / b) * b. When a / b rounds up to a whole number the result is off by a whole b, an infinite divisor gives nan, and large quotients lose their low digits.
import torch
class Model(torch.nn.Module):
def forward(self, a, b):
return a % b
inf = float("inf")
args = (torch.tensor([1.0, 4.2, 1e10, 5.0, -5.0]), torch.tensor([0.1, 1.4, 3.0, inf, inf]))
onnx_program = torch.onnx.export(Model(), args, dynamo=True)
print(onnx_program(*args)[0]) # tensor([0., 0., 0., nan, nan])
print(Model()(*args)) # tensor([0.1000, 1.4000, 1.0000, 5.0000, inf])
This matters for code that wraps a value into a period, such as a phase or an angle (phase % 1.0, theta % (2 * math.pi)). At the boundary, the exported model gives 0 where PyTorch gives a value just below the period.
The TODO in _aten_remainder already points at the PyTorch kernel, which takes the exact fmod(a, b) and adds b when the signs differ.
Versions: onnxscript main (d7cb02b0), torch 2.14.1, onnxruntime 1.31.0, Linux, CPU.
- 主要语言
- Python
- 星标
- 456
- 派生
- 148
- 平均合并
- 3 天 13 小时
- 30 天内合并 PR
- 21
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/onnxscript 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/onnxscript#3003 · 3 条评论 ·
维护者通常 3 天内回复
-
CI : Pin github actions to full commit SHA可能已有人在做 @Aniketsy 于 178 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/onnxscript#2903 · 6 条评论 ·
维护者通常 3 天内回复
-
optimize() crashes when constant folding produces a string tensor可能已有人在做 @nniiovoo 于 3 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 35/100
microsoft/onnxscript#3129 ·
维护者通常 3 天内回复
-
bug module: torchlib
难度 3/5 1-2 天 新手友好度 64/100
microsoft/onnxscript#3124 · 3 条评论 · 1 个 reaction ·
维护者通常 3 天内回复
-
[torchlib] Float floor_divide is one too large when the quotient rounds up to a whole number可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 4/5 3-5 天 新手友好度 57/100
microsoft/onnxscript#3115 ·
维护者通常 3 天内回复
查看 microsoft/onnxscript 的全部 Issue
相似的 Issue
-
priority middle
难度 1/5 1 小时以内 新手友好度 62/100
KATO-Hiro/AtCoderClans#12940 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 76/100
huggingface/huggingface_hub#5283 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 86/100
维护者通常 1 天内回复
-
bug example
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复