Skip to content

Add regression test for length-1 tensor int casts#2662

Open
hayeah wants to merge 1 commit intoapple:mainfrom
hayeah:test-cast-length1-const
Open

Add regression test for length-1 tensor int casts#2662
hayeah wants to merge 1 commit intoapple:mainfrom
hayeah:test-cast-length1-const

Conversation

@hayeah
Copy link
Copy Markdown

@hayeah hayeah commented Mar 16, 2026

Summary

  • add a Torch frontend regression test for int() on a foldable length-1 tensor
  • cover the minimal shape pattern that previously failed in coremltools 9.0
  • keep the test conversion-only so it exercises the frontend bug without requiring CoreML runtime prediction

Context

The released 9.0 converter fails on traced Torch graphs that contain aten::Int over a foldable length-1 tensor, for example a model that reshapes with int(h * w) after unpacking x.shape. Current main already handles this correctly in _cast; this test locks that behavior in.

Minimal repro shape pattern:

b, c, h, w = x.shape
return x.reshape(b, c, int(h * w))

I verified locally that:

  • coremltools 9.0 fails on this pattern with TypeError: only 0-dimensional arrays can be converted to Python scalars
  • current main converts it successfully

@TobyRoseman
Copy link
Copy Markdown
Collaborator

Your unit test passes for me with the 9.0 release.

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.

2 participants