Skip to content

Convert torch.cond to TensorRT IIfConditional - #4657

Open
micwill755 wants to merge 1 commit into
mainfrom
convert-torch-cond
Open

Convert torch.cond to TensorRT IIfConditional#4657
micwill755 wants to merge 1 commit into
mainfrom
convert-torch-cond

Conversation

@micwill755

Copy link
Copy Markdown
Collaborator

Summary

  • Convert torch.ops.higher_order.cond / torch.cond to TensorRT IIfConditional so the predicate and both branches stay in one TRT engine instead of falling back to PyTorch.
  • Support cond only when both branch GraphModules are fully convertible; otherwise the capability validator returns false and the partitioner keeps cond in PyTorch.
  • Recurse pre/post lowering into cond subgraphs, pass branch GraphModules through get_attr, and convert each branch in the existing network via a subgraph interpreter.

Fixes #3923

Test plan

  • tests/py/dynamo/conversion/test_cond_aten.py (add/sub, 1-element pred, multi-output, clone pass-through, Linear outside cond, nested cond)
  • tests/py/dynamo/models/test_cond.py (converter membership, unsupported-op fallback, require_full_compilation=True e2e for both pred values)

Keep both branches in one TRT engine when the predicate and subgraphs are convertible, instead of partitioning cond back to PyTorch.
@meta-cla meta-cla Bot added the cla signed label Sep 2, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: lowering Issues re: The lowering / preprocessing passes component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Sep 2, 2026
@github-actions
github-actions Bot requested a review from cehongwang September 2, 2026 09:29
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: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: lowering Issues re: The lowering / preprocessing passes component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert torch.cond

1 participant