Skip to content

Commit dd01bd4

Browse files
committed
fix: --fast-deps now respects --skip-torch-or-directml (#246)
1 parent c106693 commit dd01bd4

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

comfy_cli/command/install.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def execute(
287287
gpu=gpu,
288288
cuda_version=cuda_version.value,
289289
rocm_version=rocm_version.value,
290+
skip_torch=skip_torch_or_directml,
290291
)
291292
depComp.compile_deps()
292293
depComp.install_deps()

comfy_cli/uv.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def __init__(
367367
extraSpecs: list[str] | None = None,
368368
cuda_version: str | None = None,
369369
rocm_version: str | None = None,
370+
skip_torch: bool = False,
370371
):
371372
"""Compiler/installer of Python dependencies based on uv
372373
@@ -379,16 +380,21 @@ def __init__(
379380
reqFilesCore (Optional[list[PathLike]]): list of core requirement files (requirements.txt, pyproject.toml, etc) to be included in the compilation. Any requirements determined from these files will override all other requirements
380381
reqFilesExt (Optional[list[PathLike]]): list of requirement files (requirements.txt, pyproject.toml, etc) to be included in the compilation
381382
extraSpecs (Optional[list[str]]): list of extra Python requirement specifiers to be included in the compilation
383+
skip_torch (bool): if True, skip torch/torchvision/torchaudio installation and GPU index URLs
382384
"""
383385
self.cwd = Path(cwd).expanduser().resolve()
384386
self.outDir: Path = Path(outDir).expanduser().resolve()
385387
# use .absolute since .resolve breaks the softlink-is-interpreter assumption of venvs
386388
self.executable = Path(executable).expanduser().absolute()
387389
self.gpu = DependencyCompiler.Resolve_Gpu(gpu)
390+
self.skip_torch = skip_torch
388391
self.reqFiles = [Path(reqFile) for reqFile in reqFilesExt] if reqFilesExt is not None else None
389392
self.extraSpecs = [] if extraSpecs is None else extraSpecs
390393

391-
if self.gpu == GPU_OPTION.NVIDIA:
394+
if self.skip_torch:
395+
self.gpuUrl = None
396+
self.torchBackend = None
397+
elif self.gpu == GPU_OPTION.NVIDIA:
392398
tag = f"cu{cuda_version.replace('.', '')}" if cuda_version else DependencyCompiler.nvidiaTorchBackend
393399
self.gpuUrl = f"https://download.pytorch.org/whl/{tag}"
394400
self.torchBackend = tag

tests/uv/test_uv.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,35 @@ def test_amd_custom_rocm_version():
177177
)
178178
assert depComp.torchBackend == "rocm7.1"
179179
assert depComp.gpuUrl == "https://download.pytorch.org/whl/rocm7.1"
180+
181+
182+
@pytest.mark.parametrize("gpu", [GPU_OPTION.NVIDIA, GPU_OPTION.AMD, GPU_OPTION.CPU])
183+
def test_skip_torch_disables_gpu_url_and_backend(gpu):
184+
depComp = DependencyCompiler(cwd=temp, gpu=gpu, outDir=temp, reqFilesCore=[], reqFilesExt=[], skip_torch=True)
185+
assert depComp.torchBackend is None
186+
assert depComp.gpuUrl is None
187+
188+
189+
def test_skip_torch_override_has_no_torch():
190+
depComp = DependencyCompiler(
191+
cwd=temp,
192+
gpu=GPU_OPTION.NVIDIA,
193+
outDir=temp,
194+
reqFilesCore=[mockReqsDir / "core_reqs.txt"],
195+
reqFilesExt=[],
196+
skip_torch=True,
197+
)
198+
depComp.make_override()
199+
content = depComp.override.read_text()
200+
assert "torch" not in content
201+
202+
203+
def test_skip_torch_install_deps_no_extra_index_url():
204+
depComp = DependencyCompiler(
205+
cwd=temp, gpu=GPU_OPTION.NVIDIA, outDir=temp, reqFilesCore=[], reqFilesExt=[], skip_torch=True
206+
)
207+
depComp.out.write_text("requests==2.31.0\n")
208+
with patch("comfy_cli.uv._check_call") as mock_check_call:
209+
depComp.install_deps()
210+
cmd = mock_check_call.call_args[0][0]
211+
assert "--extra-index-url" not in cmd

0 commit comments

Comments
 (0)