MCPcopy Create free account
hub / github.com/pytorch/tutorials / cond_predicate

Function cond_predicate

intermediate_source/torch_export_tutorial.py:933–941  ·  view source on GitHub ↗

The conditional statement (aka predicate) passed to ``cond()`` must be one of the following: - ``torch.Tensor`` with a single element - boolean expression NOTE: If the `pred` is test on a dim with batch size < 2, it will be specialized.

(x)

Source from the content-addressed store, hash-verified

931# We can look at the example called ``cond_predicate``, which has a ``torch.cond`` tag. The example code looks like:
932
933def cond_predicate(x):
934 """
935 The conditional statement (aka predicate) passed to ``cond()`` must be one of the following:
936 - ``torch.Tensor`` with a single element
937 - boolean expression
938 NOTE: If the `pred` is test on a dim with batch size < 2, it will be specialized.
939 """
940 pred = x.dim() > 2 and x.shape[2] > 10
941 return cond(pred, lambda x: x.cos(), lambda y: y.sin(), [x])
942
943######################################################################
944# More generally, ExportDB can be used as a reference when one of the following occurs:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected