python.context-manager ========================== null_context_manager ^^^^^^^^^^^^^^^^^^^^ .. note:: Tags: :doc:`python.context-manager ` Support Level: SUPPORTED Original source code: .. code-block:: python import contextlib import torch class NullContextManager(torch.nn.Module): """ Null context manager in Python will be traced out. """ def __init__(self): super().__init__() def forward(self, x): """ Null context manager in Python will be traced out. """ ctx = contextlib.nullcontext() with ctx: return x.sin() + x.cos() Result: .. code-block:: ExportedProgram: class GraphModule(torch.nn.Module): def forward(self, arg0_1: "f32[3, 2]"): sin: "f32[3, 2]" = torch.ops.aten.sin.default(arg0_1) cos: "f32[3, 2]" = torch.ops.aten.cos.default(arg0_1); arg0_1 = None add: "f32[3, 2]" = torch.ops.aten.add.Tensor(sin, cos); sin = cos = None return (add,) Graph signature: ExportGraphSignature(input_specs=[InputSpec(kind=, arg=TensorArgument(name='arg0_1'), target=None, persistent=None)], output_specs=[OutputSpec(kind=, arg=TensorArgument(name='add'), target=None)]) Range constraints: {}