When I run python setup.py bdistwheel --verbose, it shows aotitorchgetcurrentcudastream…
- User
When I run
python setup.py bdist_wheel --verbose, it showsaoti_torch_get_current_cuda_streamincsrc\causal_conv1d.cppis not found. Previously I've tested that it works with torch 3.12 nightly, and now you need to make it work with torch 3.11 . You may checkC:\Python312\Lib\site-packages\torch\include\and see how to do it with torch stable ABI. - Assistant
Inspecting the extension code and the current torch include usage first, then I’ll patch the smallest compatibility fix for the stable ABI build.
- Assistant
I found the immediate issue: the extension is pulling CUDA stream access from the inductor AOTI shim, but the stable ABI headers expose a different interface. I’m checking the stable shim API now and will switch to that path if it matches the needed behavior.
- Assistant
The breakage is very localized: all CUDA launches go through one helper,
get_cuda_stream(). I’m checking the stable-ABI port commit and PyTorch’s stream encoding so I can patch that single point cleanly instead of broadening the dependency surface. - Assistant
I found one important clue in PyTorch itself:
StreamIdmay carry a native pointer on some backends, but it’s explicitly documented as opaque. I’m checking the CUDA stream implementation next so I can avoid relying on an accident of encoding unless PyTorch itself does. - Assistant
I reproduced that the installed env is
torch 2.11.0+cu130. Before changing code, I’m checking the actual compile command because there’s a second possibility here: the symbol exists in the torch DLLs, but the C++ translation unit may not be gettingUSE_CUDA, which would hide the declaration in the headers. - Assistant
The failure is simpler than it first looked:
torchdoes export the CUDA stream shim on 2.11, butcausal_conv1d.cppis compiled withoutUSE_CUDA, so the header hides the declaration. I’m patching the build flags to defineUSE_CUDAfor the CUDA extension. - Assistant
The compile-time problem is gone; the build got through
causal_conv1d.cppand into the CUDA objects. I’m checking whether the full extension linked cleanly or if there’s a later build issue. - Assistant
The wheel now builds end-to-end. I’m doing one extra sanity check by importing the freshly built
.pyd, just to confirm the stream symbol resolves at load time too. - Assistant
Fixed in
setup.py:227-233.Root cause:
aoti_torch_get_current_cuda_streamis declared in PyTorch’s shim headers only whenUSE_CUDAis defined.csrc/causal_conv1d.cppwas being compiled as part of aCUDAExtension, but the C++ compile flags did not defineUSE_CUDA, so the identifier was hidden by the header.
Change made:
- Added
-DUSE_CUDAto both thecxxandnvcccompile args for the CUDA build.
Verification:
python setup.py build_ext --verbosenow compilescsrc/causal_conv1d.cppsuccessfully.python setup.py bdist_wheel --verbosenow succeeds.- Built wheel:
dist\causal_conv1d-1.6.1-cp310-abi3-win_amd64.whl - Import check of the built extension succeeded:
import causal_conv1d_cuda->ok
Unrelated warnings still present:
wheel/setup.pydeprecation warningsMANIFEST.inwarning aboutREADME.md
- User
I've changed TORCH_TARGET_VERSION to 0x0209000000000000 . Now it shows
code - Assistant
Checking which stable operators are actually available at 2.9, then I’ll replace the missing ones with a small local compatibility shim rather than broad code churn.
- Assistant
The missing APIs are exactly 2.10+ wrappers in
torch/csrc/stable/ops.h. I found one easy direct fallback already:subtractexists asaoti_torch_aten_subtract_Tensor, so onlysumandcontiguousneed a lower-level path. - Assistant
I’ve got a clean compatibility path: keep 2.10+ builds on the official stable wrappers, and for 2.9 provide local fallbacks for
contiguousand the deterministic workspace reduction.subtractcan already fall back to the generated AOTI shim directly. - Assistant
Patching a local stable-ABI compat layer now: one new header, one CUDA file for the 2.9 reduction fallback, then a small swap-over in
causal_conv1d.cppandsetup.py. - Assistant
The compat layer is in place. I’m rebuilding now to catch any ABI-2.9-specific compile issues in the new shim rather than guessing.
- Assistant
The 2.9 compile succeeded; only the link step failed because the fallback inline wrapper was calling an accidentally block-scoped declaration instead of the namespaced CUDA helper. I’m fixing that and rerunning the build.
- Assistant
The header fix is correct; MSVC/Ninja just didn’t rebuild
causal_conv1d.cppafter the header change. I’m forcing a full rebuild so the caller picks up the namespaced symbol. - Assistant
Build and import are good. I’m running one targeted runtime check with
CAUSAL_CONV1D_DETERMINISTIC=1and a deliberately non-contiguousdoutso the 2.9 fallbacks for both workspace reduction andcontiguous()are actually exercised. - Assistant
Made it build with
TORCH_TARGET_VERSION = 0x0209000000000000.What changed:
- Added
csrc/causal_conv1d_stable_compat.h - Added
csrc/causal_conv1d_stable_compat.cu - Updated
csrc/causal_conv1d.cpp - Updated
setup.pyto compile the new.cufile
Compat strategy:
contiguousfallback for 2.9:- implemented as
new_empty(...sizes..., dtype) + copy_
- implemented as
subtractfallback for 2.9:- uses
aoti_torch_aten_subtract_Tensordirectly
- uses
sumfallback for 2.9:- avoided dispatcher/list APIs entirely
- implemented a small CUDA reduction path for the deterministic workspace accumulation used in backward
- Added
- User
Can we avoid writing a custom CUDA kernel for sum? It's surely less optimized than torch's sum kernel.
- Assistant
Checking whether 2.9 already has enough raw dispatcher/list support to call
aten::sumdirectly, so we can drop the local reduction kernel if possible. - Assistant
Replacing the bespoke reduction kernel with a 2.9-compatible composition of stable ops:
transpose/flatten/matmul/select. That keeps the fallback on PyTorch kernels without relying on 2.10 list APIs. - Assistant
Switching the 2.9 fallback from a bespoke CUDA reduction to a stable-op composition. I’m removing the extra
.cufile and keeping the compat layer header-only. - Assistant
The current link error is stale object reuse again:
causal_conv1d.cppdidn’t rebuild after the header changed. I’m forcing a full rebuild so the old reference to the removed helper disappears. - Assistant
Ninja is ignoring the header-only change; I’m touching
csrc/causal_conv1d.cppwith a no-op edit so it recompiles and drops the stale symbol reference. - Assistant
The stale link issue is gone. I’m rerunning the deterministic backward smoke test now to make sure the new matmul-based 2.9 reduction path actually works at runtime.
- Assistant
Yes.
I removed the custom CUDA reduction kernel and replaced the 2.9 fallback with a composition of 2.9-stable ops in
csrc/causal_conv1d_stable_compat.h:transposeflattenmatmulselectnew_empty+fill_copy_
Important nuance:
- This does not call
torch::stable::sum, because that wrapper only exists for 2.10+. - For actual 2.9 stable ABI, there is no safe public list-construction API for the
dim_IntListdispatcher path, so calling realaten::sum(..., dim=[...])through the stable ABI is not practical. - So the best 2.9-compatible “no custom kernel” option is to express the reduction in terms of supported stable ops.
What changed:
- Deleted
csrc/causal_conv1d_stable_compat.cu - Removed it from
setup.py - Kept the compat layer header-only
- User
It looks too much overhead. I've saved your changes in the branch abi3_stable_torch2.9 and reverted the current branch. Now cd to the folder
tests/and runpytest -n 0 -x test_causal_conv1d.py::test_causal_conv1d_bwd_deterministic_reproducible. How to fix it? - Assistant
Reproducing the failing deterministic backward test first, then I’ll trace the reduction path that makes it nondeterministic and patch the smallest fix.
- Assistant
The repro is clean: nondeterminism is in
dweightaccumulation, notdx. I’m reading the current backward reduction path and the test helper now. - Assistant
The reduction wrapper itself looks straightforward. I’m checking the CUDA kernels next to see whether the “deterministic” path still has races before the final
sum(). - Assistant
I need to separate two possibilities: the workspace kernel is still racing, or the final CUDA reduction is the unstable step. I’m running a small CUDA reproducibility check on
torch.sumitself next. - Assistant
I found a more direct bug than the reduction:
cpp_functions.pysnapshots determinism at import time. The test togglestorch.use_deterministic_algorithms(True)later, so the extension keeps using the old cached value and falls back to the atomic path. - Assistant
Patching the Python wrapper now so determinism is resolved at call time from the env override or the current
torch.use_deterministic_algorithms()state. - User
No, we need to be compatible with torch.compile, and os.getenv cannot be traced by torch.compile . Resolving determinism at import time is usually ok in real usages. Is there a better way to do the test?
- Assistant
Keeping the import-time cache in runtime code. I’m reverting my wrapper change and moving the control into the test so it toggles the exact module-global that the op wrapper reads.
- Assistant
Adjusting the tests now so they drive the same
DETERMINISTICmodule-global the wrapper actually consumes, instead of assuming it followstorch.use_deterministic_algorithms()after import. - Assistant
The runtime code is back to import-time behavior. I’ve moved the test to drive the cached wrapper flag directly and am rerunning the targeted case now.
- Assistant
The originally failing test now passes. I’m running the other deterministic-mode tests I touched to make sure the new test control is consistent end-to-end.
- Assistant
Yes. The better fix is in the test, not the runtime code.
Root cause:
causal_conv1d/cpp_functions.pyresolvesDETERMINISTIConce at import time.- The test was toggling
torch.use_deterministic_algorithms(True)later and assuming that would affect the wrapper. - It does not, so the test was still exercising the non-deterministic atomic path.
What I changed:
- Reverted the runtime wrapper change.
- Updated
tests/test_causal_conv1d.pyto controlcausal_conv1d.cpp_functions.DETERMINISTICdirectly inside the test helper_conv1d_bwd_once(...).
Why this is better:
- Keeps runtime behavior compatible with
torch.compile. - Tests the actual switch the wrapper uses.
- Avoids relying on post-import env/global state that the wrapper does not consume.
Verification:
pytest -n 0 -x test_causal_conv1d.py::test_causal_conv1d_bwd_deterministic_reproducible-> passedpytest -n 0 -x test_causal_conv1d.py -k "deterministic or default_mode_is_not_reproducible"-> 6 passed