[MLX] cumsum accumulates in the input dtype: integer sums wrap and `dtype=` is ignored
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
Start in _cumsum_handler in backends/mlx/ops.py, where the dtype kwarg is accepted by require_kwargs but never read. Check open PR #25521 first, since a fix is already under way. Done when the int8 example matches PyTorch: int64 output without dtype, and float32 with it, with tests covering integer and bool inputs.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The MLX delegate lowers torch.cumsum to a CumsumNode on the input tensor as-is. PyTorch accumulates in the output dtype: the dtype argument if given, otherwise int64 for bool and integer inputs. MLX accumulates in the input dtype, so small integer inputs overflow and wrap. The result is silently wrong, with the dtype PyTorch promised but wrapped values.
For x = torch.tensor([100, 100, 100], dtype=torch.int8):
| Call | PyTorch / expected | MLX delegate / actual |
|---|---|---|
torch.cumsum(x, 0) |
[100, 200, 300] int64 |
[100, -56, 44] int64 |
torch.cumsum(x, 0, dtype=torch.float32) |
[100., 200., 300.] |
[100., -56., 44.] |
Reproduced on ExecuTorch 8c3f75dfb1d70ad12161ab3c42b06b7e7a65e8ce.
Environment: Apple Silicon MacBook Air, macOS 15.1, Xcode 16.2, Python 3.12, built with install_executorch.py.
import torch
from executorch.backends.mlx.partitioner import MLXPartitioner
from executorch.exir import to_edge_transform_and_lower
from executorch.extension.pybindings.portable_lib import (
_load_for_executorch_from_buffer,
)
class Model(torch.nn.Module):
def forward(self, x):
return torch.cumsum(x, 0, dtype=torch.float32)
inputs = (torch.tensor([100, 100, 100], dtype=torch.int8),)
model = Model().eval()
print(model(*inputs)) # tensor([100., 200., 300.])
ep = torch.export.export(model, inputs)
edge = to_edge_transform_and_lower(ep, partitioner=[MLXPartitioner()])
runtime = _load_for_executorch_from_buffer(edge.to_executorch().buffer)
print(runtime.forward(inputs)) # [tensor([100., -56., 44.])]
Dropping dtype=torch.float32 gives [100, -56, 44] as int64.
_cumsum_handler in backends/mlx/ops.py accepts the dtype kwarg (require_kwargs(..., {"dtype"}, ...)) but never reads it, and it does no integer promotion. The existing cumsum tests only cover float32 inputs with no dtype.
Found by reading the op handlers for accepted-but-unused arguments, after #25332 and #25363. I have a fix with tests and will open a PR.
Investigated and written with assistance from Anthropic Claude.
cc @metascroy
- Ngôn ngữ chính
- Python
- Star
- 5.2k
- Fork
- 1.3k
- Merge trung bình
- 1 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 644
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pytorch/executorch
-
to_edge_transform_and_lower ignores some ops_to_not_decompose requests: multi-output ops, and non-core ops without a decompositionCó thể đã có người làm @Eureka-Zhang đã nhận 7 ngày trước. Đang mởmodule: exir
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
pytorch/executorch#25620 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Qualcomm AI Engine Direct - fp16a8w quantization crashes on layer_normCó thể đã có người làm @psiddh đã nhận 21 ngày trước. Đang mởbug module: qnn partner: qualcomm
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
pytorch/executorch#24434 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement triaged
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 68/100
pytorch/executorch#21640 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
quantize_per_channel and dequantize_per_tensor.tensor abort the process on a float32 scaleCó thể đã có người làm @AxelNoun đã nhận hôm nay. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
pytorch/executorch#25873 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
XNNPACK INT4 linear returns incorrect per-channel outputs and fails groupwise FP16 on Apple M4 MaxCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug module: quantization module: xnnpack
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 43/100
pytorch/executorch#25854 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của pytorch/executorch
Issue tương tự
-
Container fails to start when GitHub Releases is unavailable: uv run re-downloads the tvl wheelĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
trezor/trezor-user-env#421 ·
-
Support new version of pythonĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 91/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
tangentcode/tangentswarm#167 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày