[Bug][torchlib] aten_scatter_reduce(include_self=False) uses finite finfo.min/max instead of -inf/+inf, corrupting +/-inf inputs
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
Línea de trabajo
Lee aten_scatter_reduce en onnxscript/function_libs/torch_lib/ops/core.py alrededor de las líneas 9169–9198 y luego revisa sus pruebas existentes para scatter reduce. Reproduce el problema con include_self=False y valores de origen infinitos para amax y amin en los tipos de datos de punto flotante indicados. La tarea estará completa cuando los resultados ONNX exportados conserven los infinitos esperados y el comportamiento para enteros siga siendo correcto.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
When include_self=False and reduce="amax" or reduce="amin", aten_scatter_reduce in onnxscript/function_libs/torch_lib/ops/core.py (lines 9169–9198) pre-fills impacted target indices before calling op.ScatterElements(..., reduction="max" | "min").
Although the comment on line 9169 notes # fill a dummy value (inf or -inf), the implementation fills finite np.finfo(dtype).min / np.finfo(dtype).max (±3.4028235e+38 for float32, ±65504.0 for float16) and torch.finfo(torch.bfloat16).min / max (±3.3895314e+38 for bfloat16) instead of IEEE-754 -inf / +inf.
As a result, whenever src contains -inf (under reduce="amax") or +inf (under reduce="amin"), max(-3.4028235e38, -inf) / min(+3.4028235e38, +inf) silently produces a finite float instead of -inf / +inf across float16, bfloat16, float32, and float64.
Minimal Reproduction
import onnx.reference
import torch
class ScatterReduceMaxNoSelf(torch.nn.Module):
def forward(self, x: torch.Tensor, index: torch.Tensor, src: torch.Tensor) -> torch.Tensor:
return torch.scatter_reduce(x, 0, index, src, reduce="amax", include_self=False)
model = ScatterReduceMaxNoSelf()
x = torch.tensor([10.0, 20.0], dtype=torch.float32)
index = torch.tensor([0], dtype=torch.int64)
src = torch.tensor([-float("inf")], dtype=torch.float32)
eager_out = model(x, index, src)
prog = torch.onnx.export(model, (x, index, src), dynamo=True)
ref = onnx.reference.ReferenceEvaluator(prog.model_proto)
(onnx_out,) = ref.run(None, {"x": x.numpy(), "index": index.numpy(), "src": src.numpy()})
print("PyTorch eager:", eager_out) # tensor([-inf, 20.])
print("ONNX exported:", onnx_out) # [-3.4028235e+38 20. ]
Root Cause
In onnxscript/function_libs/torch_lib/ops/core.py (aten_scatter_reduce):
reduce == "amax"usesnp.finfo(np_dtype).min/torch.finfo(torch.bfloat16).minfor floating-point dtypes instead of-float("inf").reduce == "amin"usesnp.finfo(np_dtype).max/torch.finfo(torch.bfloat16).maxfor floating-point dtypes instead of+float("inf").
(Integer dtypes do not have±inf, sonp.iinfo(np_dtype).min/maxremains the exact identity there.)
Environment
onnxscript:0.7.2andmain(f51083c)torch:2.11.0+cpuonnx:1.23.2
(Note: I noticed #3094 is currently open touching aten_scatter_reduce for reduce="mean", so I avoided opening a competing PR to prevent merge conflicts—happy to submit a small fix with float/int dtype tests once #3094 lands if helpful.)
- Lenguaje dominante
- Python
- Estrellas
- 456
- Forks
- 159
- Merge medio
- 3 d 5 h
- PR fusionados (30 d)
- 23
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/onnxscript
-
`fuse_skip_rms_normalization` fuses a float16 residual into a norm whose scale is float32, which ONNX Runtime rejectsPosiblemente ocupada @justinchuby la tomó hace 8 días. Abiertomodule: optimizer
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
microsoft/onnxscript#3155 · 3 comentarios · 1 reacción · 2 asignados ·
Los mantenedores suelen responder en 2 días
-
Constant folding uses onnx's plain reference ops, never onnx.reference.ops_optimizedPosiblemente ocupada @todkarsant la tomó hace 8 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
microsoft/onnxscript#3003 · 3 comentarios ·
Los mantenedores suelen responder en 2 días
-
CI : Pin github actions to full commit SHAPosiblemente ocupada @Aniketsy la tomó hace 193 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
microsoft/onnxscript#2903 · 6 comentarios ·
Los mantenedores suelen responder en 2 días
-
CastCast rewrite changes rounding for DOUBLE inputs by removing the FLOAT intermediatePosiblemente ocupada @itsrayeedscodespace la tomó hace 1 día. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
microsoft/onnxscript#3204 ·
Los mantenedores suelen responder en 2 días
-
Partial rotary fusion sets `rotary_embedding_dim` without `num_heads`, which ONNX Runtime requiresPosiblemente ocupada @justinchuby la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 25/100
microsoft/onnxscript#3185 ·
Los mantenedores suelen responder en 2 días
Todos los issues de microsoft/onnxscript
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Cygnux-Labs/Tracekit#827 ·
Los mantenedores suelen responder en 1 día
-
SPIDevice selects an active-high device as soon as it is createdPosiblemente ocupada @mikeysklar la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
adafruit/circuitpython#11869 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
glossyio/traffic-monitor#312 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
narwhals-dev/narwhals#4154 ·
Los mantenedores suelen responder en 1 día