[MLX] cumsum accumulates in the input dtype: integer sums wrap and `dtype=` is ignored

Aperta
#25,519 1 commento 0 reazioni 2 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@nil-is-all ci sta già lavorando.

Dal 24/11/2026.

  • #25521 di @vineetha00 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug module: mlx triaged

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

Lingua principale
Python
Stelle
5.2k
Fork
1.3k
Merge medio
1g 7h
PR unite (30g)
644

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pytorch/executorch

Tutte le issue di pytorch/executorch

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.