liger-kernel-nightly 0.5.2.dev20241219211841__py3-none-any.whl → 0.5.2.dev20241220220835__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- liger_kernel/chunked_loss/cpo_loss.py +15 -3
- liger_kernel/chunked_loss/dpo_loss.py +2 -2
- liger_kernel/chunked_loss/simpo_loss.py +18 -3
- {liger_kernel_nightly-0.5.2.dev20241219211841.dist-info → liger_kernel_nightly-0.5.2.dev20241220220835.dist-info}/METADATA +1 -1
- {liger_kernel_nightly-0.5.2.dev20241219211841.dist-info → liger_kernel_nightly-0.5.2.dev20241220220835.dist-info}/RECORD +9 -9
- {liger_kernel_nightly-0.5.2.dev20241219211841.dist-info → liger_kernel_nightly-0.5.2.dev20241220220835.dist-info}/LICENSE +0 -0
- {liger_kernel_nightly-0.5.2.dev20241219211841.dist-info → liger_kernel_nightly-0.5.2.dev20241220220835.dist-info}/NOTICE +0 -0
- {liger_kernel_nightly-0.5.2.dev20241219211841.dist-info → liger_kernel_nightly-0.5.2.dev20241220220835.dist-info}/WHEEL +0 -0
- {liger_kernel_nightly-0.5.2.dev20241219211841.dist-info → liger_kernel_nightly-0.5.2.dev20241220220835.dist-info}/top_level.txt +0 -0
@@ -9,7 +9,9 @@ from liger_kernel.chunked_loss.fused_linear_preference import (
|
|
9
9
|
class LigerFusedLinearCPOFunction(LigerFusedLinearPreferenceBase):
|
10
10
|
|
11
11
|
@staticmethod
|
12
|
-
def preference_loss_fn(
|
12
|
+
def preference_loss_fn(
|
13
|
+
chosen_logps, rejected_logps, full_target, beta=0.1, label_smoothing=0.0
|
14
|
+
):
|
13
15
|
"""
|
14
16
|
Paper: https://arxiv.org/pdf/2401.08417
|
15
17
|
|
@@ -30,9 +32,14 @@ class LigerFusedLinearCPOFunction(LigerFusedLinearPreferenceBase):
|
|
30
32
|
rejected_logps (torch.Tensor): Avg log probabilities of rejected tokens. Shape: (batch_size,).
|
31
33
|
full_target (torch.Tensor): Non chunked full target tensor
|
32
34
|
beta (float): Weight for the CPO loss
|
35
|
+
label_smoothing (float): Label smoothing factor, will reduce to Equation above when label_smoothing -> 0.
|
33
36
|
"""
|
34
37
|
logits = beta * (chosen_logps - rejected_logps)
|
35
|
-
loss =
|
38
|
+
loss = (
|
39
|
+
F.logsigmoid(logits) * (1 - label_smoothing)
|
40
|
+
+ F.logsigmoid(-logits) * label_smoothing
|
41
|
+
).sum() / (full_target.shape[0] // 2)
|
42
|
+
|
36
43
|
return loss
|
37
44
|
|
38
45
|
@staticmethod
|
@@ -45,6 +52,7 @@ class LigerFusedLinearCPOFunction(LigerFusedLinearPreferenceBase):
|
|
45
52
|
ignore_index=-100,
|
46
53
|
beta=0.1,
|
47
54
|
alpha=1.0,
|
55
|
+
label_smoothing=0.0,
|
48
56
|
compute_nll_loss=True,
|
49
57
|
compiled=True,
|
50
58
|
):
|
@@ -58,6 +66,7 @@ class LigerFusedLinearCPOFunction(LigerFusedLinearPreferenceBase):
|
|
58
66
|
ignore_index=ignore_index,
|
59
67
|
alpha=alpha,
|
60
68
|
beta=beta,
|
69
|
+
label_smoothing=label_smoothing,
|
61
70
|
compute_nll_loss=compute_nll_loss,
|
62
71
|
compiled=compiled,
|
63
72
|
)
|
@@ -65,7 +74,7 @@ class LigerFusedLinearCPOFunction(LigerFusedLinearPreferenceBase):
|
|
65
74
|
@staticmethod
|
66
75
|
def backward(ctx, *grad_output):
|
67
76
|
grads = LigerFusedLinearPreferenceBase.backward(ctx, grad_output)[:4]
|
68
|
-
return *grads, None, None, None, None, None
|
77
|
+
return *grads, None, None, None, None, None, None
|
69
78
|
|
70
79
|
|
71
80
|
class LigerFusedLinearCPOLoss(torch.nn.Module):
|
@@ -78,6 +87,7 @@ class LigerFusedLinearCPOLoss(torch.nn.Module):
|
|
78
87
|
ignore_index: int = -100,
|
79
88
|
beta: float = 0.1,
|
80
89
|
alpha: float = 1.0,
|
90
|
+
label_smoothing: float = 0.0,
|
81
91
|
compute_nll_loss: bool = True,
|
82
92
|
compiled: bool = True,
|
83
93
|
):
|
@@ -90,6 +100,7 @@ class LigerFusedLinearCPOLoss(torch.nn.Module):
|
|
90
100
|
self.ignore_index = ignore_index
|
91
101
|
self.beta = beta
|
92
102
|
self.alpha = alpha
|
103
|
+
self.label_smoothing = label_smoothing
|
93
104
|
self.compute_nll_loss = compute_nll_loss
|
94
105
|
self.compiled = compiled
|
95
106
|
|
@@ -102,6 +113,7 @@ class LigerFusedLinearCPOLoss(torch.nn.Module):
|
|
102
113
|
self.ignore_index,
|
103
114
|
self.beta,
|
104
115
|
self.alpha,
|
116
|
+
self.label_smoothing,
|
105
117
|
self.compute_nll_loss,
|
106
118
|
self.compiled,
|
107
119
|
)
|
@@ -64,7 +64,7 @@ class LigerFusedLinearDPOFunction(LigerFusedLinearPreferenceBase):
|
|
64
64
|
ref_bias=None,
|
65
65
|
ignore_index=-100,
|
66
66
|
beta=0.1,
|
67
|
-
compute_nll_loss=
|
67
|
+
compute_nll_loss=False,
|
68
68
|
compiled=True,
|
69
69
|
use_ref_model=True,
|
70
70
|
):
|
@@ -100,7 +100,7 @@ class LigerFusedLinearDPOLoss(torch.nn.Module):
|
|
100
100
|
self,
|
101
101
|
ignore_index: int = -100,
|
102
102
|
beta: float = 0.1,
|
103
|
-
compute_nll_loss: bool =
|
103
|
+
compute_nll_loss: bool = False,
|
104
104
|
compiled: bool = True,
|
105
105
|
use_ref_model: bool = False,
|
106
106
|
):
|
@@ -10,7 +10,12 @@ class LigerFusedLinearSimPOFunction(LigerFusedLinearPreferenceBase):
|
|
10
10
|
|
11
11
|
@staticmethod
|
12
12
|
def preference_loss_fn(
|
13
|
-
chosen_logps,
|
13
|
+
chosen_logps,
|
14
|
+
rejected_logps,
|
15
|
+
full_target,
|
16
|
+
beta=0.1,
|
17
|
+
gamma=0.5,
|
18
|
+
label_smoothing=0.0,
|
14
19
|
):
|
15
20
|
"""
|
16
21
|
Paper: https://arxiv.org/pdf/2405.14734
|
@@ -33,9 +38,14 @@ class LigerFusedLinearSimPOFunction(LigerFusedLinearPreferenceBase):
|
|
33
38
|
full_target: Non chunked full target tensor
|
34
39
|
beta (float): beta weight
|
35
40
|
gamma (float): gemma margin term
|
41
|
+
label_smoothing (float): Label smoothing factor, will reduce to Equation above when label_smoothing -> 0.
|
36
42
|
"""
|
37
43
|
logits = beta * (chosen_logps - rejected_logps) - gamma
|
38
|
-
loss =
|
44
|
+
loss = (
|
45
|
+
F.logsigmoid(logits) * (1 - label_smoothing)
|
46
|
+
+ F.logsigmoid(-logits) * label_smoothing
|
47
|
+
).sum() / (full_target.shape[0] // 2)
|
48
|
+
|
39
49
|
return loss
|
40
50
|
|
41
51
|
@staticmethod
|
@@ -48,6 +58,7 @@ class LigerFusedLinearSimPOFunction(LigerFusedLinearPreferenceBase):
|
|
48
58
|
ignore_index=-100,
|
49
59
|
beta=0.1,
|
50
60
|
alpha=1.0,
|
61
|
+
label_smoothing=0.0,
|
51
62
|
compute_nll_loss=False,
|
52
63
|
compiled=True,
|
53
64
|
gamma=0.5,
|
@@ -63,6 +74,7 @@ class LigerFusedLinearSimPOFunction(LigerFusedLinearPreferenceBase):
|
|
63
74
|
ignore_index=ignore_index,
|
64
75
|
alpha=alpha,
|
65
76
|
beta=beta,
|
77
|
+
label_smoothing=label_smoothing,
|
66
78
|
compiled=compiled,
|
67
79
|
gamma=gamma,
|
68
80
|
)
|
@@ -70,7 +82,7 @@ class LigerFusedLinearSimPOFunction(LigerFusedLinearPreferenceBase):
|
|
70
82
|
@staticmethod
|
71
83
|
def backward(ctx, *grad_output):
|
72
84
|
grads = LigerFusedLinearPreferenceBase.backward(ctx, grad_output)[:4]
|
73
|
-
return *grads, None, None, None, None, None, None
|
85
|
+
return *grads, None, None, None, None, None, None, None
|
74
86
|
|
75
87
|
|
76
88
|
class LigerFusedLinearSimPOLoss(torch.nn.Module):
|
@@ -83,6 +95,7 @@ class LigerFusedLinearSimPOLoss(torch.nn.Module):
|
|
83
95
|
ignore_index: int = -100,
|
84
96
|
beta: float = 0.1,
|
85
97
|
alpha: float = 1.0,
|
98
|
+
label_smoothing: float = 0.0,
|
86
99
|
compute_nll_loss: bool = True,
|
87
100
|
compiled: bool = True,
|
88
101
|
gamma: float = 0.5,
|
@@ -96,6 +109,7 @@ class LigerFusedLinearSimPOLoss(torch.nn.Module):
|
|
96
109
|
self.ignore_index = ignore_index
|
97
110
|
self.beta = beta
|
98
111
|
self.alpha = alpha
|
112
|
+
self.label_smoothing = label_smoothing
|
99
113
|
self.compute_nll_loss = compute_nll_loss
|
100
114
|
self.compiled = compiled
|
101
115
|
self.gamma = gamma
|
@@ -109,6 +123,7 @@ class LigerFusedLinearSimPOLoss(torch.nn.Module):
|
|
109
123
|
self.ignore_index,
|
110
124
|
self.beta,
|
111
125
|
self.alpha,
|
126
|
+
self.label_smoothing,
|
112
127
|
self.compute_nll_loss,
|
113
128
|
self.compiled,
|
114
129
|
self.gamma,
|
@@ -3,13 +3,13 @@ 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=
|
7
|
-
liger_kernel/chunked_loss/dpo_loss.py,sha256=
|
6
|
+
liger_kernel/chunked_loss/cpo_loss.py,sha256=_0phkDQg_SG239xNVlaAvGoL33myt0Zt6avDJfg6HC0,3552
|
7
|
+
liger_kernel/chunked_loss/dpo_loss.py,sha256=jbTno1pKEc-HxAGFY3NSycBzdWyTacyRCzH3FhrMUMo,4383
|
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
10
|
liger_kernel/chunked_loss/fused_linear_preference.py,sha256=AsovMdfsOjgWVxtDhZ_rXqpahMsKTg8YueXnZcHt1XQ,16376
|
11
11
|
liger_kernel/chunked_loss/orpo_loss.py,sha256=ZuKGjbkIYzV4UzvupNdq6vyxCp7-BztQkUt8ZnFvKos,3531
|
12
|
-
liger_kernel/chunked_loss/simpo_loss.py,sha256=
|
12
|
+
liger_kernel/chunked_loss/simpo_loss.py,sha256=Lb7v-a1nmapiCZGxgoWtoLRBiSLI3arFJ-WstjTqIAs,3757
|
13
13
|
liger_kernel/ops/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
14
14
|
liger_kernel/ops/cross_entropy.py,sha256=oG5hfrlmnlF5lOoZRhHRglObxgH4B0KadjWMJj9EWPM,15860
|
15
15
|
liger_kernel/ops/fused_linear_cross_entropy.py,sha256=Tnw4gyAYVVdnCOqhOuLEzbUQ3goOTnoAfk3pqSIM5ac,9301
|
@@ -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.
|
62
|
-
liger_kernel_nightly-0.5.2.
|
63
|
-
liger_kernel_nightly-0.5.2.
|
64
|
-
liger_kernel_nightly-0.5.2.
|
65
|
-
liger_kernel_nightly-0.5.2.
|
66
|
-
liger_kernel_nightly-0.5.2.
|
61
|
+
liger_kernel_nightly-0.5.2.dev20241220220835.dist-info/LICENSE,sha256=OhzLDHJ0to4a8sodVLELZiCFylZ1NAAYLs-HrjPy0ag,1312
|
62
|
+
liger_kernel_nightly-0.5.2.dev20241220220835.dist-info/METADATA,sha256=TKTsG1OaMEqrbqun7C_JsCMT3Ui6ED2G0CPLnno79QA,21055
|
63
|
+
liger_kernel_nightly-0.5.2.dev20241220220835.dist-info/NOTICE,sha256=njwnoPZLh9AN8SJQzxvCGLHi-8X__AvWRze6joNXIY8,2066
|
64
|
+
liger_kernel_nightly-0.5.2.dev20241220220835.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
65
|
+
liger_kernel_nightly-0.5.2.dev20241220220835.dist-info/top_level.txt,sha256=2eghu4hA3LnkM7ElW92tQ8zegWKgSbeo-k-aGe1YnvY,13
|
66
|
+
liger_kernel_nightly-0.5.2.dev20241220220835.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|