MCPcopy Create free account
hub / github.com/apache/tvm / test_cond_nested

Function test_cond_nested

tests/python/relax/test_frontend_from_exported_program.py:9253–9287  ·  view source on GitHub ↗

Nested cond: a cond inside one of the branches.

()

Source from the content-addressed store, hash-verified

9251
9252
9253def test_cond_nested():
9254 """Nested cond: a cond inside one of the branches."""
9255
9256 class CondNestedModel(Module):
9257 def forward(self, x):
9258 def true_fn(x):
9259 def inner_true(x):
9260 return x * 2.0
9261
9262 def inner_false(x):
9263 return x * 3.0
9264
9265 return torch.cond(x.sum() > 1, inner_true, inner_false, (x,))
9266
9267 def false_fn(x):
9268 return x - 1.0
9269
9270 return torch.cond(x.sum() > 0, true_fn, false_fn, (x,))
9271
9272 example_args = (torch.randn(3, 4),)
9273 exported_program = export(CondNestedModel(), args=example_args)
9274 mod = from_exported_program(exported_program)
9275
9276 assert isinstance(mod, tvm.IRModule)
9277
9278 # Should have at least 4 branch functions (2 outer + 2 inner) plus main
9279 func_names = [gv.name_hint for gv in mod.get_global_vars()]
9280 branch_funcs = [n for n in func_names if n != "main"]
9281 assert len(branch_funcs) >= 4, (
9282 f"Expected at least 4 branch functions for nested cond, got {branch_funcs}"
9283 )
9284 # Verify no duplicate function names
9285 assert len(set(branch_funcs)) == len(branch_funcs), (
9286 f"Duplicate branch function names: {branch_funcs}"
9287 )
9288
9289
9290def test_affine_grid():

Callers

nothing calls this directly

Calls 3

from_exported_programFunction · 0.90
CondNestedModelClass · 0.85
get_global_varsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…