liger-kernel-nightly 0.4.2.dev20241209234352__py3-none-any.whl → 0.4.2.dev20241210002150__py3-none-any.whl

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.
@@ -285,11 +285,12 @@ def cross_entropy_forward(
285
285
  num_warps=32 if not is_hip() else 16,
286
286
  )
287
287
 
288
- loss = torch.sum(loss_1d)
289
- if return_z_loss == _TRUE.value:
290
- z_loss = torch.sum(z_loss_1d)
288
+ if reduction == "none":
289
+ loss = loss_1d
290
+ z_loss = z_loss_1d if return_z_loss == _TRUE.value else None
291
291
  else:
292
- z_loss = None
292
+ loss = torch.sum(loss_1d)
293
+ z_loss = torch.sum(z_loss_1d) if return_z_loss == _TRUE.value else None
293
294
 
294
295
  return loss, z_loss, _input
295
296
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: liger_kernel_nightly
3
- Version: 0.4.2.dev20241209234352
3
+ Version: 0.4.2.dev20241210002150
4
4
  Summary: Efficient Triton kernels for LLM Training
5
5
  License: BSD 2-CLAUSE LICENSE
6
6
  Copyright 2024 LinkedIn Corporation
@@ -110,7 +110,7 @@ Requires-Dist: transformers~=4.0; extra == "transformers"
110
110
 
111
111
  <img src="https://raw.githubusercontent.com/linkedin/Liger-Kernel/main/docs/images/logo-banner.png">
112
112
 
113
- [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)
114
114
 
115
115
  <details>
116
116
  <summary>Latest News 🔥</summary>
@@ -266,7 +266,7 @@ loss = loss_fn(model.weight, input, target)
266
266
  loss.backward()
267
267
  ```
268
268
 
269
- ## APIs
269
+ ## High-level APIs
270
270
 
271
271
  ### AutoModel
272
272
 
@@ -290,8 +290,12 @@ loss.backward()
290
290
  | Phi3 & Phi3.5 | `liger_kernel.transformers.apply_liger_kernel_to_phi3` | RoPE, RMSNorm, SwiGLU, CrossEntropyLoss, FusedLinearCrossEntropy |
291
291
 
292
292
 
293
+ ## Low-level APIs
293
294
 
294
- ### Kernels
295
+ - `Fused Linear` kernels combine linear layers with losses, reducing memory usage by up to 80% - ideal for HBM-constrained workloads.
296
+ - Other kernels use fusion and in-place techniques for memory and performance optimization.
297
+
298
+ ### Model Kernels
295
299
 
296
300
  | **Kernel** | **API** |
297
301
  |---------------------------------|-------------------------------------------------------------|
@@ -301,39 +305,33 @@ loss.backward()
301
305
  | SwiGLU | `liger_kernel.transformers.LigerSwiGLUMLP` |
302
306
  | GeGLU | `liger_kernel.transformers.LigerGEGLUMLP` |
303
307
  | CrossEntropy | `liger_kernel.transformers.LigerCrossEntropyLoss` |
304
- | FusedLinearCrossEntropy | `liger_kernel.transformers.LigerFusedLinearCrossEntropyLoss`|
308
+ | Fused Linear CrossEntropy | `liger_kernel.transformers.LigerFusedLinearCrossEntropyLoss`|
309
+
310
+
311
+ ### Alignment Kernels
312
+
313
+ | **Kernel** | **API** |
314
+ |---------------------------------|-------------------------------------------------------------|
315
+ | Fused Linear CPO Loss | `liger_kernel.chunked_loss.LigerFusedLinearCPOLoss` |
316
+ | Fused Linear DPO Loss | `liger_kernel.chunked_loss.LigerFusedLinearDPOLoss` |
317
+ | Fused Linear ORPO Loss | `liger_kernel.chunked_loss.LigerFusedLinearORPOLoss` |
318
+ | Fused Linear SimPO Loss | `liger_kernel.chunked_loss.LigerFusedLinearSimPOLoss` |
319
+
320
+ ### Distillation Kernels
321
+
322
+ | **Kernel** | **API** |
323
+ |---------------------------------|-------------------------------------------------------------|
305
324
  | KLDivergence | `liger_kernel.transformers.LigerKLDIVLoss` |
306
325
  | JSD | `liger_kernel.transformers.LigerJSD` |
307
- | FusedLinearJSD | `liger_kernel.transformers.LigerFusedLinearJSD` |
308
-
309
- - **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.
310
- - **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.
311
- - **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.
312
- - **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.
313
- - **SwiGLU**: [Swish Gated Linear Units](https://arxiv.org/pdf/2002.05202), given by
314
- $$\text{SwiGLU}(x)=\text{Swish}_{\beta}(xW+b)\otimes(xV+c)$$
315
- , 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.
316
- - **GeGLU**: [GELU Gated Linear Units](https://arxiv.org/pdf/2002.05202), given by
317
- $$\text{GeGLU}(x)=\text{GELU}(xW+b)\otimes(xV+c)$$
318
- , 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.
319
- - **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.).
320
- <!-- TODO: verify vocab sizes are accurate -->
321
- - **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.
322
- - **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.
323
- - **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. **NOTE**: It implements forward/reverse KL when `beta` equals 0 and 1 respectively.
324
- - **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. **NOTE**: It implements forward/reverse KL when `beta` equals 0 and 1 respectively.
325
-
326
+ | Fused Linear JSD | `liger_kernel.transformers.LigerFusedLinearJSD` |
326
327
 
327
328
  ### Experimental Kernels
328
329
 
329
330
  | **Kernel** | **API** |
330
331
  |---------------------------------|-------------------------------------------------------------|
331
332
  | Embedding | `liger_kernel.transformers.experimental.LigerEmbedding` |
332
- | Matmul int2xint8 | `liger_kernel.transformers.experimental.matmul`
333
+ | Matmul int2xint8 | `liger_kernel.transformers.experimental.matmul` |
333
334
 
334
- - **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.
335
- - **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
336
- <!-- TODO: be more specific about batch size -->
337
335
 
338
336
  ## Contributing, Acknowledgements, and License
339
337
 
@@ -10,7 +10,7 @@ liger_kernel/chunked_loss/fused_linear_preference.py,sha256=vlWfaaIECWvCQhY9PM7z
10
10
  liger_kernel/chunked_loss/orpo_loss.py,sha256=ZuKGjbkIYzV4UzvupNdq6vyxCp7-BztQkUt8ZnFvKos,3531
11
11
  liger_kernel/chunked_loss/simpo_loss.py,sha256=Wa4LOlDG9PbJkOOkKg8hbKvnKgg7OTBz6-qIkwPK1yw,3275
12
12
  liger_kernel/ops/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- liger_kernel/ops/cross_entropy.py,sha256=VqaYB9Zirc51eZ28OmjEZRrrV9UysRjS_vhIftB9sKo,15753
13
+ liger_kernel/ops/cross_entropy.py,sha256=oG5hfrlmnlF5lOoZRhHRglObxgH4B0KadjWMJj9EWPM,15860
14
14
  liger_kernel/ops/fused_linear_cross_entropy.py,sha256=Tnw4gyAYVVdnCOqhOuLEzbUQ3goOTnoAfk3pqSIM5ac,9301
15
15
  liger_kernel/ops/fused_linear_jsd.py,sha256=nOv4zwfxHqqepKEmMsQuz-B3H-gRjyo8uClpmqSGLYA,9693
16
16
  liger_kernel/ops/geglu.py,sha256=MQL4zyzneZqZYUGPvb1QjI_EYT9_pKfSDgR25WD9jrI,4127
@@ -56,9 +56,9 @@ liger_kernel/transformers/model/qwen2.py,sha256=EyhSSzQOskGjSnCsKMZpd1s5IAIlHd5P
56
56
  liger_kernel/transformers/model/qwen2_vl.py,sha256=bIQe2bWiY--G84FhCD29Gdi64_qHP6vbcGsK6vKysQE,8547
57
57
  liger_kernel/triton/__init__.py,sha256=yfRe0zMb47QnqjecZWG7LnanfCTzeku7SgWRAwNVmzU,101
58
58
  liger_kernel/triton/monkey_patch.py,sha256=5BcGKTtdqeYchypBIBopGIWPx1-cFALz7sOKoEsqXJ0,1584
59
- liger_kernel_nightly-0.4.2.dev20241209234352.dist-info/LICENSE,sha256=OhzLDHJ0to4a8sodVLELZiCFylZ1NAAYLs-HrjPy0ag,1312
60
- liger_kernel_nightly-0.4.2.dev20241209234352.dist-info/METADATA,sha256=DXgBwRWN509ykIXn_83UuDRiwhZ-1RQPv4ubuieBXBA,22801
61
- liger_kernel_nightly-0.4.2.dev20241209234352.dist-info/NOTICE,sha256=njwnoPZLh9AN8SJQzxvCGLHi-8X__AvWRze6joNXIY8,2066
62
- liger_kernel_nightly-0.4.2.dev20241209234352.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
63
- liger_kernel_nightly-0.4.2.dev20241209234352.dist-info/top_level.txt,sha256=2eghu4hA3LnkM7ElW92tQ8zegWKgSbeo-k-aGe1YnvY,13
64
- liger_kernel_nightly-0.4.2.dev20241209234352.dist-info/RECORD,,
59
+ liger_kernel_nightly-0.4.2.dev20241210002150.dist-info/LICENSE,sha256=OhzLDHJ0to4a8sodVLELZiCFylZ1NAAYLs-HrjPy0ag,1312
60
+ liger_kernel_nightly-0.4.2.dev20241210002150.dist-info/METADATA,sha256=XMk5DN74rqGLsOWe-dmLLHrueliPJ-XBn9zsyanKt9o,19485
61
+ liger_kernel_nightly-0.4.2.dev20241210002150.dist-info/NOTICE,sha256=njwnoPZLh9AN8SJQzxvCGLHi-8X__AvWRze6joNXIY8,2066
62
+ liger_kernel_nightly-0.4.2.dev20241210002150.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
63
+ liger_kernel_nightly-0.4.2.dev20241210002150.dist-info/top_level.txt,sha256=2eghu4hA3LnkM7ElW92tQ8zegWKgSbeo-k-aGe1YnvY,13
64
+ liger_kernel_nightly-0.4.2.dev20241210002150.dist-info/RECORD,,