Compute
PyTorch + CUDA
这是不加预设的那个选项:官方 PyTorch 镜像、和构建版本匹配好的 CUDA、一个通过 SSH 使用的 root shell,除此之外没有任何东西挡路。
你会得到什么
Section titled “你会得到什么”模板列表里有四个上游 tag。它们就是官方的 pytorch/pytorch 镜像,除了平台的 SSH 层之外没有改动。
| 模板 | 镜像 | PyTorch | CUDA |
|---|---|---|---|
| PyTorch 2.8 - Cuda 12.9 | pytorch/pytorch:2.8.0-cuda12.9-cudnn9-runtime | 2.8.0 | 12.9 |
| PyTorch | pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime | 2.5.1 | 12.4 |
| PyTorch 2.2 - Cuda 12.1 | pytorch/pytorch:2.2.0-cuda12.1-cudnn8-runtime | 2.2.0 | 12.1 |
| PyTorch 2.1 - Cuda 11.8 | pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime | 2.1.0 | 11.8 |
选最新的那个,除非有东西把你钉在旧版本上 —— 比如某个依赖是针对旧 CUDA 构建的,或者某个仓库还没跟上 PyTorch 的大版本。
开始之前要知道两件事:
- 没有 Web UI。 这些模板不在 80 端口上跑任何东西,所以
https://<your-slug>.instance.grafilab.ai不会有响应。你通过 SSH 工作,想在浏览器里看的东西由你自己启动,再用 Web Access 暴露。 - 这些是
runtime镜像,不是devel。 它们带 CUDA 运行时库但不带工具链,所以没有nvcc。安装时需要编译 CUDA kernel 的包会失败 —— 见故障排查。
跑脚本时选这个模板:一个启动后就让它跑着的训练循环、一轮评测扫描、一个自带 CLI 的仓库。你得到一个干净的环境和对它的完全控制。
如果你更想在浏览器里逐个 cell 地做,JupyterLab 是同样的东西加一层 notebook 服务。如果你想在浏览器 IDE 里改文件,用 code-server。
部署实例,在第 2 步 Template Selection 里选其中一张 PyTorch 卡片。把卡的 VRAM 和你打算训练或部署的模型匹配起来。完整流程见部署 GPU 实例。
连接并验证 CUDA
Section titled “连接并验证 CUDA”-
In the console open My Instance (
https://app.grafilab.ai/orders) and find the card for your instance. Wait until its status reads Active. -
Click Connect. The Connect with SSH dialog shows an SSH Connect command and a Password.
-
Copy the command into a terminal, press Enter, and paste the password when prompted. You land in a root shell inside the container.
先确认驱动看得到卡:
nvidia-smi再确认 PyTorch 也看得到:
python -c "import torch; print(torch.__version__, torch.cuda.is_available(), torch.cuda.get_device_name(0))"你要看到 True 和你租的那块卡的名字。如果得到 False,见故障排查。
把代码和数据弄到机器上
Section titled “把代码和数据弄到机器上”git clone https://github.com/<owner>/<repo>.gitcd <repo>pip install -r requirements.txt主机和端口取自 Connect 对话框里的 SSH Connect 命令:
scp -P <port> ./dataset.zip <your-slug>@<ssh-proxy-host>:/root/rsync -avP -e "ssh -p <port>" ./project/ <your-slug>@<ssh-proxy-host>:/root/project/实例的网络比你的上行快得多,所以公开数据直接拉:
wget https://example.com/dataset.tar.gzhuggingface-cli download <repo-id> --local-dir ./data比一杯咖啡时间更长的任务都放进 tmux 里跑,这样 SSH 断了任务也还活着:
tmux new -s trainpython train.py按 Ctrl-b 再按 d 分离,用 tmux attach -t train 回来。如果你只需要把输出写进文件,nohup python train.py > train.log 2>&1 & 也行。
暴露一个服务
Section titled “暴露一个服务”一开始 80 端口上没有服务,所以你想从浏览器访问的东西都得自己启动并通过代理映射。绑定到所有网卡,不要绑 localhost:
pip install jupyterlabjupyter lab --ip 0.0.0.0 --port 8888 --allow-root然后打开实例卡片上的 Web Access,添加一条映射,填 Service Name 和 Port 8888,使用它生成的代理 URL。Gradio 应用或你跑的任何其他服务同理。步骤见管理实例。
持久化与备份
Section titled “持久化与备份”Nothing persists past the rental
Instances have no persistent volume. Anything you write at runtime — downloaded models, installed packages, notebooks, outputs — lives in the container for the lifetime of the rental and is gone when it expires. Before Expire at, back up the folders you care about to Grafilab storage and download the archive.
checkpoint 是要保护的东西。把它们写到你有意选定的位置,随着训练产出把它们推离这台机器 —— 推到 git 远端、对象存储或 Hugging Face 仓库 —— 并在 Expire at 之前用实例卡片上的 Backup 处理仍然只存在于实例上的东西。
- 在 GPU 节点上
torch.cuda.is_available()返回False。 该节点的 NVIDIA 驱动比镜像构建时用的 CUDA 版本旧。换一个 CUDA tag 更旧的模板重新启动 ——2.5.1-cuda12.4或2.2.0-cuda12.1—— 或者换一个节点。 nvcc: command not found,或某个包编译 CUDA 扩展失败。 这些是不带 CUDA 工具链的runtime镜像。如果该包有预编译 wheel 就装 wheel,或者用对应的-devel镜像 tag 创建一个自定义模板 —— 见自定义模板。- 刚启动后
Connection refused。 容器还在启动中。等实例卡片显示 Active。 - DataLoader 因共享内存报错崩溃。 容器只有 2 GB 的
/dev/shm。调低num_workers,或者设置torch.multiprocessing.set_sharing_strategy("file_system")。

