Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#3,116 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@usmanmateen ci sta già lavorando.

Dal 21/10/2026.

  • #3113 di @usmanmateen — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
456
Fork
148
Merge medio
3g 13h
PR unite (30g)
21

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/onnxscript

Tutte le issue di microsoft/onnxscript

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.