Skip to content

fix: resolve ExecuTorch TRT target_device per partition (coalesced multi-engine)#4350

Open
shoumikhin wants to merge 2 commits into
pytorch:mainfrom
shoumikhin:fix/executorch-per-partition-device
Open

fix: resolve ExecuTorch TRT target_device per partition (coalesced multi-engine)#4350
shoumikhin wants to merge 2 commits into
pytorch:mainfrom
shoumikhin:fix/executorch-per-partition-device

Conversation

@shoumikhin

@shoumikhin shoumikhin commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

What's broken

When coalescing TensorRT with other delegates into one .pte, the graph has multiple TensorRT engines. TensorRTPartitioner resolved target_device once for the whole program via _get_engine_info_from_edge_program(), which requires exactly one engine node. With more than one engine it raised, so every TensorRT partition fell back to cuda:0 with a spurious warning:

Could not derive target_device from the TensorRT engine (... expects exactly 1
engine node per partition, found 2); falling back to cuda:0.

On a single GPU this is just noise, but a multi-GPU graph cannot label each delegate with its own device.

The fix

Extract _get_engine_info_for_node() (single-node engine-info extraction) out of _get_engine_info_from_edge_program() (which keeps its one-engine contract used by preprocess()), then resolve target_device per partition from that partition's own engine node.

  • Single-GPU behavior is unchanged (still cuda:0), minus the spurious warning.
  • Multi-engine / multi-GPU graphs now get a correct per-delegate device label.
  • Any extraction failure (no single engine node in the partition, or an unreadable index) still falls back to cuda:0 rather than aborting the export.

Test

  • Unit tests over the partitioner path in tests/py/dynamo/executorch/test_partitioner_target_device.py and tests/py/dynamo/executorch/test_api.py: default GPU, non-zero GPU, a coalesced multi-engine graph resolving partition 0 → cuda:0 and partition 1 → cuda:1, the >1-engine-in-one-partition fallback, a malformed-partition fallback, and an explicit target_device pin taking precedence.
  • Verified on a coalesced TensorRT → Another → TensorRT model (two TRT engines plus one other delegate): the .pte still contains both TensorRTBackend and AnotherBackend, and the "found 2 engines" warning no longer fires.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project (isort + black)
  • I have added tests that prove my fix is effective
  • Commit is signed off (DCO)

@meta-cla meta-cla Bot added the cla signed label Jun 18, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Jun 18, 2026
@github-actions github-actions Bot requested a review from lanluo-nvidia June 18, 2026 04:35
@shoumikhin shoumikhin force-pushed the fix/executorch-per-partition-device branch 2 times, most recently from 380e295 to 6971383 Compare June 18, 2026 05:07
@narendasan narendasan requested a review from cehongwang June 22, 2026 19:08
@cehongwang

cehongwang commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

The existing test_partitioner_target_device.py is not updated and will fail under the new per‑partition logic. tests/py/dynamo/executorch/test_partitioner_target_device.py

@shoumikhin

Copy link
Copy Markdown
Contributor Author

Good catch, fixed in the latest commit. Updated tests/py/dynamo/executorch/test_partitioner_target_device.py for the per-partition resolution: the fake partitioner now puts each engine node in its own partition, so the real _get_engine_info_for_node path runs per partition. Added a coalesced multi-engine test asserting partition 0 -> cuda:0 and partition 1 -> cuda:1, and a >1-engine-in-one-partition fallback case. The default / nonzero-GPU / explicit-pin / malformed-graph cases still pass. PTAL.

@shoumikhin shoumikhin force-pushed the fix/executorch-per-partition-device branch from fd3c628 to 5933f20 Compare July 6, 2026 21:29
Comment thread py/torch_tensorrt/executorch/partitioner.py
shoumikhin and others added 2 commits July 6, 2026 15:08
TensorRTPartitioner resolved target_device once for the whole exported program
via _get_engine_info_from_edge_program(), which requires exactly one engine
node. A coalesced graph (TensorRT + CUDA delegates) has multiple TRT engines,
so that call raised and every TRT partition fell back to cuda:0 with a spurious
"expects exactly 1 engine node per partition, found N" warning; multi-GPU
graphs also could not be labeled per partition.

Extract _get_engine_info_for_node() (single-node engine-info extraction) from
_get_engine_info_from_edge_program() and resolve target_device per partition
from that partition's own engine node. Single-GPU behavior is unchanged (still
cuda:0) minus the warning; multi-engine/multi-GPU graphs now label each delegate
correctly.
The partitioner now derives target_device from each partition's own engine
node (coalesced multi-engine), so the test must place the engine node in the
partition and assert per-partition devices. Adds a coalesced multi-engine case
and a >1-engine-per-partition fallback case.
@shoumikhin shoumikhin force-pushed the fix/executorch-per-partition-device branch from 5933f20 to a5d4dbb Compare July 6, 2026 22:08

partition_tags: Dict[str, DelegationSpec] = {}
for partition in partition_list:
tag = f"tensorrt_{partition.id}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@narendasan Should the naming be consistent with dynamo's format like "run_on_acc" and "run_on_gpu"?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont think it matters as much for the executorch partitioner. For the other partitioners we need to match on tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants