Hugging Face Out of Space Fix: The Storage Trap A developer outlines a fix for Hugging Face's default cache directory, which stores gigabytes of model weights in the home folder and causes storage exhaustion on cloud servers. The solution involves setting the HF_HOME environment variable to a secondary storage array and using offline mode to avoid write permission issues in production. The post also warns against deprecated parameters and unsafe deletion methods. By default, whenever you request a machine learning model, the underlying architecture saves gigabytes of tensor data into a hidden directory located directly inside your home folder ~/.cache/huggingface . Because standard bare metal and virtual cloud configurations typically isolate the root operating system on a smaller, highly optimized boot drive, pouring 140GB+ of raw weights into the home folder guarantees absolute storage exhaustion. Here is the engineering blueprint to fix it cleanly on Linux. When attempting to solve this problem, avoid outdated tutorials recommending deprecated parameters like TRANSFORMERS CACHE . | Environment Route | Support Status | Architecture Impact | |---|---|---| HF HOME | Active Master Route | Safely redirects all models, datasets, and core assets globally. | TRANSFORMERS CACHE | Deprecated Warning | Fails to capture datasets and will be removed in version 5.0. | HUGGINGFACE HUB CACHE | Deprecated Warning | Legacy routing path that creates unnecessary diagnostic warnings. | 🛑 The Symlink Security Risk Creating symbolic links symlinks to trick the OS into routing files elsewhere is a common anti-pattern. Mapping these links improperly or running your workflow with elevated rights introduces privilege escalation vulnerabilities, compromising container and host security. To change your Hugging Face cache directory on Linux permanently, target an expansive secondary storage array instead by appending a direct master route into your user profile configuration: Create a dedicated folder inside your secondary storage array sudo mkdir -p /mnt/massive drive/ai model cache sudo chown -R $USER:$USER /mnt/massive drive/ai model cache Append the master environment variable to your bash profile echo 'export HF HOME="/mnt/massive drive/ai model cache"' ~/.bashrc source ~/.bashrc If you declare your custom storage location programmatically inside an application script instead of host environment configs, you must define the environment destination before any machine learning libraries are loaded into system memory: python import os CRITICAL SRE MANDATE: Define the destination BEFORE requesting any libraries os.environ "HF HOME" = "/mnt/massive drive/ai model cache" Now it is completely safe to initialize the heavy components from transformers import AutoModelForCausalLM, AutoTokenizer If you call from transformers import ... before defining os.environ "HF HOME" , the library will evaluate against the default location and ruthlessly fill your small boot partition anyway. If your server has already met a disk space crash, do not delete hidden folders using raw Linux rm -rf commands. Doing so leaves behind orphaned registry files that confuse future framework download attempts. Use the official interactive CLI tools instead: Scan the local environment to identify massive space hogs huggingface-cli scan-cache Launch the interactive deletion tool to safely purge specific weight snapshots huggingface-cli delete-cache When deploying downloaded weights across a distributed cluster, system administrators naturally map the shared storage volume as read-only. However, this causes the inference container to crash instantly on boot with a fatal Permission Denied exception. This happens because the core library inherently tries to write synchronization lock files inside the cache directory to prevent concurrent modification corruption. To bypass this write requirement in production, enforce the offline override mode: python import os Prevent the library from attempting remote writes or lock files os.environ "HF HUB OFFLINE" = "1" os.environ "HF HOME" = "/mnt/massive drive/ai model cache" from transformers import AutoModelForCausalLM To truly extract value from high-performance language models without hitting storage performance bottlenecks, running compute-heavy workloads on top of unshared, local hardware infrastructure is crucial. Deploying your instances on dedicated infrastructure like ServerMO GPU Dedicated Servers guarantees raw processing power, lightning-fast NVMe storage speed, and complete control over your system's data routing architectures. 👉 For detailed baseline configurations and advanced architecture metrics, read the full engineering guide on our platform: Read the Complete Hugging Face Cache Guide on ServerMO https://www.servermo.com/howto/fix-huggingface-no-space-left-on-device/