MCPcopy Create free account
hub / github.com/pytorch/executorch / dynamo_trace

Function dynamo_trace

exir/tracer.py:653–704  ·  view source on GitHub ↗

TODO: Once we fully migrate to torchdynamo frontend, we will remove this config option alltogether. For now, it helps with quick experiments with playing around with TorchDynamo

(
    f: Callable[..., Value],
    # pyre-ignore
    args: Tuple[Any, ...],
    aten_graph: bool,
    tracing_mode: str = "real",
    dynamo_config: Optional[ExirDynamoConfig] = None,
    # pyre-ignore
    dynamic_shapes: Optional[List[Any]] = None,
    _use_old_decomp_table: bool = False,
)

Source from the content-addressed store, hash-verified

651
652
653def dynamo_trace(
654 f: Callable[..., Value],
655 # pyre-ignore
656 args: Tuple[Any, ...],
657 aten_graph: bool,
658 tracing_mode: str = "real",
659 dynamo_config: Optional[ExirDynamoConfig] = None,
660 # pyre-ignore
661 dynamic_shapes: Optional[List[Any]] = None,
662 _use_old_decomp_table: bool = False,
663) -> Tuple[torch.fx.GraphModule, Set[Guard]]:
664 """
665 TODO: Once we fully migrate to torchdynamo frontend, we will remove
666 this config option alltogether. For now, it helps with quick
667 experiments with playing around with TorchDynamo
668 """
669 if dynamo_config is None:
670 dynamo_config = ExirDynamoConfig()
671
672 with torchdynamo.config.patch(
673 asdict(dynamo_config)
674 ), setting_python_recursive_limit(2000):
675 torchdynamo.reset()
676 try:
677 # TODO merge executorch functionalization with official
678 # functionalization
679 # pyre-fixme[7]: Expected `Tuple[GraphModule, Set[Guard]]` but got
680 # `ExportResult`.
681 return torchdynamo.export(
682 f,
683 aten_graph=aten_graph,
684 tracing_mode=tracing_mode,
685 assume_static_by_default=dynamo_config.assume_static_by_default,
686 decomposition_table=(
687 _default_decomposition_table(_use_old_decomp_table)
688 if aten_graph
689 else None
690 ),
691 dynamic_shapes=dynamic_shapes,
692 )(
693 *copy.deepcopy(args),
694 )
695 except torchdynamo.exc.Unsupported as exc:
696 raise ExportError(
697 ExportErrorType.NOT_SUPPORTED,
698 "The user code is using a feature we don't support. "
699 "Please try torchdynamo.explain() to get possible the reasons",
700 ) from exc
701 except Exception as exc:
702 raise InternalError(
703 "torchdynamo internal error occurred. Please see above stacktrace"
704 ) from exc
705
706
707def dispatch_trace(

Callers 2

captureFunction · 0.90
dispatch_traceFunction · 0.85

Calls 7

ExportErrorClass · 0.90
InternalErrorClass · 0.90
ExirDynamoConfigClass · 0.85
resetMethod · 0.45
exportMethod · 0.45

Tested by

no test coverage detected