@@ -143,6 +143,27 @@ def test_cuda_libraries_resolve_relatively() -> None:
143143 print (f"✓ { name } resolves the CUDA runtime relatively ({ relative [0 ]} )" )
144144
145145
146+ def test_no_library_needs_cuda_torch () -> None :
147+ """No shipped library may record a dependency on PyTorch's own CUDA libraries.
148+
149+ The CUDA delegate needs only the CUDA runtime. A library that names libtorch_cuda or
150+ libc10_cuda cannot load next to a CPU-only torch, so the whole wheel then fails to import
151+ there even though nothing in it calls into those libraries.
152+ """
153+ package_dir = _package_dir ()
154+ cuda_torch = {"libtorch_cuda.so" , "libc10_cuda.so" }
155+ offenders = {}
156+ for library in test_shared_libraries ._shipped_shared_objects (package_dir ):
157+ needed = test_shared_libraries ._recorded_dependencies (library ) & cuda_torch
158+ if needed :
159+ offenders [str (library .relative_to (package_dir ))] = sorted (needed )
160+ assert not offenders , (
161+ f"these libraries depend on PyTorch's CUDA libraries, so the wheel cannot be imported "
162+ f"with a CPU-only torch: { offenders } "
163+ )
164+ print ("✓ no shipped library depends on PyTorch's CUDA libraries" )
165+
166+
146167def _row_architectures () -> list [str ]:
147168 """The architectures this row claims, from the same script the build uses.
148169
@@ -586,6 +607,7 @@ def test_a_model_runs_through_the_delegate() -> None:
586607 test_cuda_libraries_are_shipped ()
587608 test_cuda_runtime_is_declared ()
588609 test_cuda_libraries_resolve_relatively ()
610+ test_no_library_needs_cuda_torch ()
589611 test_device_code_covers_the_row ()
590612 test_portable_device_code_is_present ()
591613 test_the_delegate_registers ()
0 commit comments