Skip to content

State the limitation when chunk / unbind meet a dynamic dim - #2811

Open
LeSingh1 wants to merge 1 commit into
apple:mainfrom
LeSingh1:torch-dynamic-output-count
Open

State the limitation when chunk / unbind meet a dynamic dim#2811
LeSingh1 wants to merge 1 commit into
apple:mainfrom
LeSingh1:torch-dynamic-output-count

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

chunk and unbind both derive their number of outputs from the size of the dim they act on, so that dim has to be known at conversion time. Neither says so.

# torch.chunk(x, 3, dim=0) with a dynamic dim 0
TypeError: Cannot convert expression to float          # float(x.shape[dim])

# torch.unbind(x, dim=0) with a dynamic dim 0
TypeError: can't multiply sequence by non-int of type 'Symbol'   # [1] * x.shape[dim]

Neither message names the op or the limitation, and both come from inside the converter.

This raises a ValueError saying which dim is the problem and what to do instead, following what _adaptive_pool2d already does for the same situation. No model that converts today is affected — these paths only ever raised.

Also adds the first chunk tests; there were none.

Both ops derive their number of outputs from the size of the dim they act
on, so that dim has to be known at conversion time. Neither said so.

constantchunk did float(x.shape[dim]) and unbind did [1] * x.shape[dim],
which on a symbolic dim raise "TypeError: Cannot convert expression to
float" and "TypeError: can't multiply sequence by non-int of type
'Symbol'" from inside the converter, with nothing naming the op or the
limitation.

Raise a ValueError that says which dim is the problem and what to do
instead, as _adaptive_pool2d already does for the same situation. No model
that converts today is affected: these paths only ever raised.

Also adds the first chunk tests; there were none.
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