3232yaml : Any = None
3333
3434
35+ def _ensure_download_deps () -> None :
36+ """Import only what a plain snapshot/file download needs: huggingface_hub + yaml.
37+
38+ Downloading model weights must not require Torch — importing Torch pulls in
39+ native DLLs (c10.dll etc.) that can fail to load in some environments (e.g. a
40+ conda-based interpreter on Windows), which would needlessly block downloads for
41+ models whose loading/inference happens entirely in the C++ server."""
42+ global hf_hub_download , yaml
43+ if hf_hub_download is not None :
44+ return
45+ from huggingface_hub import hf_hub_download as _hf_hub_download
46+ import yaml as _yaml
47+
48+ hf_hub_download = _hf_hub_download
49+ yaml = _yaml
50+
51+
3552def _ensure_install_deps () -> None :
36- """Import Torch / huggingface_hub / safetensors / yaml on first install/convert use."""
53+ """Import Torch / huggingface_hub / safetensors / yaml on first install/convert use.
54+
55+ Only needed for conversion (torch.load / safetensors round-trips). Snapshot
56+ downloads should call _ensure_download_deps() instead, so they don't drag in Torch."""
3757 global torch , hf_hub_download , safe_open , load_file , save_file , yaml
3858 if torch is not None :
3959 return
60+ _ensure_download_deps ()
4061 import torch as _torch
41- from huggingface_hub import hf_hub_download as _hf_hub_download
4262 from safetensors import safe_open as _safe_open
4363 from safetensors .torch import load_file as _load_file
4464 from safetensors .torch import save_file as _save_file
45- import yaml as _yaml
4665
4766 torch = _torch
48- hf_hub_download = _hf_hub_download
4967 safe_open = _safe_open
5068 load_file = _load_file
5169 save_file = _save_file
52- yaml = _yaml
5370
5471
5572REPO_ROOT = Path (__file__ ).resolve ().parents [1 ]
@@ -2661,7 +2678,6 @@ def command_info(args: argparse.Namespace) -> int:
26612678
26622679
26632680def command_install (args : argparse .Namespace ) -> int :
2664- _ensure_install_deps ()
26652681 package = PACKAGE_BY_ID .get (args .package_id )
26662682 if package is None :
26672683 raise RuntimeError (f"unknown package id: { args .package_id } " )
@@ -2671,10 +2687,15 @@ def command_install(args: argparse.Namespace) -> int:
26712687 if isinstance (source , UnsupportedSource ):
26722688 raise RuntimeError (f"{ package .id } is not installable: { source .reason } " )
26732689 if isinstance (source , SnapshotSource ):
2690+ # Plain download: huggingface_hub only, no Torch DLLs.
2691+ _ensure_download_deps ()
26742692 install_path = install_snapshot (package , source , models_root , args .overwrite )
26752693 elif isinstance (source , CompositeSnapshotSource ):
2694+ # Composite snapshots may run a Torch post-process step, so bring in full deps.
2695+ _ensure_install_deps ()
26762696 install_path = install_composite_snapshot (package , source , models_root , args .overwrite )
26772697 else :
2698+ _ensure_install_deps ()
26782699 install_path = install_converter (
26792700 package ,
26802701 source ,
0 commit comments