liger-kernel-nightly 0.4.2.dev20241119223206__py3-none-any.whl → 0.4.2.dev20241121054604__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.
- liger_kernel/chunked_loss/__init__.py +4 -0
- liger_kernel/chunked_loss/cpo_loss.py +41 -1
- liger_kernel/chunked_loss/dpo_loss.py +38 -1
- liger_kernel/chunked_loss/functional.py +9 -0
- liger_kernel/chunked_loss/fused_linear_preference.py +1 -1
- liger_kernel/chunked_loss/orpo_loss.py +38 -2
- liger_kernel/chunked_loss/simpo_loss.py +43 -0
- {liger_kernel_nightly-0.4.2.dev20241119223206.dist-info → liger_kernel_nightly-0.4.2.dev20241121054604.dist-info}/METADATA +1 -1
- {liger_kernel_nightly-0.4.2.dev20241119223206.dist-info → liger_kernel_nightly-0.4.2.dev20241121054604.dist-info}/RECORD +13 -12
- {liger_kernel_nightly-0.4.2.dev20241119223206.dist-info → liger_kernel_nightly-0.4.2.dev20241121054604.dist-info}/LICENSE +0 -0
- {liger_kernel_nightly-0.4.2.dev20241119223206.dist-info → liger_kernel_nightly-0.4.2.dev20241121054604.dist-info}/NOTICE +0 -0
- {liger_kernel_nightly-0.4.2.dev20241119223206.dist-info → liger_kernel_nightly-0.4.2.dev20241121054604.dist-info}/WHEEL +0 -0
- {liger_kernel_nightly-0.4.2.dev20241119223206.dist-info → liger_kernel_nightly-0.4.2.dev20241121054604.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,4 @@
|
|
1
|
+
from liger_kernel.chunked_loss.cpo_loss import LigerFusedLinearCPOLoss # noqa: F401
|
2
|
+
from liger_kernel.chunked_loss.dpo_loss import LigerFusedLinearDPOLoss # noqa: F401
|
3
|
+
from liger_kernel.chunked_loss.orpo_loss import LigerFusedLinearORPOLoss # noqa: F401
|
4
|
+
from liger_kernel.chunked_loss.simpo_loss import LigerFusedLinearSimPOLoss # noqa: F401
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import torch
|
1
2
|
import torch.nn.functional as F
|
2
3
|
|
3
4
|
from liger_kernel.chunked_loss.fused_linear_preference import (
|
@@ -46,10 +47,10 @@ class LigerFusedLinearCPOFunction(LigerFusedLinearPreferenceBase):
|
|
46
47
|
target,
|
47
48
|
bias,
|
48
49
|
loss_fn=LigerFusedLinearCPOFunction.preference_loss_fn,
|
49
|
-
compute_nll_loss=compute_nll_loss,
|
50
50
|
ignore_index=ignore_index,
|
51
51
|
alpha=alpha,
|
52
52
|
beta=beta,
|
53
|
+
compute_nll_loss=compute_nll_loss,
|
53
54
|
compiled=compiled,
|
54
55
|
)
|
55
56
|
|
@@ -59,3 +60,42 @@ class LigerFusedLinearCPOFunction(LigerFusedLinearPreferenceBase):
|
|
59
60
|
grads = LigerFusedLinearPreferenceBase.backward(ctx, grad_output)[:4]
|
60
61
|
# Return these gradients, followed by None for the remaining inputs
|
61
62
|
return *grads, None, None, None, None, None
|
63
|
+
|
64
|
+
|
65
|
+
class LigerFusedLinearCPOLoss(torch.nn.Module):
|
66
|
+
"""
|
67
|
+
Fused linear layer with CPO loss.
|
68
|
+
"""
|
69
|
+
|
70
|
+
def __init__(
|
71
|
+
self,
|
72
|
+
ignore_index: int = -100,
|
73
|
+
beta: float = 0.1,
|
74
|
+
alpha: float = 1.0,
|
75
|
+
compute_nll_loss: bool = True,
|
76
|
+
compiled: bool = True,
|
77
|
+
):
|
78
|
+
"""
|
79
|
+
Args:
|
80
|
+
ignore_index (int): Index to ignore in the loss.
|
81
|
+
beta (float): Weight for the odds ratio loss.
|
82
|
+
"""
|
83
|
+
super().__init__()
|
84
|
+
self.ignore_index = ignore_index
|
85
|
+
self.beta = beta
|
86
|
+
self.alpha = alpha
|
87
|
+
self.compute_nll_loss = compute_nll_loss
|
88
|
+
self.compiled = compiled
|
89
|
+
|
90
|
+
def forward(self, lin_weight, _input, target, bias=None):
|
91
|
+
return LigerFusedLinearCPOFunction.apply(
|
92
|
+
_input,
|
93
|
+
lin_weight,
|
94
|
+
target,
|
95
|
+
bias,
|
96
|
+
self.ignore_index,
|
97
|
+
self.beta,
|
98
|
+
self.alpha,
|
99
|
+
self.compute_nll_loss,
|
100
|
+
self.compiled,
|
101
|
+
)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import torch
|
1
2
|
import torch.nn.functional as F
|
2
3
|
|
3
4
|
from liger_kernel.chunked_loss.fused_linear_preference import (
|
@@ -43,9 +44,9 @@ class LigerFusedLinearDPOFunction(LigerFusedLinearPreferenceBase):
|
|
43
44
|
target=target,
|
44
45
|
bias=bias,
|
45
46
|
loss_fn=LigerFusedLinearDPOFunction.preference_loss_fn,
|
46
|
-
compute_nll_loss=compute_nll_loss,
|
47
47
|
ignore_index=ignore_index,
|
48
48
|
beta=beta,
|
49
|
+
compute_nll_loss=compute_nll_loss,
|
49
50
|
compiled=compiled,
|
50
51
|
)
|
51
52
|
|
@@ -55,3 +56,39 @@ class LigerFusedLinearDPOFunction(LigerFusedLinearPreferenceBase):
|
|
55
56
|
grads = LigerFusedLinearPreferenceBase.backward(ctx, grad_output)[:4]
|
56
57
|
# Return these gradients, followed by None for the remaining inputs
|
57
58
|
return *grads, None, None, None, None
|
59
|
+
|
60
|
+
|
61
|
+
class LigerFusedLinearDPOLoss(torch.nn.Module):
|
62
|
+
"""
|
63
|
+
Fused linear layer with DPO loss.
|
64
|
+
"""
|
65
|
+
|
66
|
+
def __init__(
|
67
|
+
self,
|
68
|
+
ignore_index: int = -100,
|
69
|
+
beta: float = 0.1,
|
70
|
+
compute_nll_loss: bool = True,
|
71
|
+
compiled: bool = True,
|
72
|
+
):
|
73
|
+
"""
|
74
|
+
Args:
|
75
|
+
ignore_index (int): Index to ignore in the loss.
|
76
|
+
beta (float): Weight for the odds ratio loss.
|
77
|
+
"""
|
78
|
+
super().__init__()
|
79
|
+
self.ignore_index = ignore_index
|
80
|
+
self.beta = beta
|
81
|
+
self.compute_nll_loss = compute_nll_loss
|
82
|
+
self.compiled = compiled
|
83
|
+
|
84
|
+
def forward(self, lin_weight, _input, target, bias=None):
|
85
|
+
return LigerFusedLinearDPOFunction.apply(
|
86
|
+
_input,
|
87
|
+
lin_weight,
|
88
|
+
target,
|
89
|
+
bias,
|
90
|
+
self.ignore_index,
|
91
|
+
self.beta,
|
92
|
+
self.compute_nll_loss,
|
93
|
+
self.compiled,
|
94
|
+
)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from liger_kernel.chunked_loss.cpo_loss import LigerFusedLinearCPOFunction
|
2
|
+
from liger_kernel.chunked_loss.dpo_loss import LigerFusedLinearDPOFunction
|
3
|
+
from liger_kernel.chunked_loss.orpo_loss import LigerFusedLinearORPOFunction
|
4
|
+
from liger_kernel.chunked_loss.simpo_loss import LigerFusedLinearSimPOFunction
|
5
|
+
|
6
|
+
liger_fused_linear_orpo = LigerFusedLinearORPOFunction.apply
|
7
|
+
liger_fused_linear_dpo = LigerFusedLinearDPOFunction.apply
|
8
|
+
liger_fused_linear_cpo = LigerFusedLinearCPOFunction.apply
|
9
|
+
liger_fused_linear_simpo = LigerFusedLinearSimPOFunction.apply
|
@@ -27,10 +27,10 @@ class LigerFusedLinearPreferenceBase(torch.autograd.Function):
|
|
27
27
|
bias=None,
|
28
28
|
loss_fn=None,
|
29
29
|
chunk_size=1,
|
30
|
-
compute_nll_loss=True,
|
31
30
|
ignore_index=-100,
|
32
31
|
alpha=1.0,
|
33
32
|
beta=0.1,
|
33
|
+
compute_nll_loss=True,
|
34
34
|
compiled=True,
|
35
35
|
**loss_kwargs,
|
36
36
|
):
|
@@ -34,7 +34,7 @@ class LigerFusedLinearORPOFunction(LigerFusedLinearPreferenceBase):
|
|
34
34
|
ignore_index=-100,
|
35
35
|
beta=0.1,
|
36
36
|
compute_nll_loss=True,
|
37
|
-
compiled=
|
37
|
+
compiled=True,
|
38
38
|
):
|
39
39
|
"""
|
40
40
|
Fused linear layer with ORPO (Odds-Ratio Preference Optimization) loss.
|
@@ -49,9 +49,9 @@ class LigerFusedLinearORPOFunction(LigerFusedLinearPreferenceBase):
|
|
49
49
|
target=target,
|
50
50
|
bias=bias,
|
51
51
|
loss_fn=LigerFusedLinearORPOFunction.preference_loss_fn,
|
52
|
-
compute_nll_loss=compute_nll_loss,
|
53
52
|
ignore_index=ignore_index,
|
54
53
|
beta=beta,
|
54
|
+
compute_nll_loss=compute_nll_loss,
|
55
55
|
compiled=compiled,
|
56
56
|
)
|
57
57
|
|
@@ -61,3 +61,39 @@ class LigerFusedLinearORPOFunction(LigerFusedLinearPreferenceBase):
|
|
61
61
|
grads = LigerFusedLinearPreferenceBase.backward(ctx, grad_output)[:4]
|
62
62
|
# Return these gradients, followed by None for the remaining inputs
|
63
63
|
return *grads, None, None, None, None
|
64
|
+
|
65
|
+
|
66
|
+
class LigerFusedLinearORPOLoss(torch.nn.Module):
|
67
|
+
"""
|
68
|
+
Fused linear layer with ORPO (Odds-Ratio Preference Optimization) loss.
|
69
|
+
"""
|
70
|
+
|
71
|
+
def __init__(
|
72
|
+
self,
|
73
|
+
ignore_index: int = -100,
|
74
|
+
beta: float = 0.1,
|
75
|
+
compute_nll_loss: bool = True,
|
76
|
+
compiled: bool = True,
|
77
|
+
):
|
78
|
+
"""
|
79
|
+
Args:
|
80
|
+
ignore_index (int): Index to ignore in the loss.
|
81
|
+
beta (float): Weight for the odds ratio loss.
|
82
|
+
"""
|
83
|
+
super().__init__()
|
84
|
+
self.ignore_index = ignore_index
|
85
|
+
self.beta = beta
|
86
|
+
self.compute_nll_loss = compute_nll_loss
|
87
|
+
self.compiled = compiled
|
88
|
+
|
89
|
+
def forward(self, lin_weight, _input, target, bias=None):
|
90
|
+
return LigerFusedLinearORPOFunction.apply(
|
91
|
+
_input,
|
92
|
+
lin_weight,
|
93
|
+
target,
|
94
|
+
bias,
|
95
|
+
self.ignore_index,
|
96
|
+
self.beta,
|
97
|
+
self.compute_nll_loss,
|
98
|
+
self.compiled,
|
99
|
+
)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import torch
|
1
2
|
import torch.nn.functional as F
|
2
3
|
|
3
4
|
from liger_kernel.chunked_loss.fused_linear_preference import (
|
@@ -62,3 +63,45 @@ class LigerFusedLinearSimPOFunction(LigerFusedLinearPreferenceBase):
|
|
62
63
|
grads = LigerFusedLinearPreferenceBase.backward(ctx, grad_output)[:4]
|
63
64
|
# Return these gradients, followed by None for the remaining inputs
|
64
65
|
return *grads, None, None, None, None, None, None
|
66
|
+
|
67
|
+
|
68
|
+
class LigerFusedLinearSimPOLoss(torch.nn.Module):
|
69
|
+
"""
|
70
|
+
Fused linear layer with SimPO loss.
|
71
|
+
"""
|
72
|
+
|
73
|
+
def __init__(
|
74
|
+
self,
|
75
|
+
ignore_index: int = -100,
|
76
|
+
beta: float = 0.1,
|
77
|
+
alpha: float = 1.0,
|
78
|
+
compute_nll_loss: bool = True,
|
79
|
+
compiled: bool = True,
|
80
|
+
gamma: float = 0.5,
|
81
|
+
):
|
82
|
+
"""
|
83
|
+
Args:
|
84
|
+
ignore_index (int): Index to ignore in the loss.
|
85
|
+
beta (float): Weight for the odds ratio loss.
|
86
|
+
"""
|
87
|
+
super().__init__()
|
88
|
+
self.ignore_index = ignore_index
|
89
|
+
self.beta = beta
|
90
|
+
self.alpha = alpha
|
91
|
+
self.compute_nll_loss = compute_nll_loss
|
92
|
+
self.compiled = compiled
|
93
|
+
self.gamma = gamma
|
94
|
+
|
95
|
+
def forward(self, lin_weight, _input, target, bias=None):
|
96
|
+
return LigerFusedLinearSimPOFunction.apply(
|
97
|
+
_input,
|
98
|
+
lin_weight,
|
99
|
+
target,
|
100
|
+
bias,
|
101
|
+
self.ignore_index,
|
102
|
+
self.beta,
|
103
|
+
self.alpha,
|
104
|
+
self.compute_nll_loss,
|
105
|
+
self.compiled,
|
106
|
+
self.gamma,
|
107
|
+
)
|
@@ -1,10 +1,11 @@
|
|
1
1
|
liger_kernel/env_report.py,sha256=jye8RvUkmhqaIshdeIpoUABoAu7FPKJUib4FnAfvkpw,1132
|
2
|
-
liger_kernel/chunked_loss/__init__.py,sha256=
|
3
|
-
liger_kernel/chunked_loss/cpo_loss.py,sha256=
|
4
|
-
liger_kernel/chunked_loss/dpo_loss.py,sha256=
|
5
|
-
liger_kernel/chunked_loss/
|
6
|
-
liger_kernel/chunked_loss/
|
7
|
-
liger_kernel/chunked_loss/
|
2
|
+
liger_kernel/chunked_loss/__init__.py,sha256=R2wCcz4Y0kTAve926DH3k182XKezpXeACMHj05g9Mm8,346
|
3
|
+
liger_kernel/chunked_loss/cpo_loss.py,sha256=H2L6mNtU8RMJ17u4aMZ9FHEfBvg1Z_hliY5-jZxiDBM,3079
|
4
|
+
liger_kernel/chunked_loss/dpo_loss.py,sha256=Y6NIU93D_QrhcxXU8Z8zNliqCFAIeQARnNBhUdbX8_w,2884
|
5
|
+
liger_kernel/chunked_loss/functional.py,sha256=9Gr-YXIuEzEJkBUhDx3G2fuQayckLor7cC7svhmPML4,549
|
6
|
+
liger_kernel/chunked_loss/fused_linear_preference.py,sha256=AXr7oHCoca2feYSCmlSAJq8mndm09ky0-kcQOAdcc6k,8727
|
7
|
+
liger_kernel/chunked_loss/orpo_loss.py,sha256=DZ-_hm1twllBWujEV4M4-VDBkxMDBvoGqMGe-aGP1hA,3147
|
8
|
+
liger_kernel/chunked_loss/simpo_loss.py,sha256=Jpl_U6DfxlzyHnlKN2i05K0vwz-ouiTmxlLGb439FwY,3328
|
8
9
|
liger_kernel/ops/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
10
|
liger_kernel/ops/cross_entropy.py,sha256=sfUb7-jIZp0EKXjg1DYy2Wdzw_Mg-mHmGoR5bpdm4tw,15526
|
10
11
|
liger_kernel/ops/fused_linear_cross_entropy.py,sha256=ib7M3AjJE164yMfuS9R39k-5qnDgYOXptIT146lqYbg,9964
|
@@ -51,9 +52,9 @@ liger_kernel/transformers/model/qwen2.py,sha256=EyhSSzQOskGjSnCsKMZpd1s5IAIlHd5P
|
|
51
52
|
liger_kernel/transformers/model/qwen2_vl.py,sha256=bIQe2bWiY--G84FhCD29Gdi64_qHP6vbcGsK6vKysQE,8547
|
52
53
|
liger_kernel/triton/__init__.py,sha256=yfRe0zMb47QnqjecZWG7LnanfCTzeku7SgWRAwNVmzU,101
|
53
54
|
liger_kernel/triton/monkey_patch.py,sha256=5BcGKTtdqeYchypBIBopGIWPx1-cFALz7sOKoEsqXJ0,1584
|
54
|
-
liger_kernel_nightly-0.4.2.
|
55
|
-
liger_kernel_nightly-0.4.2.
|
56
|
-
liger_kernel_nightly-0.4.2.
|
57
|
-
liger_kernel_nightly-0.4.2.
|
58
|
-
liger_kernel_nightly-0.4.2.
|
59
|
-
liger_kernel_nightly-0.4.2.
|
55
|
+
liger_kernel_nightly-0.4.2.dev20241121054604.dist-info/LICENSE,sha256=OhzLDHJ0to4a8sodVLELZiCFylZ1NAAYLs-HrjPy0ag,1312
|
56
|
+
liger_kernel_nightly-0.4.2.dev20241121054604.dist-info/METADATA,sha256=JFMw-oIVSlNwaCh7Fi2x1Q-JdLAOK_s9qxkV4idrGEQ,21723
|
57
|
+
liger_kernel_nightly-0.4.2.dev20241121054604.dist-info/NOTICE,sha256=njwnoPZLh9AN8SJQzxvCGLHi-8X__AvWRze6joNXIY8,2066
|
58
|
+
liger_kernel_nightly-0.4.2.dev20241121054604.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
59
|
+
liger_kernel_nightly-0.4.2.dev20241121054604.dist-info/top_level.txt,sha256=2eghu4hA3LnkM7ElW92tQ8zegWKgSbeo-k-aGe1YnvY,13
|
60
|
+
liger_kernel_nightly-0.4.2.dev20241121054604.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|