SuperAPI AI Directory

torchtune

torchtune is a PyTorch-native library that makes it easy to write, fine-tune, and experiment with LLMs.

Open website

About this tool

torchtune is a PyTorch-native post-training library designed to make it easy for users to write, post-train, and experiment with large language models (LLMs).

Key capabilities

  • Modifiable training recipes: supports supervised fine-tuning (SFT), knowledge distillation, DPO, PPO, GRPO, and quantization-aware training (QAT).
  • Concise PyTorch implementations: covers popular LLMs such as Llama, Gemma, Mistral, Phi, and Qwen.
  • Memory efficiency, performance improvements, and scalability: leverages the latest PyTorch APIs to achieve optimal memory efficiency and performance.
  • YAML configuration: used to easily configure training, evaluation, quantization, or inference recipes.
  • Covers the entire post-training lifecycle: a successful post-trained model may use multiple methods.

How to use

  • Installation: torchtune is only tested with the latest stable version of PyTorch (currently 2.6.0) and preview nightly versions, and depends on torchvision for multimodal LLM fine-tuning and torchao for the latest quantization techniques, which need to be installed as well. It supports installing the stable or nightly version, and can also be installed from source.
  • Verify installation: after running the corresponding command, you should see output.
  • Quick start: refer to the "First Finetune Tutorial" and the "End-to-End Workflow Tutorial"; the latter shows how to evaluate, quantize, and run inference on a Llama model.
  • Download models: follow the official meta-llama repository instructions to obtain access to Llama model weights, then run the command to download the weights, tokenizer model, and responsible use guide. Downloading Llama3.1 requires setting the HF_TOKEN environment variable or passing --hf-token in the command to verify access permissions.
  • Run a fine-tuning recipe: for example, fine-tune Llama3.1 8B with LoRA on a single GPU; for distributed training, the tune CLI integrates with torchrun, allowing full fine-tuning of Llama3.1 8B on two GPUs. The torchrun command must be placed before the recipe specification; subsequent CLI arguments will override the configuration without affecting distributed training.
  • Modify configuration: there are two ways, one is to directly override configuration fields from the command line (Config Overrides), and the other is to copy the configuration to a local directory, modify its contents directly, and then point to the local file when running a custom recipe.
  • Custom datasets: supports fine-tuning on a variety of datasets, including instruct-style, chat-style, preference datasets, and more.
  • Device support: supports devices such as NVIDIA GPU, Intel XPU, AMD ROCm, Apple MPS, and Ascend NPU.

Use cases

  • Post-train and fine-tune LLMs, including SFT, knowledge distillation, DPO, PPO, GRPO, and quantization-aware training.
  • Train in single-device or distributed environments (multi-node training), leveraging larger batch sizes and models.
  • Quantize, evaluate, and run inference on LLMs.
  • Integrate with ecosystem tools such as Hugging Face Hub, EleutherAI LM Eval Harness, Hugging Face Datasets, PyTorch FSDP2, torchao, Weights & Biases, Comet, ExecuTorch, bitsandbytes, and PEFT.

Limitations and notes

  • torchtune has no longer been actively maintained since 2025, and development work has ended.
  • It is only tested with the latest stable version of PyTorch (currently 2.6.0) and preview nightly versions.
  • It requires access to the official Llama model weights and configuration of permissions such as HF_TOKEN.
  • torchtune is released under the BSD 3 license, but the use of other content such as third-party models may be subject to other legal obligations, such as the terms of service of third-party models.