cciwon-code-review-cli 2.0.2 → 2.0.3
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.
- package/lib/chat-mode.js +7 -2
- package/package.json +1 -1
- package/unsloth_compiled_cache/.locks/.lock.AqlmLoraLinear_peft_forward.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.AwqLoraLinear_peft_forward.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.BatchNorm1d.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.BatchNorm2d.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.BatchNorm3d.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.Conv1d.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.Conv2d.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.Conv3d.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.ConvTranspose1d.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.ConvTranspose2d.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.ConvTranspose3d.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.GPTQLoraLinear_peft_forward.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.GroupNorm.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.LayerNorm.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.Linear4bit_peft_forward.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.Linear8bitLt_peft_forward.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.Linear_peft_forward.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.LoraParallelLinear_peft_forward.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.RMSNorm.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothBCOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothCPOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothDPOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothGKDTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothGRPOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothKTOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothNashMDTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothORPOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothOnlineDPOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothPPOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothPRMTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothRLOOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothRewardTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothSFTTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.UnslothXPOTrainer.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.unsloth_compiled_module_qwen3_moe.py +0 -0
- package/unsloth_compiled_cache/.locks/.lock.unsloth_compiled_module_siglip.py +0 -0
- package/unsloth_compiled_cache/AqlmLoraLinear_peft_forward.py +88 -0
- package/unsloth_compiled_cache/AwqLoraLinear_peft_forward.py +87 -0
- package/unsloth_compiled_cache/BatchNorm1d.py +117 -0
- package/unsloth_compiled_cache/BatchNorm2d.py +117 -0
- package/unsloth_compiled_cache/BatchNorm3d.py +117 -0
- package/unsloth_compiled_cache/Conv1d.py +70 -0
- package/unsloth_compiled_cache/Conv2d.py +70 -0
- package/unsloth_compiled_cache/Conv3d.py +70 -0
- package/unsloth_compiled_cache/ConvTranspose1d.py +97 -0
- package/unsloth_compiled_cache/ConvTranspose2d.py +106 -0
- package/unsloth_compiled_cache/ConvTranspose3d.py +98 -0
- package/unsloth_compiled_cache/GPTQLoraLinear_peft_forward.py +95 -0
- package/unsloth_compiled_cache/GroupNorm.py +70 -0
- package/unsloth_compiled_cache/LayerNorm.py +72 -0
- package/unsloth_compiled_cache/Linear4bit_peft_forward.py +115 -0
- package/unsloth_compiled_cache/Linear8bitLt_peft_forward.py +113 -0
- package/unsloth_compiled_cache/Linear_peft_forward.py +104 -0
- package/unsloth_compiled_cache/LoraParallelLinear_peft_forward.py +91 -0
- package/unsloth_compiled_cache/RMSNorm.py +73 -0
- package/unsloth_compiled_cache/UnslothBCOTrainer.py +2026 -0
- package/unsloth_compiled_cache/UnslothCPOTrainer.py +1806 -0
- package/unsloth_compiled_cache/UnslothDPOTrainer.py +2750 -0
- package/unsloth_compiled_cache/UnslothGKDTrainer.py +1157 -0
- package/unsloth_compiled_cache/UnslothGRPOTrainer.py +3607 -0
- package/unsloth_compiled_cache/UnslothKTOTrainer.py +2220 -0
- package/unsloth_compiled_cache/UnslothNashMDTrainer.py +1210 -0
- package/unsloth_compiled_cache/UnslothORPOTrainer.py +1730 -0
- package/unsloth_compiled_cache/UnslothOnlineDPOTrainer.py +2313 -0
- package/unsloth_compiled_cache/UnslothPPOTrainer.py +1504 -0
- package/unsloth_compiled_cache/UnslothPRMTrainer.py +979 -0
- package/unsloth_compiled_cache/UnslothRLOOTrainer.py +2674 -0
- package/unsloth_compiled_cache/UnslothRewardTrainer.py +1197 -0
- package/unsloth_compiled_cache/UnslothSFTTrainer.py +1416 -0
- package/unsloth_compiled_cache/UnslothXPOTrainer.py +1255 -0
- package/unsloth_compiled_cache/__pycache__/AqlmLoraLinear_peft_forward.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/AwqLoraLinear_peft_forward.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/BatchNorm1d.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/BatchNorm2d.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/BatchNorm3d.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/Conv1d.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/Conv2d.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/Conv3d.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/ConvTranspose1d.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/ConvTranspose2d.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/ConvTranspose3d.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/GPTQLoraLinear_peft_forward.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/GroupNorm.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/LayerNorm.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/Linear4bit_peft_forward.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/Linear8bitLt_peft_forward.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/Linear_peft_forward.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/LoraParallelLinear_peft_forward.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/RMSNorm.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothBCOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothCPOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothDPOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothGKDTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothGRPOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothKTOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothNashMDTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothORPOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothOnlineDPOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothPPOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothPRMTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothRLOOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothRewardTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothSFTTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/UnslothXPOTrainer.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/unsloth_compiled_module_qwen3_moe.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/__pycache__/unsloth_compiled_module_siglip.cpython-312.pyc +0 -0
- package/unsloth_compiled_cache/unsloth_compiled_module_qwen3_moe.py +726 -0
- package/unsloth_compiled_cache/unsloth_compiled_module_siglip.py +534 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""
|
|
2
|
+
2025.12.6
|
|
3
|
+
2025.12.7
|
|
4
|
+
4.57.1
|
|
5
|
+
0.24.0
|
|
6
|
+
__UNSLOTH_VERSIONING__
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Unsloth auto generated code
|
|
10
|
+
# Copyright 2023-present Daniel Han-Chen, Michael Han-Chen & the Unsloth team. All rights reserved.
|
|
11
|
+
#
|
|
12
|
+
# This program is free software: you can redistribute it and/or modify
|
|
13
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
14
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
15
|
+
# (at your option) any later version.
|
|
16
|
+
#
|
|
17
|
+
# This program is distributed in the hope that it will be useful,
|
|
18
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
# GNU General Public License for more details.
|
|
21
|
+
#
|
|
22
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
23
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
import os
|
|
27
|
+
import torch
|
|
28
|
+
import importlib.util
|
|
29
|
+
import math
|
|
30
|
+
if importlib.util.find_spec("unsloth_studio") is None:
|
|
31
|
+
UNSLOTH_STUDIO_ENABLED = False
|
|
32
|
+
else:
|
|
33
|
+
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
|
34
|
+
pass
|
|
35
|
+
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
|
36
|
+
import math
|
|
37
|
+
|
|
38
|
+
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
|
39
|
+
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
|
40
|
+
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
|
41
|
+
|
|
42
|
+
import logging
|
|
43
|
+
logger_compiler = logging.getLogger(__name__)
|
|
44
|
+
if UNSLOTH_ENABLE_LOGGING:
|
|
45
|
+
logger_compiler.setLevel(logging.DEBUG)
|
|
46
|
+
|
|
47
|
+
global INFERENCE_RUNS
|
|
48
|
+
INFERENCE_RUNS = 0
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
|
52
|
+
torch_dynamo_eval_frame._stance.stance
|
|
53
|
+
torch_compiler_set_stance = torch.compiler.set_stance
|
|
54
|
+
except:
|
|
55
|
+
torch_dynamo_eval_frame = None
|
|
56
|
+
torch_compiler_set_stance = None
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
|
60
|
+
|
|
61
|
+
torch_compile_options = {'epilogue_fusion': True, 'max_autotune': False, 'shape_padding': True, 'trace.enabled': False, 'triton.cudagraphs': False, 'debug': False, 'dce': True, 'memory_planning': True, 'coordinate_descent_tuning': False, 'trace.graph_diagram': False, 'compile_threads': 32, 'group_fusion': True, 'disable_progress': True, 'verbose_progress': False, 'triton.multi_kernel': 0, 'triton.use_block_ptr': False, 'triton.enable_persistent_tma_matmul': True, 'triton.autotune_at_compile_time': False, 'triton.cooperative_reductions': False, 'cuda.compile_opt_level': '-O2', 'cuda.enable_cuda_lto': True, 'combo_kernels': False, 'benchmark_combo_kernel': True, 'combo_kernel_foreach_dynamic_shapes': True}
|
|
62
|
+
from torch import Tensor
|
|
63
|
+
import torch
|
|
64
|
+
import torch.nn as nn
|
|
65
|
+
from torch.nn import functional as F
|
|
66
|
+
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
|
67
|
+
from transformers.models.qwen3_moe.modeling_qwen3_moe import (F)
|
|
68
|
+
|
|
69
|
+
def forward(self, input: Tensor) -> Tensor:
|
|
70
|
+
return F.layer_norm(
|
|
71
|
+
input, self.normalized_shape, self.weight, self.bias, self.eps
|
|
72
|
+
).to(input.dtype).to(input.dtype)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""
|
|
2
|
+
2025.12.6
|
|
3
|
+
2025.12.7
|
|
4
|
+
4.57.1
|
|
5
|
+
0.24.0
|
|
6
|
+
__UNSLOTH_VERSIONING__
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Unsloth auto generated code
|
|
10
|
+
# Copyright 2023-present Daniel Han-Chen, Michael Han-Chen & the Unsloth team. All rights reserved.
|
|
11
|
+
#
|
|
12
|
+
# This program is free software: you can redistribute it and/or modify
|
|
13
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
14
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
15
|
+
# (at your option) any later version.
|
|
16
|
+
#
|
|
17
|
+
# This program is distributed in the hope that it will be useful,
|
|
18
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
# GNU General Public License for more details.
|
|
21
|
+
#
|
|
22
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
23
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
torch_compile_options = {'epilogue_fusion': True, 'max_autotune': False, 'shape_padding': True, 'trace.enabled': False, 'triton.cudagraphs': False, 'debug': False, 'dce': True, 'memory_planning': True, 'coordinate_descent_tuning': False, 'trace.graph_diagram': False, 'compile_threads': 32, 'group_fusion': True, 'disable_progress': True, 'verbose_progress': False, 'triton.multi_kernel': 0, 'triton.use_block_ptr': False, 'triton.enable_persistent_tma_matmul': True, 'triton.autotune_at_compile_time': False, 'triton.cooperative_reductions': False, 'cuda.compile_opt_level': '-O2', 'cuda.enable_cuda_lto': True, 'combo_kernels': False, 'benchmark_combo_kernel': True, 'combo_kernel_foreach_dynamic_shapes': True}
|
|
27
|
+
from torch import Tensor
|
|
28
|
+
import torch
|
|
29
|
+
import torch.nn as nn
|
|
30
|
+
from torch.nn import functional as F
|
|
31
|
+
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
|
32
|
+
from peft.tuners.lora.bnb import (torch)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
torch_addmm = torch.addmm
|
|
36
|
+
torch_add = torch.add
|
|
37
|
+
# @torch.compile(fullgraph = False, dynamic = True, options = torch_compile_options)
|
|
38
|
+
def lora_forward(result, lora_A, lora_B, dropout, x, scaling):
|
|
39
|
+
# Use result.dtype (bfloat16 from base layer) since x may have been cast to float32
|
|
40
|
+
# by _cast_input_dtype when autocast is disabled
|
|
41
|
+
target_dtype = result.dtype
|
|
42
|
+
xA = dropout(x).to(target_dtype) @ lora_A.weight.to(target_dtype).t()
|
|
43
|
+
# output = result + scaling * xA @ lora_B.weight.t()
|
|
44
|
+
shape = result.shape
|
|
45
|
+
output = torch_addmm(
|
|
46
|
+
result.view(-1, shape[-1]),
|
|
47
|
+
xA.view(-1, xA.shape[-1]),
|
|
48
|
+
lora_B.weight.to(target_dtype).t(),
|
|
49
|
+
alpha = scaling,
|
|
50
|
+
beta = 1,
|
|
51
|
+
).view(shape)
|
|
52
|
+
|
|
53
|
+
bias = lora_B.bias
|
|
54
|
+
if bias is not None:
|
|
55
|
+
output = torch_add(
|
|
56
|
+
output,
|
|
57
|
+
bias.to(target_dtype),
|
|
58
|
+
alpha = scaling,
|
|
59
|
+
)
|
|
60
|
+
return output
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
def unsloth_forward(self, x: torch.Tensor, *args, **kwargs) -> torch.Tensor:
|
|
64
|
+
|
|
65
|
+
adapter_names = kwargs.pop("adapter_names", None)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if self.disable_adapters:
|
|
69
|
+
if self.merged:
|
|
70
|
+
self.unmerge()
|
|
71
|
+
result = self.base_layer(x, *args, **kwargs)
|
|
72
|
+
elif adapter_names is not None:
|
|
73
|
+
result = self._mixed_batch_forward(x, *args, adapter_names=adapter_names, **variant_kwargs, **kwargs)
|
|
74
|
+
elif self.merged:
|
|
75
|
+
result = self.base_layer(x, *args, **kwargs)
|
|
76
|
+
else:
|
|
77
|
+
result = self.base_layer(x, *args, **kwargs)
|
|
78
|
+
# As per Tim Dettmers, for 4bit, we need to defensively clone here.
|
|
79
|
+
# The reason is that in some cases, an error can occur that backprop
|
|
80
|
+
# does not work on a manipulated view. This issue may be solved with
|
|
81
|
+
# newer PyTorch versions but this would need extensive testing to be
|
|
82
|
+
# sure.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
for active_adapter in self.active_adapters:
|
|
86
|
+
if active_adapter not in self.lora_A.keys():
|
|
87
|
+
continue
|
|
88
|
+
lora_A = self.lora_A[active_adapter]
|
|
89
|
+
lora_B = self.lora_B[active_adapter]
|
|
90
|
+
dropout = self.lora_dropout[active_adapter]
|
|
91
|
+
scaling = self.scaling[active_adapter]
|
|
92
|
+
|
|
93
|
+
requires_conversion = not torch.is_autocast_enabled()
|
|
94
|
+
if requires_conversion:
|
|
95
|
+
expected_dtype = result.dtype
|
|
96
|
+
x = self._cast_input_dtype(x, lora_A.weight.dtype)
|
|
97
|
+
|
|
98
|
+
if active_adapter not in self.lora_variant: # vanilla LoRA
|
|
99
|
+
return lora_forward(result, lora_A, lora_B, dropout, x, scaling)
|
|
100
|
+
if requires_conversion:
|
|
101
|
+
output = output.to(expected_dtype)
|
|
102
|
+
result = result + output
|
|
103
|
+
else:
|
|
104
|
+
result = self.lora_variant[active_adapter].forward(
|
|
105
|
+
self,
|
|
106
|
+
active_adapter=active_adapter,
|
|
107
|
+
x=x,
|
|
108
|
+
result=result,
|
|
109
|
+
**variant_kwargs,
|
|
110
|
+
**kwargs,
|
|
111
|
+
)
|
|
112
|
+
if requires_conversion:
|
|
113
|
+
result = result.to(expected_dtype)
|
|
114
|
+
|
|
115
|
+
return result
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""
|
|
2
|
+
2025.12.6
|
|
3
|
+
2025.12.7
|
|
4
|
+
4.57.1
|
|
5
|
+
0.24.0
|
|
6
|
+
__UNSLOTH_VERSIONING__
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Unsloth auto generated code
|
|
10
|
+
# Copyright 2023-present Daniel Han-Chen, Michael Han-Chen & the Unsloth team. All rights reserved.
|
|
11
|
+
#
|
|
12
|
+
# This program is free software: you can redistribute it and/or modify
|
|
13
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
14
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
15
|
+
# (at your option) any later version.
|
|
16
|
+
#
|
|
17
|
+
# This program is distributed in the hope that it will be useful,
|
|
18
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
# GNU General Public License for more details.
|
|
21
|
+
#
|
|
22
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
23
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
torch_compile_options = {'epilogue_fusion': True, 'max_autotune': False, 'shape_padding': True, 'trace.enabled': False, 'triton.cudagraphs': False, 'debug': False, 'dce': True, 'memory_planning': True, 'coordinate_descent_tuning': False, 'trace.graph_diagram': False, 'compile_threads': 32, 'group_fusion': True, 'disable_progress': True, 'verbose_progress': False, 'triton.multi_kernel': 0, 'triton.use_block_ptr': False, 'triton.enable_persistent_tma_matmul': True, 'triton.autotune_at_compile_time': False, 'triton.cooperative_reductions': False, 'cuda.compile_opt_level': '-O2', 'cuda.enable_cuda_lto': True, 'combo_kernels': False, 'benchmark_combo_kernel': True, 'combo_kernel_foreach_dynamic_shapes': True}
|
|
27
|
+
|
|
28
|
+
import torch._dynamo
|
|
29
|
+
@torch._dynamo.disable
|
|
30
|
+
def _call_8bit_base_layer(base_layer, x, *args, **kwargs):
|
|
31
|
+
return base_layer(x, *args, **kwargs)
|
|
32
|
+
from torch import Tensor
|
|
33
|
+
import torch
|
|
34
|
+
import torch.nn as nn
|
|
35
|
+
from torch.nn import functional as F
|
|
36
|
+
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
|
37
|
+
from peft.tuners.lora.bnb import (torch)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
torch_addmm = torch.addmm
|
|
41
|
+
torch_add = torch.add
|
|
42
|
+
# @torch.compile(fullgraph = False, dynamic = True, options = torch_compile_options)
|
|
43
|
+
def lora_forward(result, lora_A, lora_B, dropout, x, scaling):
|
|
44
|
+
# Use result.dtype (bfloat16 from base layer) since x may have been cast to float32
|
|
45
|
+
# by _cast_input_dtype when autocast is disabled
|
|
46
|
+
target_dtype = result.dtype
|
|
47
|
+
xA = dropout(x).to(target_dtype) @ lora_A.weight.to(target_dtype).t()
|
|
48
|
+
# output = result + scaling * xA @ lora_B.weight.t()
|
|
49
|
+
shape = result.shape
|
|
50
|
+
output = torch_addmm(
|
|
51
|
+
result.view(-1, shape[-1]),
|
|
52
|
+
xA.view(-1, xA.shape[-1]),
|
|
53
|
+
lora_B.weight.to(target_dtype).t(),
|
|
54
|
+
alpha = scaling,
|
|
55
|
+
beta = 1,
|
|
56
|
+
).view(shape)
|
|
57
|
+
|
|
58
|
+
bias = lora_B.bias
|
|
59
|
+
if bias is not None:
|
|
60
|
+
output = torch_add(
|
|
61
|
+
output,
|
|
62
|
+
bias.to(target_dtype),
|
|
63
|
+
alpha = scaling,
|
|
64
|
+
)
|
|
65
|
+
return output
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
def unsloth_forward(self, x: torch.Tensor, *args, **kwargs) -> torch.Tensor:
|
|
69
|
+
|
|
70
|
+
adapter_names = kwargs.pop("adapter_names", None)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if self.disable_adapters:
|
|
74
|
+
if self.merged:
|
|
75
|
+
self.unmerge()
|
|
76
|
+
result = _call_8bit_base_layer(self.base_layer, x, *args, **kwargs)
|
|
77
|
+
elif adapter_names is not None:
|
|
78
|
+
result = self._mixed_batch_forward(x, *args, adapter_names=adapter_names, **variant_kwargs, **kwargs)
|
|
79
|
+
elif self.merged:
|
|
80
|
+
result = _call_8bit_base_layer(self.base_layer, x, *args, **kwargs)
|
|
81
|
+
else:
|
|
82
|
+
result = _call_8bit_base_layer(self.base_layer, x, *args, **kwargs)
|
|
83
|
+
for active_adapter in self.active_adapters:
|
|
84
|
+
if active_adapter not in self.lora_A.keys():
|
|
85
|
+
continue
|
|
86
|
+
lora_A = self.lora_A[active_adapter]
|
|
87
|
+
lora_B = self.lora_B[active_adapter]
|
|
88
|
+
dropout = self.lora_dropout[active_adapter]
|
|
89
|
+
scaling = self.scaling[active_adapter]
|
|
90
|
+
|
|
91
|
+
requires_conversion = not torch.is_autocast_enabled()
|
|
92
|
+
if requires_conversion:
|
|
93
|
+
expected_dtype = result.dtype
|
|
94
|
+
x = self._cast_input_dtype(x, lora_A.weight.dtype)
|
|
95
|
+
|
|
96
|
+
if active_adapter not in self.lora_variant: # vanilla LoRA
|
|
97
|
+
return lora_forward(result, lora_A, lora_B, dropout, x, scaling)
|
|
98
|
+
if requires_conversion:
|
|
99
|
+
output = output.to(expected_dtype)
|
|
100
|
+
result = result + output
|
|
101
|
+
else:
|
|
102
|
+
result = self.lora_variant[active_adapter].forward(
|
|
103
|
+
self,
|
|
104
|
+
active_adapter=active_adapter,
|
|
105
|
+
x=x,
|
|
106
|
+
result=result,
|
|
107
|
+
**variant_kwargs,
|
|
108
|
+
**kwargs,
|
|
109
|
+
)
|
|
110
|
+
if requires_conversion:
|
|
111
|
+
result = result.to(expected_dtype)
|
|
112
|
+
|
|
113
|
+
return result
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""
|
|
2
|
+
2025.12.6
|
|
3
|
+
2025.12.7
|
|
4
|
+
4.57.1
|
|
5
|
+
0.24.0
|
|
6
|
+
__UNSLOTH_VERSIONING__
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Unsloth auto generated code
|
|
10
|
+
# Copyright 2023-present Daniel Han-Chen, Michael Han-Chen & the Unsloth team. All rights reserved.
|
|
11
|
+
#
|
|
12
|
+
# This program is free software: you can redistribute it and/or modify
|
|
13
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
14
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
15
|
+
# (at your option) any later version.
|
|
16
|
+
#
|
|
17
|
+
# This program is distributed in the hope that it will be useful,
|
|
18
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
# GNU General Public License for more details.
|
|
21
|
+
#
|
|
22
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
23
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
torch_compile_options = {'epilogue_fusion': True, 'max_autotune': False, 'shape_padding': True, 'trace.enabled': False, 'triton.cudagraphs': False, 'debug': False, 'dce': True, 'memory_planning': True, 'coordinate_descent_tuning': False, 'trace.graph_diagram': False, 'compile_threads': 32, 'group_fusion': True, 'disable_progress': True, 'verbose_progress': False, 'triton.multi_kernel': 0, 'triton.use_block_ptr': False, 'triton.enable_persistent_tma_matmul': True, 'triton.autotune_at_compile_time': False, 'triton.cooperative_reductions': False, 'cuda.compile_opt_level': '-O2', 'cuda.enable_cuda_lto': True, 'combo_kernels': False, 'benchmark_combo_kernel': True, 'combo_kernel_foreach_dynamic_shapes': True}
|
|
27
|
+
from torch import Tensor
|
|
28
|
+
import torch
|
|
29
|
+
import torch.nn as nn
|
|
30
|
+
from torch.nn import functional as F
|
|
31
|
+
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
|
32
|
+
from peft.tuners.lora.torchao import (Any, torch)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
torch_addmm = torch.addmm
|
|
36
|
+
torch_add = torch.add
|
|
37
|
+
# @torch.compile(fullgraph = False, dynamic = True, options = torch_compile_options)
|
|
38
|
+
def lora_forward(result, lora_A, lora_B, dropout, x, scaling):
|
|
39
|
+
# Use result.dtype (bfloat16 from base layer) since x may have been cast to float32
|
|
40
|
+
# by _cast_input_dtype when autocast is disabled
|
|
41
|
+
target_dtype = result.dtype
|
|
42
|
+
xA = dropout(x).to(target_dtype) @ lora_A.weight.to(target_dtype).t()
|
|
43
|
+
# output = result + scaling * xA @ lora_B.weight.t()
|
|
44
|
+
shape = result.shape
|
|
45
|
+
output = torch_addmm(
|
|
46
|
+
result.view(-1, shape[-1]),
|
|
47
|
+
xA.view(-1, xA.shape[-1]),
|
|
48
|
+
lora_B.weight.to(target_dtype).t(),
|
|
49
|
+
alpha = scaling,
|
|
50
|
+
beta = 1,
|
|
51
|
+
).view(shape)
|
|
52
|
+
|
|
53
|
+
bias = lora_B.bias
|
|
54
|
+
if bias is not None:
|
|
55
|
+
output = torch_add(
|
|
56
|
+
output,
|
|
57
|
+
bias.to(target_dtype),
|
|
58
|
+
alpha = scaling,
|
|
59
|
+
)
|
|
60
|
+
return output
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
def unsloth_forward(self, x: torch.Tensor, *args: Any, **kwargs: Any) -> torch.Tensor:
|
|
64
|
+
|
|
65
|
+
adapter_names = kwargs.pop("adapter_names", None)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if self.disable_adapters:
|
|
69
|
+
if self.merged:
|
|
70
|
+
self.unmerge()
|
|
71
|
+
result = self.base_layer(x, *args, **kwargs)
|
|
72
|
+
elif adapter_names is not None:
|
|
73
|
+
result = self._mixed_batch_forward(x, *args, adapter_names=adapter_names, **variant_kwargs, **kwargs)
|
|
74
|
+
elif self.merged:
|
|
75
|
+
result = self.base_layer(x, *args, **kwargs)
|
|
76
|
+
else:
|
|
77
|
+
result = self.base_layer(x, *args, **kwargs)
|
|
78
|
+
torch_result_dtype = result.dtype
|
|
79
|
+
|
|
80
|
+
lora_A_keys = self.lora_A.keys()
|
|
81
|
+
for active_adapter in self.active_adapters:
|
|
82
|
+
if active_adapter not in lora_A_keys:
|
|
83
|
+
continue
|
|
84
|
+
|
|
85
|
+
lora_A = self.lora_A[active_adapter]
|
|
86
|
+
lora_B = self.lora_B[active_adapter]
|
|
87
|
+
dropout = self.lora_dropout[active_adapter]
|
|
88
|
+
scaling = self.scaling[active_adapter]
|
|
89
|
+
if not torch.is_autocast_enabled(): result, x = result.to(lora_A.weight.dtype), x.to(lora_A.weight.dtype)
|
|
90
|
+
if active_adapter not in self.lora_variant: # vanilla LoRA
|
|
91
|
+
return lora_forward(result, lora_A, lora_B, dropout, x, scaling)
|
|
92
|
+
else:
|
|
93
|
+
result = self.lora_variant[active_adapter].forward(
|
|
94
|
+
self,
|
|
95
|
+
active_adapter=active_adapter,
|
|
96
|
+
x=x,
|
|
97
|
+
result=result,
|
|
98
|
+
**variant_kwargs,
|
|
99
|
+
**kwargs,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
result = result.to(torch_result_dtype)
|
|
103
|
+
|
|
104
|
+
return result
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""
|
|
2
|
+
2025.12.6
|
|
3
|
+
2025.12.7
|
|
4
|
+
4.57.1
|
|
5
|
+
0.24.0
|
|
6
|
+
__UNSLOTH_VERSIONING__
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Unsloth auto generated code
|
|
10
|
+
# Copyright 2023-present Daniel Han-Chen, Michael Han-Chen & the Unsloth team. All rights reserved.
|
|
11
|
+
#
|
|
12
|
+
# This program is free software: you can redistribute it and/or modify
|
|
13
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
14
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
15
|
+
# (at your option) any later version.
|
|
16
|
+
#
|
|
17
|
+
# This program is distributed in the hope that it will be useful,
|
|
18
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
# GNU General Public License for more details.
|
|
21
|
+
#
|
|
22
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
23
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
torch_compile_options = {'epilogue_fusion': True, 'max_autotune': False, 'shape_padding': True, 'trace.enabled': False, 'triton.cudagraphs': False, 'debug': False, 'dce': True, 'memory_planning': True, 'coordinate_descent_tuning': False, 'trace.graph_diagram': False, 'compile_threads': 32, 'group_fusion': True, 'disable_progress': True, 'verbose_progress': False, 'triton.multi_kernel': 0, 'triton.use_block_ptr': False, 'triton.enable_persistent_tma_matmul': True, 'triton.autotune_at_compile_time': False, 'triton.cooperative_reductions': False, 'cuda.compile_opt_level': '-O2', 'cuda.enable_cuda_lto': True, 'combo_kernels': False, 'benchmark_combo_kernel': True, 'combo_kernel_foreach_dynamic_shapes': True}
|
|
27
|
+
from torch import Tensor
|
|
28
|
+
import torch
|
|
29
|
+
import torch.nn as nn
|
|
30
|
+
from torch.nn import functional as F
|
|
31
|
+
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
|
32
|
+
from peft.tuners.lora.tp_layer import (Any, __name__, torch)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
torch_addmm = torch.addmm
|
|
36
|
+
torch_add = torch.add
|
|
37
|
+
# @torch.compile(fullgraph = False, dynamic = True, options = torch_compile_options)
|
|
38
|
+
def lora_forward(result, lora_A, lora_B, dropout, x, scaling):
|
|
39
|
+
# Use result.dtype (bfloat16 from base layer) since x may have been cast to float32
|
|
40
|
+
# by _cast_input_dtype when autocast is disabled
|
|
41
|
+
target_dtype = result.dtype
|
|
42
|
+
xA = dropout(x).to(target_dtype) @ lora_A.weight.to(target_dtype).t()
|
|
43
|
+
# output = result + scaling * xA @ lora_B.weight.t()
|
|
44
|
+
shape = result.shape
|
|
45
|
+
output = torch_addmm(
|
|
46
|
+
result.view(-1, shape[-1]),
|
|
47
|
+
xA.view(-1, xA.shape[-1]),
|
|
48
|
+
lora_B.weight.to(target_dtype).t(),
|
|
49
|
+
alpha = scaling,
|
|
50
|
+
beta = 1,
|
|
51
|
+
).view(shape)
|
|
52
|
+
|
|
53
|
+
bias = lora_B.bias
|
|
54
|
+
if bias is not None:
|
|
55
|
+
output = torch_add(
|
|
56
|
+
output,
|
|
57
|
+
bias.to(target_dtype),
|
|
58
|
+
alpha = scaling,
|
|
59
|
+
)
|
|
60
|
+
return output
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
def unsloth_forward(self, x: torch.Tensor, *args: Any, **kwargs: Any):
|
|
64
|
+
|
|
65
|
+
adapter_names = kwargs.pop("adapter_names", None)
|
|
66
|
+
# If weight is used for matrix multiplication here, the final aggregation operation of the original
|
|
67
|
+
# parallel_linear layer will be missing, so we need to directly call its forward function to obtain the
|
|
68
|
+
# output of the original parallel_linear layer.
|
|
69
|
+
if self.disable_adapters:
|
|
70
|
+
if self.merged:
|
|
71
|
+
self.unmerge()
|
|
72
|
+
result, bias = self.base_layer(x, *args, **kwargs)
|
|
73
|
+
elif adapter_names is not None:
|
|
74
|
+
raise ValueError(f"{self.__class__.__name__} does not support mixed_batch_forward yet.")
|
|
75
|
+
elif self.merged:
|
|
76
|
+
result, bias = self.base_layer(x, *args, **kwargs)
|
|
77
|
+
else:
|
|
78
|
+
result, bias = self.base_layer(x, *args, **kwargs)
|
|
79
|
+
torch_result_dtype = result.dtype
|
|
80
|
+
for active_adapter in self.active_adapters:
|
|
81
|
+
if active_adapter not in self.lora_A.keys():
|
|
82
|
+
continue
|
|
83
|
+
lora_A = self.lora_A[active_adapter]
|
|
84
|
+
lora_B = self.lora_B[active_adapter]
|
|
85
|
+
dropout = self.lora_dropout[active_adapter]
|
|
86
|
+
scaling = self.scaling[active_adapter]
|
|
87
|
+
if not torch.is_autocast_enabled(): result, x = result.to(lora_A.weight.dtype), x.to(lora_A.weight.dtype)
|
|
88
|
+
return lora_forward(result, lora_A, lora_B, dropout, x, scaling)
|
|
89
|
+
|
|
90
|
+
result = result.to(torch_result_dtype)
|
|
91
|
+
return result, bias
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""
|
|
2
|
+
2025.12.6
|
|
3
|
+
2025.12.7
|
|
4
|
+
4.57.1
|
|
5
|
+
0.24.0
|
|
6
|
+
__UNSLOTH_VERSIONING__
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# Unsloth auto generated code
|
|
10
|
+
# Copyright 2023-present Daniel Han-Chen, Michael Han-Chen & the Unsloth team. All rights reserved.
|
|
11
|
+
#
|
|
12
|
+
# This program is free software: you can redistribute it and/or modify
|
|
13
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
14
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
15
|
+
# (at your option) any later version.
|
|
16
|
+
#
|
|
17
|
+
# This program is distributed in the hope that it will be useful,
|
|
18
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
+
# GNU General Public License for more details.
|
|
21
|
+
#
|
|
22
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
23
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
import os
|
|
27
|
+
import torch
|
|
28
|
+
import importlib.util
|
|
29
|
+
import math
|
|
30
|
+
if importlib.util.find_spec("unsloth_studio") is None:
|
|
31
|
+
UNSLOTH_STUDIO_ENABLED = False
|
|
32
|
+
else:
|
|
33
|
+
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
|
34
|
+
pass
|
|
35
|
+
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
|
36
|
+
import math
|
|
37
|
+
|
|
38
|
+
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
|
39
|
+
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
|
40
|
+
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
|
41
|
+
|
|
42
|
+
import logging
|
|
43
|
+
logger_compiler = logging.getLogger(__name__)
|
|
44
|
+
if UNSLOTH_ENABLE_LOGGING:
|
|
45
|
+
logger_compiler.setLevel(logging.DEBUG)
|
|
46
|
+
|
|
47
|
+
global INFERENCE_RUNS
|
|
48
|
+
INFERENCE_RUNS = 0
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
|
52
|
+
torch_dynamo_eval_frame._stance.stance
|
|
53
|
+
torch_compiler_set_stance = torch.compiler.set_stance
|
|
54
|
+
except:
|
|
55
|
+
torch_dynamo_eval_frame = None
|
|
56
|
+
torch_compiler_set_stance = None
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
|
60
|
+
|
|
61
|
+
torch_compile_options = {'epilogue_fusion': True, 'max_autotune': False, 'shape_padding': True, 'trace.enabled': False, 'triton.cudagraphs': False, 'debug': False, 'dce': True, 'memory_planning': True, 'coordinate_descent_tuning': False, 'trace.graph_diagram': False, 'compile_threads': 32, 'group_fusion': True, 'disable_progress': True, 'verbose_progress': False, 'triton.multi_kernel': 0, 'triton.use_block_ptr': False, 'triton.enable_persistent_tma_matmul': True, 'triton.autotune_at_compile_time': False, 'triton.cooperative_reductions': False, 'cuda.compile_opt_level': '-O2', 'cuda.enable_cuda_lto': True, 'combo_kernels': False, 'benchmark_combo_kernel': True, 'combo_kernel_foreach_dynamic_shapes': True}
|
|
62
|
+
from torch import Tensor
|
|
63
|
+
import torch
|
|
64
|
+
import torch.nn as nn
|
|
65
|
+
from torch.nn import functional as F
|
|
66
|
+
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
|
67
|
+
from transformers.models.qwen3_moe.modeling_qwen3_moe import (F, torch)
|
|
68
|
+
|
|
69
|
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
70
|
+
"""
|
|
71
|
+
Runs the forward pass.
|
|
72
|
+
"""
|
|
73
|
+
return F.rms_norm(x, self.normalized_shape, self.weight, self.eps).to(input.dtype).to(input.dtype)
|