[Admin maintenance] Support new ZeroGPU hardware

#5
by multimodalart HF Staff - opened
networks/op/_cudart_preload.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Preload libcudart.so.13 with RTLD_GLOBAL.
2
+
3
+ The ZeroGPU (Blackwell) image's nvcc is CUDA 13, so from-source JIT-compiled
4
+ CUDA extensions (built via torch.utils.cpp_extension.load) link against
5
+ libcudart.so.13. torch's own pip wheel (cu12x) does not ship that version,
6
+ so the compiled extension fails to dlopen with:
7
+ libcudart.so.13: cannot open shared object file: No such file or directory
8
+ `nvidia-cuda-runtime>=13,<14` (in requirements.txt) provides the .so inside
9
+ its package dir, but it isn't on the default loader search path — preload it
10
+ explicitly before any extension that needs it is imported.
11
+ """
12
+ import ctypes
13
+ import glob
14
+ import os
15
+ import sys
16
+
17
+
18
+ def preload_libcudart():
19
+ patterns = []
20
+ for p in sys.path:
21
+ patterns.append(os.path.join(p, "nvidia", "**", "libcudart.so.13*"))
22
+ patterns += [
23
+ "/usr/local/cuda*/targets/*/lib/libcudart.so.13*",
24
+ "/usr/local/cuda*/lib64/libcudart.so.13*",
25
+ ]
26
+ for pattern in patterns:
27
+ for path in glob.glob(pattern, recursive=True):
28
+ try:
29
+ ctypes.CDLL(path, mode=ctypes.RTLD_GLOBAL)
30
+ return path
31
+ except OSError:
32
+ continue
33
+ return None
34
+
35
+
36
+ preload_libcudart()
networks/op/fused_act.py CHANGED
@@ -6,18 +6,21 @@ from torch.nn import functional as F
6
  from torch.autograd import Function
7
  from torch.utils.cpp_extension import load
8
 
9
-
10
- if os.getenv("SPACE_ID"):
11
- import networks.op.fused as fused
12
- else:
13
- module_path = os.path.dirname(__file__)
14
- fused = load(
15
- "fused",
16
- sources=[
17
- os.path.join(module_path, "fused_bias_act.cpp"),
18
- os.path.join(module_path, "fused_bias_act_kernel.cu"),
19
- ],
20
- )
 
 
 
21
 
22
 
23
  class FusedLeakyReLUFunctionBackward(Function):
 
6
  from torch.autograd import Function
7
  from torch.utils.cpp_extension import load
8
 
9
+ from . import _cudart_preload # noqa: F401 - preloads libcudart.so.13 for the JIT build below
10
+
11
+ # The prebuilt networks/op/fused.so was compiled against an old torch C++ ABI
12
+ # and fails with "undefined symbol" on newer torch / Blackwell (sm_120)
13
+ # runtimes. Always rebuild the extension from source at runtime instead of
14
+ # importing the stale binary.
15
+ os.environ.setdefault("TORCH_CUDA_ARCH_LIST", "12.0")
16
+ module_path = os.path.dirname(__file__)
17
+ fused = load(
18
+ "fused",
19
+ sources=[
20
+ os.path.join(module_path, "fused_bias_act.cpp"),
21
+ os.path.join(module_path, "fused_bias_act_kernel.cu"),
22
+ ],
23
+ )
24
 
25
 
26
  class FusedLeakyReLUFunctionBackward(Function):
networks/op/upfirdn2d.py CHANGED
@@ -6,18 +6,21 @@ from torch.nn import functional as F
6
  from torch.autograd import Function
7
  from torch.utils.cpp_extension import load
8
 
9
-
10
- if os.getenv("SPACE_ID"):
11
- import networks.op.upfirdn2d_op as upfirdn2d_op
12
- else:
13
- module_path = os.path.dirname(__file__)
14
- upfirdn2d_op = load(
15
- "upfirdn2d",
16
- sources=[
17
- os.path.join(module_path, "upfirdn2d.cpp"),
18
- os.path.join(module_path, "upfirdn2d_kernel.cu"),
19
- ],
20
- )
 
 
 
21
 
22
 
23
  class UpFirDn2dBackward(Function):
 
6
  from torch.autograd import Function
7
  from torch.utils.cpp_extension import load
8
 
9
+ from . import _cudart_preload # noqa: F401 - preloads libcudart.so.13 for the JIT build below
10
+
11
+ # The prebuilt networks/op/upfirdn2d_op.so was compiled against an old torch
12
+ # C++ ABI and fails with "undefined symbol" on newer torch / Blackwell
13
+ # (sm_120) runtimes. Always rebuild the extension from source at runtime
14
+ # instead of importing the stale binary.
15
+ os.environ.setdefault("TORCH_CUDA_ARCH_LIST", "12.0")
16
+ module_path = os.path.dirname(__file__)
17
+ upfirdn2d_op = load(
18
+ "upfirdn2d",
19
+ sources=[
20
+ os.path.join(module_path, "upfirdn2d.cpp"),
21
+ os.path.join(module_path, "upfirdn2d_kernel.cu"),
22
+ ],
23
+ )
24
 
25
 
26
  class UpFirDn2dBackward(Function):
requirements.txt CHANGED
@@ -4,4 +4,5 @@ imageio==2.37.0
4
  imageio-ffmpeg==0.6.0
5
  ninja==1.11.1.4
6
  torch==2.8.0
7
- torchvision==0.23
 
 
4
  imageio-ffmpeg==0.6.0
5
  ninja==1.11.1.4
6
  torch==2.8.0
7
+ torchvision==0.23
8
+ nvidia-cuda-runtime>=13,<14