Model or dataset
linkedin/Liger-Kernel avatar
linkedin/Liger-Kernel

Liger-Kernel: Triton kernels that replace Hugging Face training ops

Efficient Triton Kernels for LLM Training

6,612 stars599 forksPythonBSD-2-Clause

At a glance

What is it?
Liger-Kernel swaps RMSNorm, RoPE, SwiGLU and CrossEntropy for fused Triton implementations behind a Hugging Face compatible interface. The pitch is throughput and memory, the cost is a narrower support surface than stock PyTorch.
Who is it for?
Adopt Liger-Kernel if you are fine-tuning a supported architecture (Llama, Gemma2, Mistral, Phi3) on NVIDIA or AMD hardware and you already have a working FSDP or DeepSpeed baseline to compare against. Do not adopt it if your model family is not in the supported list, or if you cannot re-run your evaluation suite after swapping kernels, because the fused ops change the numerical path.
Can I use it commercially?
Yes. BSD-2-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

The problem: unfused ops waste memory bandwidth during training

A standard Hugging Face transformer forward pass computes RMSNorm, rotary position embeddings, the SwiGLU activation and the cross-entropy loss as separate PyTorch operations. Each one writes an intermediate tensor to high-bandwidth memory and reads it back for the next step. For the loss in particular, materialising a full logits tensor of shape (batch, sequence, vocab) is the dominant memory cost in fine-tuning, and it grows linearly with vocabulary size. Liger-Kernel's stated goal is to fuse these operations so the intermediate never lands in memory. The README claims a 20% increase in multi-GPU training throughput and a 60% reduction in memory usage, measured on LLaMA 3-8B with batch size 8, bf16, AdamW, gradient checkpointing enabled and FSDP1 across 8 A100s. The audience is people running supervised fine-tuning or alignment jobs on a fixed GPU budget, where the difference between a 4K and a 16K context length is whether the job runs at all. The README notes that Hugging Face models start to OOM at 4K context on that configuration while Hugging Face plus Liger scales to 16K.

What actually gets replaced, and how the patch mechanism works

Liger ships Triton implementations of RMSNorm, RoPE, SwiGLU, CrossEntropy and FusedLinearCrossEntropy, and the README describes them as Hugging Face compatible. Compatibility here means the modules are drop-in replacements that keep the same call signature, so a model built from Hugging Face classes can be rewired without editing its forward method. The high-level API is a monkey-patch: you call a function that walks the model object and substitutes the attention, MLP and norm layers with Liger equivalents. The low-level API exposes the kernels themselves for people writing custom training loops. The fused cross-entropy is the most consequential substitution. Instead of computing logits, storing them, then reducing to a scalar loss, FusedLinearCrossEntropy consumes the hidden states and the LM head weight and produces the loss directly, so the (batch, sequence, vocab) tensor is never allocated. The README also points to a joint PyTorch blog post on combining torch.compile with Liger Kernel, which suggests the two are meant to be stacked rather than chosen between.

Installation and the one-line patch

The package is on PyPI as liger-kernel, with a separate liger-kernel-nightly channel for unreleased work. The README's installation section points at the documentation site for the full matrix, and the repository carries both stable and nightly badges, which implies two install paths. The usage pattern shown in the README is a single patching call against a loaded model, followed by training as normal. Because the patch mutates the model in place, it has to happen after from_pretrained and before the optimizer is constructed, otherwise the parameter set the optimizer captured will not match the modules being trained. The post-training losses are used differently: they are imported as Python modules and called directly. The README gives this example for ORPO: from liger_kernel.chunked_loss import LigerFusedLinearORPOLoss, then instantiate the loss object and call it with the LM head weight, the hidden states and the target. The loss returns the value directly rather than a logits tensor, which is the whole point of the chunked_loss module name. The README lists DPO, CPO, ORPO, SimPO, KTO and JSD among the supported losses, and states up to 80% memory savings for alignment and distillation tasks.

The support surface is narrower than the pitch suggests

The repository topics name gemma2, llama, llama3, mistral and phi3. That is the concrete list of architectures the project advertises, and it is a small slice of what Hugging Face Transformers supports. If you are fine-tuning a model outside that set, the monkey-patch has nothing to bind to and the kernels will not be applied. There is a second constraint that the README does not resolve: the benchmark conditions specify FSDP1 on 8 A100s. Whether the same throughput and memory figures hold under FSDP2, under tensor parallelism, or on a single GPU is not stated in the supplied material. The README does say the kernels work out of the box with Flash Attention, PyTorch FSDP and Microsoft DeepSpeed, but working out of the box and reproducing the headline numbers are different claims. There is also a numerical question. A fused RMSNorm that computes in a different order or accumulates in a different precision than the reference implementation will produce slightly different gradients. For a short fine-tune this is usually invisible; for a long alignment run or a reproduction study it can matter. The README gives no tolerance figures and no numerical parity statement, so treat kernel substitution as a change to your training run rather than a transparent optimisation.

Liger versus writing your own Triton kernels

The obvious alternative is to write the fused kernels yourself, or to use whatever fused ops already ship in your training stack. Writing them yourself gives you exact control over the numerical path, the tile sizes and the memory layout, and it removes a dependency from your training environment. The cost is that Triton kernel development is a specialist skill, and you inherit the maintenance burden for every model architecture and every GPU generation you support. Liger's approach is to centralise that work: one library, Hugging Face compatible interfaces, and a community contribution model, with the README explicitly inviting contributions to gather kernels for LLM training. The trade is control for coverage. A second alternative is to stay on stock PyTorch and rely on torch.compile to fuse what it can. The PyTorch blog post linked from the README covers combining torch.compile with Liger, which suggests the maintainers see them as complementary rather than competing: torch.compile handles the general graph, Liger handles the specific ops where a hand-written kernel beats the compiler. If your bottleneck is not in the ops Liger replaces, neither approach will help much.

Maintenance, versioning and the licence

The release cadence visible in the supplied data is roughly one tagged release every two to three months, with v0.8.0 in April 2026, v0.8.1 in July and v0.8.2 in August. Pre-1.0 versioning means the API can still move between minor releases, and the existence of a nightly channel alongside stable means some users are tracking unreleased commits deliberately. The practical upgrade cost is that Liger sits between your training framework and your model code, so a bump in either direction can break the patch. Before upgrading, check that the Liger release you are moving to supports the torch and triton versions already installed in your environment, and re-run a short training step to confirm the patch still binds. The licence is BSD-2-Clause, a permissive licence that permits redistribution and modification with the copyright notice retained and the standard disclaimer of warranty. That is compatible with commercial fine-tuning work. It is not a copyleft licence, so it imposes no obligation to publish your training code. This is a description of the licence text, not legal advice; if you are redistributing Liger inside a product, have counsel read the actual licence file.

Who should patch their model and who should not

The case for adopting Liger-Kernel is strongest when three things are true at once: the model is one of the advertised architectures, the hardware is NVIDIA or AMD with a working Triton install, and the job is memory-bound rather than compute-bound. That last condition is what the fused cross-entropy addresses, and it is where the largest claimed savings sit, particularly for large vocabularies. The case against is equally clear. If the model family is not supported, the patch does nothing and the dependency is pure overhead. If the training run is a reproduction of a published result, substituting kernels without a numerical parity check makes the comparison meaningless. And if the bottleneck is data loading or communication rather than the ops Liger fuses, the memory savings will not translate into wall-clock time. The honest framing is that Liger is an optimisation you apply after you have a working baseline, not a component you build the baseline on.

Editorial conclusion

Adopt Liger-Kernel if you are fine-tuning a supported architecture (Llama, Gemma2, Mistral, Phi3) on NVIDIA or AMD hardware and you already have a working FSDP or DeepSpeed baseline to compare against. Do not adopt it if your model family is not in the supported list, or if you cannot re-run your evaluation suite after swapping kernels, because the fused ops change the numerical path. Verify first that your installed torch and triton versions satisfy the constraints in pyproject.toml, and that LigerRMSNorm matches your model's epsilon convention before you trust a full training run.

Official sources

  1. License: BSD-2-Clause
  2. linkedin/Liger-Kernel on GitHub
  3. Project website
  4. README
  5. Releases
Community notes

Community notes