> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/huggingface/trl/llms.txt
> Use this file to discover all available pages before exploring further.

# Liger Kernel Integration

> Speed up LLM training and reduce GPU memory usage with Liger Kernel's optimized Triton kernels, compatible with FlashAttention, FSDP, and DeepSpeed.

[Liger Kernel](https://github.com/linkedin/Liger-Kernel) is a collection of Triton kernels designed specifically for LLM training. It can increase multi-GPU training throughput by **20%** and reduce memory usage by **60%**, enabling up to a **4x** increase in context length.

Liger Kernel provides Hugging Face-compatible replacements for `RMSNorm`, `RoPE`, `SwiGLU`, `CrossEntropy`, and `FusedLinearCrossEntropy`. It works out of the box with [FlashAttention](https://github.com/Dao-AILab/flash-attention), [PyTorch FSDP](https://pytorch.org/tutorials/intermediate/FSDP_tutorial.html), and [Microsoft DeepSpeed](https://github.com/microsoft/DeepSpeed).

With the memory reduction from Liger Kernel, you can potentially disable `cpu_offloading` or gradient checkpointing to further boost performance.

## Installation

```bash theme={null}
pip install liger-kernel
```

## Supported trainers

Liger Kernel is supported in the following TRL trainers:

<CardGroup cols={3}>
  <Card title="SFT" icon="check">
    Supervised Fine-Tuning
  </Card>

  <Card title="DPO" icon="check">
    Direct Preference Optimization
  </Card>

  <Card title="GRPO" icon="check">
    Group Relative Policy Optimization
  </Card>

  <Card title="KTO" icon="check">
    Kahneman-Tversky Optimization
  </Card>

  <Card title="GKD" icon="check">
    Generalized Knowledge Distillation
  </Card>
</CardGroup>

## Usage

Set `use_liger_kernel=True` in your trainer config. No other changes are needed.

<Tabs>
  <Tab title="SFT">
    ```python theme={null}
    from trl import SFTConfig

    training_args = SFTConfig(..., use_liger_kernel=True)
    ```
  </Tab>

  <Tab title="DPO">
    ```python theme={null}
    from trl import DPOConfig

    training_args = DPOConfig(..., use_liger_kernel=True)
    ```
  </Tab>

  <Tab title="GRPO">
    ```python theme={null}
    from trl import GRPOConfig

    training_args = GRPOConfig(..., use_liger_kernel=True)
    ```
  </Tab>

  <Tab title="KTO">
    ```python theme={null}
    from trl import KTOConfig

    training_args = KTOConfig(..., use_liger_kernel=True)
    ```
  </Tab>

  <Tab title="GKD">
    ```python theme={null}
    from trl.experimental.gkd import GKDConfig

    training_args = GKDConfig(..., use_liger_kernel=True)
    ```
  </Tab>
</Tabs>

## Performance benefits

| Metric                    | Improvement              |
| ------------------------- | ------------------------ |
| Training throughput       | +20% on multi-GPU setups |
| GPU memory usage          | −60%                     |
| Achievable context length | Up to 4x longer          |

The memory reduction comes from fused kernel implementations that avoid materializing large intermediate tensors. For example, `FusedLinearCrossEntropy` fuses the final linear projection with the cross-entropy loss, which removes the need to store the full vocabulary-sized logit tensor.

<Tip>
  Because Liger Kernel reduces memory usage significantly, you may be able to turn off gradient checkpointing or CPU offloading after enabling it, which can recover additional training throughput.
</Tip>

## Additional resources

<CardGroup cols={2}>
  <Card title="Liger Kernel repository" icon="github" href="https://github.com/linkedin/Liger-Kernel">
    Source code, benchmarks, and detailed documentation.
  </Card>
</CardGroup>
