liger-kernel-nightly 0.4.2.dev20241122052539__py3-none-any.whl → 0.4.2.dev20241122175637__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.
@@ -92,8 +92,8 @@ def liger_cross_entropy_kernel(
92
92
  # 3. [Online softmax] first pass: find max + sum
93
93
  m = float("-inf") # m is the max value. use the notation from the paper
94
94
  d = 0.0 # d is the sum. use the notation from the paper
95
- ori_X_y = tl.load(
96
- X_ptr + y
95
+ ori_X_y = tl.load(X_ptr + y).cast(
96
+ tl.float32
97
97
  ) # we need to store the original value of X_y for the loss calculation
98
98
  if HAS_SOFTCAPPING:
99
99
  ori_X_y = softcap * tanh(ori_X_y / softcap)
@@ -106,8 +106,11 @@ def liger_cross_entropy_kernel(
106
106
  for i in range(0, n_cols, BLOCK_SIZE):
107
107
  X_offsets = i + tl.arange(0, BLOCK_SIZE)
108
108
  X_block = tl.load(
109
- X_ptr + X_offsets, mask=X_offsets < n_cols, other=float("-inf")
110
- )
109
+ X_ptr + X_offsets,
110
+ mask=X_offsets < n_cols,
111
+ other=float("-inf"),
112
+ # Ensure float32 precision for softmax calculation
113
+ ).cast(tl.float32)
111
114
  if HAS_SOFTCAPPING:
112
115
  X_block = softcap * tanh(X_block / softcap)
113
116
  block_max = tl.max(X_block)
@@ -141,8 +144,11 @@ def liger_cross_entropy_kernel(
141
144
  for i in range(0, n_cols, BLOCK_SIZE):
142
145
  X_offsets = i + tl.arange(0, BLOCK_SIZE)
143
146
  X_block = tl.load(
144
- X_ptr + X_offsets, mask=X_offsets < n_cols, other=float("-inf")
145
- )
147
+ X_ptr + X_offsets,
148
+ mask=X_offsets < n_cols,
149
+ other=float("-inf"),
150
+ # Ensure float32 precision for softmax calculation
151
+ ).cast(tl.float32)
146
152
  if HAS_SOFTCAPPING:
147
153
  intermediate = tanh(X_block / softcap)
148
154
  X_block = softcap * intermediate
@@ -26,7 +26,6 @@ def fused_linear_cross_entropy_forward(
26
26
  reduction="mean",
27
27
  softcap=None,
28
28
  ):
29
- dtype = _input.dtype
30
29
  device = _input.device
31
30
 
32
31
  # inputs have shape: BT x H
@@ -74,9 +73,6 @@ def fused_linear_cross_entropy_forward(
74
73
  loss_1d_slice = loss_1d[start_idx:end_idx] # chunk_size,
75
74
  n_non_ignore = (target_chunk != ignore_index).sum().item()
76
75
 
77
- # when doing CE, use the upcasted precision
78
- logits_chunk = logits_chunk.float()
79
-
80
76
  # ensure _input and target are contiguous
81
77
  logits_chunk = logits_chunk.contiguous()
82
78
  target_chunk = target_chunk.contiguous()
@@ -103,13 +99,6 @@ def fused_linear_cross_entropy_forward(
103
99
  num_warps=32 if not is_hip() else 16,
104
100
  )
105
101
 
106
- # gradient of logits_chunk is computed in-place by the above triton kernel.
107
- # Following HuggingFace model source code, we do the forward and backward
108
- # w.r.t. logits in fp32 for numerical stability especially as the num classes (vocab size) is huge.
109
- # (reference: https://github.com/huggingface/transformers/blob/v4.42.4/src/transformers/models/llama/modeling_llama.py#L1194)
110
- # Propagating to lm_head's backward, we'll switch back to the original dtype.
111
- logits_chunk = logits_chunk.to(dtype)
112
-
113
102
  # gradient of logits_chunk is computed in-place by the above triton kernel and is of shape: chunk_size x V
114
103
  # thus grad_input[start_idx: end_idx] should be of shape: chunk_size x H
115
104
  # additionally, since we are chunking the inputs, observe that the loss and gradients are calculated only
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: liger_kernel_nightly
3
- Version: 0.4.2.dev20241122052539
3
+ Version: 0.4.2.dev20241122175637
4
4
  Summary: Efficient Triton kernels for LLM Training
5
5
  License: BSD 2-CLAUSE LICENSE
6
6
  Copyright 2024 LinkedIn Corporation
@@ -7,8 +7,8 @@ liger_kernel/chunked_loss/fused_linear_preference.py,sha256=nkEpNWTHh5GmlnHOnGx5
7
7
  liger_kernel/chunked_loss/orpo_loss.py,sha256=DZ-_hm1twllBWujEV4M4-VDBkxMDBvoGqMGe-aGP1hA,3147
8
8
  liger_kernel/chunked_loss/simpo_loss.py,sha256=Jpl_U6DfxlzyHnlKN2i05K0vwz-ouiTmxlLGb439FwY,3328
9
9
  liger_kernel/ops/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- liger_kernel/ops/cross_entropy.py,sha256=sfUb7-jIZp0EKXjg1DYy2Wdzw_Mg-mHmGoR5bpdm4tw,15526
11
- liger_kernel/ops/fused_linear_cross_entropy.py,sha256=ib7M3AjJE164yMfuS9R39k-5qnDgYOXptIT146lqYbg,9964
10
+ liger_kernel/ops/cross_entropy.py,sha256=VqaYB9Zirc51eZ28OmjEZRrrV9UysRjS_vhIftB9sKo,15753
11
+ liger_kernel/ops/fused_linear_cross_entropy.py,sha256=Tnw4gyAYVVdnCOqhOuLEzbUQ3goOTnoAfk3pqSIM5ac,9301
12
12
  liger_kernel/ops/fused_linear_jsd.py,sha256=nOv4zwfxHqqepKEmMsQuz-B3H-gRjyo8uClpmqSGLYA,9693
13
13
  liger_kernel/ops/geglu.py,sha256=MQL4zyzneZqZYUGPvb1QjI_EYT9_pKfSDgR25WD9jrI,4127
14
14
  liger_kernel/ops/group_norm.py,sha256=VaRErVJGR4JqgXXvuIjNGTn3E2egjLtU1y3ymwIf4d8,10961
@@ -52,9 +52,9 @@ liger_kernel/transformers/model/qwen2.py,sha256=EyhSSzQOskGjSnCsKMZpd1s5IAIlHd5P
52
52
  liger_kernel/transformers/model/qwen2_vl.py,sha256=bIQe2bWiY--G84FhCD29Gdi64_qHP6vbcGsK6vKysQE,8547
53
53
  liger_kernel/triton/__init__.py,sha256=yfRe0zMb47QnqjecZWG7LnanfCTzeku7SgWRAwNVmzU,101
54
54
  liger_kernel/triton/monkey_patch.py,sha256=5BcGKTtdqeYchypBIBopGIWPx1-cFALz7sOKoEsqXJ0,1584
55
- liger_kernel_nightly-0.4.2.dev20241122052539.dist-info/LICENSE,sha256=OhzLDHJ0to4a8sodVLELZiCFylZ1NAAYLs-HrjPy0ag,1312
56
- liger_kernel_nightly-0.4.2.dev20241122052539.dist-info/METADATA,sha256=4fPpoJL_3aqEC-teWIauvl_VbNer1TYZ-7s8znCLSgs,21891
57
- liger_kernel_nightly-0.4.2.dev20241122052539.dist-info/NOTICE,sha256=njwnoPZLh9AN8SJQzxvCGLHi-8X__AvWRze6joNXIY8,2066
58
- liger_kernel_nightly-0.4.2.dev20241122052539.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
59
- liger_kernel_nightly-0.4.2.dev20241122052539.dist-info/top_level.txt,sha256=2eghu4hA3LnkM7ElW92tQ8zegWKgSbeo-k-aGe1YnvY,13
60
- liger_kernel_nightly-0.4.2.dev20241122052539.dist-info/RECORD,,
55
+ liger_kernel_nightly-0.4.2.dev20241122175637.dist-info/LICENSE,sha256=OhzLDHJ0to4a8sodVLELZiCFylZ1NAAYLs-HrjPy0ag,1312
56
+ liger_kernel_nightly-0.4.2.dev20241122175637.dist-info/METADATA,sha256=jxja3ZGNuVc_U6JWdjw23O6IdeKK5h45_X16xh-e6xc,21891
57
+ liger_kernel_nightly-0.4.2.dev20241122175637.dist-info/NOTICE,sha256=njwnoPZLh9AN8SJQzxvCGLHi-8X__AvWRze6joNXIY8,2066
58
+ liger_kernel_nightly-0.4.2.dev20241122175637.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
59
+ liger_kernel_nightly-0.4.2.dev20241122175637.dist-info/top_level.txt,sha256=2eghu4hA3LnkM7ElW92tQ8zegWKgSbeo-k-aGe1YnvY,13
60
+ liger_kernel_nightly-0.4.2.dev20241122175637.dist-info/RECORD,,