Skip to content

Commit 3002f30

Browse files
committed
Add support all the way from py3.10, bring back cublas dep
1 parent 2d24160 commit 3002f30

File tree

5 files changed

+72
-34
lines changed

5 files changed

+72
-34
lines changed

.github/workflows/build-wheels.yml

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ jobs:
3535
# CUDA 13.0 will be installed inside the container
3636
CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64
3737

38-
# Build only for Python 3.12 with stable ABI
39-
CIBW_BUILD: "cp312-manylinux_x86_64"
38+
# Build for Python 3.10, 3.11, and 3.12
39+
# 3.10/3.11 will be version-specific, 3.12 will be abi3 (stable ABI)
40+
CIBW_BUILD: "cp310-manylinux_x86_64 cp311-manylinux_x86_64 cp312-manylinux_x86_64"
4041
CIBW_SKIP: "*-musllinux_*"
4142

4243
# Install CUDA 13.0 toolkit inside the container
@@ -109,8 +110,11 @@ jobs:
109110
if-no-files-found: error
110111

111112
build_wheels_windows:
112-
name: Build Windows wheel
113+
name: Build Windows wheel (Python ${{ matrix.python-version }})
113114
runs-on: windows-2022
115+
strategy:
116+
matrix:
117+
python-version: ["3.10", "3.11", "3.12"]
114118

115119
steps:
116120
- name: Checkout code
@@ -219,12 +223,13 @@ jobs:
219223
220224
Write-Host "CUDA MSBuild integration configured successfully"
221225
222-
- name: Set up Python 3.12
226+
- name: Set up Python ${{ matrix.python-version }}
223227
uses: actions/setup-python@v5
224228
with:
225-
python-version: "3.12"
229+
python-version: ${{ matrix.python-version }}
226230

227231
- name: Create python3.lib for stable ABI
232+
if: matrix.python-version == '3.12'
228233
shell: pwsh
229234
run: |
230235
# Create python3.lib for stable ABI support
@@ -254,10 +259,11 @@ jobs:
254259
python -m pip install --upgrade pip
255260
pip install build setuptools wheel nanobind
256261
257-
- name: Build CUDA wheel (Stable ABI - cp312-abi3)
262+
- name: Build CUDA wheel
258263
shell: bash
259264
run: |
260265
# Build with default platform-specific CUDA architectures from setup.py
266+
# Python 3.12 will produce abi3 wheel, 3.10/3.11 will be version-specific
261267
python setup.py bdist_wheel
262268
263269
- name: List built wheels
@@ -270,23 +276,26 @@ jobs:
270276
- name: Upload Windows wheel
271277
uses: actions/upload-artifact@v4
272278
with:
273-
name: wheels-windows-cuda
279+
name: wheels-windows-cuda-${{ matrix.python-version }}
274280
path: dist/*.whl
275281
if-no-files-found: error
276282

277283
test_linux:
278-
name: Test on Linux
284+
name: Test on Linux (Python ${{ matrix.python-version }})
279285
needs: build_wheels_linux
280286
runs-on: ubuntu-22.04
287+
strategy:
288+
matrix:
289+
python-version: ["3.10", "3.11", "3.12"]
281290

282291
steps:
283292
- name: Checkout code
284293
uses: actions/checkout@v4
285294

286-
- name: Set up Python 3.12
295+
- name: Set up Python ${{ matrix.python-version }}
287296
uses: actions/setup-python@v5
288297
with:
289-
python-version: "3.12"
298+
python-version: ${{ matrix.python-version }}
290299

291300
- name: Download CPU-only wheel
292301
uses: actions/download-artifact@v4
@@ -317,23 +326,26 @@ jobs:
317326
python -m pytest tests/ -v --tb=short
318327
319328
test_windows:
320-
name: Test on Windows
329+
name: Test on Windows (Python ${{ matrix.python-version }})
321330
needs: build_wheels_windows
322331
runs-on: windows-2022
332+
strategy:
333+
matrix:
334+
python-version: ["3.10", "3.11", "3.12"]
323335

324336
steps:
325337
- name: Checkout code
326338
uses: actions/checkout@v4
327339

328-
- name: Set up Python 3.12
340+
- name: Set up Python ${{ matrix.python-version }}
329341
uses: actions/setup-python@v5
330342
with:
331-
python-version: "3.12"
343+
python-version: ${{ matrix.python-version }}
332344

333345
- name: Download Windows wheel
334346
uses: actions/download-artifact@v4
335347
with:
336-
name: wheels-windows-cuda
348+
name: wheels-windows-cuda-${{ matrix.python-version }}
337349
path: dist/
338350

339351
- name: Install wheel and test dependencies
@@ -372,10 +384,22 @@ jobs:
372384
name: wheels-linux-cuda
373385
path: dist/
374386

375-
- name: Download Windows CUDA wheel
387+
- name: Download Windows CUDA wheel (3.10)
388+
uses: actions/download-artifact@v4
389+
with:
390+
name: wheels-windows-cuda-3.10
391+
path: dist/
392+
393+
- name: Download Windows CUDA wheel (3.11)
394+
uses: actions/download-artifact@v4
395+
with:
396+
name: wheels-windows-cuda-3.11
397+
path: dist/
398+
399+
- name: Download Windows CUDA wheel (3.12)
376400
uses: actions/download-artifact@v4
377401
with:
378-
name: wheels-windows-cuda
402+
name: wheels-windows-cuda-3.12
379403
path: dist/
380404

381405
- name: Download CPU-only wheel

comfy_kitchen/backends/cuda/CMakeLists.txt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,20 @@ if(CMAKE_CONFIGURATION_TYPES)
170170
)
171171
endif()
172172

173-
# Set properties for ABI3 compatibility (Stable ABI)
174-
target_compile_definitions(_C PRIVATE
175-
Py_LIMITED_API=0x030C0000
176-
NB_STATIC
177-
)
173+
# Set properties for ABI3 compatibility (Stable ABI) - Python 3.12+ only
174+
# Nanobind's stable ABI support requires Python 3.12+
175+
if(Python_VERSION VERSION_GREATER_EQUAL "3.12")
176+
message(STATUS "Python ${Python_VERSION} detected - enabling stable ABI (abi3)")
177+
target_compile_definitions(_C PRIVATE
178+
Py_LIMITED_API=0x030C0000
179+
NB_STATIC
180+
)
181+
else()
182+
message(STATUS "Python ${Python_VERSION} detected - building version-specific wheel")
183+
target_compile_definitions(_C PRIVATE
184+
NB_STATIC
185+
)
186+
endif()
178187

179188

180189
# Install target

comfy_kitchen/tensor/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from abc import ABC, abstractmethod
88
from dataclasses import dataclass
99
from functools import lru_cache
10-
from typing import Any, Self
10+
from typing import Any
1111

1212
import torch
1313
import torch._dynamo
@@ -39,21 +39,21 @@ def _tensor_fields(self) -> list[str]:
3939
"""Return list of field names that are tensors. Override in subclass."""
4040
return ["scale"]
4141

42-
def to_device(self, device: torch.device) -> Self:
42+
def to_device(self, device: torch.device) -> BaseLayoutParams:
4343
"""Move all tensor fields to the specified device."""
4444
kwargs = {f.name: getattr(self, f.name) for f in dataclasses.fields(self)}
4545
for field in self._tensor_fields():
4646
kwargs[field] = kwargs[field].to(device=device)
4747
return type(self)(**kwargs)
4848

49-
def clone(self) -> Self:
49+
def clone(self) -> BaseLayoutParams:
5050
"""Clone all tensor fields."""
5151
kwargs = {f.name: getattr(self, f.name) for f in dataclasses.fields(self)}
5252
for field in self._tensor_fields():
5353
kwargs[field] = kwargs[field].clone()
5454
return type(self)(**kwargs)
5555

56-
def copy_from(self, src: Self, non_blocking: bool = False) -> None:
56+
def copy_from(self, src: BaseLayoutParams, non_blocking: bool = False) -> None:
5757
"""Copy tensor fields in-place from src, reusing existing memory.
5858
5959
Args:

pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ requires = [
33
"setuptools>=61.0",
44
"wheel",
55
"nanobind>=2.0.0",
6+
"tomli; python_version < '3.11'",
67
]
78
build-backend = "setuptools.build_meta"
89

910
[project]
1011
name = "comfy-kitchen"
11-
version = "0.1.1"
12+
version = "0.1.2"
1213
description = "Fast Kernel Library for ComfyUI with multiple compute backends"
1314
readme = "README.md"
14-
requires-python = ">=3.12"
15+
requires-python = ">=3.10"
1516
license = {text = "Apache-2.0"}
1617
keywords = ["pytorch", "cuda", "quantization", "kernels", "diffusion"]
1718
classifiers = [
@@ -22,8 +23,8 @@ classifiers = [
2223
]
2324
dependencies = [
2425
"torch>=2.5.0",
26+
"nvidia-cublas>=13.0.0",
2527
]
26-
# "nvidia-cublas>=13.0.0", <= we are purposefully leaving this out for now, should be installed when NVIDIA pytorch is
2728

2829
[project.urls]
2930
Homepage = "https://github.com/comfyanonymous/ComfyKitchen"
@@ -50,8 +51,8 @@ exclude = ["tests*"]
5051
# Set the maximum line length to 100.
5152
line-length = 100
5253

53-
# Assume Python 3.12
54-
target-version = "py312"
54+
# Assume Python 3.10 (lowest supported)
55+
target-version = "py310"
5556

5657
# Exclude commonly ignored directories
5758
exclude = [

setup.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
import shutil
55
import subprocess
66
import sys
7-
import tomllib
87
from typing import ClassVar
98

9+
try:
10+
import tomllib
11+
except ModuleNotFoundError:
12+
import tomli as tomllib
13+
1014
import setuptools
1115
from setuptools import Extension
1216
from setuptools.command.build_ext import build_ext
@@ -289,9 +293,9 @@ def get_cmdclass(has_extensions):
289293
class CUDABdistWheel(bdist_wheel):
290294
def finalize_options(self):
291295
super().finalize_options()
292-
if not BUILD_NO_CUDA:
293-
# Set stable ABI tag: cp312-abi3 instead of cp312-cp312
294-
# This indicates the extension uses Python's Limited API
296+
# Set stable ABI tag only for Python 3.12+ (nanobind requirement)
297+
# For 3.10/3.11, leave as version-specific (cpXXX-cpXXX)
298+
if not BUILD_NO_CUDA and sys.version_info >= (3, 12):
295299
self.py_limited_api = "cp312"
296300

297301
cmdclass["bdist_wheel"] = CUDABdistWheel

0 commit comments

Comments
 (0)