Skip to content

Commit 16c3c88

Browse files
committed
test: add torch backend compilation integration tests
Real uv pip compile tests that verify each GPU backend produces the correct torch variant: NVIDIA gets +cu126, AMD gets +rocm6.1, CPU gets +cpu, and macOS gets default PyPI torch without GPU suffixes. Gated behind TEST_TORCH_BACKEND=true. Added to CI: - test-mac.yml: runs mac compile test - test-windows.yml: runs nvidia and cpu compile tests
1 parent e453e82 commit 16c3c88

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

.github/workflows/test-mac.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ jobs:
2929
python -m venv venv
3030
source venv/bin/activate
3131
python -m pip install --upgrade pip
32+
pip install pytest
3233
pip install -e .
34+
35+
- name: Test torch backend compilation (mac)
36+
run: |
37+
source venv/bin/activate
38+
TEST_TORCH_BACKEND=true pytest tests/uv/test_torch_backend_compile.py::test_compile_mac -xvs
39+
40+
- name: Install and launch ComfyUI
41+
run: |
42+
source venv/bin/activate
3343
comfy --skip-prompt --workspace ./ComfyUI install --fast-deps --m-series --skip-manager
3444
comfy --here launch -- --cpu --quick-test-for-ci

.github/workflows/test-windows.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,21 @@ jobs:
3232
python -m pip install --upgrade pip
3333
pip install pytest
3434
pip install -e .
35+
36+
- name: Test torch backend compilation (nvidia)
37+
run: |
38+
.\venv\Scripts\Activate.ps1
39+
$env:TEST_TORCH_BACKEND = "true"
40+
pytest tests/uv/test_torch_backend_compile.py::test_compile_nvidia -xvs
41+
42+
- name: Test torch backend compilation (cpu)
43+
run: |
44+
.\venv\Scripts\Activate.ps1
45+
$env:TEST_TORCH_BACKEND = "true"
46+
pytest tests/uv/test_torch_backend_compile.py::test_compile_cpu -xvs
47+
48+
- name: Install and launch ComfyUI
49+
run: |
50+
.\venv\Scripts\Activate.ps1
3551
comfy --skip-prompt --workspace ./ComfyUI install --fast-deps --nvidia --cuda-version 12.6 --skip-manager
3652
comfy --here launch -- --cpu --quick-test-for-ci
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""Integration tests for torch backend compilation.
2+
3+
These tests do real uv pip compile with a torch requirement and verify
4+
the compiled output contains the correct torch variant for each backend.
5+
6+
Requires network access. Gated behind TEST_TORCH_BACKEND=true.
7+
"""
8+
9+
import os
10+
import shutil
11+
from pathlib import Path
12+
13+
import pytest
14+
15+
from comfy_cli.constants import GPU_OPTION
16+
from comfy_cli.uv import DependencyCompiler
17+
18+
pytestmark = pytest.mark.skipif(
19+
os.environ.get("TEST_TORCH_BACKEND") != "true",
20+
reason="Set TEST_TORCH_BACKEND=true to run torch backend integration tests",
21+
)
22+
23+
_here = Path(__file__).parent.resolve()
24+
_temp = _here.parent / "temp" / "test_torch_backend"
25+
26+
27+
@pytest.fixture(autouse=True)
28+
def _setup_temp():
29+
shutil.rmtree(_temp, ignore_errors=True)
30+
_temp.mkdir(exist_ok=True, parents=True)
31+
(_temp / "reqs.txt").write_text("torch\n")
32+
33+
34+
def _compile_for(gpu):
35+
dc = DependencyCompiler(
36+
cwd=_temp,
37+
gpu=gpu,
38+
outDir=_temp,
39+
reqFilesCore=[_temp / "reqs.txt"],
40+
reqFilesExt=[],
41+
)
42+
dc.make_override()
43+
dc.compile_core_plus_ext()
44+
return dc.out.read_text()
45+
46+
47+
def test_compile_nvidia():
48+
content = _compile_for(GPU_OPTION.NVIDIA)
49+
assert "+cu126" in content
50+
assert "download.pytorch.org/whl/cu126" in content
51+
assert "--extra-index-url" not in content
52+
53+
54+
def test_compile_amd():
55+
content = _compile_for(GPU_OPTION.AMD)
56+
assert "+rocm" in content
57+
assert "download.pytorch.org/whl/rocm" in content
58+
assert "--extra-index-url" not in content
59+
60+
61+
def test_compile_cpu():
62+
content = _compile_for(GPU_OPTION.CPU)
63+
assert "+cpu" in content
64+
assert "download.pytorch.org/whl/cpu" in content
65+
assert "--extra-index-url" not in content
66+
# must not pull in nvidia CUDA libraries
67+
assert "nvidia-" not in content
68+
69+
70+
def test_compile_mac():
71+
content = _compile_for(GPU_OPTION.MAC_M_SERIES)
72+
assert "torch==" in content
73+
# default PyPI torch — no GPU-specific local version suffix
74+
assert "+cu" not in content
75+
assert "+rocm" not in content
76+
assert "+cpu" not in content
77+
assert "--extra-index-url" not in content

0 commit comments

Comments
 (0)