What’s the difference between torch.fx.symbolic_trace
and torch.fx.Tracer().trace
?
import torch
from torchvision.models.resnet import resnet18
m = resnet18()
m1 = torch.fx.symbolic_trace(m)
m2 = torch.fx.Tracer().trace(m)
type(m1) <class ‘torch.fx.graph_module.GraphModule.new..GraphModuleImpl’>
type(m2) <class ‘torch.fx.graph.Graph’>
grpollak
(Georg Richard Pollak)
2
torch.fx.symbolic_trace
is a wrapper around a call to fx.Tracer.trace
to constructs a torch.fx.GraphModule
that holds a torch.fx.Graph
attribute.
torch.fx.Tracer().trace()
calls the tracer only to construct only the FX graph:
graph : torch.fx.Graph = torch.fx.Tracer().trace(m)
See also torch.fx — PyTorch 2.0 documentation