Repository navigation
fix(dynamo): honor Input.profiles on the whole-graph path and document how to set opt for exported programs - #5085
Draft
shoumikhin wants to merge 4 commits into
Draft
shoumikhin wants to merge 4 commits into
shoumikhin wants to merge 4 commits into
Conversation
shoumikhin
force-pushed
the
opt-shape-exported-program
branch
from
November 20, 2026 11:52
f9f6fdb to
fb0fc92
Compare
shoumikhin
force-pushed
the
opt-shape-exported-program
branch
2 times, most recently
from
November 20, 2026 21:51
f118f99 to
1f76ef6
Compare
shoumikhin
force-pushed
the
opt-shape-exported-program
branch
4 times, most recently
from
November 21, 2026 14:21
f012726 to
ca7e49c
Compare
shoumikhin
force-pushed
the
opt-shape-exported-program
branch
2 times, most recently
from
November 21, 2026 21:17
e689f7e to
3c8b2c1
Compare
shoumikhin
force-pushed
the
opt-shape-exported-program
branch
2 times, most recently
from
November 22, 2026 00:39
b64999f to
89a1a5c
Compare
shoumikhin
force-pushed
the
opt-shape-exported-program
branch
2 times, most recently
from
November 23, 2026 19:56
78e64a0 to
dd94db4
Compare
…t how to set opt for exported programs With require_full_compilation=True and every operator supported, compile converts the whole graph as one engine and skips partitioning. That path ignored Input.profiles. It built one profile, tuned for the export example, that covered every entry, so optimization_profile(model, 1) had no profile to select. The partitioned path builds one profile per entry, and before the whole-graph path existed (2.14) this case took it too. Build the profiles once, before the path is chosen, and use them on both paths: each engine gets one profile per entry, and different profile counts raise. This changes the whole-graph path for inputs with more than one profile. A call outside profile 0 must now pick a profile with optimization_profile, a size that no profile covers cannot run, and inputs with different profile counts no longer compile. That is how the partitioned path already works. Match the Inputs to the graph inputs through the export input spec, as _build_user_symbol_bounds already does, instead of by position. Without a spec, for example after a mutated buffer becomes an engine input, match kwargs by name and take the args in order, then any kwarg that names no graph input, as export can rename an argument (X becomes x). Before, kwargs passed in a different order than at export, a tuple input before a profiled one, or a mutated buffer next to profiled kwargs gave an input the profile of another input. For an ExportedProgram, the engine opt comes from the export example, and a plain Input(min_shape, opt_shape, max_shape) does not change it. Warn once per compile when opt_shape differs from the example in a dynamic dimension of the export that no profile covers, and document the two ways to set opt: export with an example of that size, or pass the input as a single entry in Input(profiles=[...]). The 0/1 specialization message said the engine min would be 2, but the engine keeps min 1. Make it a debug message that says so. Signed-off-by: Anthony Shoumikhin <[email protected]>
The warning that a plain Input.opt_shape does not set the engine opt was logged before compile_module knew whether TensorRT would get any part of the graph, so a compile that converts nothing still warned about an engine. _build_user_symbol_bounds now returns the dims it would warn about, and compile_module warns on the whole-graph path, and on the partitioned path only when a TensorRT part exists. The input checks in _build_user_symbol_bounds still run where they did. The unit tests that exported at their opt_shape only to avoid the old warning go back to their original examples, and the guide says when the warning is logged. Signed-off-by: Anthony Shoumikhin <[email protected]>
The 0/1 specialization test passed whether or not the branch ran, so check its debug record. Signed-off-by: Anthony Shoumikhin <[email protected]>
save_dynamic_shapes_example.py exported its first model at batch 2 with opt_shape batch 8, so the engine was tuned for batch 2. Export it at batch 8. Signed-off-by: Anthony Shoumikhin <[email protected]>
shoumikhin
force-pushed
the
opt-shape-exported-program
branch
from
November 23, 2026 20:35
dd94db4 to
89ee0d5
Compare
shoumikhin
marked this pull request as draft
November 23, 2026 21:54
Collaborator
|
The explicit-profile propagation fix looks good. For a follow-up API cleanup, could we make the intent explicit? When compiling an ExportedProgram, opt_shape=None would use the export example, while an explicitly supplied opt_shape would override it. For Input.profiles, we could also accept a named OptimizationProfile(min_shape, opt_shape, max_shape) alongside dictionaries? For example: This would make profiles clearer to construct and distinguish an omitted optimization shape from an explicit override. Let me know what you think? |
Contributor
Author
|
Thanks for the review. I agree with both points.
Both change the public |
This branch has not been deployed
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.
What is wrong today
TensorRT tunes an engine for one size in each dynamic range, the opt size. For a dynamic
ExportedProgram:require_full_compilation=True, the whole-graph path (taken when every operator converts) ignoresInput.profiles, sooptimization_profile(model, 1)has nothing to select. In 2.14 the same call built one profile per entry.Input(min_shape, opt_shape, max_shape)does not set opt for an exported program. Opt comes from the export example. This is undocumented (🐛 [Bug]Input(opt_shape=...)is ignored when compiling anExportedProgram, so decode steps run prefill-sized kernels #5076).Dim(min=1), compile warns that the engine min will be 2, but it is 1.What this change does
profilesentry, matched to the inputs through the export input spec.optimization_profile, a size that no profile covers cannot run, and different profile counts raise.Input.opt_shapediffers from the export example in a dynamic dimension no profile covers, and TensorRT gets part of the graph, compile logs one warning naming both ways to set opt.save_dynamic_shapes_example.pynow exports at its opt size.Tests
opt_shape.Models without
profilesbuild the same engines.