Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/194703
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 2558ce6 with merge base 3196064 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@zoranzhao has exported this pull request. If you are a Meta employee, you can view the originating Diff in D115659603. |
9f5609c to
bfb2797
Compare
Summary:
`CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any
`torch.compiler.nested_compile_region` under AOTInductor died at codegen:
```
torch._inductor.exc.InductorError: NotImplementedError:
codegen invoke_subgraph is not implemented for cpp wrapper
cpp_wrapper_cpu.py:2813
```
Two parts.
**1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete
subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop;
invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle`
per output -- the same shape as `codegen_switch`, because in ABI-compatible mode
`ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises
explicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own `Scheduler`,
which re-emits per-device state -- notably `<stream_t> stream0;` from
`write_get_raw_stream` -- and in the parent's scope that is a redefinition
(`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so
`codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state`
keeps the region's device-guard bookkeeping from leaking out.
**2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes.
`AllocateLine`/`FreeIfNotReusedLine` record
`scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits
its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent
free with a region allocation then compares indices into two different node lists:
```
ValueError: Start index must be less than or equal to end index
segmented_tree.py:234, via should_reuse_buffer -> peak_between
```
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited.
Test Plan:
`test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with
the very message this diff deletes; the skip is removed.
New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip
through `check_model`: compile, package, dlopen, run and compare against eager. That is
what a generated-C++ assertion cannot cover.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \
-- --regex "invoke_subgraph"
=> Pass 4. Fail 0. Skip 1.
buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \
-- --regex "regional|lite_"
=> Pass 8. Fail 0. Skip 3.
```
**cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every
case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined
subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with
`config.cpp_wrapper=True`, and turns it on for the four suites that pass:
`CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`,
`SwitchTestsCppWrapper`.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper"
=> Pass 122. Fail 0. Skip 6.
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow
=> Pass 799. Fail 0. Skip 104.
```
(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on
this one -- identical both times, Pass 341 / Fail 337:
- `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names
would rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
- `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL`
(`test_cond_unbacked_symint_inner*`).
Two distinct causes, each worth its own diff:
- `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers
in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region `stream0` collision fixed above, but for buffers rather than per-device
state.
- `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`.
Authored with an AI assistant.
Differential Revision: D115659603
Summary:
`CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any
`torch.compiler.nested_compile_region` under AOTInductor died at codegen:
```
torch._inductor.exc.InductorError: NotImplementedError:
codegen invoke_subgraph is not implemented for cpp wrapper
cpp_wrapper_cpu.py:2813
```
Two parts.
**1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete
subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop;
invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle`
per output -- the same shape as `codegen_switch`, because in ABI-compatible mode
`ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises
explicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own `Scheduler`,
which re-emits per-device state -- notably `<stream_t> stream0;` from
`write_get_raw_stream` -- and in the parent's scope that is a redefinition
(`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so
`codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state`
keeps the region's device-guard bookkeeping from leaking out.
**2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes.
`AllocateLine`/`FreeIfNotReusedLine` record
`scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits
its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent
free with a region allocation then compares indices into two different node lists:
```
ValueError: Start index must be less than or equal to end index
segmented_tree.py:234, via should_reuse_buffer -> peak_between
```
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited.
Test Plan:
`test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with
the very message this diff deletes; the skip is removed.
New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip
through `check_model`: compile, package, dlopen, run and compare against eager. That is
what a generated-C++ assertion cannot cover.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \
-- --regex "invoke_subgraph"
=> Pass 4. Fail 0. Skip 1.
buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \
-- --regex "regional|lite_"
=> Pass 8. Fail 0. Skip 3.
```
**cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every
case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined
subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with
`config.cpp_wrapper=True`, and turns it on for the four suites that pass:
`CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`,
`SwitchTestsCppWrapper`.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper"
=> Pass 122. Fail 0. Skip 6.
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow
=> Pass 799. Fail 0. Skip 104.
```
(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on
this one -- identical both times, Pass 341 / Fail 337:
- `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names
would rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
- `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL`
(`test_cond_unbacked_symint_inner*`).
Two distinct causes, each worth its own diff:
- `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers
in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region `stream0` collision fixed above, but for buffers rather than per-device
state.
- `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`.
Authored with an AI assistant.
Differential Revision: D115659603
Summary:
`CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any
`torch.compiler.nested_compile_region` under AOTInductor died at codegen:
```
torch._inductor.exc.InductorError: NotImplementedError:
codegen invoke_subgraph is not implemented for cpp wrapper
cpp_wrapper_cpu.py:2813
```
Two parts.
**1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete
subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop;
invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle`
per output -- the same shape as `codegen_switch`, because in ABI-compatible mode
`ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises
explicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own `Scheduler`,
which re-emits per-device state -- notably `<stream_t> stream0;` from
`write_get_raw_stream` -- and in the parent's scope that is a redefinition
(`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so
`codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state`
keeps the region's device-guard bookkeeping from leaking out.
**2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes.
`AllocateLine`/`FreeIfNotReusedLine` record
`scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits
its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent
free with a region allocation then compares indices into two different node lists:
```
ValueError: Start index must be less than or equal to end index
segmented_tree.py:234, via should_reuse_buffer -> peak_between
```
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited.
Test Plan:
`test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with
the very message this diff deletes; the skip is removed.
New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip
through `check_model`: compile, package, dlopen, run and compare against eager. That is
what a generated-C++ assertion cannot cover.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \
-- --regex "invoke_subgraph"
=> Pass 4. Fail 0. Skip 1.
buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \
-- --regex "regional|lite_"
=> Pass 8. Fail 0. Skip 3.
```
**cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every
case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined
subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with
`config.cpp_wrapper=True`, and turns it on for the four suites that pass:
`CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`,
`SwitchTestsCppWrapper`.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper"
=> Pass 122. Fail 0. Skip 6.
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow
=> Pass 799. Fail 0. Skip 104.
```
(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on
this one -- identical both times, Pass 341 / Fail 337:
- `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names
would rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
- `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL`
(`test_cond_unbacked_symint_inner*`).
Two distinct causes, each worth its own diff:
- `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers
in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region `stream0` collision fixed above, but for buffers rather than per-device
state.
- `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`.
Authored with an AI assistant.
Differential Revision: D115659603
bfb2797 to
f0aa307
Compare
|
@claude review this pr |
|
Claude finished @desertfire's task in 27m 45s —— View job The Full reviewPR Review: #194703SummaryImplements Testing1. if self._testMethodName in _CPP_WRAPPER_XFAIL:
raise unittest.SkipTest("not yet supported by the cpp wrapper")These are deterministic assertion/codegen failures (per the PR body: unbacked SymInts not bound correctly in the inlined C++), not crashes, hangs, or flakes. A skip silently disables the test forever — once inner-unbacked-SymInt binding is fixed, nobody will notice these four cases are still off, and the coverage this PR is explicitly adding is lost. Use 2. Hardcoded The suites parametrize with _CPP_WRAPPER_XFAIL = frozenset(
f"test_cond_unbacked_symint_inner{suffix}_device_{dev}"
for suffix in ("", "_to_outer")
for dev in ("cpu", GPU_TYPE)
)3. The test relies entirely on Separately, the model calls Code Quality4. The The reason a parent The guard is a defensible choice — adding the bracket would call Consequence worth noting in the comment too: cond/while_loop get a real per-subgraph reuse pool, whereas invoke_subgraph regions now get reuse disabled across the boundary — a small, permanent peak-memory regression for regions relative to the other HOPs. 5. Comments narrate the diff instead of the code — several places CLAUDE.md asks for minimal comments that supply non-obvious global context, and specifically not references to the current change. Three spots read as changelog:
RecommendationRequest Changes — the codegen and the reuse guard look right, and the Two things I did not flag, for the record, since they look like plausible objections:
|
Summary:
`CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any
`torch.compiler.nested_compile_region` under AOTInductor died at codegen:
```
torch._inductor.exc.InductorError: NotImplementedError:
codegen invoke_subgraph is not implemented for cpp wrapper
cpp_wrapper_cpu.py:2813
```
Two parts.
**1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete
subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop;
invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle`
per output -- the same shape as `codegen_switch`, because in ABI-compatible mode
`ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises
explicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own `Scheduler`,
which re-emits per-device state -- notably `<stream_t> stream0;` from
`write_get_raw_stream` -- and in the parent's scope that is a redefinition
(`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so
`codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state`
keeps the region's device-guard bookkeeping from leaking out.
**2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes.
`AllocateLine`/`FreeIfNotReusedLine` record
`scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits
its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent
free with a region allocation then compares indices into two different node lists:
```
ValueError: Start index must be less than or equal to end index
segmented_tree.py:234, via should_reuse_buffer -> peak_between
```
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited.
Test Plan:
`test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with
the very message this diff deletes; the skip is removed.
New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip
through `check_model`: compile, package, dlopen, run and compare against eager. That is
what a generated-C++ assertion cannot cover.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \
-- --regex "invoke_subgraph"
=> Pass 4. Fail 0. Skip 1.
buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \
-- --regex "regional|lite_"
=> Pass 8. Fail 0. Skip 3.
```
**cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every
case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined
subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with
`config.cpp_wrapper=True`, and turns it on for the four suites that pass:
`CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`,
`SwitchTestsCppWrapper`.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper"
=> Pass 122. Fail 0. Skip 6.
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow
=> Pass 799. Fail 0. Skip 104.
```
(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on
this one -- identical both times, Pass 341 / Fail 337:
- `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names
would rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
- `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL`
(`test_cond_unbacked_symint_inner*`).
Two distinct causes, each worth its own diff:
- `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers
in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region `stream0` collision fixed above, but for buffers rather than per-device
state.
- `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`.
Authored with an AI assistant.
Differential Revision: D115659603
|
Claude's review about the tests are valid. Please address before landing. |
f0aa307 to
4f37bed
Compare
Summary:
`CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any
`torch.compiler.nested_compile_region` under AOTInductor died at codegen:
```
torch._inductor.exc.InductorError: NotImplementedError:
codegen invoke_subgraph is not implemented for cpp wrapper
cpp_wrapper_cpu.py:2813
```
Two parts.
**1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete
subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop;
invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle`
per output -- the same shape as `codegen_switch`, because in ABI-compatible mode
`ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises
explicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own `Scheduler`,
which re-emits per-device state -- notably `<stream_t> stream0;` from
`write_get_raw_stream` -- and in the parent's scope that is a redefinition
(`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so
`codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state`
keeps the region's device-guard bookkeeping from leaking out.
**2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes.
`AllocateLine`/`FreeIfNotReusedLine` record
`scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits
its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent
free with a region allocation then compares indices into two different node lists:
```
ValueError: Start index must be less than or equal to end index
segmented_tree.py:234, via should_reuse_buffer -> peak_between
```
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited.
Test Plan:
`test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with
the very message this diff deletes; the skip is removed.
New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip
through `check_model`: compile, package, dlopen, run and compare against eager. That is
what a generated-C++ assertion cannot cover.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \
-- --regex "invoke_subgraph"
=> Pass 4. Fail 0. Skip 1.
buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \
-- --regex "regional|lite_"
=> Pass 8. Fail 0. Skip 3.
```
**cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every
case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined
subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with
`config.cpp_wrapper=True`, and turns it on for the four suites that pass:
`CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`,
`SwitchTestsCppWrapper`.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper"
=> Pass 122. Fail 0. Skip 6.
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow
=> Pass 799. Fail 0. Skip 104.
```
(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on
this one -- identical both times, Pass 341 / Fail 337:
- `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names
would rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
- `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL`
(`test_cond_unbacked_symint_inner*`).
Two distinct causes, each worth its own diff:
- `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers
in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region `stream0` collision fixed above, but for buffers rather than per-device
state.
- `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`.
Authored with an AI assistant.
Reviewed By: desertfire
Differential Revision: D115659603
Summary:
`CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any
`torch.compiler.nested_compile_region` under AOTInductor died at codegen:
```
torch._inductor.exc.InductorError: NotImplementedError:
codegen invoke_subgraph is not implemented for cpp wrapper
cpp_wrapper_cpu.py:2813
```
Two parts.
**1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete
subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop;
invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle`
per output -- the same shape as `codegen_switch`, because in ABI-compatible mode
`ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises
explicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own `Scheduler`,
which re-emits per-device state -- notably `<stream_t> stream0;` from
`write_get_raw_stream` -- and in the parent's scope that is a redefinition
(`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so
`codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state`
keeps the region's device-guard bookkeeping from leaking out.
**2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes.
`AllocateLine`/`FreeIfNotReusedLine` record
`scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits
its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent
free with a region allocation then compares indices into two different node lists:
```
ValueError: Start index must be less than or equal to end index
segmented_tree.py:234, via should_reuse_buffer -> peak_between
```
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited.
Test Plan:
`test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with
the very message this diff deletes; the skip is removed.
New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip
through `check_model`: compile, package, dlopen, run and compare against eager. That is
what a generated-C++ assertion cannot cover.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \
-- --regex "invoke_subgraph"
=> Pass 4. Fail 0. Skip 1.
buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \
-- --regex "regional|lite_"
=> Pass 8. Fail 0. Skip 3.
```
**cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every
case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined
subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with
`config.cpp_wrapper=True`, and turns it on for the four suites that pass:
`CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`,
`SwitchTestsCppWrapper`.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper"
=> Pass 122. Fail 0. Skip 6.
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow
=> Pass 799. Fail 0. Skip 104.
```
(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on
this one -- identical both times, Pass 341 / Fail 337:
- `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names
would rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
- `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL`
(`test_cond_unbacked_symint_inner*`).
Two distinct causes, each worth its own diff:
- `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers
in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region `stream0` collision fixed above, but for buffers rather than per-device
state.
- `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`.
Authored with an AI assistant.
Reviewed By: desertfire
Differential Revision: D115659603
4f37bed to
12370fd
Compare
Summary:
`CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any
`torch.compiler.nested_compile_region` under AOTInductor died at codegen:
```
torch._inductor.exc.InductorError: NotImplementedError:
codegen invoke_subgraph is not implemented for cpp wrapper
cpp_wrapper_cpu.py:2813
```
Two parts.
**1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete
subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop;
invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle`
per output -- the same shape as `codegen_switch`, because in ABI-compatible mode
`ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises
explicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own `Scheduler`,
which re-emits per-device state -- notably `<stream_t> stream0;` from
`write_get_raw_stream` -- and in the parent's scope that is a redefinition
(`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so
`codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state`
keeps the region's device-guard bookkeeping from leaking out.
**2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes.
`AllocateLine`/`FreeIfNotReusedLine` record
`scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits
its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent
free with a region allocation then compares indices into two different node lists:
```
ValueError: Start index must be less than or equal to end index
segmented_tree.py:234, via should_reuse_buffer -> peak_between
```
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited.
Test Plan:
`test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with
the very message this diff deletes; the skip is removed.
New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip
through `check_model`: compile, package, dlopen, run and compare against eager. That is
what a generated-C++ assertion cannot cover.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \
-- --regex "invoke_subgraph"
=> Pass 4. Fail 0. Skip 1.
buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \
-- --regex "regional|lite_"
=> Pass 8. Fail 0. Skip 3.
```
**cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every
case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined
subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with
`config.cpp_wrapper=True`, and turns it on for the four suites that pass:
`CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`,
`SwitchTestsCppWrapper`.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper"
=> Pass 122. Fail 0. Skip 6.
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow
=> Pass 799. Fail 0. Skip 104.
```
(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on
this one -- identical both times, Pass 341 / Fail 337:
- `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names
would rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
- `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL`
(`test_cond_unbacked_symint_inner*`).
Two distinct causes, each worth its own diff:
- `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers
in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region `stream0` collision fixed above, but for buffers rather than per-device
state.
- `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`.
Authored with an AI assistant.
Reviewed By: desertfire
Differential Revision: D115659603
Summary:
`CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any
`torch.compiler.nested_compile_region` under AOTInductor died at codegen:
```
torch._inductor.exc.InductorError: NotImplementedError:
codegen invoke_subgraph is not implemented for cpp wrapper
cpp_wrapper_cpu.py:2813
```
Two parts.
**1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete
subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop;
invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle`
per output -- the same shape as `codegen_switch`, because in ABI-compatible mode
`ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises
explicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own `Scheduler`,
which re-emits per-device state -- notably `<stream_t> stream0;` from
`write_get_raw_stream` -- and in the parent's scope that is a redefinition
(`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so
`codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state`
keeps the region's device-guard bookkeeping from leaking out.
**2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes.
`AllocateLine`/`FreeIfNotReusedLine` record
`scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits
its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent
free with a region allocation then compares indices into two different node lists:
```
ValueError: Start index must be less than or equal to end index
segmented_tree.py:234, via should_reuse_buffer -> peak_between
```
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited.
Test Plan:
`test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with
the very message this diff deletes; the skip is removed.
New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip
through `check_model`: compile, package, dlopen, run and compare against eager. That is
what a generated-C++ assertion cannot cover.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \
-- --regex "invoke_subgraph"
=> Pass 4. Fail 0. Skip 1.
buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \
-- --regex "regional|lite_"
=> Pass 8. Fail 0. Skip 3.
```
**cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every
case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined
subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with
`config.cpp_wrapper=True`, and turns it on for the four suites that pass:
`CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`,
`SwitchTestsCppWrapper`.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper"
=> Pass 122. Fail 0. Skip 6.
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow
=> Pass 799. Fail 0. Skip 104.
```
(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on
this one -- identical both times, Pass 341 / Fail 337:
- `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names
would rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
- `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL`
(`test_cond_unbacked_symint_inner*`).
Two distinct causes, each worth its own diff:
- `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers
in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region `stream0` collision fixed above, but for buffers rather than per-device
state.
- `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`.
Authored with an AI assistant.
Reviewed By: desertfire
Differential Revision: D115659603
12370fd to
2558ce6
Compare
Summary:
`CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any
`torch.compiler.nested_compile_region` under AOTInductor died at codegen:
```
torch._inductor.exc.InductorError: NotImplementedError:
codegen invoke_subgraph is not implemented for cpp wrapper
cpp_wrapper_cpu.py:2813
```
Two parts.
**1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete
subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop;
invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle`
per output -- the same shape as `codegen_switch`, because in ABI-compatible mode
`ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises
explicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own `Scheduler`,
which re-emits per-device state -- notably `<stream_t> stream0;` from
`write_get_raw_stream` -- and in the parent's scope that is a redefinition
(`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so
`codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state`
keeps the region's device-guard bookkeeping from leaking out.
**2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes.
`AllocateLine`/`FreeIfNotReusedLine` record
`scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits
its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent
free with a region allocation then compares indices into two different node lists:
```
ValueError: Start index must be less than or equal to end index
segmented_tree.py:234, via should_reuse_buffer -> peak_between
```
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited.
Test Plan:
`test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with
the very message this diff deletes; the skip is removed.
New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip
through `check_model`: compile, package, dlopen, run and compare against eager. That is
what a generated-C++ assertion cannot cover.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \
-- --regex "invoke_subgraph"
=> Pass 4. Fail 0. Skip 1.
buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \
-- --regex "regional|lite_"
=> Pass 8. Fail 0. Skip 3.
```
**cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every
case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined
subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with
`config.cpp_wrapper=True`, and turns it on for the four suites that pass:
`CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`,
`SwitchTestsCppWrapper`.
```
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper"
=> Pass 122. Fail 0. Skip 6.
buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow
=> Pass 799. Fail 0. Skip 104.
```
(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on
this one -- identical both times, Pass 341 / Fail 337:
- `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names
would rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
- `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL`
(`test_cond_unbacked_symint_inner*`).
Two distinct causes, each worth its own diff:
- `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers
in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region `stream0` collision fixed above, but for buffers rather than per-device
state.
- `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`.
Authored with an AI assistant.
Reviewed By: desertfire
Differential Revision: D115659603
|
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
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 |
Merge failedReason: 1 jobs have failed, first few of them are: torchtitan-test / torchtitan-x-pytorch-test / test (torchtitan_models_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8) Details for Dev Infra teamRaised by workflow job |
|
@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 |
…pytorch#194703) Summary: `CppWrapperCpu.codegen_invoke_subgraph` was a bare `raise NotImplementedError`, so any `torch.compiler.nested_compile_region` under AOTInductor died at codegen: ``` torch._inductor.exc.InductorError: NotImplementedError: codegen invoke_subgraph is not implemented for cpp wrapper cpp_wrapper_cpu.py:2813 ``` Two parts. **1. Implement `CppWrapperCpu.codegen_invoke_subgraph`.** The class already has a complete subgraph-inlining implementation, `codegen_subgraph`, used by cond/switch/while_loop; invoke_subgraph was the only HOP left raising. Declare one owning `RAIIAtenTensorHandle` per output -- the same shape as `codegen_switch`, because in ABI-compatible mode `ir.MultiOutput` is not codegened -- and delegate. A non-tensor region output raises explicitly rather than emitting C++ that will not compile. The region body is emitted inside its own C++ block. The region has its own `Scheduler`, which re-emits per-device state -- notably `<stream_t> stream0;` from `write_get_raw_stream` -- and in the parent's scope that is a redefinition (`error: redefinition of 'stream0'`). The outputs are declared *outside* the block so `codegen_subgraph_suffix` can still assign into them, and `_preserve_device_guard_state` keeps the region's device-guard bookkeeping from leaking out. **2. Fix a cross-graph index bug in wrapper-IR memory planning** that (1) exposes. `AllocateLine`/`FreeIfNotReusedLine` record `scheduler_node_index = V.graph.scheduler.nodes.index(...)`, but an inlined subgraph emits its lines into the *parent's* line list while `V.graph` is the *subgraph*. Pairing a parent free with a region allocation then compares indices into two different node lists: ``` ValueError: Start index must be less than or equal to end index segmented_tree.py:234, via should_reuse_buffer -> peak_between ``` Record the scheduler alongside the index and refuse reuse across schedulers. This is a latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable -- but it is only reproducible once (1) lands. Per-region Inductor config under the cpp wrapper is the next diff in the stack. Note: `caffe2/...` and `xplat/caffe2/...` are separate synced copies; both are edited. Test Plan: `test_lite_regional_compile_invoke_subgraph` was skipped under `config.cpp_wrapper` with the very message this diff deletes; the skip is removed. New `test_invoke_subgraph_nested_region` in test_aot_inductor.py -- a full AOTI round trip through `check_model`: compile, package, dlopen, run and compare against eager. That is what a generated-C++ assertion cannot cover. ``` buck2 test @//mode/opt fbcode//caffe2/test/inductor:test_aot_inductor \ -- --regex "invoke_subgraph" => Pass 4. Fail 0. Skip 1. buck2 test @//mode/opt-amd-gpu fbcode//caffe2/test/inductor:test_inductor \ -- --regex "regional|lite_" => Pass 8. Fail 0. Skip 3. ``` **cpp wrapper coverage for the other subgraph HOPs.** `test_control_flow.py` had none: every case ran only under the default python wrapper, even though cond/while_loop/scan/map/switch all reach `CppWrapperCpu.codegen_subgraph` and part (2) above touches every inlined subgraph. This diff adds a `_CppWrapperMixin` that re-runs a suite with `config.cpp_wrapper=True`, and turns it on for the four suites that pass: `CondTestsCppWrapper`, `AssociativeScanTestsCppWrapper`, `MapTestsCppWrapper`, `SwitchTestsCppWrapper`. ``` buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow -- --regex "CppWrapper" => Pass 122. Fail 0. Skip 6. buck2 test @//mode/opt fbcode//caffe2/test/inductor:control_flow => Pass 799. Fail 0. Skip 104. ``` (799 = the suite's previous 677 plus these 122; no existing case changed.) Not everything could be turned on, and the reasons are pre-existing rather than caused by this diff. Measured under `TORCHINDUCTOR_CPP_WRAPPER=1` on the parent commit and again on this one -- identical both times, Pass 341 / Fail 337: - `ScanTests` (264 cases) and `WhileLoopTests` (69) still fail. Pinning that many names would rot on the next parametrization, so those two suites are left off with the reasons recorded in the file. - `CondTests` needed only four exclusions, listed in `_CPP_WRAPPER_XFAIL` (`test_cond_unbacked_symint_inner*`). Two distinct causes, each worth its own diff: - `error: redefinition of 'true_graph_0_bufN'` -- a branch subgraph declares its buffers in the parent's C++ scope, so two branches reusing a name collide. Same class of bug as the region `stream0` collision fixed above, but for buffers rather than per-device state. - `NotImplementedError: NYI cpp wrapper for while_loop_stack_output`. Authored with an AI assistant. Reviewed By: desertfire Differential Revision: D115659603 Pull Request resolved: pytorch#194703 Approved by: https://github.com/desertfire
Summary:
CppWrapperCpu.codegen_invoke_subgraphwas a bareraise NotImplementedError, so anytorch.compiler.nested_compile_regionunder AOTInductor died at codegen:Two parts.
1. Implement
CppWrapperCpu.codegen_invoke_subgraph. The class already has a completesubgraph-inlining implementation,
codegen_subgraph, used by cond/switch/while_loop;invoke_subgraph was the only HOP left raising. Declare one owning
RAIIAtenTensorHandleper output -- the same shape as
codegen_switch, because in ABI-compatible modeir.MultiOutputis not codegened -- and delegate. A non-tensor region output raisesexplicitly rather than emitting C++ that will not compile.
The region body is emitted inside its own C++ block. The region has its own
Scheduler,which re-emits per-device state -- notably
<stream_t> stream0;fromwrite_get_raw_stream-- and in the parent's scope that is a redefinition(
error: redefinition of 'stream0'). The outputs are declared outside the block socodegen_subgraph_suffixcan still assign into them, and_preserve_device_guard_statekeeps the region's device-guard bookkeeping from leaking out.
2. Fix a cross-graph index bug in wrapper-IR memory planning that (1) exposes.
AllocateLine/FreeIfNotReusedLinerecordscheduler_node_index = V.graph.scheduler.nodes.index(...), but an inlined subgraph emitsits lines into the parent's line list while
V.graphis the subgraph. Pairing a parentfree with a region allocation then compares indices into two different node lists:
Record the scheduler alongside the index and refuse reuse across schedulers. This is a
latent pre-existing bug for cond/while_loop too -- inlining is what makes it reachable --
but it is only reproducible once (1) lands.
Per-region Inductor config under the cpp wrapper is the next diff in the stack.
Note:
caffe2/...andxplat/caffe2/...are separate synced copies; both are edited.Test Plan:
test_lite_regional_compile_invoke_subgraphwas skipped underconfig.cpp_wrapperwiththe very message this diff deletes; the skip is removed.
New
test_invoke_subgraph_nested_regionin test_aot_inductor.py -- a full AOTI round tripthrough
check_model: compile, package, dlopen, run and compare against eager. That iswhat a generated-C++ assertion cannot cover.
cpp wrapper coverage for the other subgraph HOPs.
test_control_flow.pyhad none: everycase ran only under the default python wrapper, even though cond/while_loop/scan/map/switch
all reach
CppWrapperCpu.codegen_subgraphand part (2) above touches every inlinedsubgraph. This diff adds a
_CppWrapperMixinthat re-runs a suite withconfig.cpp_wrapper=True, and turns it on for the four suites that pass:CondTestsCppWrapper,AssociativeScanTestsCppWrapper,MapTestsCppWrapper,SwitchTestsCppWrapper.(799 = the suite's previous 677 plus these 122; no existing case changed.)
Not everything could be turned on, and the reasons are pre-existing rather than caused by
this diff. Measured under
TORCHINDUCTOR_CPP_WRAPPER=1on the parent commit and again onthis one -- identical both times, Pass 341 / Fail 337:
ScanTests(264 cases) andWhileLoopTests(69) still fail. Pinning that many nameswould rot on the next parametrization, so those two suites are left off with the
reasons recorded in the file.
CondTestsneeded only four exclusions, listed in_CPP_WRAPPER_XFAIL(
test_cond_unbacked_symint_inner*).Two distinct causes, each worth its own diff:
error: redefinition of 'true_graph_0_bufN'-- a branch subgraph declares its buffersin the parent's C++ scope, so two branches reusing a name collide. Same class of bug as
the region
stream0collision fixed above, but for buffers rather than per-devicestate.
NotImplementedError: NYI cpp wrapper for while_loop_stack_output.Authored with an AI assistant.
Reviewed By: desertfire
Differential Revision: D115659603
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo