Skip to content

Deprecate compile, enable_ac, and numerics_logger from AutoParallel API - #415

Merged
aditvenk merged 1 commit into
mainfrom
ps/rr/deprecate_compile__enable_ac__and_numerics_logger_from_autoparallel_api
Apr 27, 2026
Merged

aditvenk merged 1 commit into
mainfrom
ps/rr/deprecate_compile__enable_ac__and_numerics_logger_from_autoparallel_api

Conversation

@aditvenk

@aditvenk aditvenk commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Make compilation a composable, downstream concern: users call torch.compile() on the module AP returns, optionally using the new inductor_config() context manager for AP-optimized passes (activation checkpointing, overlap scheduling).

The key insight is that AP already partitions the joint graph into fwd/bwd via aot_compile_joint_with_descriptors. The returned module's forward() is a normal callable -- torch.compile() traces it with Dynamo, AOTAutograd creates a fresh joint graph, and Inductor's min-cut partitioner operates on that new graph (not AP's original). AC recomputation tags (MUST_RECOMPUTE/MUST_SAVE from FSDP all-gather tagging) are structural after AP's partitioner runs, so they survive the torch.compile round-trip.

Examples that previously used compile=True now use:
with inductor_config():
parallel_mod = torch.compile(parallel_mod)

Tests that previously used compile=True are updated similarly. Three obsolete tests in test_api.py (overlap scheduling under compile, compile_true smoke test, inference-with-compile) are removed since they tested the old in-AP compile path.

Depends on pytorch/pytorch#179649 which fixes torch.compile over pre-partitioned AOTAutograd graphs containing
graphsafe_run_with_rng_state (from selective activation checkpointing).

@aditvenk
aditvenk requested a review from fmassa April 8, 2026 00:35
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 8, 2026
@aditvenk
aditvenk force-pushed the ps/rr/deprecate_compile__enable_ac__and_numerics_logger_from_autoparallel_api branch from fa90f00 to bf6bad8 Compare April 21, 2026 19:29
@aditvenk
aditvenk marked this pull request as ready for review April 21, 2026 19:30
@aditvenk
aditvenk force-pushed the ps/rr/deprecate_compile__enable_ac__and_numerics_logger_from_autoparallel_api branch 4 times, most recently from a4d4fe1 to 3da4f5f Compare April 21, 2026 21:28

@fmassa fmassa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @aditvenk !

Upon reviewing it, I remembered one of the blocker issues I had when working on this in the past, which unfortunately is not handled by this PR.

The problem is around maintaining user-specified AC regions in the second compilation (i.e., the external torch.compile).
In the current setting, AP's partitioner will be taking the user-specified AC regions into account during the fwd/bwd split. But during the second compilation, the joint graph will be the stitching between the fwd and the bwd+fwd recomputations, and the AC tags are not present anymore. Given that the joint graph will have redundant computations, the partitioner could actually decide to simplify the graph, which would remove the recomputation.

Do you agree with the issue?

Comment thread autoparallel/api.py Resolved
@fmassa

fmassa commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Here is some discussion from Claude, discussing about the lack of AC propagation through the second recompilation.

This is a great question. Let me think through what the ideal PyTorch-side solution looks like.                                                                                                                                             
                                                            
  The core tension                                                                                                                                                                                                                            
   
  AP has already made partitioning decisions (AC, FSDP recomputation, user checkpoints). When torch.compile runs, AOTAutograd creates a fresh joint graph and re-partitions from scratch, potentially undoing all of those decisions. The root
   cause: AOTAutograd couples "trace ops for Inductor" with "partition into fwd/bwd", and there's no way to do the former without the latter.

  Why a "simple" partitioner doesn't help either

  You might think: use a data-dependency-only partitioner (no min-cut) to preserve the structure. But it still fails. After AP's partitioner recomputes an all-gather in backward, the fresh joint graph has two all-gather nodes taking the
  same primal as input. Neither depends on tangents. Any partitioner — even a trivial one — would classify both as forward ops, undoing the recomputation.

  The only nodes that naturally land in backward are those that transitively depend on tangents. Ops that AP chose to recompute (all-gathers, checkpointed regions) don't depend on tangents — they depend on primals. So any partitioner will
   pull them into forward unless told otherwise via explicit tags.

  What PyTorch should provide

  The key insight is: AP's graphs are already partitioned. What we want from torch.compile is Inductor's per-graph optimizations (kernel fusion, memory planning, overlap scheduling), not re-partitioning.

  PyTorch should provide a way to decouple these two concerns. Concretely:

  A "pre-partitioned autograd.Function" protocol:

  1. The CompiledFunction (or a wrapper) declares itself as pre-partitioned — it already has separate fwd/bwd graphs with correct saved-tensor wiring
  2. AOTAutograd recognizes this and treats it as an opaque node in the joint graph — no re-partitioning. The function's own autograd.Function handles the fwd/bwd boundary
  3. Inductor receives the forward graph containing this opaque node. During lowering, Inductor inlines the function's ops and runs its optimization passes (fusion, scheduling, memory planning) on the expanded ops
  4. Same for backward

  AOTAutograd sees:  [DTensor ops] → [opaque pre-partitioned node] → [output]
                     ↓ trivial partition (opaque node stays in fwd)
  Inductor receives: [DTensor ops] → [opaque node] → [output]
                     ↓ inline during lowering
  Inductor optimizes: [DTensor ops] → [all_gather → mm → ...] → [output]

  This gives you:
  - No re-partitioning: AP's AC, FSDP recomputation, and user checkpoint decisions are preserved
  - Inductor optimization: fusion, overlap scheduling, memory planning all work on the inlined ops
  - Dynamo benefits preserved: guards, caching, tracing of the outer code (DTensor ops, input validation)

  What about joint-graph passes?

  The existing joint-graph passes in _aot_stage2a_partition are:
  - joint_custom_pass — AC (AP already handled this)
  - run_joint_graph_passes_on_hops — HOP subgraph partitioning (AP already resolved HOPs)
  - partition_fn — min-cut (exactly what we want to skip)

  All of these are partition-related. Inductor's actual value-add (fusion, scheduling, overlap, codegen) operates on individual post-partition graphs, not the joint graph. So skipping joint-graph passes is fine for the current set.

  The risk is future joint-graph passes that are NOT partition-related. But this can be addressed incrementally: if PyTorch adds a new joint pass that's valuable independent of partitioning, it can be run separately on the pre-partitioned
   fwd/bwd graphs. The protocol could include a hook for "post-partition joint-compatible passes" that operate on individual graphs.

  What this requires from PyTorch

  Concretely, the changes needed:

  1. A flag or protocol on autograd.Function: something like _is_pre_partitioned = True that AOTAutograd checks. When set, AOTAutograd wraps the function in invoke_leaf_function (or similar) with a ProxyTorchDispatchMode handler that
  creates an opaque node — preventing re-partitioning.
  2. Inductor lowering for the opaque node: when Inductor encounters the opaque pre-partitioned node, it inlines the function's FX graph and runs its standard optimization passes. This is the key piece — opacity at the AOTAutograd level
  but transparency at the Inductor level.
  3. Backward compilation path: the autograd.Function's backward also needs Inductor compilation. This could be triggered lazily (on first backward call) or eagerly. The backward function's ops would similarly be inlined into an Inductor
  graph.

  Practical path forward

  In the short term (before PyTorch provides this), the inductor_config approach works if _make_ac_joint_pass is augmented to also call mark_fsdp_all_gather_recomputation. User-specified AC regions remain at risk, but AP's own AC and FSDP
   decisions would be protected.

  In the medium term, the pre-partitioned protocol is the clean solution. It aligns with a natural separation of concerns: AP owns partitioning, Inductor owns code generation, and they don't step on each other.

@fmassa

fmassa commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Actually, it might be that the issue I was mentioning isn't applicable, because even though the duplicate nodes might be CSE, the returned graph from AutoParallel seems to contain the original AC tags, which then get used by the second partitioner. So maybe everything works fine! I'm testing it out

@aditvenk

Copy link
Copy Markdown
Contributor Author

Actually, it might be that the issue I was mentioning isn't applicable, because even though the duplicate nodes might be CSE, the returned graph from AutoParallel seems to contain the original AC tags, which then get used by the second partitioner. So maybe everything works fine! I'm testing it out

Pl let me know what you find out!

@aditvenk
aditvenk force-pushed the ps/rr/deprecate_compile__enable_ac__and_numerics_logger_from_autoparallel_api branch from 3da4f5f to b3e33a6 Compare April 22, 2026 16:38

@fmassa fmassa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you very much @aditvenk !

@aditvenk
aditvenk force-pushed the ps/rr/deprecate_compile__enable_ac__and_numerics_logger_from_autoparallel_api branch 7 times, most recently from faa2706 to 71161b7 Compare April 27, 2026 01:31
Make compilation a composable, downstream concern: users call
torch.compile() on the module AP returns, optionally using the new
inductor_config() context manager for AP-optimized passes (activation
checkpointing, overlap scheduling).

The key insight is that AP already partitions the joint graph into
fwd/bwd via aot_compile_joint_with_descriptors. The returned module's
forward() is a normal callable -- torch.compile() traces it with
Dynamo, AOTAutograd creates a fresh joint graph, and Inductor's
min-cut partitioner operates on that new graph (not AP's original).
AC recomputation tags (MUST_RECOMPUTE/MUST_SAVE from FSDP all-gather
tagging) are structural after AP's partitioner runs, so they survive
the torch.compile round-trip.

Changes to api.py:
- Remove compile, enable_ac, ac_stage_size_in_GiB, numerics_logger
  parameters from AutoParallel.__init__
- Remove compile parameter from auto_parallel()
- Remove ac_joint_pass call from _apply_placement_common (moved to
  inductor_config context manager)
- Run view_to_reshape unconditionally in _apply_placement_common
  (previously only ran in the compile path; needed for eager too)
- Simplify _boxed_nop_preserve_node_meta to just an FX Interpreter
  wrapper (remove view_to_reshape and overlap scheduling from it)

New file autoparallel/compile.py:
- inductor_config() context manager that sets torch._functorch.config
  .joint_custom_pass for AC and torch._inductor.config
  .aten_distributed_optimizations.* for overlap scheduling
- Exported from autoparallel.__init__

Examples that previously used compile=True now use:
  with inductor_config():
      parallel_mod = torch.compile(parallel_mod)

Tests that previously used compile=True are updated similarly.
Three obsolete tests in test_api.py (overlap scheduling under compile,
compile_true smoke test, inference-with-compile) are removed since
they tested the old in-AP compile path.

Depends on pytorch/pytorch#179649 which fixes torch.compile over
pre-partitioned AOTAutograd graphs containing
graphsafe_run_with_rng_state (from selective activation checkpointing).

<!-- ps-id: fb58a4ab-f887-4e79-bea8-56ae48f6f36f -->
@aditvenk
aditvenk force-pushed the ps/rr/deprecate_compile__enable_ac__and_numerics_logger_from_autoparallel_api branch from 71161b7 to 1b7d486 Compare April 27, 2026 18:08
@aditvenk

Copy link
Copy Markdown
Contributor Author

TorchTitan update in pytorch/torchtitan#3114

@aditvenk
aditvenk merged commit 6215d55 into main Apr 27, 2026
10 of 11 checks passed
aditvenk added a commit to pytorch/torchtitan that referenced this pull request Apr 28, 2026
Update autoparallel experiments to match the new API from
meta-pytorch/autoparallel#415 which removes the
`compile` parameter from AutoParallel and replaces it with an explicit
`torch.compile(model, backend=autoparallel_backend())` call.

<!-- ps-id: 6002b76c-ab28-4486-be71-2fceec67c4d8 -->
@fmassa
fmassa deleted the ps/rr/deprecate_compile__enable_ac__and_numerics_logger_from_autoparallel_api branch April 29, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants