Fix Reshape with 0-dims and rank change (issue #2104)#2142
Open
Fix Reshape with 0-dims and rank change (issue #2104)#2142
Conversation
compute_shape_with_tf_rules used a volume-matching approach to replace 0s in the shape spec, which failed when consecutive input dims of value 1 caused the iterator to not advance. Replace with simple positional substitution per the ONNX spec: shape[i]=0 means copy input[i]. Fixes Moonshine TTS model loading where RoPE reshapes like [1,52,8,32] → [0,0,8,16,2] produced [1,1,8,16,2] instead of [1,52,8,16,2].
ONNX Shape/Size outputs are declared TDim in tract so symbolic dims survive shape-plumbing chains. The Cast loader already rewrites Cast(to=i64) to Cast(to=TDim) to keep that invariant when the exporter inserts an explicit int64 round-trip. Some exporters (e.g. Moonshine) cast shape values to int32 instead. Widen the same rewrite to i32 so those chains also stay in TDim; without this, the first Cast(TDim->i32) loses the symbol and downstream Reshape lowering bails with "shape input is variable".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
compute_shape_with_tf_rules used a volume-matching approach to replace 0s in the shape spec, which failed when consecutive input dims of value 1 caused the iterator to not advance. Replace with simple positional substitution per the ONNX spec: shape[i]=0 means copy input[i].
Fixes Moonshine TTS model loading where RoPE reshapes like [1,52,8,32] → [0,0,8,16,2] produced [1,1,8,16,2] instead of [1,52,8,16,2].