python.context-manager¶
null_context_manager¶
Original source code:
import contextlib
import torch
def null_context_manager(x):
"""
Null context manager in Python will be traced out.
"""
ctx = contextlib.nullcontext()
with ctx:
return x.sin() + x.cos()
Result:
ExportedProgram:
class GraphModule(torch.nn.Module):
def forward(self, l_x_: "f32[3, 2]"):
sin: "f32[3, 2]" = torch.ops.aten.sin.default(l_x_)
cos: "f32[3, 2]" = torch.ops.aten.cos.default(l_x_); l_x_ = None
add: "f32[3, 2]" = torch.ops.aten.add.Tensor(sin, cos); sin = cos = None
return (add,)
Graph signature: ExportGraphSignature(input_specs=[InputSpec(kind=<InputKind.USER_INPUT: 1>, arg=TensorArgument(name='l_x_'), target=None)], output_specs=[OutputSpec(kind=<OutputKind.USER_OUTPUT: 1>, arg=TensorArgument(name='add'), target=None)])
Range constraints: {}
Equality constraints: []