Skip to content

Polygraphy: reject a tensor shape with unbalanced brackets - #4865

Open
SashaMIT wants to merge 1 commit into
NVIDIA:mainfrom
SashaMIT:fix/unbalanced-shape-brackets
Open

SashaMIT wants to merge 1 commit into
NVIDIA:mainfrom
SashaMIT:fix/unbalanced-shape-brackets

Conversation

@SashaMIT

Copy link
Copy Markdown

What does this PR do?

Closes #4864.

cast() removed brackets with str.strip("[]"). That drops any [ or ] from either end, so a shape does not have to be a matched pair. parse_meta("input:[1,2", includes_dtype=False) returned shape [1, 2]. The same wrong shape came back for 1,2], ]1,2[, and [1,2]].

A list now has to start with [ and end with ], and the inside cannot contain another bracket. [], [1,2], [1,2,], [-1,2], and ["batch",3] stay valid.

Testing

pytest --noconftest tests/tools/args/util/test_util.py: 46 passed.

On main, the four unbalanced shapes above each returned [1, 2]. After this change they raise PolygraphyException.

Drafted with Grok 4.7. The code has not yet been reviewed by a human.

parse_meta read input:[1,2 as shape [1, 2]. A list now has to start with '[' and end with ']', with no extra brackets.

Signed-off-by: Sasha Mitchell <sash.t.mitchell@gmail.com>
@SashaMIT
SashaMIT requested a review from a team as a code owner September 30, 2026 22:30
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.

Polygraphy parse_meta accepts a shape with a missing bracket

1 participant