From 38d700ecb0e13d167076a003fefb6cbd5dd0bcfc Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sat, 14 Mar 2026 08:56:08 +0000 Subject: [PATCH] studio: check disk space before downloading GGUF models Query file sizes from HuggingFace via get_paths_info() before downloading, and compare against free disk space on the cache partition. Raises a clear error if there is not enough space, instead of failing mid-download. Uses get_paths_info() instead of repo_info() because xet-stored repos return size=None from repo_info().siblings, but get_paths_info() returns the actual file sizes. If the size check fails for any reason (network error, API change), it logs a warning and continues with the download anyway. --- studio/backend/core/inference/llama_cpp.py | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py index e97c5e3457..2676c072ad 100644 --- a/studio/backend/core/inference/llama_cpp.py +++ b/studio/backend/core/inference/llama_cpp.py @@ -418,6 +418,47 @@ class LlamaCppBackend: repo_name = hf_repo.split("/")[-1].replace("-GGUF", "") gguf_filename = f"{repo_name}-{hf_variant}.gguf" + # Check disk space before downloading + all_gguf_files = [gguf_filename] + gguf_extra_shards + try: + from huggingface_hub import get_paths_info + + path_infos = list( + get_paths_info(hf_repo, all_gguf_files, token = hf_token) + ) + total_download_bytes = sum( + (p.size or 0) for p in path_infos + ) + + if total_download_bytes > 0: + import os + + cache_dir = os.environ.get( + "HF_HUB_CACHE", + str(Path.home() / ".cache" / "huggingface" / "hub"), + ) + Path(cache_dir).mkdir(parents = True, exist_ok = True) + free_bytes = shutil.disk_usage(cache_dir).free + + total_gb = total_download_bytes / (1024 ** 3) + free_gb = free_bytes / (1024 ** 3) + + logger.info( + f"GGUF download: {total_gb:.1f} GB needed, " + f"{free_gb:.1f} GB free on disk" + ) + + if total_download_bytes > free_bytes: + raise RuntimeError( + f"Not enough disk space to download model. " + f"Need {total_gb:.1f} GB but only " + f"{free_gb:.1f} GB free in {cache_dir}" + ) + except RuntimeError: + raise + except Exception as e: + logger.warning(f"Could not check disk space: {e}") + logger.info( f"Downloading GGUF: {hf_repo}/{gguf_filename}" + (