[Bug][Relax] Integer tensor with a Python float scalar is truncated: `x * 0.5` returns zeros

Abierto
#20,926 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

@GoyalIshaan ya está trabajando en esto.

Desde el 6/11/2026.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
compilers

Línea de trabajo

Start by tracing the Relax PyTorch frontend's _binary_op handling of Python scalar operands; the issue suggests it may construct the scalar using the tensor's dtype. Check how dtype promotion is handled for arithmetic and comparisons, then reproduce the provided integer tensor cases and compare them with PyTorch eager results. Done means float scalars produce the expected promoted results across the listed operations and tensor dtypes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

needs-triage type: bug
Expected behavior

An integer tensor with a Python float scalar is promoted to float32: x * 0.5 is [0.5, 1.0, 1.5] and x + 1.5 is [2.5, 3.5, 4.5].

Actual behavior

The result keeps the integer dtype and the scalar is truncated, so x * 0.5 is all zeros. The same happens for -, for the scalar on the left, for int32, uint8 and bool tensors, and for comparisons (x < 1.5 is all False). An integer scalar, or a float tensor, works.

eager: [([0.5, 1.0, 1.5], torch.float32), ([2.5, 3.5, 4.5], torch.float32)]
tvm:   [([0, 0, 0], dtype('int64')), ([2, 3, 4], dtype('int64'))]

Possibly _binary_op builds the scalar as relax.const(rhs, lhs.ty.dtype), so a float scalar is cast to the tensor's integer dtype instead of the tensor being promoted.

Environment
  • TVM: main @ 2bf0532 (0.28.dev0), built from source, target llvm
  • PyTorch: 2.12.0+cu130
  • Python: 3.12, Ubuntu x86_64
Steps to reproduce
import torch
import tvm
import tvm_tirx
from tvm import relax
from tvm.relax.frontend.torch import from_exported_program


class M(torch.nn.Module):
    def forward(self, x):
        return x * 0.5, x + 1.5


x = torch.tensor([1, 2, 3])
args = (x,)
print("eager:", [(t.tolist(), t.dtype) for t in M()(x)])

ep = torch.export.export(M(), args)
mod = from_exported_program(ep)
ex = tvm.compile(mod, target="llvm")
vm = relax.VirtualMachine(ex, tvm_tirx.cpu())
out = vm["main"](*[tvm_tirx.runtime.tensor(a.numpy()) for a in args])
print("tvm:  ", [(o.numpy().tolist(), o.numpy().dtype) for o in out])
Lenguaje dominante
Python
Estrellas
13.9k
Forks
4.1k
Merge medio
4 d 22 h
PR fusionados (30 d)
22

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/tvm

Todos los issues de apache/tvm

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.