[tensor-shapes] Missing scalar divisor overloads for torch.fmod and Tensor.fmod
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 70/100
Direzione di ricerca
Riproduci prima con il repro.py fornito e il comando di controllo di pyrefly; il problema è in pyrefly-torch-stubs, non in pyrefly stesso, quindi individua dove sono dichiarati torch.fmod e Tensor.fmod e la firma che accetta solo un divisore tensore. Aggiungi un overload scalare per ciascuno che restituisca la forma dell'input S, poi riesegui il repro per confermare che entrambe le chiamate passano mentre il comportamento con divisore tensore resta invariato. È fatto quando i due errori segnalati scompaiono e le chiamate esistenti con broadcasting continuano a passare il controllo dei tipi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
(Only applicable for extension issues) IDE Information
No response
- Lingua principale
- Rust
- Stelle
- 7.2k
- Fork
- 578
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di facebook/pyrefly
-
good first issue typechecking
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
cargo b warning: unused dependency `zstd`Forse già presa @Narendersingh007 l’ha presa 4 giorni fa. Apertagood first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
-
pydantic
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
False negative when assigning generic function without parameter default to callback protocolApertatypechecking
Difficoltà 4/5 3-5 giorni Idoneità per principianti 40/100
Tutte le issue di facebook/pyrefly
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
eventflux-io/eventflux#203 ·
I maintainer di solito rispondono entro 1 giorno
-
bug ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
userFRM/egui-charts#4068 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
trezor/trezor-firmware#8357 ·
I maintainer di solito rispondono entro 2 giorni
-
fuzz-crash review-followup
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno