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 9 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
01798b0 to
fd52275
Compare
|
|
||
| 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
…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
dae27b3 to
69a0857
Compare
|
failing tests- |
|
|
||
| # Forwarded to the partitioner to fill Dim.DYNAMIC upper bounds. | ||
| # Read-only w.r.t. ShapeEnv so range_constraints survive save/re-export. | ||
| user_symbol_bounds = _build_user_symbol_bounds( |
There was a problem hiding this comment.
instead of trying to handle args, kwargs, why not operate on the flattened pytree inputs? If you really do need to do this work this early then you can always call in_spec to flatten the args, kwargs. Then the order is deterministic and you arent doing name matching
| """ | ||
| placeholders = [n for n in gm.graph.nodes if n.op == "placeholder"] | ||
|
|
||
| sample_by_name: dict[str, Input] = {} |
There was a problem hiding this comment.
Like this code should go away with pytree flattening and you can just zip the placeholders
|
|
||
| # Flatten args+kwargs in pytree order — guaranteed to match placeholder | ||
| # order by torch.export, so we can zip directly without name matching. | ||
| flat_inputs, _ = pytree.tree_flatten((list(sample_arg_inputs), sample_kwarg_inputs)) |
There was a problem hiding this comment.
This should come from the exported program (i believe its called in_spec)
| log only); the ``user_min=1, exp_min=2`` case warns -- it's PyTorch's | ||
| 0/1 specialization artifact, not a user error. | ||
| """ | ||
| placeholders = [n for n in gm.graph.nodes if n.op == "placeholder"] |
There was a problem hiding this comment.
Same thing here, there should be a flat list of inputs to the graph
There was a problem hiding this comment.
we would need the placeholders for the faketensor values right?
This PR validates user bounds against any finite exporter bounds, with three branches: