pytorch/torch/_dynamo
zhxchen17 757975ad50 [export] Unified graph capture with fullgraph_capture. (#165562)
Summary:
_dynamo_graph_capture_for_export in the current form has the compability issue
with the main torch.compile() path despite we reuse fullgraph_capture as the
bytecode tracer. The reason is that we flip on many export specific flags
and even trace with a wrapped function which will cause divergence with
torch.compile() again.

This PR instead creates a new implementation of dynamo_graph_capture_for_export
which 100% relies on fullgraph capture and post-processing on CaptureOutput so
that we can avoid the inversion of phases in PT2 compiler stack.

This also benefits precompile workflow since we want to have a feature that
only accepts pytree inputs and ship portable python wrappers in package. In
other words, I think the code here is sharable between export and precompile
for exporting portable graph.

Test Plan:
===================================================================== test session starts =====================================================================
platform linux -- Python 3.12.11, pytest-7.3.2, pluggy-1.6.0
rootdir: /data/users/zhxchen17/pytorch
configfile: pytest.ini
plugins: xdoctest-1.1.0, hypothesis-5.35.1, xdist-3.3.1, subtests-0.13.1, rerunfailures-14.0, flakefinder-1.1.0, cpp-2.3.0, anyio-4.10.0
collected 9 items
Running 9 items in this shard

test/distributed/tensor/test_dtensor_export.py ........x                                                                                                [100%]

================================================================ 8 passed, 1 xfailed in 11.42s ================================================================

Reviewers:

Subscribers:

Tasks:

Tags:

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/165562
Approved by: https://github.com/tugsbayasgalan
2025-10-22 20:44:55 +00:00
..
backends Enable PLC1802 on ruff (#165813) 2025-10-18 05:44:14 +00:00
polyfills [pytree][dynamo] trace on native optree functions for community pytree support (#165860) 2025-10-21 14:13:08 +00:00
repro Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
variables [dynamo][user_defined] Replace UserFunctionVariable with VariableTracker build (#165706) 2025-10-22 19:28:27 +00:00
__init__.py [dynamo, nested graph breaks] fix nested step graph break related issues (#162737) 2025-10-08 22:02:52 +00:00
_trace_wrapped_higher_order_op.py Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
aot_compile_types.py Implement an AOT precompile mode for standalone_compile (#165843) 2025-10-21 15:02:45 +00:00
aot_compile.py Implement an AOT precompile mode for standalone_compile (#165843) 2025-10-21 15:02:45 +00:00
bytecode_analysis.py Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
bytecode_transformation.py [dynamo, nested graph breaks] fix nested step graph break related issues (#162737) 2025-10-08 22:02:52 +00:00
cache_size.py [Dynamo][Better Engineering] Add typing for comptime, cache, and convert_frame (#158379) 2025-07-18 02:11:57 +00:00
callback.py increment pending_callbacks_counter before initation the pt2 compile callbacks (#157185) 2025-06-30 01:23:59 +00:00
code_context.py
codegen.py Enable ruff rule E721 (#165162) 2025-10-13 01:48:55 +00:00
compiled_autograd.py [Fix] Adding missing f prefixes to formatted strings [1/N] (#164065) 2025-09-29 04:53:00 +00:00
comptime.py [Dynamo][Better Engineering] Add typing for comptime, cache, and convert_frame (#158379) 2025-07-18 02:11:57 +00:00
config.py [dynamo][ac] Config flag to allow eager and compile AC divergence for side-effects (#165775) 2025-10-17 22:04:19 +00:00
convert_frame.py [export] Unified graph capture with fullgraph_capture. (#165562) 2025-10-22 20:44:55 +00:00
create_parameter_op.py Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
current_scope_id.py
debug_utils.py Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
decorators.py [dynamo, nested graph breaks] fix nested step graph break related issues (#162737) 2025-10-08 22:02:52 +00:00
device_interface.py Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
distributed.py Implement guard collectives (optimized version) (#156562) 2025-06-24 04:59:49 +00:00
eval_frame.py better error message when there is no pytree impl (#165955) 2025-10-21 18:49:22 +00:00
exc.py Fix dynamo stack trace (#165930) 2025-10-21 01:32:23 +00:00
external_utils.py Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
funcname_cache.py
functional_export.py [export] Unified graph capture with fullgraph_capture. (#165562) 2025-10-22 20:44:55 +00:00
graph_break_hints.py
graph_break_registry.json [dynamo][annotate] Graph break cleanly on fx.traceback.annotate reconstruction (#166006) 2025-10-21 20:48:04 +00:00
graph_bytecode_inputs.py [user-cuda-streams] Pass streams/events to the graph via lookup table (#162899) 2025-10-14 05:43:19 +00:00
graph_deduplication.py Helper to augment graph with additional deps (#163959) 2025-09-30 04:53:58 +00:00
graph_region_tracker.py Enable all flake8-logging-format rules (#164655) 2025-10-19 00:59:28 +00:00
graph_utils.py [Intel GPU][pre_compile] Add XPU toolkit version and hardware info in compiled model check. (#162951) 2025-09-18 00:04:22 +00:00
guards.py [dynamo] Remove duplicated guards (#165806) 2025-10-20 05:50:33 +00:00
hooks.py
logging.py
metrics_context.py Optimize dynamo typing (#147499) 2025-08-25 13:20:45 +00:00
mutation_guard.py Revert "[dynamo][executorch] Do not trace into exeuctorch LoweredBackendModule (#165126)" 2025-10-10 19:21:41 +00:00
output_graph.py [export] Unified graph capture with fullgraph_capture. (#165562) 2025-10-22 20:44:55 +00:00
package.py Enable all flake8-logging-format rules (#164655) 2025-10-19 00:59:28 +00:00
pgo.py [PGO] log missing sources in allowlist (#164881) 2025-10-09 04:39:09 +00:00
precompile_context.py Enable all flake8-logging-format rules (#164655) 2025-10-19 00:59:28 +00:00
profiler.py Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
replay_record.py [Dynamo][Better Engineering] Type coverage for torch/_dynamo/utils.py (#159580) 2025-08-04 21:51:53 +00:00
resume_execution.py [dynamo, nested graph breaks] fix nested step graph break related issues (#162737) 2025-10-08 22:02:52 +00:00
side_effects.py [dynamo][ac] Config flag to allow eager and compile AC divergence for side-effects (#165775) 2025-10-17 22:04:19 +00:00
source.py [dynamo, 3.14] fix BUILD_TUPLE with 0 args (#163818) 2025-09-30 17:42:40 +00:00
symbolic_convert.py [dynamo] Fix MATCH_KEYS for dict pattern matching (#165956) 2025-10-22 02:52:07 +00:00
tensor_version_op.py [Dynamo][Better Engineering] Type devices, resume_execution and testing utils (#158593) 2025-07-18 18:22:06 +00:00
test_case.py Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
test_dont_skip_tracing_functions.py
test_minifier_common.py Pyrefly suppressions 7/n (#164913) 2025-10-08 07:27:17 +00:00
testing.py [dynamo][logging] Add most recent bytecode to graph break with torch._dynamo.graph_break() and verbose (#164422) 2025-10-10 17:33:06 +00:00
trace_rules.py Introduce a generic API torch._C._accelerator_setAllocatorSettings (#165291) 2025-10-19 15:34:36 +00:00
types.py Implement guard collectives (optimized version) (#156562) 2025-06-24 04:59:49 +00:00
utils.py inductor_provenance: Correctly handle null provenance (#166019) 2025-10-22 18:21:57 +00:00