Skip to content

Model weights land in a cache folder you never chose

PyTorch, Hugging Face and the rest download gigabytes into hidden folders. Where they are on Windows and how to move them.

5 min read

The first time a model is loaded, the library downloads its weights and caches them so the second time is instant. That is sensible, and it means a machine used for experiments accumulates gigabytes of weights for models used once.

Where each framework caches on Windows

Get-ChildItem "$env:USERPROFILE\.cache\huggingface","$env:USERPROFILE\.cache\torch","$env:LOCALAPPDATA\torch","$env:USERPROFILE\.keras" -EA SilentlyContinue |
  ForEach-Object {
    $s = (Get-ChildItem $_.FullName -Recurse -Force -File -EA SilentlyContinue | Measure-Object Length -Sum).Sum
    '{0,8:N0} MB  {1}' -f ($s/1MB), $_.FullName
  }
$env:HF_HOME; $env:TORCH_HOME

Most of these libraries use a .cache folder in the user profile on Windows too, which is unusual for the platform and is why they escape every Windows specific cleanup guide.

Moving them rather than clearing them

[Environment]::SetEnvironmentVariable('HF_HOME','D:\ml\huggingface','User')
[Environment]::SetEnvironmentVariable('TORCH_HOME','D:\ml\torch','User')

Every one of these libraries respects an environment variable for its cache location. On a machine with a second drive, pointing them there is the better answer than repeated clearing, and it is the same move as a Dev Drive for build output.

Clearing safely

huggingface-cli scan-cache
huggingface-cli delete-cache

The Hugging Face tool shows sizes and last used dates before deleting, which makes the decision easy and is the model the others should follow. For the rest, deleting the cache directory is safe and costs a download.

The one thing to check first

A checkpoint you produced yourself, or a model you fine tuned, can sit in the same folder as downloaded weights and is the one thing no reinstall brings back. Look before clearing a directory wholesale.

CUDA and the runtime

On a Windows machine with an Nvidia GPU, the CUDA toolkit and cuDNN are separate multi gigabyte installs under Program Files, and several versions accumulate the same way SDKs do. They uninstall from Settings, Apps.

Common questions

Where does PyTorch cache models on Windows?

In %USERPROFILE%\.cache\torch by default, or wherever TORCH_HOME points. Hugging Face uses %USERPROFILE%\.cache\huggingface unless HF_HOME is set.

How do I move ML caches to another drive on Windows?

Set the environment variables each library respects, such as HF_HOME and TORCH_HOME, to a path on the other drive. It is a better long term answer than clearing them repeatedly.

Is it safe to delete the Hugging Face cache?

Yes, everything in it is downloadable again. Use huggingface-cli scan-cache and delete-cache, which show sizes and last used dates so you can remove selectively.

Do CUDA installs take much space?

Yes, several gigabytes each under Program Files, and versions accumulate like SDKs. They uninstall individually from Settings, Apps.

Read next