torchtune is a PyTorch-native library designed for authoring, fine-tuning, and experimenting with Large Language Models (LLMs). It provides hackable training recipes for techniques like SFT, LoRA, QLoRA, FSDP, DPO, PPO, and QAT, supporting popular architectures such as Llama, Gemma, Mistral, Phi, and Qwen. While it offers a componentized design, memory efficiency, and strong integrations, active feature development for torchtune officially ceased in July 2025. The library will receive critical bug fixes and security patches through 2025, but no new features will be added, as the PyTorch team is developing a new product.
pip install torch torchvision torchaoVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `tune` CLI to download a Llama2 7B model from Hugging Face Hub (requiring an `HF_TOKEN`), copy a built-in LoRA single-device fine-tuning configuration, and then execute the fine-tuning process. This is the primary way to interact with torchtune for running pre-defined recipes. Ensure PyTorch and torchtune are installed and replace 'YOUR_HF_TOKEN_HERE' or set the HF_TOKEN environment variable.
Plan for migration to a future PyTorch offering or ensure current needs are met by the existing feature set and bug fixes. Regularly check PyTorch's official announcements.
Reduce batch size, enable activation checkpointing, use LoRA/QLoRA for parameter-efficient fine-tuning, or use `bf16` precision. Refer to torchtune's memory optimization documentation for specific guidance.
Set the `HF_TOKEN` environment variable or pass it directly via `--hf-token` to the `tune download` command. Obtain a token from your Hugging Face settings page.
Refer to official examples and GitHub issues for common patterns. Expect to consult the source code or community forums for advanced customization of configs and recipes. The team has acknowledged and is working on improving documentation.