[tensor-shapes] torch.maximum rejects an inline torch.where result with the same variadic shape
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 30/100
調査の方向性
Reproduce first via the sandbox link or the repro.py commands: the inline torch.where(...) and the named selected form must both report Tensor[S]. Then find the Rust checker's call-argument inference where a generic function's type-var tuple is solved — the named form solves it when binding selected, the inline form does so mid-argument. Done means pyrefly check passes on repro.py and the type-checker tests stay green. The payload names no source files, so start from call inference.
索引モデルが issue の本文から書いたものです。
説明
Describe the Bug
Hej,
With Pyrefly and the PyTorch shape stubs at 1.5.0, I get a false positive when passing a torch.where result directly to torch.maximum. Giving that same result a local name makes the error disappear. Both forms should return Tensor[S]: the boolean mask and the two real-valued tensors all have shape S.
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 example[S: IntTuple](mask: Tensor[S], x: Tensor[S], y: Tensor[S]) -> Tensor[S]:
return torch.maximum(torch.where(mask, x, y), y)
Run the following:
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
The checker exits with status 1 and underlines torch.where(mask, x, y).
ERROR repro.py:13:26-49: Argument `Tensor[S]` is not assignable to parameter `input` with type `Tensor[S]` in function `torch.maximum` [bad-argument-type]
Replacing the return statement with these two lines passes. reveal_type(selected) and reveal_type(torch.maximum(selected, y)) both report Tensor[S].
selected = torch.where(mask, x, y)
return torch.maximum(selected, y)
The inline form also passes when the rank is fixed, including Tensor[[N, M]] with two symbolic extents. A direct maximum on incompatible shapes (2, 3) and (3, 2) correctly fails. Calling the original function with same-shaped CPU tensors succeeds and gives the expected elementwise values.
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
- 主要言語
- Rust
- スター
- 7.2k
- フォーク
- 578
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
facebook/pyrefly のほかの issue
-
pytorch tensor-shapes typechecking
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
good first issue typechecking
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
cargo b warning: unused dependency `zstd`対応中かも @Narendersingh007 が 4 日前に担当しました。 オープンgood first issue
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
-
pydantic
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
facebook/pyrefly の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
eventflux-io/eventflux#203 ·
メンテナーはふだん 1 日以内に返信
-
bug ui
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
userFRM/egui-charts#4068 ·
メンテナーはふだん 1 日以内に返信
-
fuzz-crash review-followup
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
marketing
難易度 2/5 半日 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
aws/aws-emulator#610 ·