快捷方式

安装说明

先决条件

torchtune 需要 PyTorch,因此请使用“在本地开始”页面根据你的主机和环境进行安装。你还应安装 torchvision(用于多模态 LLM)和 torchao(用于量化 API)。你可以使用以下命令安装稳定版或每夜构建版

# Install stable version of PyTorch libraries using pip
pip install torch torchvision torchao

# Or nightly install for latest features
pip install --pre torch torchvision torchao --index-url https://download.pytorch.org/whl/nightly/cu126 # full options are cpu/cu118/cu121/cu124/cu126

通过 PyPI 安装

torchtune 最新的稳定版托管在 PyPI 上,可以使用以下命令下载

pip install torchtune

要确认软件包已正确安装,可以运行以下命令

tune

并应看到以下输出

usage: tune [-h] {download,ls,cp,run,validate} ...

Welcome to the torchtune CLI!

options:
-h, --help            show this help message and exit

...

通过 git clone 安装

如果你想要 torchtune 最新的功能,或者想成为贡献者,你也可以使用以下命令在本地安装该软件包。

git clone https://github.com/pytorch/torchtune.git
cd torchtune
pip install -e .

# or for a developer installation
pip install -e .["dev"]

安装每夜构建版

torchtune 每晚都会使用 main 分支的最新提交进行构建。如果你想要软件包的最新更新,但不想通过 git clone 安装,可以使用以下命令进行安装

pip install --pre torchtune --extra-index-url https://download.pytorch.org/whl/nightly/cpu --no-cache-dir

注意

--no-cache-dir 将指示 pip 不查找 torchtune 的缓存版本,从而覆盖现有的 torchtune 安装。

如果你已经安装了 PyTorch,torchtune 将默认使用该版本。但是,如果你想使用 PyTorch 的每夜构建版,可以在上述命令中添加 --force-reinstall 选项。如果选择此安装方法,你可能需要更改索引 URL 中的“cpu”后缀,使其与你的 CUDA 版本匹配。例如,如果你正在运行 CUDA 12,你的索引 URL 将是“https://download.pytorch.org/whl/nightly/cu126”。

文档

查阅 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获取问题解答

查看资源