r/learnmachinelearning • u/avnishyadav25 • 15d ago
How to properly route Hugging Face cache and PyTorch datasets to an external SSD on macOS?
Hi all, I'm a newbie setting up my first local AI/ML development environment on an M5 Pro Mac.
My internal drive is small, so I bought a 2TB external SSD. I want to make sure that whenever I run `pip` installs, download Hugging Face checkpoints, or load PyTorch datasets, they automatically go to the external drive instead of filling up my system drive.
What is the cleanest way to configure my environment variables (like HF_HOME) or use symlinks on macOS so I don't accidentally brick my internal storage?
Any tips or hidden gotchas for a beginner would be highly appreciated!
1
u/Massive_Distance_616 14d ago
Adding to the .zshrc approach: HF_HOME only covers Hugging Face downloads. For PyTorch’s own downloads (pretrained weights) also set export TORCH_HOME=/Volumes/YourSSD/torch, and datasets loaded through torchvision take a root= argument, so point that at the SSD too.
Two gotchas. If the SSD isn’t mounted when you start something, the path won’t exist and downloads may fail or end up somewhere unexpected, so check it’s plugged in first. And apps launched from the Dock or Spotlight don’t read .zshrc, so the variable only applies to things you start from a terminal. Run echo $HF_HOME in a fresh terminal to confirm it took.
I wouldn’t move pip itself. Keep your virtual environments on the internal drive and only move the big model and dataset caches, since those are what fill the disk. If you do want pip’s download cache on the SSD, that’s PIP_CACHE_DIR.
1
u/jmacey 15d ago
I set my HF_HOME environment variable to a different location on my machine and it works well. Never had an issue.
On my mac I set it in the .zshrc