Repository navigation
[inductor] Enable per-region cudagraphs for invoke_subgraph via auto graph partition - #190091
desertfire wants to merge 10 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190091
Note: Links to docs will display an error until the docs builds have been completed. ❌ 22 New Failures, 1 Unrelated FailureAs of commit b8e2e85 with merge base 5a7eae4 ( NEW FAILURES - The following jobs have failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@claude review this pr |
|
Claude finished @desertfire's task in 10m 7s —— View job PR Review: #190091One-sentence summary: The mechanism is well-designed and correct for the tested paths, but the region-body cudagraph-safety check drops two safety checks that the main Full reviewSummaryEnables per-region cudagraphs for Testing
Code Quality
Performance / Behavior
Backward path
RecommendationNeeds Discussion — no blocking bug in the tested paths, but the unsafe-unbacked-symint gap is a genuine (if niche) capture-correctness hole with no test, and the |
…graph partition Building on nested Inductor configs, a region can set triton.cudagraphs to opt into or out of cudagraphs independently of the enclosing graph. When a region's preference differs from the enclosing graph and graph partition is globally off, compile_fx enables graph partition just for that compile and should_partition isolates the region: an opted-in region becomes its own cudagraph partition (captured even when the enclosing graph has cudagraphs off), while an opted-out region stays inlined (excluded from the enclosing cudagraph). The region body is codegened without inner partitioning, so it is captured or skipped as a unit; a region whose body has a non-cudagraphable op falls back to running uncaptured. Forward and backward are controlled separately: bw_inductor_config_patches (from the fw/bw config split below) sets triton.cudagraphs for the backward, and compile_fx_backward re-derives the region-partition decision from the backward graph since the forward-derived config cannot see the backward regions. The partition detection reads the backward HOP node's config on node.meta["custom"], which the fw/bw config change below stamps in run_joint_graph_passes_on_hops. This change was authored with the assistance of an AI coding agent. ghstack-source-id: 08a0f2c Pull-Request: #190091
|
@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
…graph partition Building on nested Inductor configs, a region can set triton.cudagraphs to opt into or out of cudagraphs independently of the enclosing graph. When a region's preference differs from the enclosing graph and graph partition is globally off, compile_fx enables graph partition just for that compile and should_partition isolates the region: an opted-in region becomes its own cudagraph partition (captured even when the enclosing graph has cudagraphs off), while an opted-out region stays inlined (excluded from the enclosing cudagraph). The region body is codegened without inner partitioning, so it is captured or skipped as a unit; a region whose body has a non-cudagraphable op falls back to running uncaptured. Forward and backward are controlled separately: bw_inductor_config_patches (from the fw/bw config split below) sets triton.cudagraphs for the backward, and compile_fx_backward re-derives the region-partition decision from the backward graph since the forward-derived config cannot see the backward regions. The partition detection reads the backward HOP node's config on node.meta["custom"], which the fw/bw config change below stamps in run_joint_graph_passes_on_hops. This change was authored with the assistance of an AI coding agent. ghstack-source-id: e95de42 Pull-Request: #190091
|
@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
…graph partition Building on nested Inductor configs, a region can set triton.cudagraphs to opt into or out of cudagraphs independently of the enclosing graph. When a region's preference differs from the enclosing graph and graph partition is globally off, compile_fx enables graph partition just for that compile and should_partition isolates the region: an opted-in region becomes its own cudagraph partition (captured even when the enclosing graph has cudagraphs off), while an opted-out region stays inlined (excluded from the enclosing cudagraph). The region body is codegened without inner partitioning, so it is captured or skipped as a unit; a region whose body has a non-cudagraphable op falls back to running uncaptured. Forward and backward are controlled separately: bw_inductor_config_patches (from the fw/bw config split below) sets triton.cudagraphs for the backward, and compile_fx_backward re-derives the region-partition decision from the backward graph since the forward-derived config cannot see the backward regions. The partition detection reads the backward HOP node's config on node.meta["custom"], which the fw/bw config change below stamps in run_joint_graph_passes_on_hops. This change was authored with the assistance of an AI coding agent. ghstack-source-id: e95de42 Pull-Request: #190091
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Rebase failed due to Command |
…graph partition Building on nested Inductor configs, a region can set triton.cudagraphs to opt into or out of cudagraphs independently of the enclosing graph. When a region's preference differs from the enclosing graph and graph partition is globally off, compile_fx enables graph partition just for that compile and should_partition isolates the region: an opted-in region becomes its own cudagraph partition (captured even when the enclosing graph has cudagraphs off), while an opted-out region stays inlined (excluded from the enclosing cudagraph). The region body is codegened without inner partitioning, so it is captured or skipped as a unit; a region whose body has a non-cudagraphable op falls back to running uncaptured. Forward and backward are controlled separately: bw_inductor_config_patches (from the fw/bw config split below) sets triton.cudagraphs for the backward, and compile_fx_backward re-derives the region-partition decision from the backward graph since the forward-derived config cannot see the backward regions. The partition detection reads the backward HOP node's config on node.meta["custom"], which the fw/bw config change below stamps in run_joint_graph_passes_on_hops. This change was authored with the assistance of an AI coding agent. ghstack-source-id: 4c9fa38 Pull-Request: #190091
|
@claude review this pr |
|
Claude finished @desertfire's task in 24m 25s —— View job PR Review: #190091One-sentence summary: The isolation mechanism is sound on the cold-compile path the tests exercise, but it makes Full reviewSummaryLets an Correctness1. Warm start (AOTAutogradCache hit) diverges from cold compile — if config.graph_partition and policy is None:
cudagraph_partition_post_compile(...) # per-partition cudagraphify
else:
cudagraph_post_compile(...) # whole-graph cudagraphifyBecause this PR is the first thing to compile a partitioned graph while the global flag stays 2. Backward-only region opt-in is silently lost on a cache hit. Same root cause, second symptom. With only 3. The opt-in
This is a behavior change even when the region agrees with the enclosing graph: with Code Quality4. 5. The region-isolation mechanism's dependence on 6. The forward decision is computed from a different graph than it is applied to. Testing7. Body scan does not recurse into 8. Unsafe unbacked symints in a region body remain undetected and untested. Repeating from my earlier pass since it is unaddressed: RecommendationRequest Changes — finding 1 is a warm-start capture-correctness hazard on an untested path, and finding 3 is a silent loss of existing safety checks. Findings 2, 4, 7, 8 should be resolved or explicitly deferred with a comment. |
|
@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
…graph partition Building on nested Inductor configs, a region can set triton.cudagraphs to opt into or out of cudagraphs independently of the enclosing graph. When a region's preference differs from the enclosing graph and graph partition is globally off, compile_fx enables graph partition just for that compile and should_partition isolates the region: an opted-in region becomes its own cudagraph partition (captured even when the enclosing graph has cudagraphs off), while an opted-out region stays inlined (excluded from the enclosing cudagraph). The region body is codegened without inner partitioning, so it is captured or skipped as a unit; a region whose body has a non-cudagraphable op falls back to running uncaptured. Forward and backward are controlled separately: bw_inductor_config_patches (from the fw/bw config split below) sets triton.cudagraphs for the backward, and compile_fx_backward re-derives the region-partition decision from the backward graph since the forward-derived config cannot see the backward regions. The partition detection reads the backward HOP node's config on node.meta["custom"], which the fw/bw config change below stamps in run_joint_graph_passes_on_hops. This change was authored with the assistance of an AI coding agent. ghstack-source-id: e85e7ab Pull-Request: #190091
…graph partition
Allow an invoke_subgraph region to opt into or out of cudagraph capture
independently of its enclosing graph, with separate forward and backward
configuration. When a region differs from the top-level decision and graph
partitioning is globally disabled, temporarily enable partitioning and isolate
that region as the unit that is captured or skipped.
Cold compilation previously depended on transient global config patches and on
re-deriving backward state from the backward graph. AOTAutograd cache hits bypass
both paths, which could capture an unsafe opt-out region or lose a backward-only
opt-in. Persist each graph's post-compile cudagraph override in CompiledFxGraph,
include the backward annotation decision in the cache configuration, and select
partition post-processing from the serialized partition maps. Persisting the
decision with the compiled artifact avoids reconstructing cold-path global state
during cache loading.
An explicit region opt-in also bypassed general scheduler-node safety checks, and
the region-body scan did not cover nested control-flow subgraphs or unsafe
unbacked SymInts. Apply the scheduler checks to the complete region family,
recurse through IR subgraphs such as WhileLoop, include output-layout symbols,
and share unsafe-unbacked-SymInt analysis between scheduled nodes and region IR.
Compiler state names now distinguish forward-derived, backward-local, top-level,
and graph-local post-compile decisions.
Test Plan:
```bash
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv=["test_cudagraph_trees.py", "-v", "-k", "aot_cache"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv=["test_cudagraph_trees.py", "-v", "-k", "invoke_subgraph"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv=["test_cudagraph_trees.py", "-v", "CudaGraphTreeTests.test_graph_partition_saved_activation_not_static", "CudaGraphTreeTests.test_graph_partition_no_partition_keeps_static"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
spin quicklint
lintrunner -a
```
The nine cache and scheduler regression instances failed on the original pre-fix
commit. The WhileLoop and unsafe-unbacked-SymInt tests also failed before their
corresponding fixes.
This change was authored with the assistance of an AI coding agent.
ghstack-source-id: 4f12977
Pull-Request: #190091
…graph partition
Allow an invoke_subgraph region to opt into or out of cudagraph capture
independently of its enclosing graph, with separate forward and backward
configuration. When a region differs from the top-level decision and graph
partitioning is globally disabled, temporarily enable partitioning and isolate
that region as the unit that is captured or skipped.
Cold compilation previously depended on transient global config patches and on
re-deriving backward state from the backward graph. AOTAutograd cache hits bypass
both paths, which could capture an unsafe opt-out region or lose a backward-only
opt-in. Persist each graph's post-compile cudagraph override in CompiledFxGraph,
include the backward annotation decision in the cache configuration, and select
partition post-processing from the serialized partition maps. Persisting the
decision with the compiled artifact avoids reconstructing cold-path global state
during cache loading.
An explicit region opt-in also bypassed general scheduler-node safety checks, and
the region-body scan did not cover nested control-flow subgraphs or unsafe
unbacked SymInts. Apply the scheduler checks to the complete region family,
recurse through IR subgraphs such as WhileLoop, include output-layout symbols,
and share unsafe-unbacked-SymInt analysis between scheduled nodes and region IR.
Compiler state names now distinguish forward-derived, backward-local, top-level,
and graph-local post-compile decisions.
Test Plan:
```bash
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv=["test_cudagraph_trees.py", "-v", "-k", "aot_cache"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv=["test_cudagraph_trees.py", "-v", "-k", "invoke_subgraph"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv=["test_cudagraph_trees.py", "-v", "CudaGraphTreeTests.test_graph_partition_saved_activation_not_static", "CudaGraphTreeTests.test_graph_partition_no_partition_keeps_static"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
spin quicklint
lintrunner -a
```
The nine cache and scheduler regression instances failed on the original pre-fix
commit. The WhileLoop and unsafe-unbacked-SymInt tests also failed before their
corresponding fixes.
This change was authored with the assistance of an AI coding agent.
ghstack-source-id: 4f12977
Pull-Request: #190091
|
@claude review this pr again |
|
Claude finished @desertfire's task in 36m 34s —— View job PR Review: #190091 (re-review)One-sentence summary: The cache-persistence rework correctly closes the warm-start hole from my last pass and the dropped-safety-check regression is fixed, but the opt-in mode's deliberate choice to leave global Full reviewStatus of prior findingsVerified fixed: (1) warm-start Correctness1. A CPU op in the enclosing graph silently disables the opted-in region's cudagraph. The opt-in mode deliberately leaves global return (torch._inductor.config.triton.cudagraphs
or _unstable_customized_partition_wrapper.wrapper is not None
) and torch._inductor.config.graph_partitionMeanwhile the guard at 2. Testing3. The unsafe-body hole remains open for regions that do not set the flag. The new body scan is gated on 4. The new scheduler unit tests bypass IR constructors, so they cannot catch real breakage. 5. Performance6. Partition reordering is silently disabled in the new opt-in mode. 7. Third lookup in Code Quality8. 9. RecommendationRequest Changes — finding 1 defeats the feature on any enclosing graph containing a CPU op and is untested; finding 2 is a cache-collision that this PR newly makes load-bearing. Findings 3 and 4 are testing gaps worth closing before landing; 5-9 can be addressed or explicitly deferred with a comment. |
…graph partition
Allow invoke_subgraph regions to opt into or out of CUDA Graph capture
independently of their enclosing graph, including separate forward and backward
configuration. When a region differs from the top-level decision and graph
partitioning is disabled, temporarily enable a region-only partitioning mode.
Only explicitly opted-in regions become capture partitions; the enclosing graph
and opted-out regions remain inline.
Derive the regional decision before AOT dispatch, preserve it through freezing,
and re-derive backward settings from the backward graph. Region identity keeps
adjacent eligible regions as separate runtime units, while regional capture
continues to respect global profitability settings unless the region overrides
them locally.
Nested regions cannot currently be partitioned independently from their
enclosing region, so reject conflicting nested CUDA Graph settings, including
regions reached through other higher-order-op subgraphs. Also reject combining
regional CUDA Graph settings with torch._dynamo.override_cudagraphs instead of
silently applying two competing override mechanisms.
Record partial forward capture and conservatively treat saved activations from
inline work as dynamic backward inputs. Resolve the CUDA Graph manager lazily at
backward execution so backward-only capture, runtime capture-size filtering, and
AOTAutograd cache hits do not require a manager that the forward has not created.
Test Plan:
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "invoke_subgraph", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "region_backward_saved_activation_is_dynamic", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
lintrunner -a
```
This change was authored with the assistance of an AI coding agent.
ghstack-source-id: dc8ad4d
Pull-Request: #190091
…graph partition
Allow invoke_subgraph regions to opt into or out of CUDA Graph capture
independently of their enclosing graph, including separate forward and backward
configuration. When a region differs from the top-level decision and graph
partitioning is disabled, temporarily enable a region-only partitioning mode.
Only explicitly opted-in regions become capture partitions; the enclosing graph
and opted-out regions remain inline.
Derive the regional decision before AOT dispatch, preserve it through freezing,
and re-derive backward settings from the backward graph. Region identity keeps
adjacent eligible regions as separate runtime units, while regional capture
continues to respect global profitability settings unless the region overrides
them locally.
Nested regions cannot currently be partitioned independently from their
enclosing region, so reject conflicting nested CUDA Graph settings, including
regions reached through other higher-order-op subgraphs. Also reject combining
regional CUDA Graph settings with torch._dynamo.override_cudagraphs instead of
silently applying two competing override mechanisms.
Record partial forward capture and conservatively treat saved activations from
inline work as dynamic backward inputs. Resolve the CUDA Graph manager lazily at
backward execution so backward-only capture, runtime capture-size filtering, and
AOTAutograd cache hits do not require a manager that the forward has not created.
Test Plan:
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "invoke_subgraph", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "region_backward_saved_activation_is_dynamic", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
lintrunner -a
```
This change was authored with the assistance of an AI coding agent.
ghstack-source-id: 6298238
Pull-Request: #190091
…graph partition
Allow invoke_subgraph regions to opt into or out of CUDA Graph capture
independently of their enclosing graph, including separate forward and backward
configuration. When a region differs from the top-level decision and graph
partitioning is disabled, temporarily enable a region-only partitioning mode.
Only explicitly opted-in regions become capture partitions; the enclosing graph
and opted-out regions remain inline.
Derive the regional decision before AOT dispatch, preserve it through freezing,
and re-derive backward settings from the backward graph. Region identity keeps
adjacent eligible regions as separate runtime units, while regional capture
continues to respect global profitability settings unless the region overrides
them locally.
Nested regions cannot currently be partitioned independently from their
enclosing region, so reject conflicting nested CUDA Graph settings, including
regions reached through other higher-order-op subgraphs. Also reject combining
regional CUDA Graph settings with torch._dynamo.override_cudagraphs instead of
silently applying two competing override mechanisms.
Record partial forward capture and conservatively treat saved activations from
inline work as dynamic backward inputs. Resolve the CUDA Graph manager lazily at
backward execution so backward-only capture, runtime capture-size filtering, and
AOTAutograd cache hits do not require a manager that the forward has not created.
Test Plan:
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "invoke_subgraph", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "region_backward_saved_activation_is_dynamic", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
lintrunner -a
```
This change was authored with the assistance of an AI coding agent.
ghstack-source-id: 6298238
Pull-Request: #190091
…graph partition
Nested compile-region CUDA Graph options were visible while compiling an
InvokeSubgraph body but did not control how the enclosing Inductor graph was
partitioned or wrapped. A region therefore could not opt into capture when the
top level was disabled, opt out when it was enabled, or select a different
forward and backward policy.
Derive the top-level and regional decisions before AOT dispatch. When a region
differs and graph partitioning is disabled, temporarily enable a region-only
mode that keeps enclosing work inline and isolates only explicitly enabled
regions. Preserve the decision through freezing, re-derive it from the backward
graph, and retain regional safety and minimum-size checks from the partitioner.
Configured regions remain separate runtime units.
Generalize the backward-only disable flag to a graph-local
cudagraphs_post_compile_override because regional forward and backward graphs
may each force capture on or off. Serialize the effective value with each FX
graph, while adding optional override and region-only fields to cache inputs only
when active so ordinary cache keys remain stable.
Reject conflicting nested-region settings and combinations with
`torch._dynamo.override_cudagraphs`. For partial forward capture, conservatively
treat saved inline activations as dynamic backward inputs. Resolve the CUDA
Graph manager lazily so backward-only capture, runtime capture-size filtering,
and AOTAutograd cache hits work even when the forward created no manager.
Test Plan:
```
python test/dynamo/test_aot_autograd_cache.py -k optional_cudagraph_kwargs_omitted_when_unset -v
```
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "invoke_subgraph", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "region_backward", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
lintrunner -a
```
This change was authored with the assistance of an AI coding agent.
ghstack-source-id: 6a95c10
Pull-Request: #190091
…graph partition
Nested compile-region CUDA Graph options were visible while compiling an
InvokeSubgraph body but did not control how the enclosing Inductor graph was
partitioned or wrapped. A region therefore could not opt into capture when the
top level was disabled, opt out when it was enabled, or select a different
forward and backward policy.
Derive the top-level and regional decisions before AOT dispatch. When a region
differs and graph partitioning is disabled, temporarily enable a region-only
mode that keeps enclosing work inline and isolates only explicitly enabled
regions. Preserve the decision through freezing, re-derive it from the backward
graph, and retain regional safety and minimum-size checks from the partitioner.
Configured regions remain separate runtime units.
Use a graph-local cudagraphs_post_compile_override for serialized FX graph state
because regional forward and backward graphs may each force capture on or off.
Keep the existing cudagraphs_bwd_override for the pre-AOT backward annotation.
Add optional override and region-only fields to cache inputs only when active so
ordinary cache keys remain stable.
Reject conflicting nested-region settings and combinations with
`torch._dynamo.override_cudagraphs`. For partial forward capture, conservatively
treat saved inline activations as dynamic backward inputs. Resolve the CUDA
Graph manager lazily so backward-only capture, runtime capture-size filtering,
and AOTAutograd cache hits work even when the forward created no manager.
Test Plan:
```
python test/dynamo/test_aot_autograd_cache.py -k optional_cudagraph_kwargs_omitted_when_unset -v
```
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "invoke_subgraph", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
python -c 'import runpy, sys, torch; torch.backends.cudnn.enabled = False; sys.argv = ["test/inductor/test_cudagraph_trees.py", "-k", "region_backward", "-v"]; runpy.run_path("test/inductor/test_cudagraph_trees.py", run_name="__main__")'
```
```
lintrunner -a
```
This change was authored with the assistance of an AI coding agent.
ghstack-source-id: 08d2b05
Pull-Request: #190091
Stack from ghstack (oldest at bottom):
Nested compile-region CUDA Graph options were visible while compiling an
InvokeSubgraph body but did not control how the enclosing Inductor graph was
partitioned or wrapped. A region therefore could not opt into capture when the
top level was disabled, opt out when it was enabled, or select a different
forward and backward policy.
Derive the top-level and regional decisions before AOT dispatch. When a region
differs and graph partitioning is disabled, temporarily enable a region-only
mode that keeps enclosing work inline and isolates only explicitly enabled
regions. Preserve the decision through freezing, re-derive it from the backward
graph, and retain regional safety and minimum-size checks from the partitioner.
Configured regions remain separate runtime units.
Use a graph-local cudagraphs_post_compile_override for serialized FX graph state
because regional forward and backward graphs may each force capture on or off.
Keep the existing cudagraphs_bwd_override for the pre-AOT backward annotation.
Add optional override and region-only fields to cache inputs only when active so
ordinary cache keys remain stable.
Reject conflicting nested-region settings and combinations with
torch._dynamo.override_cudagraphs. For partial forward capture, conservativelytreat saved inline activations as dynamic backward inputs. Resolve the CUDA
Graph manager lazily so backward-only capture, runtime capture-size filtering,
and AOTAutograd cache hits work even when the forward created no manager.
Test Plan:
This change was authored with the assistance of an AI coding agent.
Differential Revision: D112182755