Repository navigation
[inductor] Support separate forward/backward inductor configs for invoke_subgraph - #190068
desertfire wants to merge 4 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190068
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit f121f20 with merge base f30b6ce ( 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. |
|
@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
3 similar comments
|
@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@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 7m 6s —— View job PR Review: #190068Summary: Adds Full review detailsI traced both compilation paths that consume the region config: the regional pass ( The findings below are cleanup only. 1. Redundant guard duplication — The caller re-implements the exact condition ( fw_region_config = fw_node.meta.get("custom", {}).get("nested_region_config")
bw_region_config = get_backward_nested_region_config(fw_region_config)
if bw_region_config is not fw_region_config:
new_bw_hop_gm.meta["nested_region_config"] = bw_region_configThis is exactly the usage the helper's docstring says it was designed for ("callers rely on this identity to detect a distinct backward config"). Fix this → 2. Docstring "identity" contract is currently unused — The docstring states "callers rely on this identity to detect a distinct backward config," but the only production caller (finding #1) does not use identity — it re-checks the condition manually. Either adopt the identity-based caller above (preferred) or reword the docstring so it does not describe a contract no caller actually uses. 3. Derived backward config still carries
Recommendation: Approve — no correctness, BC, or test-coverage blockers; the items above are optional cleanups. |
|
@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 1m 40s —— View job PR Review: #190068Summary: Adds Full review detailsI re-traced both compilation paths that consume the region config:
Verification of prior-round findings (all resolved):
BC: Testing: Adequate. No correctness, thread-safety, or performance concerns found. Recommendation: Approve — implementation is correct, prior review comments are resolved, and coverage is adequate. |
|
@desertfire has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…oke_subgraph (pytorch#190068) get_invoke_subgraph_compile_options now takes fw_inductor_config_patches (the forward config, renamed from inductor_config_patches) and a keyword-only bw_inductor_config_patches. When bw_inductor_config_patches is set, the backward subgraph of a nested_compile_region is compiled under it, independently of the forward -- a full replacement, not merged over the forward patches, mirroring aot_autograd's separate fw_compiler/bw_compiler. When unset, the backward reuses the forward config. For example, to max-autotune the forward but not the backward: opts = get_invoke_subgraph_compile_options( fw_inductor_config_patches={"max_autotune": True}, bw_inductor_config_patches={"max_autotune": False}, ) @torch.compiler.nested_compile_region(options=opts) def region(x): return torch.matmul(x, x) The backward config is applied where the partitioned backward subgraph is created (run_joint_graph_passes_on_hops), not on the pre-partition backward graph: the partitioner restitches a fresh backward subgraph module whose meta otherwise inherits the forward config, so stamping the pre-partition graph is discarded. get_backward_nested_region_config derives the backward variant from the forward region config, and it is stamped onto the partitioned backward module only when the region requested a distinct backward config, leaving the common path unchanged. This change was authored with the assistance of an AI coding agent. Differential Revision: [D112152398](https://our.internmc.facebook.com/intern/diff/D112152398) Pull Request resolved: pytorch#190068 Approved by: https://github.com/yushangdi ghstack dependencies: pytorch#189320
…oke_subgraph (pytorch#190068) get_invoke_subgraph_compile_options now takes fw_inductor_config_patches (the forward config, renamed from inductor_config_patches) and a keyword-only bw_inductor_config_patches. When bw_inductor_config_patches is set, the backward subgraph of a nested_compile_region is compiled under it, independently of the forward -- a full replacement, not merged over the forward patches, mirroring aot_autograd's separate fw_compiler/bw_compiler. When unset, the backward reuses the forward config. For example, to max-autotune the forward but not the backward: opts = get_invoke_subgraph_compile_options( fw_inductor_config_patches={"max_autotune": True}, bw_inductor_config_patches={"max_autotune": False}, ) @torch.compiler.nested_compile_region(options=opts) def region(x): return torch.matmul(x, x) The backward config is applied where the partitioned backward subgraph is created (run_joint_graph_passes_on_hops), not on the pre-partition backward graph: the partitioner restitches a fresh backward subgraph module whose meta otherwise inherits the forward config, so stamping the pre-partition graph is discarded. get_backward_nested_region_config derives the backward variant from the forward region config, and it is stamped onto the partitioned backward module only when the region requested a distinct backward config, leaving the common path unchanged. This change was authored with the assistance of an AI coding agent. Differential Revision: [D112152398](https://our.internmc.facebook.com/intern/diff/D112152398) Pull Request resolved: pytorch#190068 Approved by: https://github.com/yushangdi ghstack dependencies: pytorch#189320
…oke_subgraph (pytorch#190068) get_invoke_subgraph_compile_options now takes fw_inductor_config_patches (the forward config, renamed from inductor_config_patches) and a keyword-only bw_inductor_config_patches. When bw_inductor_config_patches is set, the backward subgraph of a nested_compile_region is compiled under it, independently of the forward -- a full replacement, not merged over the forward patches, mirroring aot_autograd's separate fw_compiler/bw_compiler. When unset, the backward reuses the forward config. For example, to max-autotune the forward but not the backward: opts = get_invoke_subgraph_compile_options( fw_inductor_config_patches={"max_autotune": True}, bw_inductor_config_patches={"max_autotune": False}, ) @torch.compiler.nested_compile_region(options=opts) def region(x): return torch.matmul(x, x) The backward config is applied where the partitioned backward subgraph is created (run_joint_graph_passes_on_hops), not on the pre-partition backward graph: the partitioner restitches a fresh backward subgraph module whose meta otherwise inherits the forward config, so stamping the pre-partition graph is discarded. get_backward_nested_region_config derives the backward variant from the forward region config, and it is stamped onto the partitioned backward module only when the region requested a distinct backward config, leaving the common path unchanged. This change was authored with the assistance of an AI coding agent. Differential Revision: [D112152398](https://our.internmc.facebook.com/intern/diff/D112152398) Pull Request resolved: pytorch#190068 Approved by: https://github.com/yushangdi ghstack dependencies: pytorch#189320
…oke_subgraph (pytorch#190068) get_invoke_subgraph_compile_options now takes fw_inductor_config_patches (the forward config, renamed from inductor_config_patches) and a keyword-only bw_inductor_config_patches. When bw_inductor_config_patches is set, the backward subgraph of a nested_compile_region is compiled under it, independently of the forward -- a full replacement, not merged over the forward patches, mirroring aot_autograd's separate fw_compiler/bw_compiler. When unset, the backward reuses the forward config. For example, to max-autotune the forward but not the backward: opts = get_invoke_subgraph_compile_options( fw_inductor_config_patches={"max_autotune": True}, bw_inductor_config_patches={"max_autotune": False}, ) @torch.compiler.nested_compile_region(options=opts) def region(x): return torch.matmul(x, x) The backward config is applied where the partitioned backward subgraph is created (run_joint_graph_passes_on_hops), not on the pre-partition backward graph: the partitioner restitches a fresh backward subgraph module whose meta otherwise inherits the forward config, so stamping the pre-partition graph is discarded. get_backward_nested_region_config derives the backward variant from the forward region config, and it is stamped onto the partitioned backward module only when the region requested a distinct backward config, leaving the common path unchanged. This change was authored with the assistance of an AI coding agent. Differential Revision: [D112152398](https://our.internmc.facebook.com/intern/diff/D112152398) Pull Request resolved: pytorch#190068 Approved by: https://github.com/yushangdi ghstack dependencies: pytorch#189320
Fixes issues reported in: #4438 Test cases fixed: ``` dynamo.test_misc_xpu.MiscTests,test_recompile_on_global_state_change dynamo.test_regional_inductor_xpu.RegionalInductorInvokeSubgraphTests,test_max_autotune_no_cudagraphs_serialize_False dynamo.test_regional_inductor_xpu.RegionalInductorInvokeSubgraphTests,test_invalid_inductor_config ``` `test_misc_xpu` changed upstream in pytorch/pytorch#185236 `test_regional_inductor_xpu` changed upstream in pytorch/pytorch#190068
Fixes issues reported in: intel#4438 Test cases fixed: ``` dynamo.test_misc_xpu.MiscTests,test_recompile_on_global_state_change dynamo.test_regional_inductor_xpu.RegionalInductorInvokeSubgraphTests,test_max_autotune_no_cudagraphs_serialize_False dynamo.test_regional_inductor_xpu.RegionalInductorInvokeSubgraphTests,test_invalid_inductor_config ``` `test_misc_xpu` changed upstream in pytorch/pytorch#185236 `test_regional_inductor_xpu` changed upstream in pytorch/pytorch#190068
Stack from ghstack (oldest at bottom):
get_invoke_subgraph_compile_options now takes fw_inductor_config_patches (the
forward config, renamed from inductor_config_patches) and a keyword-only
bw_inductor_config_patches. When bw_inductor_config_patches is set, the backward
subgraph of a nested_compile_region is compiled under it, independently of the
forward -- a full replacement, not merged over the forward patches, mirroring
aot_autograd's separate fw_compiler/bw_compiler. When unset, the backward reuses
the forward config.
For example, to max-autotune the forward but not the backward:
The backward config is applied where the partitioned backward subgraph is created
(run_joint_graph_passes_on_hops), not on the pre-partition backward graph: the
partitioner restitches a fresh backward subgraph module whose meta otherwise
inherits the forward config, so stamping the pre-partition graph is discarded.
get_backward_nested_region_config derives the backward variant from the forward
region config, and it is stamped onto the partitioned backward module only when the
region requested a distinct backward config, leaving the common path unchanged.
This change was authored with the assistance of an AI coding agent.
Differential Revision: D112152398
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @azahed98