492bfeb791 Fix CUDA 13 Blackwell MoE with uniform 1SM UMMA (#1505)
## Summary

Make Blackwell MoE homogeneous **1SM UMMA** so the native core builds
with CUDA 13. The previous fused backward kernel combined 1SM
token-gradient/activation phases with 2SM weight-gradient phases; CUDA
13 rejects mixed `.cta_group::1` and `.cta_group::2` instructions within
one kernel.

This PR contains **only the 1SM implementation**. Uniform-2SM
alternatives were implemented and measured separately, including an NC=8
communication ablation, but are not included in the code change. Qwen is
the priority workload: 1SM outperforms both tested 2SM alternatives in
forward and backward for every measured Qwen shape.

### Implementation

- Convert SM100 MLP3/MLP4 from joined M256xN256 two-CTA tiles to
independent M128xN128 tiles, retaining the existing K tile and stage
selections.
- Use 1SM MMA atoms, CTA-local TMEM allocation, single-CTA TMA loads,
local transaction-byte accounting, and one accumulator-release arrival
per CTA.
- Remove paired-CTA TMEM and accumulator rendezvous from fused MoE
backward; retain the required CTA-local phase synchronization.
- Keep communication geometry at **TileM=128, NC=4**. Forward math is
unchanged.
- Retain the existing tuning-table row identifiers for compatibility;
map SM100 weight-gradient traits explicitly to the new tile geometry.
- Update standalone harnesses and document CUDA 13 native-source
support. The cross-entropy dW harness changes only its MoE reference
path.

**Unchanged:** production cross-entropy remains homogeneous 2SM;
Hopper-specific production sources, release workflows, CUDA 12.9
release-toolchain pins, and published wheels are not changed.

## Performance methodology

All tables report **TFLOP/s per GPU**, not the sum across GPUs.
Measurements use eight NVIDIA B300 SXM6 PC GPUs, 8,192 input tokens per
rank, eight microbatches, and 250 ms per-launch cooldown. Workload
matching uses model, GPU count, T, D, I, E, and K, not just the model
label.

| Variant | Toolchain | MoE instruction groups | Communication TileM |
NC | Weight-gradient tiles |
|---|---|---|---:|---:|---|
| Historical baseline | CUDA 12.9 | Original mixed 1SM/2SM backward |
128 | 4 | Joined M256xN256, 2SM |
| **1SM: this PR** | CUDA 13.0.88 | Uniform 1SM | 128 | 4 | Independent
M128xN128 |
| 2SM, NC=4 ablation | CUDA 13.0.88 | Uniform 2SM in forward/backward |
256 | 4 | Joined M256xN256 |
| 2SM, NC=8 ablation | CUDA 13.0.88 | Uniform 2SM in forward/backward |
256 | 8 | Joined M256xN256 |

The CUDA 13 variants use the same B300 host/image, driver 580.159.04,
PyTorch 2.11.0.1+cu130, and existing CUTLASS/NVSHMEM/TVM FFI
installations. Their source base is
`43293d84d760e402e4fd974b12410a1d47c31761`.

The benchmark is MoEBenchmark at
`85443d69ab065bfa4d303e1e4af56594c993ddf3`, with the same small adapter
updates for all CUDA 13 variants: current team-handle arguments and the
existing unique-ID bootstrap for single-node torchrun. Those changes are
outside the timed kernel regions. Timing loops, max-rank CUDA-event
latency, FLOP conventions, and correctness tolerances are unchanged.

Forward FLOPs/GPU: `6*T*K*D*I + 5*T*K*I + 2*T*K*D`. Backward FLOPs/GPU:
`16*T*K*D*I`. Percentages below are calculated from the CSV precision
before display rounding.

### Workloads

Here D is hidden size, I is per-expert intermediate size, E is total
expert count, and K is routing top-k. T=8192 and world_size=8 for every
row.

| Model | D | I | E | K |
|---|---:|---:|---:|---:|
| Llama 4 Scout | 5120 | 8192 | 16 | 1 |
| Mixtral 8x7B | 4096 | 14336 | 8 | 2 |
| Mixtral 8x22B | 6144 | 16384 | 8 | 2 |
| Qwen3 30B-A3B | 2048 | 768 | 128 | 8 |
| Qwen3 235B-A22B | 4096 | 1536 | 128 | 8 |
| Qwen3.5 35B-A3B | 2048 | 512 | 256 | 8 |
| Qwen3.5 122B-A10B | 3072 | 1024 | 256 | 8 |

## Full comparison against the historical baseline

Each ablation cell shows **TFLOP/s (throughput change vs. baseline)**.
Positive is faster; negative is slower.

### Forward

| Model | Baseline | 1SM: this PR | 2SM, NC=4 | 2SM, NC=8 |
|---|---:|---:|---:|---:|
| Llama 4 Scout | 886.7 | 851.6 (-3.96%) | 865.9 (-2.35%) | 920.8
(+3.85%) |
| Mixtral 8x7B | 1,175.8 | 1,140.1 (-3.04%) | 1,203.1 (+2.32%) | 1,194.4
(+1.58%) |
| Mixtral 8x22B | 1,174.3 | 1,155.9 (-1.56%) | 1,099.2 (-6.39%) |
1,107.6 (-5.68%) |
| Qwen3 30B-A3B | 467.8 | 465.8 (-0.44%) | 366.8 (-21.60%) | 361.1
(-22.82%) |
| Qwen3 235B-A22B | 762.2 | 766.4 (+0.56%) | 663.8 (-12.90%) | 704.3
(-7.60%) |
| Qwen3.5 35B-A3B | 273.8 | 272.9 (-0.31%) | 232.5 (-15.09%) | 241.8
(-11.68%) |
| Qwen3.5 122B-A10B | 551.1 | 554.9 (+0.68%) | 462.8 (-16.03%) | 489.7
(-11.14%) |

### Backward

| Model | Baseline | 1SM: this PR | 2SM, NC=4 | 2SM, NC=8 |
|---|---:|---:|---:|---:|
| Llama 4 Scout | 714.0 | 614.6 (-13.93%) | 683.4 (-4.29%) | 731.5
(+2.45%) |
| Mixtral 8x7B | 956.3 | 796.3 (-16.74%) | 916.4 (-4.18%) | 934.5
(-2.28%) |
| Mixtral 8x22B | 1,018.2 | 839.1 (-17.59%) | 960.8 (-5.64%) | 989.1
(-2.86%) |
| Qwen3 30B-A3B | 402.5 | 390.9 (-2.89%) | 327.7 (-18.58%) | 353.9
(-12.08%) |
| Qwen3 235B-A22B | 646.2 | 577.8 (-10.58%) | 554.0 (-14.27%) | 571.6
(-11.53%) |
| Qwen3.5 35B-A3B | 290.0 | 280.7 (-3.22%) | 226.1 (-22.05%) | 234.3
(-19.22%) |
| Qwen3.5 122B-A10B | 534.0 | 489.3 (-8.36%) | 426.1 (-20.19%) | 436.4
(-18.27%) |

### Aggregate throughput changes

These are unweighted geometric means of per-model throughput ratios, not
arithmetic averages of TFLOP/s and not an end-to-end training-speed
claim.

| Comparison | Forward | Backward |
|---|---:|---:|
| 1SM vs. historical baseline | -1.17% | -10.64% |
| 2SM NC=4 vs. historical baseline | -10.63% | -13.05% |
| 2SM NC=8 vs. historical baseline | -8.02% | -9.44% |
| 2SM NC=4 vs. 1SM | -9.57% | -2.69% |
| 2SM NC=8 vs. 1SM | -6.94% | +1.34% |
| 2SM NC=8 vs. 2SM NC=4 | +2.92% | +4.14% |

## Why choose 1SM?

Qwen is the priority workload. Even the improved NC=8 2SM candidate is
slower than 1SM for every measured Qwen shape in both directions:

| Qwen model | 2SM NC=4 vs. 1SM forward | Backward | 2SM NC=8 vs. 1SM
forward | Backward |
|---|---:|---:|---:|---:|
| Qwen3 30B-A3B | -21.26% | -16.15% | -22.48% | -9.46% |
| Qwen3 235B-A22B | -13.39% | -4.13% | -8.11% | -1.07% |
| Qwen3.5 35B-A3B | -14.83% | -19.46% | -11.41% | -16.54% |
| Qwen3.5 122B-A10B | -16.59% | -12.91% | -11.75% | -10.81% |

Uniform 2SM does have a useful counterexample: with NC=8, backward
throughput exceeds 1SM by 19.03% for Scout, 17.36% for Mixtral 8x7B, and
17.88% for Mixtral 8x22B. Those gains explain its slightly positive
all-model backward geometric mean, but do not justify choosing it for
the Qwen-focused workload.

The NC=8 experiment restores the communication band from 64 rows/CTA
(`256/4`) to 32 (`256/8`, matching the original `128/4`). It improves
backward over NC=4 for all seven shapes. However, it also changes the
number of independent communication groups, ring capacity/adaptive
grouping, and the existing NC-aligned launch grid: on this 148-SM GPU,
NC=4 launches 148 CTAs/37 groups, while NC=8 launches 144 CTAs/18
groups. Other tuning parameters were not retuned.

The proposed choice is therefore **uniform 1SM for CUDA 13
compatibility**, accepting the explicitly reported historical-baseline
regressions rather than introducing the larger Qwen regressions and
paired scheduling changes of the tested 2SM alternatives.
Shape-selective 2SM tuning is outside this PR.

### Interpretation limits

- The baseline is the recorded September CUDA 12.9 campaign, not a fresh
same-image baseline. It differs in toolchain, dependencies, and
intervening code. Its changes cannot be attributed exclusively to the
UMMA instruction group. The unchanged-math 1SM forward control itself
moves -1.17% geometrically.
- The 1SM/2SM comparisons use the same CUDA 13 environment, but compare
complete implementations: tile dimensions and required
pairing/scheduling change with the instruction group. They do not
isolate the causal cost of a single instruction choice.
- These are single-campaign point estimates, without confidence
intervals. In particular, small differences such as the +1.34% overall
backward result are not statistical-significance claims.
- The conclusion is scoped to these seven eight-GPU, 8K-token BF16
workloads; no claim is made about every Qwen configuration or multi-node
performance.

## Validation

- Full native CUDA 13 `sm_100f` core build.
- B300 standalone MLP3/MLP4 correctness, MLP1
forward/activation-recompute correctness, and the separate
MoE-reference/FSLCE-dW harness.
- All seven eight-B300 model shapes compared with the existing Torch
reference in forward and backward for the 1SM candidate and both 2SM
ablations; no tolerances relaxed.
- Retained Hopper MLP3/MLP4 harness correctness on H200 with CUDA 12.9.

The benchmark's reference column is labeled "TE", but these runs were
built with `HAVE_TE=OFF`: the reference is Torch matmul, not Transformer
Engine. Reference comparisons were run separately from the
eight-microbatch, cooled Liger-only performance measurements.

### Benchmark invocation

Using the same existing MoEBenchmark executable and adapter for each
candidate:

```bash
export BENCH_NAMED_ONLY=1 BENCH_ONLY_CFG=_t8k
export NVSHMEM_DISABLE_NCCL=1 NVSHMEM_REMOTE_TRANSPORT=none
export NVSHMEM_SYMMETRIC_SIZE=6G OMP_NUM_THREADS=1

# Run separately for bench_moe_mlp and bench_moe_mlp_bwd.
BENCH_BACKENDS=liger,torch_baseline N_MICROBATCHES=1 BENCH_COOLDOWN_MS=0 \
  uv run --no-project python -m torch.distributed.run \
  --standalone --nproc-per-node=8 --no-python ./build/bench_moe_mlp

BENCH_ONLY_BACKEND=liger BENCH_SKIP_CORRECTNESS=1 \
  N_MICROBATCHES=8 BENCH_COOLDOWN_MS=250 BENCH_CSV=forward_gpu8.csv \
  uv run --no-project python -m torch.distributed.run \
  --standalone --nproc-per-node=8 --no-python ./build/bench_moe_mlp
```

Native library SHA256 identifiers for the measured CUDA 13 candidates:

```text
1SM:     6226ae0c033515746eec2bf3bc2430624e10577f9b6ac2b72fd3ea45c90b162e
2SM NC4: 193decd95a38a8e2838379f84660c00ce42c2d3d4c027d167fae9d46c36265f8
2SM NC8: 8bc029baaecdab649a30199146867ef59e6da099801675fe49e7e50132f26b4b
```

Co-authored-by: jkolehma <[email protected]>
Co-authored-by: Copilot <[email protected]>
2026-10-01 17:01:18 +00:00
2024-08-13 11:09:50 -07:00
2025-08-30 08:33:05 -07:00
2024-10-01 21:10:42 +00:00
2026-09-16 16:17:49 +00:00

Liger Kernel: Efficient Triton Kernels for LLM Training

Stable Nightly Discord
Downloads (Stable) PyPI - Version Downloads (Nightly) PyPI - Version Join Our Discord

Installation | Getting Started | Examples | High-level APIs | Low-level APIs | Cite our work

Latest News 🔥

Liger Kernel is a collection of Triton kernels designed specifically for LLM training. It can effectively increase multi-GPU training throughput by 20% and reduces memory usage by 60%. We have implemented Hugging Face Compatible RMSNorm, RoPE, SwiGLU, CrossEntropy, FusedLinearCrossEntropy, and more to come. The kernel works out of the box with Flash Attention, PyTorch FSDP, and Microsoft DeepSpeed. We welcome contributions from the community to gather the best kernels for LLM training.

We've also added optimized Post-Training kernels that deliver up to 80% memory savings for alignment and distillation tasks. We support losses like DPO, CPO, ORPO, SimPO, KTO, JSD, and many more. Check out how we optimize the memory.

You can view the documentation site for additional installation, usage examples, and API references:https://linkedin.github.io/Liger-Kernel/

You can view the Liger Kernel Technical Report: https://openreview.net/forum?id=36SjAIT42G

Supercharge Your Model with Liger Kernel

Banner

With one line of code, Liger Kernel can increase throughput by more than 20% and reduce memory usage by 60%, thereby enabling longer context lengths, larger batch sizes, and massive vocabularies.

Speed Up Memory Reduction
Speed up Memory

Note:

  • Benchmark conditions: LLaMA 3-8B, Batch Size = 8, Data Type = bf16, Optimizer = AdamW, Gradient Checkpointing = True, Distributed Strategy = FSDP1 on 8 A100s.
  • Hugging Face models start to OOM at a 4K context length, whereas Hugging Face + Liger Kernel scales up to 16K.

Optimize Post Training with Liger Kernel

Post Training

We provide optimized post training kernels like DPO, ORPO, SimPO, and more which can reduce memory usage by up to 80%. You can easily use them as python modules.

from liger_kernel.chunked_loss import LigerFusedLinearORPOLoss
orpo_loss = LigerFusedLinearORPOLoss()
y = orpo_loss(lm_head.weight, x, target)

Examples

Use Case Description
Hugging Face Trainer Train LLaMA 3-8B ~20% faster with over 40% memory reduction on Alpaca dataset using 4 A100s with FSDP
Lightning Trainer Increase 15% throughput and reduce memory usage by 40% with LLaMA3-8B on MMLU dataset using 8 A100s with DeepSpeed ZeRO3
Medusa Multi-head LLM (Retraining Phase) Reduce memory usage by 80% with 5 LM heads and improve throughput by 40% using 8 A100s with FSDP
Vision-Language Model SFT Finetune Qwen2-VL on image-text data using 4 A100s with FSDP
Liger ORPO Trainer Align Llama 3.2 using Liger ORPO Trainer with FSDP with 50% memory reduction

Key Features

  • Ease of use: Simply patch your Hugging Face model with one line of code, or compose your own model using our Liger Kernel modules.
  • Time and memory efficient: In the same spirit as Flash-Attn, but for layers like RMSNorm, RoPE, SwiGLU, and CrossEntropy! Increases multi-GPU training throughput by 20% and reduces memory usage by 60% with kernel fusion, in-place replacement, and chunking techniques.
  • Exact: Computation is exact—no approximations! Both forward and backward passes are implemented with rigorous unit tests and undergo convergence testing against training runs without Liger Kernel to ensure accuracy.
  • Lightweight: Liger Kernel has minimal dependencies, requiring only Torch and Triton—no extra libraries needed! Say goodbye to dependency headaches!
  • Multi-GPU supported: Compatible with multi-GPU setups (PyTorch FSDP, DeepSpeed, DDP, etc.).
  • Trainer Framework Integration: Axolotl, LLaMa-Factory, SFTTrainer, Hugging Face Trainer, SWIFT, oumi

Installation

Dependencies

CUDA

  • torch >= 2.1.2
  • triton >= 2.3.1

ROCm

  • torch >= 2.5.0 Install according to the instruction in Pytorch official webpage.
  • triton >= 3.0.0 Install from pypi. (e.g. pip install triton==3.0.0)
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/rocm7.2

Ascend NPU

  • torch == 2.9.0
  • torch_npu == 2.9.0
  • triton-ascend == 3.2.2 Install from the Ascend PyPI mirror (not on default PyPI).
  • CANN == 9.1.0
pip install -e ".[dev]" --extra-index-url https://triton-ascend.osinfra.cn/pypi/simple

Optional Dependencies

  • transformers >= 4.x: Required if you plan to use the transformers models patching APIs. The specific model you are working will dictate the minimum version of transformers.
  • cuda-tile: Required when enabling the optional cuTile backend on CUDA. Use this when your environment already provides CUDA Toolkit 13.1 or newer, or an existing tileiras compiler installation.
  • cuda-tile[tileiras]: Required when enabling the optional cuTile backend with the tileiras compiler installed directly into your Python environment.
  • nvidia-cutlass-dsl >= 4.6.0: Required when enabling the optional CuTe DSL backend on CUDA (the CUDA-only Python DSL shipped with NVIDIA CUTLASS, import cutlass.cute). Targets Hopper (SM90) and Blackwell (SM100/SM110).
  • liger-cute-kernels: Native CUTLASS + NVSHMEM kernels for Hopper and Blackwell, installed at the exact matching Liger version by the lck extra.

Note: Our kernels inherit the full spectrum of hardware compatibility offered by Triton.

To install the stable version:

$ pip install liger-kernel

To also install the matching native Liger communication kernels:

$ pip install "liger-kernel[lck]" "liger-cute-kernels[cu12]"

The native LCK release wheel build remains on CUDA 12.9 (CUDA Toolkit 12.9.1). The optional cu12 extra installs nvidia-nvshmem-cu12==3.6.5; cu13 installs nvidia-nvshmem-cu13==3.6.5 for CUDA 13 source builds. Plain liger-cute-kernels does not install NVSHMEM. Select only one extra, matching the native wheel's build toolkit: extras select dependencies, not a different compiled wheel. CUDA 13 source builds currently work for Hopper, but the combined release build is blocked by mixed CTA-group instructions in the Blackwell MoE backward kernel. Previously published artifacts are unchanged. The default liger-kernel installation is unchanged. See the native wheel build instructions for source builds and compatibility details.

To install the nightly version:

$ pip install liger-kernel-nightly

To install from source:

git clone https://github.com/linkedin/Liger-Kernel.git
cd Liger-Kernel

# Install Default Dependencies
# Setup.py will detect the local backend and select default dependencies.
# On ROCm, install ROCm PyTorch first from the PyTorch ROCm index.
pip install -e .

# Setup Development Dependencies
pip install -e ".[dev]"

# ROCm source installs
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/rocm7.2
# Then choose one:
pip install -e .
pip install -e ".[dev]"

# Setup cuTile Dependencies
pip install -e ".[cutile]"

# Or install cuTile with the optional tileiras compiler
pip install -e ".[cutile-tileiras]"

# Setup CuTe DSL (NVIDIA CUTLASS Python DSL) Dependencies
pip install -e ".[cutedsl]"

# Setup native Liger communication kernels
pip install -e ".[lck]"

Enable cuTile Backend

cuTile is an optional CUDA-only DSL implementation. After installing the cutile or cutile-tileiras extra, enable it explicitly:

LIGER_KERNEL_IMPL=cutile python your_script.py

LIGER_KERNEL_IMPL selects an opt-in implementation registered with Liger (currently cutile and cutedsl). Selecting one on an unsupported device, or without the required dependencies installed, raises an error.

Enable CuTe DSL Backend

CuTe DSL is the optional, CUDA-only Python DSL shipped with NVIDIA CUTLASS (import cutlass.cute), targeting Hopper (SM90) and Blackwell (SM100/SM110). After installing the cutedsl extra, enable it explicitly:

pip install "liger-kernel[cutedsl]"
LIGER_KERNEL_IMPL=cutedsl python your_script.py

It currently provides genuine cutlass.cute implementations of:

  • RMSNorm
  • RoPE
  • SwiGLU
  • Cross entropy
  • Fused linear cross entropy (with an SM90-specialized variant)
  • Fused scaled cross entropy (SM90)

Ops without a CuTe DSL kernel transparently fall back to the default Triton kernel.

The cutedsl extra also pulls in apache-tvm-ffi, which lets compiled kernels take PyTorch tensors directly rather than marshalling each one per call. It is optional — every kernel falls back to the marshalling launch without it — but short kernels are dominated by that per-call cost, so installing it is strongly recommended.

Fused Scaled Cross Entropy

LigerFusedLinearScaledCrossEntropyFunction is an additional per-token operator, not a replacement for the reduction-oriented Triton LigerFusedLinearCrossEntropyFunction. It takes input[M, H], weight[V, H], and target[M], applies logits / temperature, and returns FP32 negative log-likelihood [M] plus optional differentiable vocabulary entropy [M] in the input dtype. Reductions remain in PyTorch, and rows whose target equals ignore_index contribute zero outputs and gradients.

from liger_kernel.ops import LigerFusedLinearScaledCrossEntropyFunction

nll, entropy = LigerFusedLinearScaledCrossEntropyFunction.apply(
    x, weight, target, 1.0, -100, 1, True
)  # [M], [M]
loss = nll.sum() / (target != -100).sum().clamp_min(1)

The implementations share this public contract but use different schedules:

  • cuTile (LIGER_KERNEL_IMPL=cutile) supports matching floating-point input and weight tensors on CUDA and a finite positive scalar temperature. The portable temporary-logits budget is 256 MiB. Large FP16/BF16 Blackwell workloads (M >= 4096, V >= 131072) automatically use 512 MiB to improve GEMM utilization. Set LIGER_CUTILE_SCALED_CE_WORKSPACE_MB to another positive MiB value for workload-specific tuning; for example, 1024 can help large combined NLL-plus-entropy workloads but is not universally faster. Backward reuses one workspace and writes dX and accumulates dW directly into their final tensors. m_tiles_per_cluster is accepted for API compatibility but does not change the cuTile schedule.
  • CuTe SM90 uses LigerFusedScaledCrossEntropySM90Function for BF16 inputs on Hopper. Its sole forward uses the fixed cluster-M2 N160 fragment kernel, with a measured split-N lookup for profiled long-sequence shapes, and never writes logits to HBM; m_tiles_per_cluster remains accepted for API compatibility but does not change that schedule. Backward runs dZ, dX, and dW in one persistent cluster kernel with a reusable 1024-token dZ workspace.
  • Fallback uses a 512-token chunked PyTorch implementation adapted from Verl's fused PPO formulas when the default frontend cannot use the SM90 kernel.

For a classifier weight sharded into equally sized contiguous ranges across a tensor-parallel process group, use the TP frontend. Targets remain global vocabulary indices:

from liger_kernel.ops import LigerFusedLinearScaledCrossEntropyTPFunction

nll, entropy = LigerFusedLinearScaledCrossEntropyTPFunction.apply(
    x, local_weight, target, tp_group, 1.0, -100, 1, True
)

The TP frontend derives vocab_start from the process-group rank. BF16 inputs on Hopper use the optional liger_cute_kernels implementation when its native core is available; other configurations use Liger's chunked tensor-parallel fallback adapted from Verl's fused PPO formulas. Both paths return globally correct per-token outputs and sum the input gradient across the TP group. The native CUTLASS + NVSHMEM paths communicate exclusively through NVSHMEM; no Torch communicator or Torch C++ ABI crosses the TVM-FFI boundary. Calls remain collectives on tp_group, so they must have the same ordering on every member.

The native operators share the process-wide NVSHMEM bootstrap used by LigerExpertParallelFusedMoe, while TP and EP use separate cached teams and separately named workspaces. Application setup must initialize NVSHMEM from a common parent group (normally WORLD) and resolve both process groups before invoking either kernel. The first FSLCE call fixes its workspace capacity, so warm it up with the largest expected token, hidden, local-vocabulary, and tiles_per_reduce settings before CUDA Graph capture.

H100 BF16 forward medians from 60 interleaved samples per provider at H=4096, V=131072. Effective TFLOPS count the common projection work, 2*M*H*V:

M Entropy CuTe SM90 cuTile Verl Torch fallback
2048 No 3.12 ms / 706 TFLOPS 3.19 ms / 690 TFLOPS 11.36 ms / 194 TFLOPS
2048 Yes 3.13 ms / 703 TFLOPS 3.25 ms / 676 TFLOPS 11.37 ms / 193 TFLOPS
4096 No 6.05 ms / 727 TFLOPS 6.28 ms / 701 TFLOPS 22.62 ms / 194 TFLOPS
4096 Yes 6.11 ms / 720 TFLOPS 6.39 ms / 688 TFLOPS 22.68 ms / 194 TFLOPS
8192 No 12.25 ms / 718 TFLOPS 12.41 ms / 709 TFLOPS 45.35 ms / 194 TFLOPS
8192 Yes 12.30 ms / 715 TFLOPS 12.70 ms / 693 TFLOPS 45.59 ms / 193 TFLOPS
16384 No 23.84 ms / 738 TFLOPS 25.11 ms / 700 TFLOPS 90.81 ms / 194 TFLOPS
16384 Yes 24.09 ms / 730 TFLOPS 26.10 ms / 674 TFLOPS 90.97 ms / 193 TFLOPS
32768 No 49.69 ms / 708 TFLOPS 54.31 ms / 648 TFLOPS 180.01 ms / 195 TFLOPS
32768 Yes 49.85 ms / 706 TFLOPS 55.69 ms / 632 TFLOPS 179.85 ms / 196 TFLOPS

Backward medians use 30 interleaved samples per provider. Effective TFLOPS count 6*M*H*V:

M Entropy CuTe SM90 cuTile Verl Torch fallback
8192 No 37.93 ms / 696 TFLOPS 42.55 ms / 620 TFLOPS 85.17 ms / 310 TFLOPS
8192 Yes 37.89 ms / 696 TFLOPS 41.43 ms / 637 TFLOPS 121.00 ms / 218 TFLOPS
16384 No 79.42 ms / 665 TFLOPS 83.78 ms / 630 TFLOPS 166.85 ms / 316 TFLOPS
16384 Yes 78.20 ms / 675 TFLOPS 84.12 ms / 627 TFLOPS 239.39 ms / 220 TFLOPS
32768 No 163.34 ms / 646 TFLOPS 163.21 ms / 647 TFLOPS 331.08 ms / 319 TFLOPS
32768 Yes 160.64 ms / 657 TFLOPS 161.73 ms / 653 TFLOPS 477.51 ms / 221 TFLOPS

Full forward-and-backward effective TFLOPS count 8*M*H*V:

M Entropy CuTe SM90 cuTile Verl Torch fallback
8192 No 50.39 ms / 698 TFLOPS 57.15 ms / 616 TFLOPS 128.76 ms / 273 TFLOPS
8192 Yes 50.22 ms / 701 TFLOPS 56.86 ms / 619 TFLOPS 165.63 ms / 212 TFLOPS
16384 No 104.77 ms / 672 TFLOPS 112.03 ms / 628 TFLOPS 254.91 ms / 276 TFLOPS
16384 Yes 103.65 ms / 679 TFLOPS 111.21 ms / 633 TFLOPS 328.37 ms / 214 TFLOPS
32768 No 211.30 ms / 666 TFLOPS 221.34 ms / 636 TFLOPS 508.33 ms / 277 TFLOPS
32768 Yes 210.60 ms / 668 TFLOPS 221.39 ms / 636 TFLOPS 655.89 ms / 215 TFLOPS

B200 measurements for the same shape, using automatic cuTile workspace selection:

Implementation Forward Backward Full Peak full memory
cuTile 2.97 ms 8.35 ms 11.36 ms 2.64 GiB
Torch 5.24 ms 7.15 ms 12.85 ms 7.22 GiB

Getting Started

There are a couple of ways to apply Liger kernels, depending on the level of customization required.

1. Use AutoLigerKernelForCausalLM

Using the AutoLigerKernelForCausalLM is the simplest approach, as you don't have to import a model-specific patching API. If the model type is supported, the modeling code will be automatically patched using the default settings.

from liger_kernel.transformers import AutoLigerKernelForCausalLM

# This AutoModel wrapper class automatically monkey-patches the
# model with the optimized Liger kernels if the model is supported.
model = AutoLigerKernelForCausalLM.from_pretrained("path/to/some/model")

2. Apply Model-Specific Patching APIs

Using the patching APIs, you can swap Hugging Face models with optimized Liger Kernels.

import transformers
from liger_kernel.transformers import apply_liger_kernel_to_llama

# 1a. Adding this line automatically monkey-patches the model with the optimized Liger kernels
apply_liger_kernel_to_llama()

# 1b. You could alternatively specify exactly which kernels are applied
apply_liger_kernel_to_llama(
  rope=True,
  swiglu=True,
  cross_entropy=True,
  fused_linear_cross_entropy=False,
  rms_norm=False
)

# 2. Instantiate patched model
model = transformers.AutoModelForCausalLM("path/to/llama/model")

3. Compose Your Own Model

You can take individual kernels to compose your models.

from liger_kernel.transformers import LigerFusedLinearCrossEntropyLoss
import torch.nn as nn
import torch

model = nn.Linear(128, 256).cuda()

# fuses linear + cross entropy layers together and performs chunk-by-chunk computation to reduce memory
loss_fn = LigerFusedLinearCrossEntropyLoss()

input = torch.randn(4, 128, requires_grad=True, device="cuda")
target = torch.randint(256, (4, ), device="cuda")

loss = loss_fn(model.weight, input, target)
loss.backward()

High-level APIs

AutoModel

AutoModel Variant API
AutoModelForCausalLM liger_kernel.transformers.AutoLigerKernelForCausalLM

Patching

Model API Supported Operations
Llama4 (Text) & (Multimodal) liger_kernel.transformers.apply_liger_kernel_to_llama4 RMSNorm, LayerNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy
LLaMA 2 & 3 liger_kernel.transformers.apply_liger_kernel_to_llama RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
LLaMA 3.2-Vision liger_kernel.transformers.apply_liger_kernel_to_mllama RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Ministral liger_kernel.transformers.apply_liger_kernel_to_ministral RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Mistral liger_kernel.transformers.apply_liger_kernel_to_mistral RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Mixtral liger_kernel.transformers.apply_liger_kernel_to_mixtral RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Muse Glimmer liger_kernel.transformers.apply_liger_kernel_to_muse_glimmer LayerNorm, RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Nemotron liger_kernel.transformers.apply_liger_kernel_to_nemotron ReLUSquared, CrossEntropyLoss, FusedLinearCrossEntropy
Pixtral liger_kernel.transformers.apply_liger_kernel_to_pixtral RoPE, RMSNorm, SwiGLU
Gemma1 liger_kernel.transformers.apply_liger_kernel_to_gemma RoPE, RMSNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Gemma2 liger_kernel.transformers.apply_liger_kernel_to_gemma2 RoPE, RMSNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Gemma3 (Text) liger_kernel.transformers.apply_liger_kernel_to_gemma3_text RoPE, RMSNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Gemma3 (Multimodal) liger_kernel.transformers.apply_liger_kernel_to_gemma3 LayerNorm, RoPE, RMSNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Gemma4 (Text) liger_kernel.transformers.apply_liger_kernel_to_gemma4_text RMSNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Gemma4 (Multimodal) liger_kernel.transformers.apply_liger_kernel_to_gemma4 RMSNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Paligemma, Paligemma2, & Paligemma2 Mix liger_kernel.transformers.apply_liger_kernel_to_paligemma LayerNorm, RoPE, RMSNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Qwen2, Qwen2.5, & QwQ liger_kernel.transformers.apply_liger_kernel_to_qwen2 RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Qwen2-VL, & QVQ liger_kernel.transformers.apply_liger_kernel_to_qwen2_vl RMSNorm, LayerNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Qwen2.5-VL liger_kernel.transformers.apply_liger_kernel_to_qwen2_5_vl RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Qwen3 liger_kernel.transformers.apply_liger_kernel_to_qwen3 RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Qwen3 MoE liger_kernel.transformers.apply_liger_kernel_to_qwen3_moe RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Qwen3.5 liger_kernel.transformers.apply_liger_kernel_to_qwen3_5 RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Qwen3.5 MoE (Text) & (Multimodal) liger_kernel.transformers.apply_liger_kernel_to_qwen3_5_moe RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Phi3 & Phi3.5 liger_kernel.transformers.apply_liger_kernel_to_phi3 RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Granite 3.0 & 3.1 liger_kernel.transformers.apply_liger_kernel_to_granite RoPE, RMSNorm, SwiGLU, CrossEntropyLoss
OLMo2 liger_kernel.transformers.apply_liger_kernel_to_olmo2 RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
Olmo3 liger_kernel.transformers.apply_liger_kernel_to_olmo3 RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
GLM-4 liger_kernel.transformers.apply_liger_kernel_to_glm4 RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
DeepSeek-V3 liger_kernel.transformers.apply_liger_kernel_to_deepseek_v3 RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
DeepSeek-V4 liger_kernel.transformers.apply_liger_kernel_to_deepseek_v4 RMSNorm, CrossEntropyLoss, FusedLinearCrossEntropy
GPT-OSS liger_kernel.transformers.apply_liger_kernel_to_gpt_oss RoPE, RMSNorm, CrossEntropyLoss, FusedLinearCrossEntropy
InternVL3 liger_kernel.transformers.apply_liger_kernel_to_internvl RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
HunyuanV1 liger_kernel.transformers.apply_liger_kernel_to_hunyuan_v1_dense RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy
HunyuanV1 MoE liger_kernel.transformers.apply_liger_kernel_to_hunyuan_v1_moe RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy

Low-level APIs

  • Fused Linear kernels combine linear layers with losses, reducing memory usage by up to 80% - ideal for HBM-constrained workloads.
  • Other kernels use fusion and in-place techniques for memory and performance optimization.

Model Kernels

Kernel API
RMSNorm liger_kernel.transformers.LigerRMSNorm
Modulated RMSNorm liger_kernel.transformers.LigerModulatedRMSNorm
LayerNorm liger_kernel.transformers.LigerLayerNorm
RoPE liger_kernel.transformers.liger_rotary_pos_emb
SwiGLU liger_kernel.transformers.LigerSwiGLUMLP
GeGLU liger_kernel.transformers.LigerGEGLUMLP
CrossEntropy liger_kernel.transformers.LigerCrossEntropyLoss
Fused Linear CrossEntropy liger_kernel.transformers.LigerFusedLinearCrossEntropyLoss
Multi Token Attention liger_kernel.transformers.LigerMultiTokenAttention
Softmax liger_kernel.transformers.LigerSoftmax
Sparsemax liger_kernel.transformers.LigerSparsemax
mHC (Hyper-Connections) liger_kernel.transformers.LigerMHC

Alignment Kernels

Kernel API
Fused Linear CPO Loss liger_kernel.chunked_loss.LigerFusedLinearCPOLoss
Fused Linear DPO Loss liger_kernel.chunked_loss.LigerFusedLinearDPOLoss
Fused Linear ORPO Loss liger_kernel.chunked_loss.LigerFusedLinearORPOLoss
Fused Linear SimPO Loss liger_kernel.chunked_loss.LigerFusedLinearSimPOLoss
Fused Linear KTO Loss liger_kernel.chunked_loss.LigerFusedLinearKTOLoss

Distillation Kernels

Kernel API
KLDivergence liger_kernel.transformers.LigerKLDIVLoss
JSD liger_kernel.transformers.LigerJSD
Fused Linear JSD liger_kernel.transformers.LigerFusedLinearJSD
Fused Linear KL Divergence liger_kernel.transformers.LigerFusedLinearKLDivLoss
TVD liger_kernel.transformers.LigerTVDLoss

Experimental Kernels

Kernel API
Embedding liger_kernel.transformers.experimental.LigerEmbedding
Matmul int2xint8 liger_kernel.transformers.experimental.matmul

Contributing, Acknowledgements, and License

Sponsorship and Collaboration

  • Glows.ai: Sponsoring NVIDIA GPUs for our open source developers.
  • AMD: Providing AMD GPUs for our AMD CI.
  • Intel: Providing Intel GPUs for our Intel CI.
  • Modal: Free 3000 credits from GPU MODE IRL for our NVIDIA CI.
  • EmbeddedLLM: Making Liger Kernel run fast and stable on AMD.
  • HuggingFace: Integrating Liger Kernel into Hugging Face Transformers and TRL.
  • Lightning AI: Integrating Liger Kernel into Lightning Thunder.
  • Axolotl: Integrating Liger Kernel into Axolotl.
  • Llama-Factory: Integrating Liger Kernel into Llama-Factory.

CI status

Platform Build
NVIDIA GPU NVIDIA GPU Build
AMD GPU AMD GPU Build
Intel GPU Intel GPU Build
Ascend NPU Ascend NPU Build

Contact

Cite this work

Biblatex entry:

@inproceedings{
hsu2025ligerkernel,
title={Liger-Kernel: Efficient Triton Kernels for {LLM} Training},
author={Pin-Lun Hsu and Yun Dai and Vignesh Kothapalli and Qingquan Song and Shao Tang and Siyu Zhu and Steven Shimizu and Shivam Sahni and Haowen Ning and Yanning Chen and Zhipeng Wang},
booktitle={Championing Open-source DEvelopment in ML Workshop @ ICML25},
year={2025},
url={https://openreview.net/forum?id=36SjAIT42G}
}

Star History

Star History Chart

↑ Back to Top ↑

Languages
Python 62.4%
Cuda 31.7%
NASL 3.9%
C++ 1.3%
CMake 0.6%
Other 0.1%