user provided bound for torchtrt compile when export dimension is unb…#4213
user provided bound for torchtrt compile when export dimension is unb…#4213apbose wants to merge 8 commits into
Conversation
4d1ff02 to
eec2c04
Compare
|
CI index put cases failing. Looking at it. |
0fe114e to
2905ff6
Compare
|
This PR is only for externally exported programs? |
|
@narendasan yeah it addresses (torch_tensorrt.dynamo.compile(exported_program, ...)). The flow for torch_tensorrt.compile(model, inputs=..) should be unaffected, since in that case export bounds and input bounds should be same |
dee44b1 to
22728b3
Compare
narendasan
left a comment
There was a problem hiding this comment.
You should use the user bounds in the narrow case
02d94e5 to
01798b0
Compare
…ympy.oo in extract_var_range_info, validate Input against finite export bounds
…specialization artifact, unify bound-mismatch message templates
…lders; sync assertions with refactored bound-mismatch messages
01798b0 to
fd52275
Compare
| if exp_max_unbounded: | ||
| # Dim.DYNAMIC: user fills the gap (intended use). | ||
| continue | ||
| try: | ||
| exp_min = int(exp_lower) | ||
| exp_max = int(exp_upper) | ||
| except (TypeError, ValueError): | ||
| continue | ||
| if user_min == exp_min and user_max == exp_max: | ||
| continue |
There was a problem hiding this comment.
Can you explain what the logic here is?
There was a problem hiding this comment.
This block runs only when the exported program already bounds the symbol to a finite range (e.g. exported with Dim("batch", min=10, max=20)). The compiled engine's TRT optimization profile follows that exported range, so we compare the user's Input range against it here, at compile time, and handle four cases:
- exported upper is unbounded (Dim.DYNAMIC) → user's Input fills the gap, nothing to validate (the continue just above);
- Input range == exported range → nothing to do;
- Input extends beyond the exported range (user_max > exp_max or user_min < exp_min) → those shapes can never run, so we raise now;
- Input strictly inside the exported range → safe to honor, we narrow the engine profile to the Input.
The user_min == exp_min and user_max == exp_max check on this line is just the "exact match → no-op" early-out.
|
|
||
| if user_max > exp_max: | ||
| raise ValueError( | ||
| f"{mismatch} Input.max_shape exceeds the exporter's max " |
There was a problem hiding this comment.
the exported program right?
There was a problem hiding this comment.
yeah the exported program. will change the wording
| if user_max > exp_max: | ||
| raise ValueError( | ||
| f"{mismatch} Input.max_shape exceeds the exporter's max " | ||
| f"({user_max} > {exp_max}); TRT will reject shapes above " |
There was a problem hiding this comment.
TRT will reject or pytorch will?
There was a problem hiding this comment.
TRT will. [10,20] + Input min_shape=2: shows
IExecutionContext::setInputShape: Error Code 3: API Usage Error
(Set dimension [2,8] for tensor x does not satisfy any optimization profiles.
Valid range for profile 0: [10,8]..[20,8])
through core/runtime/execute_engine.cpp:149.
| # 1->2 is the 0/1 specialization artifact, not a user error. | ||
| if user_min == 1 and exp_min == 2: | ||
| logger.warning( | ||
| "%s Input.min_shape=1 vs exporter min=2 is the " |
There was a problem hiding this comment.
I think we need to make sure these error messages are clear to follow from a user perspective
This PR validates user bounds against any finite exporter bounds, with three branches: