You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于MacOS系统中PyTorch模型及torchvision来源PyTorch模型默认下载路径的技术问询

PyTorch & torchvision Model Default Download Paths on macOS

Let's break down your questions step by step—since you mentioned you didn't find any torch-related content in your home directory with ls -la ~/ | grep torch, that's totally expected! The default paths are tucked away in hidden directories, which your initial command wouldn't surface directly.

1. Default Download Path for PyTorch Core Models

By default, PyTorch stores downloaded models (like those fetched via torch.hub.load()) in a hidden cache directory. If you haven't set the TORCH_HOME environment variable, the exact path is:
~/.cache/torch/hub/checkpoints/

You missed it earlier because .cache is a hidden folder—your ls -la ~/ command would show the .cache directory itself, not its contents. To check what's inside, run this command:

ls -la ~/.cache/torch/hub/checkpoints/

If you want to confirm the path programmatically, fire up a Python shell and run:

import torch
print(torch.hub.get_dir())

This will output the root hub directory, and your downloaded models live in the checkpoints subfolder under it.

2. Default Download Path for torchvision Models

For models from torchvision (like ResNet, ViT, or EfficientNet), the default path aligns with PyTorch's hub cache if you're using newer versions (torchvision >= 0.13):
~/.cache/torch/hub/checkpoints/

Older torchvision versions might use a separate hidden directory:
~/.cache/torchvision/models/

To verify, you can either check the directory directly:

ls -la ~/.cache/torchvision/models/

Or run this Python snippet to confirm where your specific model gets saved:

from torchvision.models import resnet50
# Load a model with default weights (triggers download if not already cached)
model = resnet50(weights="DEFAULT")
# Print the root cache directory for torch models
print(torch.hub.get_dir())

Quick Tip: Override the Default Path

If you want to move model downloads to a more visible location, set the TORCH_HOME environment variable in your shell config (like ~/.zshrc or ~/.bash_profile):

export TORCH_HOME="/path/to/your/custom/directory"

After adding this and restarting your shell, all PyTorch and torchvision models will download to /path/to/your/custom/directory/hub/checkpoints/ instead.

内容的提问来源于stack exchange,提问作者mrgloom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 15:03:10