Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[torchlib] Float remainder is off by the divisor when the quotient rounds up, and nan for an infinite divisor

オープン
#3,116 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

@usmanmateen がすでに取り組んでいます。

2026年10月21日 から。

  • #3113 @usmanmateen による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

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日 19時間
マージ済み PR(30日)
20

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/onnxscript のほかの issue

microsoft/onnxscript の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。