liger-kernel-nightly 0.5.2.dev20241218221959__py3-none-any.whl → 0.5.2.dev20241219211841__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,7 +47,6 @@ class LigerFusedLinearCPOFunction(LigerFusedLinearPreferenceBase):
47
47
  alpha=1.0,
48
48
  compute_nll_loss=True,
49
49
  compiled=True,
50
- is_encoder_decoder=False,
51
50
  ):
52
51
  return LigerFusedLinearPreferenceBase.forward(
53
52
  ctx,
@@ -61,13 +60,12 @@ class LigerFusedLinearCPOFunction(LigerFusedLinearPreferenceBase):
61
60
  beta=beta,
62
61
  compute_nll_loss=compute_nll_loss,
63
62
  compiled=compiled,
64
- is_encoder_decoder=is_encoder_decoder,
65
63
  )
66
64
 
67
65
  @staticmethod
68
66
  def backward(ctx, *grad_output):
69
67
  grads = LigerFusedLinearPreferenceBase.backward(ctx, grad_output)[:4]
70
- return *grads, None, None, None, None, None, None
68
+ return *grads, None, None, None, None, None
71
69
 
72
70
 
73
71
  class LigerFusedLinearCPOLoss(torch.nn.Module):
@@ -82,16 +80,11 @@ class LigerFusedLinearCPOLoss(torch.nn.Module):
82
80
  alpha: float = 1.0,
83
81
  compute_nll_loss: bool = True,
84
82
  compiled: bool = True,
85
- is_encoder_decoder: bool = False,
86
83
  ):
87
84
  """
88
85
  Args:
89
86
  ignore_index (int): Index to ignore in the loss.
90
87
  beta (float): Weight for the odds ratio loss.
91
- alpha (float): Weight for the NLL loss.
92
- compute_nll_loss (bool): Whether to compute NLL loss.
93
- compiled (bool): Whether to compile the loss function.
94
- is_encoder_decoder (bool): Whether the model is an encoder-decoder model.
95
88
  """
96
89
  super().__init__()
97
90
  self.ignore_index = ignore_index
@@ -99,7 +92,6 @@ class LigerFusedLinearCPOLoss(torch.nn.Module):
99
92
  self.alpha = alpha
100
93
  self.compute_nll_loss = compute_nll_loss
101
94
  self.compiled = compiled
102
- self.is_encoder_decoder = is_encoder_decoder
103
95
 
104
96
  def forward(self, lin_weight, _input, target, bias=None):
105
97
  return LigerFusedLinearCPOFunction.apply(
@@ -112,5 +104,4 @@ class LigerFusedLinearCPOLoss(torch.nn.Module):
112
104
  self.alpha,
113
105
  self.compute_nll_loss,
114
106
  self.compiled,
115
- self.is_encoder_decoder,
116
107
  )
@@ -67,7 +67,6 @@ class LigerFusedLinearDPOFunction(LigerFusedLinearPreferenceBase):
67
67
  compute_nll_loss=True,
68
68
  compiled=True,
69
69
  use_ref_model=True,
70
- is_encoder_decoder=False,
71
70
  ):
72
71
  return LigerFusedLinearPreferenceBase.forward(
73
72
  ctx=ctx,
@@ -84,13 +83,12 @@ class LigerFusedLinearDPOFunction(LigerFusedLinearPreferenceBase):
84
83
  ref_input=ref_input,
85
84
  ref_weight=ref_weight,
86
85
  ref_bias=ref_bias,
87
- is_encoder_decoder=is_encoder_decoder,
88
86
  )
89
87
 
90
88
  @staticmethod
91
89
  def backward(ctx, *grad_output):
92
90
  grads = LigerFusedLinearPreferenceBase.backward(ctx, grad_output)[:4]
93
- return *grads, None, None, None, None, None, None, None, None, None
91
+ return *grads, None, None, None, None, None, None, None, None
94
92
 
95
93
 
96
94
  class LigerFusedLinearDPOLoss(torch.nn.Module):
@@ -105,7 +103,6 @@ class LigerFusedLinearDPOLoss(torch.nn.Module):
105
103
  compute_nll_loss: bool = True,
106
104
  compiled: bool = True,
107
105
  use_ref_model: bool = False,
108
- is_encoder_decoder: bool = False,
109
106
  ):
110
107
  """
111
108
  Args:
@@ -114,7 +111,6 @@ class LigerFusedLinearDPOLoss(torch.nn.Module):
114
111
  compute_nll_loss (bool): Whether to compute the NLL loss.
115
112
  compiled (bool): Whether to use the torch compiled kernel.
116
113
  use_ref_model (bool): Whether to use a reference model for the DPO loss.
117
- is_encoder_decoder (bool): Whether the model is an encoder-decoder model.
118
114
  """
119
115
  super().__init__()
120
116
  self.ignore_index = ignore_index
@@ -122,7 +118,6 @@ class LigerFusedLinearDPOLoss(torch.nn.Module):
122
118
  self.compute_nll_loss = compute_nll_loss
123
119
  self.compiled = compiled
124
120
  self.use_ref_model = use_ref_model
125
- self.is_encoder_decoder = is_encoder_decoder
126
121
 
127
122
  def forward(
128
123
  self,
@@ -147,5 +142,4 @@ class LigerFusedLinearDPOLoss(torch.nn.Module):
147
142
  self.compute_nll_loss,
148
143
  self.compiled,
149
144
  self.use_ref_model,
150
- self.is_encoder_decoder,
151
145
  )
@@ -26,7 +26,6 @@ class LigerFusedLinearPreferenceBase(torch.autograd.Function):
26
26
  ignore_index=-100,
27
27
  alpha=1.0,
28
28
  beta=0.1,
29
- is_encoder_decoder=False,
30
29
  compute_nll_loss=True,
31
30
  compiled=True,
32
31
  use_ref_model=False,
@@ -57,7 +56,6 @@ class LigerFusedLinearPreferenceBase(torch.autograd.Function):
57
56
  ignore_index (int): Index to ignore for loss computation.
58
57
  alpha (float): Weight for the NLL loss.
59
58
  beta (float): Weight for the preference loss.
60
- is_encoder_decoder (bool): Whether the model is an encoder-decoder model.
61
59
  compute_nll_loss (bool): Whether to compute NLL loss.
62
60
  compiled (bool): Whether to use torch compile for chunk accumulation.
63
61
  use_ref_model (bool): Whether to use a reference model for the alignment loss.
@@ -96,7 +94,6 @@ class LigerFusedLinearPreferenceBase(torch.autograd.Function):
96
94
  use_ref_model=use_ref_model,
97
95
  ref_weight=ref_weight,
98
96
  ref_bias=ref_bias,
99
- is_encoder_decoder=is_encoder_decoder,
100
97
  **loss_kwargs,
101
98
  )
102
99
 
@@ -285,48 +282,33 @@ class LigerFusedLinearPreferenceBase(torch.autograd.Function):
285
282
  bias=None,
286
283
  ignore_index=-100,
287
284
  compute_nll_loss=True,
288
- is_encoder_decoder=False,
289
285
  ):
290
- # Calculate logits and log probabilities
286
+ len_chosen_chunk = target_chunk.shape[0] // 2
291
287
  logits_chunk = input_chunk @ weight.t()
292
288
  if bias is not None:
293
- logits_chunk += bias
289
+ logits_chunk = logits_chunk + bias
294
290
  log_probs_chunk = F.log_softmax(logits_chunk.float(), dim=-1)
295
291
 
296
- # Split chunk into chosen and rejected portions
297
- len_chosen_chunk = target_chunk.shape[0] // 2
298
-
299
- # Handle sequence shifting for non-encoder-decoder models
300
- if not is_encoder_decoder:
301
- logits_chunk = logits_chunk[:, :-1]
302
- log_probs_chunk = log_probs_chunk[:, :-1]
303
- target_chunk = target_chunk[:, 1:]
304
-
305
- # Calculate NLL loss for chosen sequences
306
292
  chosen_nll_loss = 0.0
307
293
  if compute_nll_loss:
308
- chosen_probs = log_probs_chunk[:len_chosen_chunk]
309
- chosen_targets = target_chunk[:len_chosen_chunk]
310
294
  chosen_nll_loss = F.nll_loss(
311
- chosen_probs.reshape(-1, chosen_probs.shape[-1]),
312
- chosen_targets.reshape(-1),
295
+ log_probs_chunk[:len_chosen_chunk].view(-1, log_probs_chunk.shape[-1]),
296
+ target_chunk[:len_chosen_chunk].view(-1),
313
297
  reduction="sum",
314
298
  ignore_index=ignore_index,
315
299
  )
316
300
 
317
- # Calculate per-token log probabilities
318
301
  loss_mask = target_chunk != ignore_index
319
302
  label_chunk = torch.where(loss_mask, target_chunk, 0)
303
+
320
304
  per_token_logps = log_probs_chunk.gather(-1, label_chunk.unsqueeze(-1)).squeeze(
321
305
  -1
322
306
  )
323
307
  average_log_prob = (per_token_logps * loss_mask).sum(-1) / loss_mask.sum(-1)
324
308
 
325
- # Split results for chosen and rejected
326
- chosen_logps, rejected_logps = (
327
- average_log_prob[:len_chosen_chunk],
328
- average_log_prob[len_chosen_chunk:],
329
- )
309
+ chosen_logps = average_log_prob[:len_chosen_chunk]
310
+ rejected_logps = average_log_prob[len_chosen_chunk:]
311
+
330
312
  chosen_logits = logits_chunk[:len_chosen_chunk]
331
313
  rejected_logits = logits_chunk[len_chosen_chunk:]
332
314
 
@@ -349,7 +331,6 @@ class LigerFusedLinearPreferenceBase(torch.autograd.Function):
349
331
  ignore_index=-100,
350
332
  alpha=1.0,
351
333
  beta=0.1,
352
- is_encoder_decoder=False,
353
334
  compute_nll_loss=True,
354
335
  use_ref_model=False,
355
336
  ref_input_chunk=None,
@@ -369,7 +350,6 @@ class LigerFusedLinearPreferenceBase(torch.autograd.Function):
369
350
  ignore_index (int): Index to ignore for loss computation.
370
351
  alpha (float): Weight for the NLL loss.
371
352
  beta (float): Weight for the preference loss.
372
- is_encoder_decoder (bool): Whether the model is an encoder-decoder model.
373
353
  compute_nll_loss (bool): Whether to compute NLL loss.
374
354
  use_ref_model (bool): Whether to use a reference model for the alignment loss.
375
355
  ref_weight (torch.Tensor): Reference weight tensor. Shape: (vocab_size, hidden_size).
@@ -389,43 +369,33 @@ class LigerFusedLinearPreferenceBase(torch.autograd.Function):
389
369
  bias=bias,
390
370
  ignore_index=ignore_index,
391
371
  compute_nll_loss=compute_nll_loss,
392
- is_encoder_decoder=is_encoder_decoder,
393
372
  )
394
- if not is_encoder_decoder:
395
- chosen_nll_loss = (
396
- chosen_nll_loss
397
- / (full_target[: full_target.shape[0] // 2, 1:] != ignore_index).sum()
398
- )
399
- chosen_logits_mean = chosen_logits.sum() / (
400
- full_target.shape[0] // 2 * (input_chunk.shape[1] - 1) * weight.shape[0]
401
- )
402
- rejected_logits_mean = rejected_logits.sum() / (
403
- full_target.shape[0] // 2 * (input_chunk.shape[1] - 1) * weight.shape[0]
404
- )
405
- else:
406
- chosen_nll_loss = (
407
- chosen_nll_loss
408
- / (full_target[: full_target.shape[0] // 2] != ignore_index).sum()
409
- )
410
- chosen_logits_mean = chosen_logits.sum() / (
411
- full_target.shape[0] // 2 * input_chunk.shape[1] * weight.shape[0]
412
- )
413
- rejected_logits_mean = rejected_logits.sum() / (
414
- full_target.shape[0] // 2 * input_chunk.shape[1] * weight.shape[0]
415
- )
373
+ chosen_nll_loss = (
374
+ chosen_nll_loss
375
+ / (full_target[: full_target.shape[0] // 2] != ignore_index).sum()
376
+ )
377
+ chosen_logits_mean = chosen_logits.sum() / (
378
+ full_target.shape[0] // 2 * input_chunk.shape[1] * weight.shape[0]
379
+ )
380
+ rejected_logits_mean = rejected_logits.sum() / (
381
+ full_target.shape[0] // 2 * input_chunk.shape[1] * weight.shape[0]
382
+ )
416
383
 
417
384
  if use_ref_model:
418
385
  with torch.no_grad():
419
- (ref_chosen_logps, ref_rejected_logps, _, _, _) = (
420
- LigerFusedLinearPreferenceBase.chunk_forward(
421
- ref_input_chunk,
422
- ref_weight,
423
- target_chunk,
424
- ref_bias,
425
- ignore_index=ignore_index,
426
- compute_nll_loss=False, # We don't need NLL loss for the reference model
427
- is_encoder_decoder=is_encoder_decoder, # assume the ref model is the same family
428
- )
386
+ (
387
+ ref_chosen_logps,
388
+ ref_rejected_logps,
389
+ ref_chosen_logits,
390
+ ref_rejected_logits,
391
+ ref_chosen_nll_loss,
392
+ ) = LigerFusedLinearPreferenceBase.chunk_forward(
393
+ ref_input_chunk,
394
+ ref_weight,
395
+ target_chunk,
396
+ ref_bias,
397
+ ignore_index=ignore_index,
398
+ compute_nll_loss=False, # We don't need NLL loss for the reference model
429
399
  )
430
400
  loss_kwargs["ref_chosen_logps"] = ref_chosen_logps
431
401
  loss_kwargs["ref_rejected_logps"] = ref_rejected_logps
@@ -57,7 +57,6 @@ class LigerFusedLinearORPOFunction(LigerFusedLinearPreferenceBase):
57
57
  beta=0.1,
58
58
  compute_nll_loss=True,
59
59
  compiled=True,
60
- is_encoder_decoder=False,
61
60
  ):
62
61
  return LigerFusedLinearPreferenceBase.forward(
63
62
  ctx=ctx,
@@ -70,13 +69,12 @@ class LigerFusedLinearORPOFunction(LigerFusedLinearPreferenceBase):
70
69
  beta=beta,
71
70
  compute_nll_loss=compute_nll_loss,
72
71
  compiled=compiled,
73
- is_encoder_decoder=is_encoder_decoder,
74
72
  )
75
73
 
76
74
  @staticmethod
77
75
  def backward(ctx, *grad_output):
78
76
  grads = LigerFusedLinearPreferenceBase.backward(ctx, grad_output)[:4]
79
- return *grads, None, None, None, None, None
77
+ return *grads, None, None, None, None
80
78
 
81
79
 
82
80
  class LigerFusedLinearORPOLoss(torch.nn.Module):
@@ -90,22 +88,17 @@ class LigerFusedLinearORPOLoss(torch.nn.Module):
90
88
  beta: float = 0.1,
91
89
  compute_nll_loss: bool = True,
92
90
  compiled: bool = True,
93
- is_encoder_decoder: bool = False,
94
91
  ):
95
92
  """
96
93
  Args:
97
94
  ignore_index (int): Index to ignore in the loss.
98
95
  beta (float): Weight for the odds ratio loss.
99
- compute_nll_loss (bool): Whether to compute NLL loss.
100
- compiled (bool): Whether to compile the loss function.
101
- is_encoder_decoder (bool): Whether the model is an encoder-decoder model.
102
96
  """
103
97
  super().__init__()
104
98
  self.ignore_index = ignore_index
105
99
  self.beta = beta
106
100
  self.compute_nll_loss = compute_nll_loss
107
101
  self.compiled = compiled
108
- self.is_encoder_decoder = is_encoder_decoder
109
102
 
110
103
  def forward(self, lin_weight, _input, target, bias=None):
111
104
  return LigerFusedLinearORPOFunction.apply(
@@ -117,5 +110,4 @@ class LigerFusedLinearORPOLoss(torch.nn.Module):
117
110
  self.beta,
118
111
  self.compute_nll_loss,
119
112
  self.compiled,
120
- self.is_encoder_decoder,
121
113
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: liger_kernel_nightly
3
- Version: 0.5.2.dev20241218221959
3
+ Version: 0.5.2.dev20241219211841
4
4
  Summary: Efficient Triton kernels for LLM Training
5
5
  License: BSD 2-CLAUSE LICENSE
6
6
  Copyright 2024 LinkedIn Corporation
@@ -3,12 +3,12 @@ liger_kernel/env_report.py,sha256=ok9PMXtO-8uLj_feCJI4h9hz2NtolZ2AG_OJTW5qmo4,18
3
3
  liger_kernel/utils.py,sha256=HJa-xVKOohDn6pLVIx-Fv0V9h0QAL3qZGQNRICI-OpI,249
4
4
  liger_kernel/chunked_loss/README.md,sha256=K6rucm6nqHpWCmxUOhBYcE3apwQxAy0TfRUippR7Icw,2243
5
5
  liger_kernel/chunked_loss/__init__.py,sha256=R2wCcz4Y0kTAve926DH3k182XKezpXeACMHj05g9Mm8,346
6
- liger_kernel/chunked_loss/cpo_loss.py,sha256=jtA7jA92Gv2raLzJ2QScPqgyi-S04a6aKUMRROdR3-w,3591
7
- liger_kernel/chunked_loss/dpo_loss.py,sha256=tpBw6fAVq2mujo0_NS98L1NP--m1hYqi1qHGAyfg52g,4690
6
+ liger_kernel/chunked_loss/cpo_loss.py,sha256=Qu1Ul2A12sp6CqIT-atPbHWFb_LLtINEA9mOpIRx_0g,3097
7
+ liger_kernel/chunked_loss/dpo_loss.py,sha256=9S67SzKkLyoBmHGx8bkmthSNHlCT2ikBy9CCdb7wGj0,4381
8
8
  liger_kernel/chunked_loss/functional.py,sha256=9Gr-YXIuEzEJkBUhDx3G2fuQayckLor7cC7svhmPML4,549
9
9
  liger_kernel/chunked_loss/fused_linear_distillation.py,sha256=2BH6DCPjsR2zS6zcwFPcIIZRhLF8SohjGdKsAJ_301o,10222
10
- liger_kernel/chunked_loss/fused_linear_preference.py,sha256=iHegoQ18amhXzMNLNyzntxmtz_6JSOgougHTN_rbwfY,17936
11
- liger_kernel/chunked_loss/orpo_loss.py,sha256=XkVnsJ6Qmn3lxvprXRiySl9Hbx6-UNzWDCFXu_pY6Uc,3973
10
+ liger_kernel/chunked_loss/fused_linear_preference.py,sha256=AsovMdfsOjgWVxtDhZ_rXqpahMsKTg8YueXnZcHt1XQ,16376
11
+ liger_kernel/chunked_loss/orpo_loss.py,sha256=ZuKGjbkIYzV4UzvupNdq6vyxCp7-BztQkUt8ZnFvKos,3531
12
12
  liger_kernel/chunked_loss/simpo_loss.py,sha256=Wa4LOlDG9PbJkOOkKg8hbKvnKgg7OTBz6-qIkwPK1yw,3275
13
13
  liger_kernel/ops/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  liger_kernel/ops/cross_entropy.py,sha256=oG5hfrlmnlF5lOoZRhHRglObxgH4B0KadjWMJj9EWPM,15860
@@ -58,9 +58,9 @@ liger_kernel/transformers/trainer/__init__.py,sha256=c4OQVJmhNOloj0JYSEc0j_cQuBb
58
58
  liger_kernel/transformers/trainer/orpo_trainer.py,sha256=O2k2vdHl-O1S-U61aEmyUFu3QrEuNAipQa2oUBb3HAA,7679
59
59
  liger_kernel/triton/__init__.py,sha256=yfRe0zMb47QnqjecZWG7LnanfCTzeku7SgWRAwNVmzU,101
60
60
  liger_kernel/triton/monkey_patch.py,sha256=5BcGKTtdqeYchypBIBopGIWPx1-cFALz7sOKoEsqXJ0,1584
61
- liger_kernel_nightly-0.5.2.dev20241218221959.dist-info/LICENSE,sha256=OhzLDHJ0to4a8sodVLELZiCFylZ1NAAYLs-HrjPy0ag,1312
62
- liger_kernel_nightly-0.5.2.dev20241218221959.dist-info/METADATA,sha256=3Af4_e7ToJ34MQGPqIg94fXvRKApkHFb6dV7evsm494,21055
63
- liger_kernel_nightly-0.5.2.dev20241218221959.dist-info/NOTICE,sha256=njwnoPZLh9AN8SJQzxvCGLHi-8X__AvWRze6joNXIY8,2066
64
- liger_kernel_nightly-0.5.2.dev20241218221959.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
65
- liger_kernel_nightly-0.5.2.dev20241218221959.dist-info/top_level.txt,sha256=2eghu4hA3LnkM7ElW92tQ8zegWKgSbeo-k-aGe1YnvY,13
66
- liger_kernel_nightly-0.5.2.dev20241218221959.dist-info/RECORD,,
61
+ liger_kernel_nightly-0.5.2.dev20241219211841.dist-info/LICENSE,sha256=OhzLDHJ0to4a8sodVLELZiCFylZ1NAAYLs-HrjPy0ag,1312
62
+ liger_kernel_nightly-0.5.2.dev20241219211841.dist-info/METADATA,sha256=53BLTRM2B5gVYzBVvKfDi4nWijlv2xXT63LDGXTlvQc,21055
63
+ liger_kernel_nightly-0.5.2.dev20241219211841.dist-info/NOTICE,sha256=njwnoPZLh9AN8SJQzxvCGLHi-8X__AvWRze6joNXIY8,2066
64
+ liger_kernel_nightly-0.5.2.dev20241219211841.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
65
+ liger_kernel_nightly-0.5.2.dev20241219211841.dist-info/top_level.txt,sha256=2eghu4hA3LnkM7ElW92tQ8zegWKgSbeo-k-aGe1YnvY,13
66
+ liger_kernel_nightly-0.5.2.dev20241219211841.dist-info/RECORD,,