liger-kernel 0.4.1__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. {liger_kernel-0.4.1/src/liger_kernel.egg-info → liger_kernel-0.5.0}/PKG-INFO +78 -121
  2. liger_kernel-0.5.0/README.md +331 -0
  3. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/pyproject.toml +14 -1
  4. liger_kernel-0.5.0/src/liger_kernel/chunked_loss/__init__.py +4 -0
  5. liger_kernel-0.5.0/src/liger_kernel/chunked_loss/cpo_loss.py +107 -0
  6. liger_kernel-0.5.0/src/liger_kernel/chunked_loss/dpo_loss.py +135 -0
  7. liger_kernel-0.5.0/src/liger_kernel/chunked_loss/functional.py +9 -0
  8. liger_kernel-0.5.0/src/liger_kernel/chunked_loss/fused_linear_distillation.py +252 -0
  9. liger_kernel-0.5.0/src/liger_kernel/chunked_loss/fused_linear_preference.py +386 -0
  10. liger_kernel-0.5.0/src/liger_kernel/chunked_loss/orpo_loss.py +113 -0
  11. liger_kernel-0.5.0/src/liger_kernel/chunked_loss/simpo_loss.py +115 -0
  12. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/env_report.py +22 -0
  13. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/cross_entropy.py +17 -10
  14. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/fused_linear_cross_entropy.py +1 -11
  15. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/fused_linear_jsd.py +1 -1
  16. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/jsd.py +19 -10
  17. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/layer_norm.py +6 -1
  18. liger_kernel-0.5.0/src/liger_kernel/ops/qwen2vl_mrope.py +238 -0
  19. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/rms_norm.py +6 -1
  20. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/utils.py +5 -2
  21. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/__init__.py +1 -0
  22. liger_kernel-0.5.0/src/liger_kernel/transformers/functional.py +173 -0
  23. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/fused_linear_jsd.py +1 -4
  24. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/jsd.py +1 -4
  25. liger_kernel-0.5.0/src/liger_kernel/transformers/model/__init__.py +0 -0
  26. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/model/qwen2_vl.py +43 -17
  27. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/monkey_patch.py +11 -6
  28. liger_kernel-0.5.0/src/liger_kernel/transformers/orpo_trainer.py +171 -0
  29. liger_kernel-0.5.0/src/liger_kernel/transformers/qwen2vl_mrope.py +20 -0
  30. liger_kernel-0.5.0/src/liger_kernel/utils.py +13 -0
  31. {liger_kernel-0.4.1 → liger_kernel-0.5.0/src/liger_kernel.egg-info}/PKG-INFO +78 -121
  32. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel.egg-info/SOURCES.txt +13 -0
  33. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel.egg-info/requires.txt +9 -0
  34. liger_kernel-0.4.1/README.md +0 -382
  35. liger_kernel-0.4.1/src/liger_kernel/transformers/functional.py +0 -56
  36. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/LICENSE +0 -0
  37. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/NOTICE +0 -0
  38. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/setup.cfg +0 -0
  39. {liger_kernel-0.4.1/src/liger_kernel/ops → liger_kernel-0.5.0/src/liger_kernel}/__init__.py +0 -0
  40. {liger_kernel-0.4.1/src/liger_kernel/transformers/model → liger_kernel-0.5.0/src/liger_kernel/ops}/__init__.py +0 -0
  41. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/experimental/embedding.py +0 -0
  42. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/experimental/mm_int8int2.py +0 -0
  43. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/geglu.py +0 -0
  44. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/group_norm.py +0 -0
  45. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/kl_div.py +0 -0
  46. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/rope.py +0 -0
  47. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/ops/swiglu.py +0 -0
  48. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/auto_model.py +0 -0
  49. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/cross_entropy.py +0 -0
  50. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/experimental/embedding.py +0 -0
  51. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/fused_linear_cross_entropy.py +0 -0
  52. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/geglu.py +0 -0
  53. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/group_norm.py +0 -0
  54. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/kl_div.py +0 -0
  55. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/layer_norm.py +0 -0
  56. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/model/gemma.py +0 -0
  57. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/model/gemma2.py +0 -0
  58. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/model/llama.py +0 -0
  59. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/model/mistral.py +0 -0
  60. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/model/mixtral.py +0 -0
  61. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/model/mllama.py +0 -0
  62. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/model/phi3.py +0 -0
  63. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/model/qwen2.py +0 -0
  64. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/rms_norm.py +0 -0
  65. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/rope.py +0 -0
  66. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/swiglu.py +0 -0
  67. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/transformers/trainer_integration.py +0 -0
  68. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/triton/__init__.py +0 -0
  69. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel/triton/monkey_patch.py +0 -0
  70. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel.egg-info/dependency_links.txt +0 -0
  71. {liger_kernel-0.4.1 → liger_kernel-0.5.0}/src/liger_kernel.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: liger_kernel
3
- Version: 0.4.1
3
+ Version: 0.5.0
4
4
  Summary: Efficient Triton kernels for LLM Training
5
5
  License: BSD 2-CLAUSE LICENSE
6
6
  Copyright 2024 LinkedIn Corporation
@@ -36,14 +36,22 @@ Provides-Extra: transformers
36
36
  Requires-Dist: transformers~=4.0; extra == "transformers"
37
37
  Provides-Extra: dev
38
38
  Requires-Dist: transformers>=4.44.2; extra == "dev"
39
+ Requires-Dist: trl>=0.11.0; extra == "dev"
39
40
  Requires-Dist: matplotlib>=3.7.2; extra == "dev"
40
41
  Requires-Dist: flake8>=4.0.1.1; extra == "dev"
41
42
  Requires-Dist: black>=24.4.2; extra == "dev"
42
43
  Requires-Dist: isort>=5.13.2; extra == "dev"
43
44
  Requires-Dist: pytest>=7.1.2; extra == "dev"
45
+ Requires-Dist: pytest-xdist; extra == "dev"
46
+ Requires-Dist: pytest-rerunfailures; extra == "dev"
44
47
  Requires-Dist: datasets>=2.19.2; extra == "dev"
45
48
  Requires-Dist: torchvision>=0.16.2; extra == "dev"
46
49
  Requires-Dist: seaborn; extra == "dev"
50
+ Provides-Extra: amd
51
+ Requires-Dist: torch>=2.6.0.dev; extra == "amd"
52
+ Requires-Dist: setuptools-scm>=8; extra == "amd"
53
+ Requires-Dist: torchvision>=0.20.0.dev; extra == "amd"
54
+ Requires-Dist: triton>=3.0.0; extra == "amd"
47
55
 
48
56
  <a name="readme-top"></a>
49
57
 
@@ -55,7 +63,7 @@ Requires-Dist: seaborn; extra == "dev"
55
63
  <th style="padding: 10px;" colspan="2">Stable</th>
56
64
  <th style="padding: 10px;" colspan="2">Nightly</th>
57
65
  <th style="padding: 10px;">Discord</th>
58
- <th style="padding: 10px;">Gurubase (experimental)</th>
66
+ <th style="padding: 10px;">Build</th>
59
67
  </tr>
60
68
  <tr>
61
69
  <td style="padding: 10px;">
@@ -84,9 +92,16 @@ Requires-Dist: seaborn; extra == "dev"
84
92
  </a>
85
93
  </td>
86
94
  <td style="padding: 10px;">
87
- <a href="https://gurubase.io/g/liger-kernel">
88
- <img src="https://img.shields.io/badge/Gurubase-Ask%20Liger%20Kernel%20Guru-006BFF" alt="Ask Liger Kernel Guru">
89
- </a>
95
+ <div style="display: block;">
96
+ <a href="https://github.com/linkedin/Liger-Kernel/actions/workflows/nvi-ci.yml">
97
+ <img src="https://github.com/linkedin/Liger-Kernel/actions/workflows/nvi-ci.yml/badge.svg?event=schedule" alt="Build">
98
+ </a>
99
+ </div>
100
+ <div style="display: block;">
101
+ <a href="https://github.com/linkedin/Liger-Kernel/actions/workflows/amd-ci.yml">
102
+ <img src="https://github.com/linkedin/Liger-Kernel/actions/workflows/amd-ci.yml/badge.svg?event=schedule" alt="Build">
103
+ </a>
104
+ </div>
90
105
  </td>
91
106
  </tr>
92
107
  </table>
@@ -95,12 +110,14 @@ Requires-Dist: seaborn; extra == "dev"
95
110
 
96
111
  <img src="https://raw.githubusercontent.com/linkedin/Liger-Kernel/main/docs/images/logo-banner.png">
97
112
 
98
- [Installation](#installation) | [Getting Started](#getting-started) | [Examples](#examples) | [APIs](#apis) | [Cite our work](#cite-this-work)
113
+ [Installation](#installation) | [Getting Started](#getting-started) | [Examples](#examples) | [High-level APIs](#high-level-apis) | [Low-level APIs](#low-level-apis) | [Cite our work](#cite-this-work)
99
114
 
100
115
  <details>
101
116
  <summary>Latest News 🔥</summary>
102
-
103
- - [2024/10/21] We have released the tech report of Liger Kernel on Arxiv: https://arxiv.org/pdf/2410.10989
117
+
118
+ - [2024/12/15] We release LinkedIn Engineering Blog - [Liger-Kernel: Empowering an open source ecosystem of Triton Kernels for Efficient LLM Training](https://www.linkedin.com/blog/engineering/open-source/liger-kernel-open-source-ecosystem-for-efficient-llm-training)
119
+ - [2024/11/6] We release [v0.4.0](https://github.com/linkedin/Liger-Kernel/releases/tag/v0.4.0): Full AMD support, Tech Report, Modal CI, Llama-3.2-Vision!
120
+ - [2024/10/21] We have released the tech report of Liger Kernel on Arxiv: https://arxiv.org/pdf/2410.10989
104
121
  - [2024/9/6] We release v0.2.1 ([X post](https://x.com/liger_kernel/status/1832168197002510649)). 2500+ Stars, 10+ New Contributors, 50+ PRs, 50k Downloads in two weeks!
105
122
  - [2024/8/31] CUDA MODE talk, [Liger-Kernel: Real-world Triton kernel for LLM Training](https://youtu.be/gWble4FreV4?si=dxPeIchhkJ36Mbns), [Slides](https://github.com/cuda-mode/lectures?tab=readme-ov-file#lecture-28-liger-kernel)
106
123
  - [2024/8/23] Official release: check out our [X post](https://x.com/hsu_byron/status/1827072737673982056)
@@ -110,6 +127,8 @@ Requires-Dist: seaborn; extra == "dev"
110
127
 
111
128
  **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](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). We welcome contributions from the community to gather the best kernels for LLM training.
112
129
 
130
+ 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, JSD, and many more.
131
+
113
132
  ## Supercharge Your Model with Liger Kernel
114
133
 
115
134
  ![Banner](https://raw.githubusercontent.com/linkedin/Liger-Kernel/main/docs/images/banner.GIF)
@@ -127,18 +146,13 @@ With one line of code, Liger Kernel can increase throughput by more than 20% and
127
146
 
128
147
  ## Examples
129
148
 
130
- ### Basic
131
-
132
- | **Example** | **Description** | **Lightning Studio** |
133
- |------------------------------------------------|---------------------------------------------------------------------------------------------------|----------------------|
134
- | [**Hugging Face Trainer**](https://github.com/linkedin/Liger-Kernel/tree/main/examples/huggingface) | Train LLaMA 3-8B ~20% faster with over 40% memory reduction on Alpaca dataset using 4 A100s with FSDP | TBA |
135
- | [**Lightning Trainer**](https://github.com/linkedin/Liger-Kernel/tree/main/examples/lightning) | Increase 15% throughput and reduce memory usage by 40% with LLaMA3-8B on MMLU dataset using 8 A100s with DeepSpeed ZeRO3 | TBA |
136
-
137
- ### Advanced
138
-
139
- | **Example** | **Description** | **Lightning Studio** |
140
- |------------------------------------------------|---------------------------------------------------------------------------------------------------|----------------------|
141
- | [**Medusa Multi-head LLM (Retraining Phase)**](https://github.com/linkedin/Liger-Kernel/tree/main/examples/medusa) | Reduce memory usage by 80% with 5 LM heads and improve throughput by 40% using 8 A100s with FSDP | TBA |
149
+ | **Use Case** | **Description** |
150
+ |------------------------------------------------|---------------------------------------------------------------------------------------------------|
151
+ | [**Hugging Face Trainer**](https://github.com/linkedin/Liger-Kernel/tree/main/examples/huggingface) | Train LLaMA 3-8B ~20% faster with over 40% memory reduction on Alpaca dataset using 4 A100s with FSDP |
152
+ | [**Lightning Trainer**](https://github.com/linkedin/Liger-Kernel/tree/main/examples/lightning) | Increase 15% throughput and reduce memory usage by 40% with LLaMA3-8B on MMLU dataset using 8 A100s with DeepSpeed ZeRO3 |
153
+ | [**Medusa Multi-head LLM (Retraining Phase)**](https://github.com/linkedin/Liger-Kernel/tree/main/examples/medusa) | Reduce memory usage by 80% with 5 LM heads and improve throughput by 40% using 8 A100s with FSDP |
154
+ | [**Vision-Language Model SFT**](https://github.com/linkedin/Liger-Kernel/tree/main/examples/huggingface/run_qwen2_vl.sh) | Finetune Qwen2-VL on image-text data using 4 A100s with FSDP |
155
+ | [**Liger ORPO Trainer**](https://github.com/linkedin/Liger-Kernel/blob/main/examples/alignment/run_orpo.py) | Align Llama 3.2 using Liger ORPO Trainer with FSDP with 50% memory reduction |
142
156
 
143
157
  ## Key Features
144
158
 
@@ -149,16 +163,9 @@ With one line of code, Liger Kernel can increase throughput by more than 20% and
149
163
  - **Multi-GPU supported:** Compatible with multi-GPU setups (PyTorch FSDP, DeepSpeed, DDP, etc.).
150
164
  - **Trainer Framework Integration**: [Axolotl](https://github.com/axolotl-ai-cloud/axolotl), [LLaMa-Factory](https://github.com/hiyouga/LLaMA-Factory), [SFTTrainer](https://github.com/huggingface/trl/releases/tag/v0.10.1), [Hugging Face Trainer](https://github.com/huggingface/transformers/pull/32860), [SWIFT](https://github.com/modelscope/ms-swift)
151
165
 
152
- ## Target Audiences
153
-
154
- - **Researchers**: Looking to compose models using efficient and reliable kernels for frontier experiments.
155
- - **ML Practitioners**: Focused on maximizing GPU training efficiency with optimal, high-performance kernels.
156
- - **Curious Novices**: Eager to learn how to write reliable Triton kernels to enhance training efficiency.
157
-
158
-
159
166
  ## Installation
160
167
 
161
- ### Dependencies
168
+ ### Dependencies
162
169
 
163
170
  #### CUDA
164
171
 
@@ -195,6 +202,8 @@ To install from source:
195
202
  git clone https://github.com/linkedin/Liger-Kernel.git
196
203
  cd Liger-Kernel
197
204
  pip install -e .
205
+ # or if installing on amd platform
206
+ pip install -e .[amd] --extra-index-url https://download.pytorch.org/whl/nightly/rocm6.2 # rocm6.2
198
207
  # or if using transformers
199
208
  pip install -e .[transformers]
200
209
  ```
@@ -261,24 +270,7 @@ loss = loss_fn(model.weight, input, target)
261
270
  loss.backward()
262
271
  ```
263
272
 
264
-
265
- ## Structure
266
-
267
- ### Source Code
268
-
269
- - `ops/`: Core Triton operations.
270
- - `transformers/`: PyTorch `nn.Module` implementations built on Triton operations, compliant with the `transformers` API.
271
-
272
- ### Tests
273
-
274
- - `transformers/`: Correctness tests for the Triton-based layers.
275
- - `convergence/`: Patches Hugging Face models with all kernels, runs multiple iterations, and compares weights, logits, and loss layer-by-layer.
276
-
277
- ### Benchmark
278
-
279
- - `benchmark/`: Execution time and memory benchmarks compared to Hugging Face layers.
280
-
281
- ## APIs
273
+ ## High-level APIs
282
274
 
283
275
  ### AutoModel
284
276
 
@@ -297,13 +289,17 @@ loss.backward()
297
289
  | Mixtral | `liger_kernel.transformers.apply_liger_kernel_to_mixtral` | RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy |
298
290
  | Gemma1 | `liger_kernel.transformers.apply_liger_kernel_to_gemma` | RoPE, RMSNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy |
299
291
  | Gemma2 | `liger_kernel.transformers.apply_liger_kernel_to_gemma2` | RoPE, RMSNorm, GeGLU, CrossEntropyLoss, FusedLinearCrossEntropy |
300
- | Qwen2 & Qwen2.5 | `liger_kernel.transformers.apply_liger_kernel_to_qwen2` | RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy |
292
+ | Qwen2, Qwen2.5, & QwQ | `liger_kernel.transformers.apply_liger_kernel_to_qwen2` | RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy |
301
293
  | Qwen2-VL | `liger_kernel.transformers.apply_liger_kernel_to_qwen2_vl` | RMSNorm, LayerNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy |
302
294
  | Phi3 & Phi3.5 | `liger_kernel.transformers.apply_liger_kernel_to_phi3` | RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy |
303
295
 
304
296
 
297
+ ## Low-level APIs
298
+
299
+ - `Fused Linear` kernels combine linear layers with losses, reducing memory usage by up to 80% - ideal for HBM-constrained workloads.
300
+ - Other kernels use fusion and in-place techniques for memory and performance optimization.
305
301
 
306
- ### Kernels
302
+ ### Model Kernels
307
303
 
308
304
  | **Kernel** | **API** |
309
305
  |---------------------------------|-------------------------------------------------------------|
@@ -313,87 +309,55 @@ loss.backward()
313
309
  | SwiGLU | `liger_kernel.transformers.LigerSwiGLUMLP` |
314
310
  | GeGLU | `liger_kernel.transformers.LigerGEGLUMLP` |
315
311
  | CrossEntropy | `liger_kernel.transformers.LigerCrossEntropyLoss` |
316
- | FusedLinearCrossEntropy | `liger_kernel.transformers.LigerFusedLinearCrossEntropyLoss`|
317
- | KLDivergence | `liger_kernel.transformers.LigerKLDIVLoss` |
318
- | JSD | `liger_kernel.transformers.LigerJSD` |
319
- | FusedLinearJSD | `liger_kernel.transformers.LigerFusedLinearJSD` |
320
-
321
- - **RMSNorm**: [RMSNorm](https://arxiv.org/pdf/1910.07467), which normalizes activations using their root mean square, is implemented by fusing the normalization and scaling steps into a single Triton kernel, and achieves ~3X speedup with ~3X peak memory reduction.
322
- - **LayerNorm**: [LayerNorm](https://arxiv.org/pdf/1607.06450), which centers and normalizes activations across the feature dimension, is implemented by fusing the centering, normalization and scaling steps into a single Triton kernel, and achieves ~2X speedup.
323
- - **GroupNorm**: [GroupNorm](https://arxiv.org/pdf/1803.08494), which normalizes activations across the group dimension for a given sample. Channels are grouped in K groups over which the normalization is performed, is implemented by fusing the centering, normalization and scaling steps into a single Triton kernel, and can achieve up to ~2X speedup as the number of channels/groups increases.
324
- - **RoPE**: [Rotary Positional Embedding](https://arxiv.org/pdf/2104.09864) is implemented by fusing the query and key embedding rotary into a single kernel with inplace replacement, and achieves ~3X speedup with ~3X peak memory reduction.
325
- - **SwiGLU**: [Swish Gated Linear Units](https://arxiv.org/pdf/2002.05202), given by
326
- $$\text{SwiGLU}(x)=\text{Swish}_{\beta}(xW+b)\otimes(xV+c)$$
327
- , is implemented by fusing the elementwise multiplication (denoted by $\otimes$) into a single kernel with inplace replacement, and achieves parity speed with ~1.5X peak memory reduction.
328
- - **GeGLU**: [GELU Gated Linear Units](https://arxiv.org/pdf/2002.05202), given by
329
- $$\text{GeGLU}(x)=\text{GELU}(xW+b)\otimes(xV+c)$$
330
- , is implemented by fusing the elementwise multiplication into a single kernel with inplace replacement, and achieves parity speed with ~1.5X peak memory reduction. Note that the [tanh approximation form of GELU](https://pytorch.org/docs/stable/generated/torch.nn.GELU.html) is used.
331
- - **CrossEntropy**: [Cross entropy loss](https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html) is implemented by computing both the loss and gradient in the forward pass with inplace replacement of input to reduce the peak memory by avoiding simultaneous materialization of both input logits and gradient. It achieves >2X speedup and >4X memory reduction for common vocab sizes (e.g., 32K, 128K, etc.).
332
- <!-- TODO: verify vocab sizes are accurate -->
333
- - **FusedLinearCrossEntropy**: Peak memory usage of cross entropy loss is further improved by fusing the model head with the CE loss and chunking the input for block-wise loss and gradient calculation, a technique inspired by [Efficient Cross Entropy](https://github.com/mgmalek/efficient_cross_entropy). It achieves >4X memory reduction for 128k vocab size. **This is highly effective for large batch size, large sequence length, and large vocabulary sizes.** Please refer to the [Medusa example](https://github.com/linkedin/Liger-Kernel/tree/main/examples/medusa) for individual kernel usage.
334
- - **KLDivergence**: [KL Divergence](https://pytorch.org/docs/stable/generated/torch.nn.KLDivLoss.html) is implemented by fusing the forward into a single triton kernel, with reduction done outside the kernel. It achieves ~1.5X speed and ~15% memory reduction for 128K vocab size.
335
- - **JSD**: [Generalized JSD](https://arxiv.org/pdf/2306.13649) (Jensen-Shannon divergence), is implemented by computing both the loss and gradient in the forward pass. It achieves ~1.5X speed and ~54% memory reduction for 128k vocab size.
336
- - **FusedLinearJSD**: Peak memory usage of JSD loss is further improved by fusing the model head with the JSD and chunking the input for block-wise loss and gradient calculation. It achieves ~85% memory reduction for 128k vocab size where batch size $\times$ sequence length is 8192.
312
+ | Fused Linear CrossEntropy | `liger_kernel.transformers.LigerFusedLinearCrossEntropyLoss`|
337
313
 
338
314
 
339
- ### Experimental Kernels
315
+ ### Alignment Kernels
340
316
 
341
317
  | **Kernel** | **API** |
342
318
  |---------------------------------|-------------------------------------------------------------|
343
- | Embedding | `liger_kernel.transformers.experimental.LigerEmbedding` |
344
- | Matmul int2xint8 | `liger_kernel.transformers.experimental.matmul`
345
-
346
- - **Embedding**: [Embedding](https://pytorch.org/docs/stable/generated/torch.nn.Embedding.html) is implemented by fusing embedding lookup and output operations. It achieves a peak speedup of ~1.5x in the forward pass and an overall speedup of ~1.1x.
347
- - **Matmul int2xint8**: is implemented by using the cache tiled matrix multiplication and by fusing the matmul with the unpacking process which achieves a considerable speed up and performs on par with @torch.compile
348
- <!-- TODO: be more specific about batch size -->
349
- > **Note:**
350
- > Reported speedups and memory reductions are with respect to the LLaMA 3-8B Hugging Face layer implementations. All models use 4K hidden size and 4K sequence length and are evaluated based on memory usage and wall time for the forward+backward pass on a single NVIDIA A100 80G GPU using small batch sizes. Liger kernels exhibit more efficient scaling to larger batch sizes, detailed further in the [Benchmark](./benchmark) folder.
351
-
352
- ## Contributing
353
-
354
- [CONTRIBUTING GUIDE](https://github.com/linkedin/Liger-Kernel/blob/main/CONTRIBUTING.md)
355
-
356
- ## Acknowledgement
319
+ | Fused Linear CPO Loss | `liger_kernel.chunked_loss.LigerFusedLinearCPOLoss` |
320
+ | Fused Linear DPO Loss | `liger_kernel.chunked_loss.LigerFusedLinearDPOLoss` |
321
+ | Fused Linear ORPO Loss | `liger_kernel.chunked_loss.LigerFusedLinearORPOLoss` |
322
+ | Fused Linear SimPO Loss | `liger_kernel.chunked_loss.LigerFusedLinearSimPOLoss` |
357
323
 
324
+ ### Distillation Kernels
358
325
 
359
- ### Design
360
-
361
- - [@claire_yishan](https://twitter.com/claire_yishan) for the LOGO design
362
- - [Wave Snippets](https://www.wavesnippets.com/) for generating the animated code snippets
363
-
364
- ### Code
365
-
366
- We referenced or used the following projects:
367
-
326
+ | **Kernel** | **API** |
327
+ |---------------------------------|-------------------------------------------------------------|
328
+ | KLDivergence | `liger_kernel.transformers.LigerKLDIVLoss` |
329
+ | JSD | `liger_kernel.transformers.LigerJSD` |
330
+ | Fused Linear JSD | `liger_kernel.transformers.LigerFusedLinearJSD` |
368
331
 
332
+ ### Experimental Kernels
369
333
 
370
- | # | Project | Description | Location | License |
371
- |---|----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
372
- | 1 | [Unsloth](https://github.com/unslothai/unsloth/blob/fd753fed99ed5f10ef8a9b7139588d9de9ddecfb/unsloth/kernels/utils.py#L43) | `calculate_settings` to determine block size and warp; We reuse it for Norm and MLP | [Liger Kernel Utils](https://github.com/linkedin/Liger-Kernel/blob/e249eee723978bf8610ff1ea2297d048a2417e20/src/liger_kernel/ops/utils.py#L23) | [Apache](https://github.com/unslothai/unsloth/blob/fd753fed99ed5f10ef8a9b7139588d9de9ddecfb/LICENSE) |
373
- | 2 | [Unsloth](https://github.com/unslothai/unsloth/blob/976d11a10d54383aeb7a692c69e01151a20bfd72/unsloth/kernels/rms_layernorm.py#L48) | We modified and added dW calculation on top of Unsloth implementation | [Liger Kernel RMS Norm](https://github.com/linkedin/Liger-Kernel/blob/e249eee723978bf8610ff1ea2297d048a2417e20/src/liger_kernel/ops/rms_norm.py#L50) | [Apache](https://github.com/unslothai/unsloth/blob/fd753fed99ed5f10ef8a9b7139588d9de9ddecfb/LICENSE) |
374
- | 3 | [Triton tutorial](https://triton-lang.org/main/index.html) | We modified on top of triton tutorials | [Liger Kernel RMS Norm](https://github.com/linkedin/Liger-Kernel/blob/e249eee723978bf8610ff1ea2297d048a2417e20/src/liger_kernel/ops/rms_norm.py#L50) | [MIT](https://github.com/triton-lang/triton/blob/main/LICENSE) |
375
- | 4 | [tiny shakespeare dataset](https://huggingface.co/datasets/karpathy/tiny_shakespeare) | We use tiny shakespeare dataset to conduct convergence test on mini model | [Liger Kernel Convergence](https://github.com/linkedin/Liger-Kernel/tree/main/test/convergence) | N/A |
376
- | 5 | [Efficient Cross Entropy](https://github.com/mgmalek/efficient_cross_entropy) | We use the idea of gradient-in-forward and chunking | [Liger Kernel Linear Cross Entropy](https://github.com/linkedin/Liger-Kernel/blob/main/src/liger_kernel/ops/fused_linear_cross_entropy.py) | [MIT](https://github.com/mgmalek/efficient_cross_entropy/blob/main/LICENSE) |
377
- | 6 | [Flash attn](https://github.com/Dao-AILab/flash-attention) | We take many optimization ideas from the work, such as tiling and recomputation | | [BSD](https://github.com/Dao-AILab/flash-attention/blob/main/LICENSE) |
378
- | 7 | [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) | We reference the design of automodel | [Liger Kernel Auto Model](https://github.com/linkedin/Liger-Kernel/blob/main/src/liger_kernel/transformers/auto_model.py) | [MIT](https://github.com/casper-hansen/AutoAWQ/blob/main/LICENSE) |
379
- | 8 | [llm.c](https://github.com/karpathy/llm.c) | We reference the design of end-to-end testing | [Liger Kernel Convergence Tests](https://github.com/linkedin/Liger-Kernel/tree/main/test/convergence) | [MIT](https://github.com/karpathy/llm.c/blob/master/LICENSE) |
334
+ | **Kernel** | **API** |
335
+ |---------------------------------|-------------------------------------------------------------|
336
+ | Embedding | `liger_kernel.transformers.experimental.LigerEmbedding` |
337
+ | Matmul int2xint8 | `liger_kernel.transformers.experimental.matmul` |
380
338
 
381
- Many thanks to the contributors to these projects for their invaluable work that helped make Liger possible.
382
339
 
383
- ## License
340
+ ## Contributing, Acknowledgements, and License
384
341
 
385
- This project is licensed under the [BSD 2-CLAUSE](https://github.com/linkedin/Liger-Kernel/blob/main/LICENSE) License (see `LICENSE` for details).
386
- It also includes components from projects licensed under:
342
+ - [Contributing Guidelines](https://github.com/linkedin/Liger-Kernel/blob/main/docs/CONTRIBUTING.md)
343
+ - [Acknowledgements](https://github.com/linkedin/Liger-Kernel/blob/main/docs/Acknowledgement.md)
344
+ - [License Information](https://github.com/linkedin/Liger-Kernel/blob/main/docs/License.md)
387
345
 
388
- - Apache License 2.0 (see `LICENSE-APACHE-2.0` for details).
389
- - MIT License (see `LICENSE-MIT-AutoAWQ` for details).
390
- - MIT License (see `LICENSE-MIT-Efficient Cross Entropy` for details).
391
- - MIT License (see `LICENSE-MIT-llmc` for details).
392
- - MIT License (see `LICENSE-MIT-triton` for details).
346
+ ## Sponsorship and Collaboration
347
+
348
+ - [AMD](https://www.amd.com/en.html): Providing AMD GPUs for our AMD CI.
349
+ - [Intel](https://www.intel.com/): Providing Intel GPUs for our Intel CI.
350
+ - [Modal](https://modal.com/): Free 3000 credits from GPU MODE IRL for our NVIDIA CI.
351
+ - [EmbeddedLLM](https://embeddedllm.com/): Making Liger Kernel run fast and stable on AMD.
352
+ - [HuggingFace](https://huggingface.co/): Integrating Liger Kernel into Hugging Face Transformers and TRL.
353
+ - [Lightning AI](https://lightning.ai/): Integrating Liger Kernel into Lightning Thunder.
354
+ - [Axolotl](https://axolotl.ai/): Integrating Liger Kernel into Axolotl.
355
+ - [Llama-Factory](https://github.com/hiyouga/LLaMA-Factory): Integrating Liger Kernel into Llama-Factory.
393
356
 
394
357
  ## Contact
395
358
 
396
- - For public discussion, join [our discord channel](https://discord.gg/vNBDpjhb)
359
+ - For issues, create a Github ticket in this repository
360
+ - For open discussion, join [our discord channel](https://discord.gg/gpumode)
397
361
  - For formal collaboration, send an email to byhsu@linkedin.com
398
362
 
399
363
  ## Cite this work
@@ -401,7 +365,7 @@ It also includes components from projects licensed under:
401
365
  Biblatex entry:
402
366
  ```bib
403
367
  @article{hsu2024ligerkernelefficienttriton,
404
- title={Liger Kernel: Efficient Triton Kernels for LLM Training},
368
+ title={Liger Kernel: Efficient Triton Kernels for LLM Training},
405
369
  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},
406
370
  year={2024},
407
371
  eprint={2410.10989},
@@ -415,15 +379,8 @@ Biblatex entry:
415
379
  ## Star History
416
380
  [![Star History Chart](https://api.star-history.com/svg?repos=linkedin/Liger-Kernel&type=Date)](https://star-history.com/#linkedin/Liger-Kernel&Date)
417
381
 
418
- ## Contributors
419
-
420
- <a href="https://github.com/linkedin/Liger-Kernel/graphs/contributors">
421
- <img alt="contributors" src="https://contrib.rocks/image?repo=linkedin/Liger-Kernel"/>
422
- </a>
423
-
424
382
  <p align="right" style="font-size: 14px; color: #555; margin-top: 20px;">
425
383
  <a href="#readme-top" style="text-decoration: none; color: #007bff; font-weight: bold;">
426
384
  ↑ Back to Top ↑
427
385
  </a>
428
386
  </p>
429
-