LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models

Yaowei Zheng, Richong Zhang, Junhao Zhang, Yanhan Ye, Zheyan Luo, Yongqiang MaarXiv 2024 · DOI

Introduction

The rapid proliferation of Large Language Models (LLMs) has created a significant demand for efficient fine-tuning methods. While the community has developed numerous Parameter-Efficient Fine-Tuning (PEFT) techniques—such as LoRA, QLoRA, and GaLore—to reduce computational costs, these tools remain largely fragmented. Implementing a specific method on a new model architecture typically requires extensive manual coding to align data formats, model structures, and training loops.

LLAMAFACTORY is introduced as a unified, open-source framework designed to democratize the fine-tuning of over 100 LLMs. By integrating a vast suite of cutting-edge training techniques into a modular pipeline and offering a "no-code" web interface called LLAMABOARD, it allows researchers to adapt massive models to specific tasks with minimal resources and zero boilerplate code.

The LLAMAFACTORY Framework

LLAMAFACTORY is built on a modular architecture consisting of three primary components: the Model Loader, the Data Worker, and the Trainer. This structure ensures that the framework remains extensible as new models and tuning methods emerge.

The modular architecture of LLAMAFACTORY, including the LlamaBoard UI, Trainer, Model Loader, and Data Worker.

Core Components

  1. Model Loader: This component handles model initialization, quantization (supporting 8-bit and 4-bit via bitsandbytes), and "patching." Patching allows for the seamless integration of performance-enhancing features like FlashAttention-2 or $S^2$ attention. A centralized model registry ensures that adapters are attached to the correct layers regardless of the underlying architecture.
  2. Data Worker: To solve the issue of inconsistent data formats, the Data Worker uses a standardized pipeline to load, align, and merge datasets. It employs a "data description specification" that maps various raw formats (such as Alpaca or ShareGPT) into a unified format compatible with the training loop.
  3. Trainer: The Trainer integrates state-of-the-art optimization techniques. It supports a wide array of PEFT methods including LoRA, QLoRA, DoRA, LoRA+, PiSSA, and GaLore. Beyond standard Supervised Fine-Tuning (SFT), it supports advanced alignment approaches like RLHF, DPO, KTO, and ORPO.

Unified Feature Support

A key contribution of LLAMAFACTORY is its ability to unify disparate techniques that are often only available in isolation in other frameworks. By providing a high level of abstraction, a researcher can switch from a Llama-3 model to a Mistral model, or from LoRA to GaLore, by simply changing a configuration flag.

A comparison of LLAMAFACTORY against other popular fine-tuning frameworks, highlighting its comprehensive support for various PEFT methods and training approaches.

As shown in the comparison above, LLAMAFACTORY offers the most comprehensive suite of supported features, particularly in its support for diverse optimization methods (like DoRA and PiSSA) and alignment algorithms (like KTO and ORPO) that are absent in many competing tools.

Key Insights and Efficiency Gains

Democratization through Abstraction

LLAMAFACTORY lowers the barrier to entry for LLM research. The inclusion of LLAMABOARD, a Gradio-based web UI, allows users to configure, start, and monitor training sessions without writing Python code, making advanced fine-tuning accessible to non-engineers.

Hardware-Aware Optimization

The framework leverages Unsloth to provide a massive throughput boost for LoRA and QLoRA training. Additionally, it introduces a "Model-Sharing" trick for RLHF. By dynamically switching adapters and value heads on a single pre-trained model, LLAMAFACTORY avoids the need to load four separate models (policy, value, reference, and reward) into VRAM simultaneously, enabling RLHF on consumer-grade GPUs.

Performance Results

Empirical evaluations on benchmarks like PubMed (for perplexity) and CNN/DM (for summarization) demonstrate that LLAMAFACTORY's implementations of LoRA and QLoRA consistently match or exceed full-parameter fine-tuning performance. For instance, on a Llama2-7B model, QLoRA reduced peak memory usage to just 7.52 GB, compared to the 38.72 GB required for full-tuning, without sacrificing model quality.

Conclusion

LLAMAFACTORY effectively bridges the "fragmentation gap" in the LLM ecosystem. By providing a unified, efficient, and user-friendly interface for fine-tuning, it has become a vital tool for the open-source community, as evidenced by its significant GitHub traction. Future work will focus on expanding the framework to include multi-modal data (audio and video) and integrating more advanced parallelism strategies for cluster-scale training.

Summary updated

BibTeX
@misc{zheng2024llamafactory,
  author = {Yaowei Zheng and Richong Zhang and Junhao Zhang and Yanhan Ye and Zheyan Luo and Yongqiang Ma},
  title = {{LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models}},
  year = {2024},
  eprint = {2403.13372},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.13372},
}
Figure