AI/TLDR

Liger-Kernel

Fused Triton kernels that speed up LLM training and cut memory use

GPU Kernels & CompilersOpen source
Language
Python
License
BSD-2-Clause
$pip install liger-kernel

Overview

Liger Kernel is a collection of Triton kernels built specifically for training large language models. It ships Hugging Face-compatible versions of common layers such as RMSNorm, RoPE, SwiGLU, CrossEntropy, and FusedLinearCrossEntropy, fusing them so they run faster and use less GPU memory than the stock PyTorch implementations.

It is aimed at engineers and researchers who fine-tune or pre-train LLMs and are hitting throughput limits or out-of-memory errors. According to the project, it can increase multi-GPU training throughput by about 20% and reduce memory usage by around 60%, which leaves room for longer context lengths, larger batch sizes, and bigger vocabularies.

As an efficient-training tool, it works alongside the stack you already use: Flash Attention, PyTorch FSDP, and Microsoft DeepSpeed. You can adopt it with a one-line patch on top of Hugging Face Transformers rather than rewriting your training loop, and it also includes optimized post-training loss kernels (DPO, ORPO, SimPO, KTO, and more) that cut memory for alignment and distillation work.

What it does

  • Hugging Face-compatible Triton kernels for RMSNorm, RoPE, SwiGLU, CrossEntropy, and FusedLinearCrossEntropy
  • One-line adoption via AutoLigerKernelForCausalLM, or per-architecture patch helpers like apply_liger_kernel_to_llama
  • Reported ~20% higher multi-GPU training throughput and ~60% lower memory use
  • Works with Flash Attention, PyTorch FSDP, and DeepSpeed out of the box
  • Post-training loss kernels (DPO, ORPO, CPO, SimPO, KTO, JSD) with up to 80% memory savings
  • Runs on NVIDIA (CUDA) and AMD (ROCm) GPUs

Getting started

Install the package, then enable Liger's kernels with a single change to how you load your model.

Install Liger Kernel

Install the stable release from PyPI. NVIDIA needs torch >= 2.1.2 and triton >= 2.3.0; AMD/ROCm needs torch >= 2.5.0 and triton >= 3.0.0.

bashbash
pip install liger-kernel

Patch a model in one line

Load any causal LM through the AutoModel wrapper to apply the matching Liger kernels automatically.

pythonpython
from liger_kernel.transformers import AutoLigerKernelForCausalLM

model = AutoLigerKernelForCausalLM.from_pretrained("path/to/some/model")

Or patch a specific architecture

If you load the model yourself, call the architecture-specific helper before instantiation.

pythonpython
import transformers
from liger_kernel.transformers import apply_liger_kernel_to_llama

apply_liger_kernel_to_llama()

model = transformers.AutoModelForCausalLM.from_pretrained("path/to/llama/model")

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Fine-tuning a Hugging Face LLM (e.g. LLaMA 3-8B) that runs out of memory at longer context lengths
  • Raising multi-GPU training throughput on FSDP or DeepSpeed without changing your training loop
  • Running alignment or preference tuning (DPO, ORPO, SimPO, KTO) with lower memory using the fused post-training loss kernels
  • Training with larger batch sizes or bigger vocabularies on the same hardware budget

How Liger-Kernel compares

Liger-Kernel alongside other open-source gpu kernels & compilers tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Liger-Kernel★ 6.6kFused Triton kernels that speed up LLM training and cut memory use
cuTile Rust★ 777A tile-based GPU kernel DSL for Rust from NVIDIA Labs that extends Rust's ownership model across the launch boundary, so kernels are data-race free by construction.
Cohere MegakernelA single-H100 serving engine that runs North Mini Code's entire decode pass in one persistent CUDA kernel, behind an OpenAI-compatible API.