[tensor-shapes] Missing scalar divisor overloads for torch.fmod and Tensor.fmod

Abierto Apto para principiantes
#5,711 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
devtools

Línea de trabajo

Reproduce primero con el repro.py dado y el comando de comprobación de pyrefly; el fallo está en pyrefly-torch-stubs, no en pyrefly en sí, así que localiza dónde se declaran torch.fmod y Tensor.fmod y la firma que solo admite un divisor tensor. Añade una sobrecarga escalar para cada uno que devuelva la forma de entrada S, luego vuelve a ejecutar el repro para confirmar que ambas llamadas pasan mientras el comportamiento con divisor tensor sigue igual. Está terminado cuando desaparecen los dos errores reportados y las llamadas existentes con broadcasting siguen pasando la comprobación de tipos.

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

Descripción

pytorch tensor-shapes typechecking
Describe the Bug

With pyrefly-torch-stubs==1.5.0, passing a Python float divisor to either torch.fmod(x, divisor) or x.fmod(divisor) produces a false positive (bad-argument-type). PyTorch documents a scalar divisor and gives an example with a Python float. Both calls should type-check and preserve the input tensor shape S. PyTorch fmod documentation

Reproduction

Save this as repro.py in an empty directory.

from __future__ import annotations

from typing import TYPE_CHECKING

import torch

if TYPE_CHECKING:
    from shape_extensions import IntTuple
    from torch import Tensor


def functional[S: IntTuple](x: Tensor[S], divisor: float) -> Tensor[S]:
    return torch.fmod(x, divisor)


def method[S: IntTuple](x: Tensor[S], divisor: float) -> Tensor[S]:
    return x.fmod(divisor)

An empty Pyrefly configuration is sufficient, then run thuis.

touch pyrefly.toml
uv venv --python 3.13.18 .venv
uv pip install --python .venv/bin/python --index https://download.pytorch.org/whl/cpu 'torch==2.14.0+cpu'
uv pip install --python .venv/bin/python pyrefly==1.5.0 pyrefly-torch-stubs==1.5.0
.venv/bin/pyrefly check --python-interpreter-path .venv/bin/python --output-format min-text repro.py

Pyrefly exits with status 1 and underlines the divisor in both calls.

ERROR repro.py:13:26-33: Argument `float` is not assignable to parameter `other` with type `Tensor[@_]` in function `torch.fmod` [bad-argument-type]
ERROR repro.py:17:19-26: Argument `float` is not assignable to parameter `other` with type `Tensor[@_]` in function `torch.Tensor.fmod` [bad-argument-type]

Both functions run with the same float argument.

.venv/bin/python - <<'PY'
import torch
from repro import functional, method

x = torch.tensor([-0.25, 1.25])
print(functional(x, 0.5).tolist())
print(method(x, 0.5).tolist())
PY

Both print [-0.25, 0.25]. Changing just the two divisor annotations to Tensor[[]] makes the type check pass. The current shape stubs declare a tensor divisor in both places. A scalar overload returning the input shape would cover these calls while preserving the existing broadcasting behavior for tensor divisors.

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.zVbfi9QwEP5XgvfSQs0p4ktBEZZDFzk93H2RWko2TbfFbrc0qe4p_u_OJGnS9FbvBB-Oe7huMpmf33wzPz1lDqIfjjPCLIpqBARgRabGRteYbWRLDSGtbj_fXBWrd1er9-sPb2eUAPzCa1vnQMYmVKuSNetFIU5KdJhARzXrTm1H6NiZqNbnjIK8gV_YQKzNNql7nUen1IpmmzwhZfOtge-UVECjpjnd7VR70wHaGK0O0NQn9y729kzD_x9bJ2PHG3kozF5YVBhn-9sGJC_I6giPm32tSMRjci0UIzctU9BBByDudccpFLUkrAIUNAwwQ8n1egusycE9Qb90F-STKEcuSpv3WpB-3AGr1nD0nL6kz0zZoCX4V7aH-YDdqWpgIYlQ4UQYuqUWL_cVOYFGhbGGQw7zi1ONFBtt4tUMCYbKpyTiderFzEc-Y3hMavYRvB8C2TwKSR3GKsq42vkXuRGcl875GWkJmP5OOs5TQil1gETr1rCPc-6OB45l864fVRrEl__VuX91DJCyrMTljEMeK3qoWz9ki0xdwH8_2acs2hjDQxmUxASvBtZJDCfb5lHVQWpNHp3om4WcebwfkWIKn2fZC653j8Qolr6iUmt0npnyQq_C3-p4gCoLnZbjqODbZqMUkg_NDnK0uyWM7HEXZW3zAw60ZSJhWDDkZmo0TeuHJRHMCi3Oejk5aOnrfHz-SSsqNcesRoM_OBcbWtGkFMVJFD99DTP7ib3RlrE_0T-XoEhbsbrjOIjkvhjOwRiVP14E_2Ezn_bxJc6nLGmwTz82vBYHlniMBbfSXN9tCxktZeJgCe7Ed9iBeSvtCowotm5lC9u5rvxSXdBhxUO6ZKkhIZeh5kDxnU3GrSy_fgM

(Only applicable for extension issues) IDE Information

No response

Lenguaje dominante
Rust
Estrellas
7.2k
Forks
578
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

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 facebook/pyrefly

Todos los issues de facebook/pyrefly

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.