# torchtune

> A PyTorch-native library for fine-tuning and post-training LLMs with readable recipes

- Category: Training & Fine-Tuning / Fine-Tuning Frameworks
- Language: Python
- Repository: https://github.com/meta-pytorch/torchtune
- Website: https://docs.pytorch.org/torchtune
- Canonical page: https://ai-tldr.dev/tools/torchtune/

## In short

torchtune is a PyTorch library for authoring, post-training, and experimenting with large language models. It sits in the Fine-Tuning Frameworks category of the Training & Fine-Tuning tools and is open-source, written in Python. To get started: install torchtune.

## Overview

torchtune is a PyTorch library for authoring, post-training, and experimenting with large language models. It ships hackable training recipes and plain PyTorch implementations of common model families like Llama, Gemma, Mistral, Phi, and Qwen, so you can read and edit the training loop instead of working around heavy abstractions.

It is aimed at ML engineers and researchers who want to fine-tune open models on their own data and hardware. Recipes cover the full post-training lifecycle: supervised fine-tuning (SFT), LoRA and QLoRA, knowledge distillation, preference optimization (DPO), and reinforcement learning methods (PPO, GRPO), plus quantization-aware training. Each recipe is configured with a YAML file and launched from the `tune` command line tool.

As a fine-tuning framework, torchtune leans on current PyTorch APIs for memory efficiency and scaling from a single GPU up to multi-node runs. Note that the project is no longer actively maintained — development wound down in 2025 — so treat it as a reference and a stable base rather than an evolving tool.

## What it does

- PyTorch-native model implementations for Llama, Gemma, Mistral, Phi, Qwen, and other popular LLM families
- Hackable recipes for SFT, LoRA/QLoRA, knowledge distillation, DPO, PPO, GRPO, and quantization-aware training
- YAML configs to set up training, evaluation, quantization, or inference without rewriting code
- Scales from a single device to multiple devices and multiple nodes
- Loads supported models from the Hugging Face Hub or Kaggle Hub
- `tune` CLI to list and run recipes (`tune ls`, `tune run`)

## Getting started

Install torchtune with pip, then list the available recipes and launch one with a matching config using the `tune` CLI.

1. Install torchtune

   Install the package from PyPI. torchtune builds on PyTorch, so a working PyTorch install with the right CUDA version should be in place first.

```bash
pip install torchtune
```

2. Browse available recipes

   Use `tune ls` to see the recipes and the configs bundled with each one.

```bash
tune ls lora_finetune_single_device
```

3. Run a LoRA fine-tune on a single device

   Launch a recipe with one of its configs. This example runs single-device LoRA fine-tuning on Llama 3.2 3B.

```bash
tune run lora_finetune_single_device --config llama3_2/3B_lora_single_device
```

## When to use it

- Fine-tune an open model like Llama or Qwen on your own dataset with LoRA or QLoRA on a single GPU
- Align a model to preferences using DPO, PPO, or GRPO post-training recipes
- Compress a larger model into a smaller one with knowledge distillation
- Apply quantization-aware training to prepare a model for low-precision deployment
