Skip to content

Honor explicit dtype before computing torch.cumprod - #2910

Draft
HowieYin wants to merge 1 commit into
apple:mainfrom
HowieYin:fix-cumprod-explicit-dtype-20261022
Draft

HowieYin wants to merge 1 commit into
apple:mainfrom
HowieYin:fix-cumprod-explicit-dtype-20261022

Conversation

@HowieYin

@HowieYin HowieYin commented Oct 22, 2026 •

Copy link
Copy Markdown

Summary

Draft — depends on #2909. This branch still has 4 FP16 regression failures from int32 data narrowing; the same tests pass with #2909 applied.

The PyTorch cumprod converter ignores explicit dtype. For [1.9, 2.2, 3.2] with dtype=torch.int32, PyTorch casts the input first and returns [1, 2, 6]. The converter instead multiplies the original floating-point values.

Changes

  • Read dtype from positional inputs or keyword arguments and cast before the gather/scatter loop, including for a length-one axis.
  • Use the existing int64-to-int32 and float64-to-fp32 mappings.
  • Reject explicit int8/uint8/int16 requests, which the current gather/scatter lowering cannot represent.

Testing

Local Core ML CPU prediction with Torch 2.8, TorchScript/TorchExport, FP32/FP16 compute, and an iOS17 target:

  • New tests cover fractional inputs, singleton and multiple axes, dtype=None, input dtypes, downstream consumers, and unsupported dtypes. The initial test set produces 48 failures and 14 passes before the converter fix.
  • This branch's cumprod/cumsum tests: 232 passed, 4 failed, 14 skipped.
  • Combined with Preserve int32 data when its 16-bit range is unknown #2909, including integer cast pass tests: 352 passed, 14 skipped. Skips are existing frontend/backend exclusions.

The 4 remaining failures are [200, 200, 2] and [256, 256, 1] on both frontends with FP16 compute. An int32 prefix product is narrowed before the next gather. Both examples remain as regression tests; this PR stays in draft until #2909 is incorporated and the branch is revalidated.

Existing FP16 accumulation rounding differences remain. No performance benchmark or full project test run was performed; remote CI has no results yet.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant