-
Notifications
You must be signed in to change notification settings - Fork 370
fix: Inferred dimensions at build time in reshape #3746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also is this PR required for pre-quantized models PR ?
total_elements = 1 | ||
for s in input.shape: | ||
if s != -1: | ||
total_elements *= s | ||
|
||
# Divide by known dimensions in new_shape to find the inferred dimension | ||
# This ensures the total number of elements remains the same | ||
for s in new_shape: | ||
if isinstance(s, int) and s != -1: | ||
if total_elements % s != 0: | ||
raise ValueError( | ||
f"Cannot infer dimension: {total_elements} elements not divisible by {s}" | ||
) | ||
total_elements //= s | ||
|
||
# Replace -1 with the calculated inferred dimension | ||
new_shape[inferred_dim_index] = total_elements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please give an example here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had issue with TinyLlama/TinyLlama-1.1B-Chat-v1.0 model with nvpf4 quantization. But this problem is not present with the latest torch-TRT. |
Description
Added special case handling in the reshape operation to detect and handle cases involving dynamic shape and inferred dim.
This new logic in reshape:
Fixes #3745
Type of change
Please delete options that are not relevant and/or add your own.
Checklist: