Delete folder training/unsloth_compiled_cache with huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- training/unsloth_compiled_cache/.locks/.lock.AqlmLoraLinear_peft_forward.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.AwqLoraLinear_peft_forward.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.BatchNorm1d.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.BatchNorm2d.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.BatchNorm3d.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.BlockDiagonalLinear_peft_forward.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.Conv1d.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.Conv2d.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.Conv3d.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.ConvTranspose1d.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.ConvTranspose2d.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.ConvTranspose3d.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.GPTQLoraLinear_peft_forward.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.GroupNorm.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.LayerNorm.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.Linear4bit_peft_forward.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.Linear8bitLt_peft_forward.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.Linear_peft_forward.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.LoraParallelLinear_peft_forward.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.RMSNorm.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.TeLinear_peft_forward.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothCPOTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothDPOTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothDistillationTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothGKDTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothGOLDTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothGRPOTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothKTOTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothORPOTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothOnlineDPOTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothRLOOTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothRewardTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothSDFTTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothSFTTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.UnslothServerDistillationTrainer.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.unsloth_compiled_module_gemma4.py +0 -0
- training/unsloth_compiled_cache/.locks/.lock.unsloth_compiled_module_siglip.py +0 -0
- training/unsloth_compiled_cache/AqlmLoraLinear_peft_forward.py +0 -99
- training/unsloth_compiled_cache/AwqLoraLinear_peft_forward.py +0 -98
- training/unsloth_compiled_cache/BatchNorm1d.py +0 -151
- training/unsloth_compiled_cache/BatchNorm2d.py +0 -151
- training/unsloth_compiled_cache/BatchNorm3d.py +0 -151
- training/unsloth_compiled_cache/BlockDiagonalLinear_peft_forward.py +0 -85
- training/unsloth_compiled_cache/Conv1d.py +0 -104
- training/unsloth_compiled_cache/Conv2d.py +0 -104
- training/unsloth_compiled_cache/Conv3d.py +0 -104
- training/unsloth_compiled_cache/ConvTranspose1d.py +0 -132
- training/unsloth_compiled_cache/ConvTranspose2d.py +0 -141
- training/unsloth_compiled_cache/ConvTranspose3d.py +0 -133
- training/unsloth_compiled_cache/GPTQLoraLinear_peft_forward.py +0 -106
training/unsloth_compiled_cache/.locks/.lock.AqlmLoraLinear_peft_forward.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.AwqLoraLinear_peft_forward.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.BatchNorm1d.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.BatchNorm2d.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.BatchNorm3d.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.BlockDiagonalLinear_peft_forward.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.Conv1d.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.Conv2d.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.Conv3d.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.ConvTranspose1d.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.ConvTranspose2d.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.ConvTranspose3d.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.GPTQLoraLinear_peft_forward.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.GroupNorm.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.LayerNorm.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.Linear4bit_peft_forward.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.Linear8bitLt_peft_forward.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.Linear_peft_forward.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.LoraParallelLinear_peft_forward.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.RMSNorm.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.TeLinear_peft_forward.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothCPOTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothDPOTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothDistillationTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothGKDTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothGOLDTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothGRPOTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothKTOTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothORPOTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothOnlineDPOTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothRLOOTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothRewardTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothSDFTTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothSFTTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.UnslothServerDistillationTrainer.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.unsloth_compiled_module_gemma4.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/.locks/.lock.unsloth_compiled_module_siglip.py
DELETED
|
File without changes
|
training/unsloth_compiled_cache/AqlmLoraLinear_peft_forward.py
DELETED
|
@@ -1,99 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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': False, '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 unsloth_zoo.temporary_patches.common import torch_compile
|
| 32 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 33 |
-
from peft.tuners.lora.aqlm import (torch)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
torch_addmm = torch.addmm
|
| 37 |
-
torch_add = torch.add
|
| 38 |
-
torch_is_compiling = torch.compiler.is_compiling
|
| 39 |
-
# torch 2.8 / 2.9 inductor miscompiles addmm(alpha = scaling, beta = 1) traced inside a
|
| 40 |
-
# compiled block (e.g. the VLM decoder MLP), forward and backward; fixed in 2.10 (unsloth#3271).
|
| 41 |
-
torch_lora_no_compiled_addmm = tuple(int(v) for v in torch.__version__.split(".")[:2]) < (2, 10)
|
| 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 |
-
if torch_lora_no_compiled_addmm and torch_is_compiling():
|
| 49 |
-
output = result + scaling * (xA @ lora_B.weight.to(target_dtype).t())
|
| 50 |
-
bias = lora_B.bias
|
| 51 |
-
if bias is not None:
|
| 52 |
-
output = output + scaling * bias.to(target_dtype)
|
| 53 |
-
return output
|
| 54 |
-
# output = result + scaling * xA @ lora_B.weight.t()
|
| 55 |
-
shape = result.shape
|
| 56 |
-
output = torch_addmm(
|
| 57 |
-
result.view(-1, shape[-1]),
|
| 58 |
-
xA.view(-1, xA.shape[-1]),
|
| 59 |
-
lora_B.weight.to(target_dtype).t(),
|
| 60 |
-
alpha = scaling,
|
| 61 |
-
beta = 1,
|
| 62 |
-
).view(shape)
|
| 63 |
-
|
| 64 |
-
bias = lora_B.bias
|
| 65 |
-
if bias is not None:
|
| 66 |
-
output = torch_add(
|
| 67 |
-
output,
|
| 68 |
-
bias.to(target_dtype),
|
| 69 |
-
alpha = scaling,
|
| 70 |
-
)
|
| 71 |
-
return output
|
| 72 |
-
pass
|
| 73 |
-
|
| 74 |
-
def unsloth_forward(self, x: torch.Tensor):
|
| 75 |
-
# note: logic differs from default Linear because merging is not supported
|
| 76 |
-
result = self.base_layer(x)
|
| 77 |
-
|
| 78 |
-
if self.disable_adapters:
|
| 79 |
-
return result
|
| 80 |
-
|
| 81 |
-
for active_adapter in self.active_adapters:
|
| 82 |
-
if active_adapter not in self.lora_A.keys():
|
| 83 |
-
continue
|
| 84 |
-
lora_A = self.lora_A[active_adapter]
|
| 85 |
-
lora_B = self.lora_B[active_adapter]
|
| 86 |
-
dropout = self.lora_dropout[active_adapter]
|
| 87 |
-
scaling = self.scaling[active_adapter]
|
| 88 |
-
|
| 89 |
-
requires_conversion = not torch.is_autocast_enabled()
|
| 90 |
-
if requires_conversion:
|
| 91 |
-
expected_dtype = result.dtype
|
| 92 |
-
x = self._cast_input_dtype(x, lora_A.weight.dtype)
|
| 93 |
-
|
| 94 |
-
output = lora_B(lora_A(dropout(x)))
|
| 95 |
-
if requires_conversion:
|
| 96 |
-
output = output.to(expected_dtype)
|
| 97 |
-
output = output * scaling
|
| 98 |
-
result += output
|
| 99 |
-
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/AwqLoraLinear_peft_forward.py
DELETED
|
@@ -1,98 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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': False, '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 unsloth_zoo.temporary_patches.common import torch_compile
|
| 32 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 33 |
-
from peft.tuners.lora.awq import (torch)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
torch_addmm = torch.addmm
|
| 37 |
-
torch_add = torch.add
|
| 38 |
-
torch_is_compiling = torch.compiler.is_compiling
|
| 39 |
-
# torch 2.8 / 2.9 inductor miscompiles addmm(alpha = scaling, beta = 1) traced inside a
|
| 40 |
-
# compiled block (e.g. the VLM decoder MLP), forward and backward; fixed in 2.10 (unsloth#3271).
|
| 41 |
-
torch_lora_no_compiled_addmm = tuple(int(v) for v in torch.__version__.split(".")[:2]) < (2, 10)
|
| 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 |
-
if torch_lora_no_compiled_addmm and torch_is_compiling():
|
| 49 |
-
output = result + scaling * (xA @ lora_B.weight.to(target_dtype).t())
|
| 50 |
-
bias = lora_B.bias
|
| 51 |
-
if bias is not None:
|
| 52 |
-
output = output + scaling * bias.to(target_dtype)
|
| 53 |
-
return output
|
| 54 |
-
# output = result + scaling * xA @ lora_B.weight.t()
|
| 55 |
-
shape = result.shape
|
| 56 |
-
output = torch_addmm(
|
| 57 |
-
result.view(-1, shape[-1]),
|
| 58 |
-
xA.view(-1, xA.shape[-1]),
|
| 59 |
-
lora_B.weight.to(target_dtype).t(),
|
| 60 |
-
alpha = scaling,
|
| 61 |
-
beta = 1,
|
| 62 |
-
).view(shape)
|
| 63 |
-
|
| 64 |
-
bias = lora_B.bias
|
| 65 |
-
if bias is not None:
|
| 66 |
-
output = torch_add(
|
| 67 |
-
output,
|
| 68 |
-
bias.to(target_dtype),
|
| 69 |
-
alpha = scaling,
|
| 70 |
-
)
|
| 71 |
-
return output
|
| 72 |
-
pass
|
| 73 |
-
|
| 74 |
-
def unsloth_forward(self, x: torch.Tensor):
|
| 75 |
-
result = self.quant_linear_module(x)
|
| 76 |
-
|
| 77 |
-
if self.disable_adapters:
|
| 78 |
-
return result
|
| 79 |
-
|
| 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 |
-
|
| 88 |
-
requires_conversion = not torch.is_autocast_enabled()
|
| 89 |
-
if requires_conversion:
|
| 90 |
-
expected_dtype = result.dtype
|
| 91 |
-
x = self._cast_input_dtype(x, lora_A.weight.dtype)
|
| 92 |
-
|
| 93 |
-
output = lora_B(lora_A(dropout(x)))
|
| 94 |
-
if requires_conversion:
|
| 95 |
-
output = output.to(expected_dtype)
|
| 96 |
-
output = output * scaling
|
| 97 |
-
result = result + output
|
| 98 |
-
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/BatchNorm1d.py
DELETED
|
@@ -1,151 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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 sys
|
| 28 |
-
import torch
|
| 29 |
-
import importlib.util
|
| 30 |
-
import math
|
| 31 |
-
if importlib.util.find_spec("unsloth_studio") is None:
|
| 32 |
-
UNSLOTH_STUDIO_ENABLED = False
|
| 33 |
-
else:
|
| 34 |
-
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
| 35 |
-
pass
|
| 36 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 37 |
-
import math
|
| 38 |
-
|
| 39 |
-
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
| 40 |
-
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
| 41 |
-
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
| 42 |
-
UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache")
|
| 43 |
-
if UNSLOTH_COMPILE_LOCATION not in sys.path:
|
| 44 |
-
sys.path.insert(0, UNSLOTH_COMPILE_LOCATION)
|
| 45 |
-
|
| 46 |
-
import logging
|
| 47 |
-
logger_compiler = logging.getLogger(__name__)
|
| 48 |
-
if UNSLOTH_ENABLE_LOGGING:
|
| 49 |
-
logger_compiler.setLevel(logging.DEBUG)
|
| 50 |
-
|
| 51 |
-
global INFERENCE_RUNS
|
| 52 |
-
INFERENCE_RUNS = 0
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
| 56 |
-
torch_dynamo_eval_frame._stance.stance
|
| 57 |
-
torch_compiler_set_stance = torch.compiler.set_stance
|
| 58 |
-
except:
|
| 59 |
-
torch_dynamo_eval_frame = None
|
| 60 |
-
torch_compiler_set_stance = None
|
| 61 |
-
pass
|
| 62 |
-
|
| 63 |
-
# The stance is process wide, so whether Unsloth owns it lives in unsloth_zoo, shared by
|
| 64 |
-
# every generated module: inference in one model's module, training in another's.
|
| 65 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_EAGER_STANCE_OWNED, unsloth_claim_eager_stance, unsloth_owns_stance, unsloth_release_stance
|
| 66 |
-
|
| 67 |
-
def unsloth_training_stance():
|
| 68 |
-
# eager_on_recompile is global: left on by generate() or eval forwards, every recompile
|
| 69 |
-
# in a later training step (new sequence length, model.train() without for_training)
|
| 70 |
-
# would silently run the eager body. Training forwards restore the default stance,
|
| 71 |
-
# unless the user chose eager_on_recompile themselves. Every set_stance call installs a
|
| 72 |
-
# fresh stance object, so ours is still active only if the current one `is` it; a user
|
| 73 |
-
# set_stance since then (even to eager_on_recompile again) is theirs and stays.
|
| 74 |
-
global INFERENCE_RUNS
|
| 75 |
-
INFERENCE_RUNS = 0
|
| 76 |
-
if len(UNSLOTH_EAGER_STANCE_OWNED) != 0 and torch_dynamo_eval_frame is not None:
|
| 77 |
-
current = torch_dynamo_eval_frame._stance
|
| 78 |
-
# Ownership is only dropped once ours is reset: a temporary stance scope's exit restores
|
| 79 |
-
# one of our exact objects, which a later training forward must still recognise.
|
| 80 |
-
if current.stance == "eager_on_recompile" and unsloth_owns_stance(current):
|
| 81 |
-
# Only the reset object: an outer scope may still restore another one of ours.
|
| 82 |
-
# Put back what the caller had before Unsloth switched (force_eager, a backend, ...).
|
| 83 |
-
previous = unsloth_release_stance(current)
|
| 84 |
-
if previous is not None and hasattr(torch_dynamo_eval_frame, "_set_stance"):
|
| 85 |
-
torch_dynamo_eval_frame._set_stance(previous)
|
| 86 |
-
else:
|
| 87 |
-
torch_compiler_set_stance(stance = "default", skip_guard_eval_unsafe = False)
|
| 88 |
-
pass
|
| 89 |
-
|
| 90 |
-
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
| 91 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_DECODE_COMPILE
|
| 92 |
-
|
| 93 |
-
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': False, '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}
|
| 94 |
-
from torch import Tensor
|
| 95 |
-
import torch
|
| 96 |
-
import torch.nn as nn
|
| 97 |
-
from torch.nn import functional as F
|
| 98 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 99 |
-
from transformers.models.siglip.modeling_siglip import (np, nn)
|
| 100 |
-
|
| 101 |
-
def forward(self, input: Tensor) -> Tensor:
|
| 102 |
-
original_dtype = input.dtype
|
| 103 |
-
if self.weight is not None: input = input.to(self.weight.dtype)
|
| 104 |
-
self._check_input_dim(input)
|
| 105 |
-
|
| 106 |
-
# exponential_average_factor is set to self.momentum
|
| 107 |
-
# (when it is available) only so that it gets updated
|
| 108 |
-
# in ONNX graph when this node is exported to ONNX.
|
| 109 |
-
if self.momentum is None:
|
| 110 |
-
exponential_average_factor = 0.0
|
| 111 |
-
else:
|
| 112 |
-
exponential_average_factor = self.momentum
|
| 113 |
-
|
| 114 |
-
if self.training and self.track_running_stats:
|
| 115 |
-
# TODO: if statement only here to tell the jit to skip emitting this when it is None
|
| 116 |
-
if self.num_batches_tracked is not None: # type: ignore[has-type]
|
| 117 |
-
self.num_batches_tracked.add_(1) # type: ignore[has-type]
|
| 118 |
-
if self.momentum is None: # use cumulative moving average
|
| 119 |
-
exponential_average_factor = 1.0 / float(self.num_batches_tracked)
|
| 120 |
-
else: # use exponential moving average
|
| 121 |
-
exponential_average_factor = self.momentum
|
| 122 |
-
|
| 123 |
-
r"""
|
| 124 |
-
Decide whether the mini-batch stats should be used for normalization rather than the buffers.
|
| 125 |
-
Mini-batch stats are used in training mode, and in eval mode when buffers are None.
|
| 126 |
-
"""
|
| 127 |
-
if self.training:
|
| 128 |
-
bn_training = True
|
| 129 |
-
else:
|
| 130 |
-
bn_training = (self.running_mean is None) and (self.running_var is None)
|
| 131 |
-
|
| 132 |
-
r"""
|
| 133 |
-
Buffers are only updated if they are to be tracked and we are in training mode. Thus they only need to be
|
| 134 |
-
passed when the update should occur (i.e. in training mode when they are tracked), or when buffer stats are
|
| 135 |
-
used for normalization (i.e. in eval mode when buffers are not None).
|
| 136 |
-
"""
|
| 137 |
-
return F.batch_norm(
|
| 138 |
-
input,
|
| 139 |
-
# If buffers are not to be tracked, ensure that they won't be updated
|
| 140 |
-
(
|
| 141 |
-
self.running_mean
|
| 142 |
-
if not self.training or self.track_running_stats
|
| 143 |
-
else None
|
| 144 |
-
),
|
| 145 |
-
self.running_var if not self.training or self.track_running_stats else None,
|
| 146 |
-
self.weight,
|
| 147 |
-
self.bias,
|
| 148 |
-
bn_training,
|
| 149 |
-
exponential_average_factor,
|
| 150 |
-
self.eps,
|
| 151 |
-
).to(original_dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/BatchNorm2d.py
DELETED
|
@@ -1,151 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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 sys
|
| 28 |
-
import torch
|
| 29 |
-
import importlib.util
|
| 30 |
-
import math
|
| 31 |
-
if importlib.util.find_spec("unsloth_studio") is None:
|
| 32 |
-
UNSLOTH_STUDIO_ENABLED = False
|
| 33 |
-
else:
|
| 34 |
-
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
| 35 |
-
pass
|
| 36 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 37 |
-
import math
|
| 38 |
-
|
| 39 |
-
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
| 40 |
-
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
| 41 |
-
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
| 42 |
-
UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache")
|
| 43 |
-
if UNSLOTH_COMPILE_LOCATION not in sys.path:
|
| 44 |
-
sys.path.insert(0, UNSLOTH_COMPILE_LOCATION)
|
| 45 |
-
|
| 46 |
-
import logging
|
| 47 |
-
logger_compiler = logging.getLogger(__name__)
|
| 48 |
-
if UNSLOTH_ENABLE_LOGGING:
|
| 49 |
-
logger_compiler.setLevel(logging.DEBUG)
|
| 50 |
-
|
| 51 |
-
global INFERENCE_RUNS
|
| 52 |
-
INFERENCE_RUNS = 0
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
| 56 |
-
torch_dynamo_eval_frame._stance.stance
|
| 57 |
-
torch_compiler_set_stance = torch.compiler.set_stance
|
| 58 |
-
except:
|
| 59 |
-
torch_dynamo_eval_frame = None
|
| 60 |
-
torch_compiler_set_stance = None
|
| 61 |
-
pass
|
| 62 |
-
|
| 63 |
-
# The stance is process wide, so whether Unsloth owns it lives in unsloth_zoo, shared by
|
| 64 |
-
# every generated module: inference in one model's module, training in another's.
|
| 65 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_EAGER_STANCE_OWNED, unsloth_claim_eager_stance, unsloth_owns_stance, unsloth_release_stance
|
| 66 |
-
|
| 67 |
-
def unsloth_training_stance():
|
| 68 |
-
# eager_on_recompile is global: left on by generate() or eval forwards, every recompile
|
| 69 |
-
# in a later training step (new sequence length, model.train() without for_training)
|
| 70 |
-
# would silently run the eager body. Training forwards restore the default stance,
|
| 71 |
-
# unless the user chose eager_on_recompile themselves. Every set_stance call installs a
|
| 72 |
-
# fresh stance object, so ours is still active only if the current one `is` it; a user
|
| 73 |
-
# set_stance since then (even to eager_on_recompile again) is theirs and stays.
|
| 74 |
-
global INFERENCE_RUNS
|
| 75 |
-
INFERENCE_RUNS = 0
|
| 76 |
-
if len(UNSLOTH_EAGER_STANCE_OWNED) != 0 and torch_dynamo_eval_frame is not None:
|
| 77 |
-
current = torch_dynamo_eval_frame._stance
|
| 78 |
-
# Ownership is only dropped once ours is reset: a temporary stance scope's exit restores
|
| 79 |
-
# one of our exact objects, which a later training forward must still recognise.
|
| 80 |
-
if current.stance == "eager_on_recompile" and unsloth_owns_stance(current):
|
| 81 |
-
# Only the reset object: an outer scope may still restore another one of ours.
|
| 82 |
-
# Put back what the caller had before Unsloth switched (force_eager, a backend, ...).
|
| 83 |
-
previous = unsloth_release_stance(current)
|
| 84 |
-
if previous is not None and hasattr(torch_dynamo_eval_frame, "_set_stance"):
|
| 85 |
-
torch_dynamo_eval_frame._set_stance(previous)
|
| 86 |
-
else:
|
| 87 |
-
torch_compiler_set_stance(stance = "default", skip_guard_eval_unsafe = False)
|
| 88 |
-
pass
|
| 89 |
-
|
| 90 |
-
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
| 91 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_DECODE_COMPILE
|
| 92 |
-
|
| 93 |
-
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': False, '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}
|
| 94 |
-
from torch import Tensor
|
| 95 |
-
import torch
|
| 96 |
-
import torch.nn as nn
|
| 97 |
-
from torch.nn import functional as F
|
| 98 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 99 |
-
from transformers.models.siglip.modeling_siglip import (np, nn)
|
| 100 |
-
|
| 101 |
-
def forward(self, input: Tensor) -> Tensor:
|
| 102 |
-
original_dtype = input.dtype
|
| 103 |
-
if self.weight is not None: input = input.to(self.weight.dtype)
|
| 104 |
-
self._check_input_dim(input)
|
| 105 |
-
|
| 106 |
-
# exponential_average_factor is set to self.momentum
|
| 107 |
-
# (when it is available) only so that it gets updated
|
| 108 |
-
# in ONNX graph when this node is exported to ONNX.
|
| 109 |
-
if self.momentum is None:
|
| 110 |
-
exponential_average_factor = 0.0
|
| 111 |
-
else:
|
| 112 |
-
exponential_average_factor = self.momentum
|
| 113 |
-
|
| 114 |
-
if self.training and self.track_running_stats:
|
| 115 |
-
# TODO: if statement only here to tell the jit to skip emitting this when it is None
|
| 116 |
-
if self.num_batches_tracked is not None: # type: ignore[has-type]
|
| 117 |
-
self.num_batches_tracked.add_(1) # type: ignore[has-type]
|
| 118 |
-
if self.momentum is None: # use cumulative moving average
|
| 119 |
-
exponential_average_factor = 1.0 / float(self.num_batches_tracked)
|
| 120 |
-
else: # use exponential moving average
|
| 121 |
-
exponential_average_factor = self.momentum
|
| 122 |
-
|
| 123 |
-
r"""
|
| 124 |
-
Decide whether the mini-batch stats should be used for normalization rather than the buffers.
|
| 125 |
-
Mini-batch stats are used in training mode, and in eval mode when buffers are None.
|
| 126 |
-
"""
|
| 127 |
-
if self.training:
|
| 128 |
-
bn_training = True
|
| 129 |
-
else:
|
| 130 |
-
bn_training = (self.running_mean is None) and (self.running_var is None)
|
| 131 |
-
|
| 132 |
-
r"""
|
| 133 |
-
Buffers are only updated if they are to be tracked and we are in training mode. Thus they only need to be
|
| 134 |
-
passed when the update should occur (i.e. in training mode when they are tracked), or when buffer stats are
|
| 135 |
-
used for normalization (i.e. in eval mode when buffers are not None).
|
| 136 |
-
"""
|
| 137 |
-
return F.batch_norm(
|
| 138 |
-
input,
|
| 139 |
-
# If buffers are not to be tracked, ensure that they won't be updated
|
| 140 |
-
(
|
| 141 |
-
self.running_mean
|
| 142 |
-
if not self.training or self.track_running_stats
|
| 143 |
-
else None
|
| 144 |
-
),
|
| 145 |
-
self.running_var if not self.training or self.track_running_stats else None,
|
| 146 |
-
self.weight,
|
| 147 |
-
self.bias,
|
| 148 |
-
bn_training,
|
| 149 |
-
exponential_average_factor,
|
| 150 |
-
self.eps,
|
| 151 |
-
).to(original_dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/BatchNorm3d.py
DELETED
|
@@ -1,151 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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 sys
|
| 28 |
-
import torch
|
| 29 |
-
import importlib.util
|
| 30 |
-
import math
|
| 31 |
-
if importlib.util.find_spec("unsloth_studio") is None:
|
| 32 |
-
UNSLOTH_STUDIO_ENABLED = False
|
| 33 |
-
else:
|
| 34 |
-
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
| 35 |
-
pass
|
| 36 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 37 |
-
import math
|
| 38 |
-
|
| 39 |
-
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
| 40 |
-
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
| 41 |
-
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
| 42 |
-
UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache")
|
| 43 |
-
if UNSLOTH_COMPILE_LOCATION not in sys.path:
|
| 44 |
-
sys.path.insert(0, UNSLOTH_COMPILE_LOCATION)
|
| 45 |
-
|
| 46 |
-
import logging
|
| 47 |
-
logger_compiler = logging.getLogger(__name__)
|
| 48 |
-
if UNSLOTH_ENABLE_LOGGING:
|
| 49 |
-
logger_compiler.setLevel(logging.DEBUG)
|
| 50 |
-
|
| 51 |
-
global INFERENCE_RUNS
|
| 52 |
-
INFERENCE_RUNS = 0
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
| 56 |
-
torch_dynamo_eval_frame._stance.stance
|
| 57 |
-
torch_compiler_set_stance = torch.compiler.set_stance
|
| 58 |
-
except:
|
| 59 |
-
torch_dynamo_eval_frame = None
|
| 60 |
-
torch_compiler_set_stance = None
|
| 61 |
-
pass
|
| 62 |
-
|
| 63 |
-
# The stance is process wide, so whether Unsloth owns it lives in unsloth_zoo, shared by
|
| 64 |
-
# every generated module: inference in one model's module, training in another's.
|
| 65 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_EAGER_STANCE_OWNED, unsloth_claim_eager_stance, unsloth_owns_stance, unsloth_release_stance
|
| 66 |
-
|
| 67 |
-
def unsloth_training_stance():
|
| 68 |
-
# eager_on_recompile is global: left on by generate() or eval forwards, every recompile
|
| 69 |
-
# in a later training step (new sequence length, model.train() without for_training)
|
| 70 |
-
# would silently run the eager body. Training forwards restore the default stance,
|
| 71 |
-
# unless the user chose eager_on_recompile themselves. Every set_stance call installs a
|
| 72 |
-
# fresh stance object, so ours is still active only if the current one `is` it; a user
|
| 73 |
-
# set_stance since then (even to eager_on_recompile again) is theirs and stays.
|
| 74 |
-
global INFERENCE_RUNS
|
| 75 |
-
INFERENCE_RUNS = 0
|
| 76 |
-
if len(UNSLOTH_EAGER_STANCE_OWNED) != 0 and torch_dynamo_eval_frame is not None:
|
| 77 |
-
current = torch_dynamo_eval_frame._stance
|
| 78 |
-
# Ownership is only dropped once ours is reset: a temporary stance scope's exit restores
|
| 79 |
-
# one of our exact objects, which a later training forward must still recognise.
|
| 80 |
-
if current.stance == "eager_on_recompile" and unsloth_owns_stance(current):
|
| 81 |
-
# Only the reset object: an outer scope may still restore another one of ours.
|
| 82 |
-
# Put back what the caller had before Unsloth switched (force_eager, a backend, ...).
|
| 83 |
-
previous = unsloth_release_stance(current)
|
| 84 |
-
if previous is not None and hasattr(torch_dynamo_eval_frame, "_set_stance"):
|
| 85 |
-
torch_dynamo_eval_frame._set_stance(previous)
|
| 86 |
-
else:
|
| 87 |
-
torch_compiler_set_stance(stance = "default", skip_guard_eval_unsafe = False)
|
| 88 |
-
pass
|
| 89 |
-
|
| 90 |
-
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
| 91 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_DECODE_COMPILE
|
| 92 |
-
|
| 93 |
-
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': False, '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}
|
| 94 |
-
from torch import Tensor
|
| 95 |
-
import torch
|
| 96 |
-
import torch.nn as nn
|
| 97 |
-
from torch.nn import functional as F
|
| 98 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 99 |
-
from transformers.models.siglip.modeling_siglip import (np, nn)
|
| 100 |
-
|
| 101 |
-
def forward(self, input: Tensor) -> Tensor:
|
| 102 |
-
original_dtype = input.dtype
|
| 103 |
-
if self.weight is not None: input = input.to(self.weight.dtype)
|
| 104 |
-
self._check_input_dim(input)
|
| 105 |
-
|
| 106 |
-
# exponential_average_factor is set to self.momentum
|
| 107 |
-
# (when it is available) only so that it gets updated
|
| 108 |
-
# in ONNX graph when this node is exported to ONNX.
|
| 109 |
-
if self.momentum is None:
|
| 110 |
-
exponential_average_factor = 0.0
|
| 111 |
-
else:
|
| 112 |
-
exponential_average_factor = self.momentum
|
| 113 |
-
|
| 114 |
-
if self.training and self.track_running_stats:
|
| 115 |
-
# TODO: if statement only here to tell the jit to skip emitting this when it is None
|
| 116 |
-
if self.num_batches_tracked is not None: # type: ignore[has-type]
|
| 117 |
-
self.num_batches_tracked.add_(1) # type: ignore[has-type]
|
| 118 |
-
if self.momentum is None: # use cumulative moving average
|
| 119 |
-
exponential_average_factor = 1.0 / float(self.num_batches_tracked)
|
| 120 |
-
else: # use exponential moving average
|
| 121 |
-
exponential_average_factor = self.momentum
|
| 122 |
-
|
| 123 |
-
r"""
|
| 124 |
-
Decide whether the mini-batch stats should be used for normalization rather than the buffers.
|
| 125 |
-
Mini-batch stats are used in training mode, and in eval mode when buffers are None.
|
| 126 |
-
"""
|
| 127 |
-
if self.training:
|
| 128 |
-
bn_training = True
|
| 129 |
-
else:
|
| 130 |
-
bn_training = (self.running_mean is None) and (self.running_var is None)
|
| 131 |
-
|
| 132 |
-
r"""
|
| 133 |
-
Buffers are only updated if they are to be tracked and we are in training mode. Thus they only need to be
|
| 134 |
-
passed when the update should occur (i.e. in training mode when they are tracked), or when buffer stats are
|
| 135 |
-
used for normalization (i.e. in eval mode when buffers are not None).
|
| 136 |
-
"""
|
| 137 |
-
return F.batch_norm(
|
| 138 |
-
input,
|
| 139 |
-
# If buffers are not to be tracked, ensure that they won't be updated
|
| 140 |
-
(
|
| 141 |
-
self.running_mean
|
| 142 |
-
if not self.training or self.track_running_stats
|
| 143 |
-
else None
|
| 144 |
-
),
|
| 145 |
-
self.running_var if not self.training or self.track_running_stats else None,
|
| 146 |
-
self.weight,
|
| 147 |
-
self.bias,
|
| 148 |
-
bn_training,
|
| 149 |
-
exponential_average_factor,
|
| 150 |
-
self.eps,
|
| 151 |
-
).to(original_dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/BlockDiagonalLinear_peft_forward.py
DELETED
|
@@ -1,85 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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': False, '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 unsloth_zoo.temporary_patches.common import torch_compile
|
| 32 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 33 |
-
from peft.tuners.lora.variants import (F, torch)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
torch_addmm = torch.addmm
|
| 37 |
-
torch_add = torch.add
|
| 38 |
-
torch_is_compiling = torch.compiler.is_compiling
|
| 39 |
-
# torch 2.8 / 2.9 inductor miscompiles addmm(alpha = scaling, beta = 1) traced inside a
|
| 40 |
-
# compiled block (e.g. the VLM decoder MLP), forward and backward; fixed in 2.10 (unsloth#3271).
|
| 41 |
-
torch_lora_no_compiled_addmm = tuple(int(v) for v in torch.__version__.split(".")[:2]) < (2, 10)
|
| 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 |
-
if torch_lora_no_compiled_addmm and torch_is_compiling():
|
| 49 |
-
output = result + scaling * (xA @ lora_B.weight.to(target_dtype).t())
|
| 50 |
-
bias = lora_B.bias
|
| 51 |
-
if bias is not None:
|
| 52 |
-
output = output + scaling * bias.to(target_dtype)
|
| 53 |
-
return output
|
| 54 |
-
# output = result + scaling * xA @ lora_B.weight.t()
|
| 55 |
-
shape = result.shape
|
| 56 |
-
output = torch_addmm(
|
| 57 |
-
result.view(-1, shape[-1]),
|
| 58 |
-
xA.view(-1, xA.shape[-1]),
|
| 59 |
-
lora_B.weight.to(target_dtype).t(),
|
| 60 |
-
alpha = scaling,
|
| 61 |
-
beta = 1,
|
| 62 |
-
).view(shape)
|
| 63 |
-
|
| 64 |
-
bias = lora_B.bias
|
| 65 |
-
if bias is not None:
|
| 66 |
-
output = torch_add(
|
| 67 |
-
output,
|
| 68 |
-
bias.to(target_dtype),
|
| 69 |
-
alpha = scaling,
|
| 70 |
-
)
|
| 71 |
-
return output
|
| 72 |
-
pass
|
| 73 |
-
|
| 74 |
-
def unsloth_forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 75 |
-
first_dims = x.shape[:-1]
|
| 76 |
-
if x.dim() != 2:
|
| 77 |
-
x = x.reshape(-1, x.shape[-1])
|
| 78 |
-
B = x.shape[0]
|
| 79 |
-
nb = self.nblocks
|
| 80 |
-
m = x.shape[-1] // nb
|
| 81 |
-
n = self.out_features // nb
|
| 82 |
-
x = x.reshape(B, nb, m)
|
| 83 |
-
w = self.weight.view(nb, n, m)
|
| 84 |
-
out = torch.einsum("bim,inm->bin", x, w)
|
| 85 |
-
return out.reshape(*first_dims, -1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/Conv1d.py
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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 sys
|
| 28 |
-
import torch
|
| 29 |
-
import importlib.util
|
| 30 |
-
import math
|
| 31 |
-
if importlib.util.find_spec("unsloth_studio") is None:
|
| 32 |
-
UNSLOTH_STUDIO_ENABLED = False
|
| 33 |
-
else:
|
| 34 |
-
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
| 35 |
-
pass
|
| 36 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 37 |
-
import math
|
| 38 |
-
|
| 39 |
-
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
| 40 |
-
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
| 41 |
-
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
| 42 |
-
UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache")
|
| 43 |
-
if UNSLOTH_COMPILE_LOCATION not in sys.path:
|
| 44 |
-
sys.path.insert(0, UNSLOTH_COMPILE_LOCATION)
|
| 45 |
-
|
| 46 |
-
import logging
|
| 47 |
-
logger_compiler = logging.getLogger(__name__)
|
| 48 |
-
if UNSLOTH_ENABLE_LOGGING:
|
| 49 |
-
logger_compiler.setLevel(logging.DEBUG)
|
| 50 |
-
|
| 51 |
-
global INFERENCE_RUNS
|
| 52 |
-
INFERENCE_RUNS = 0
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
| 56 |
-
torch_dynamo_eval_frame._stance.stance
|
| 57 |
-
torch_compiler_set_stance = torch.compiler.set_stance
|
| 58 |
-
except:
|
| 59 |
-
torch_dynamo_eval_frame = None
|
| 60 |
-
torch_compiler_set_stance = None
|
| 61 |
-
pass
|
| 62 |
-
|
| 63 |
-
# The stance is process wide, so whether Unsloth owns it lives in unsloth_zoo, shared by
|
| 64 |
-
# every generated module: inference in one model's module, training in another's.
|
| 65 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_EAGER_STANCE_OWNED, unsloth_claim_eager_stance, unsloth_owns_stance, unsloth_release_stance
|
| 66 |
-
|
| 67 |
-
def unsloth_training_stance():
|
| 68 |
-
# eager_on_recompile is global: left on by generate() or eval forwards, every recompile
|
| 69 |
-
# in a later training step (new sequence length, model.train() without for_training)
|
| 70 |
-
# would silently run the eager body. Training forwards restore the default stance,
|
| 71 |
-
# unless the user chose eager_on_recompile themselves. Every set_stance call installs a
|
| 72 |
-
# fresh stance object, so ours is still active only if the current one `is` it; a user
|
| 73 |
-
# set_stance since then (even to eager_on_recompile again) is theirs and stays.
|
| 74 |
-
global INFERENCE_RUNS
|
| 75 |
-
INFERENCE_RUNS = 0
|
| 76 |
-
if len(UNSLOTH_EAGER_STANCE_OWNED) != 0 and torch_dynamo_eval_frame is not None:
|
| 77 |
-
current = torch_dynamo_eval_frame._stance
|
| 78 |
-
# Ownership is only dropped once ours is reset: a temporary stance scope's exit restores
|
| 79 |
-
# one of our exact objects, which a later training forward must still recognise.
|
| 80 |
-
if current.stance == "eager_on_recompile" and unsloth_owns_stance(current):
|
| 81 |
-
# Only the reset object: an outer scope may still restore another one of ours.
|
| 82 |
-
# Put back what the caller had before Unsloth switched (force_eager, a backend, ...).
|
| 83 |
-
previous = unsloth_release_stance(current)
|
| 84 |
-
if previous is not None and hasattr(torch_dynamo_eval_frame, "_set_stance"):
|
| 85 |
-
torch_dynamo_eval_frame._set_stance(previous)
|
| 86 |
-
else:
|
| 87 |
-
torch_compiler_set_stance(stance = "default", skip_guard_eval_unsafe = False)
|
| 88 |
-
pass
|
| 89 |
-
|
| 90 |
-
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
| 91 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_DECODE_COMPILE
|
| 92 |
-
|
| 93 |
-
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': False, '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}
|
| 94 |
-
from torch import Tensor
|
| 95 |
-
import torch
|
| 96 |
-
import torch.nn as nn
|
| 97 |
-
from torch.nn import functional as F
|
| 98 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 99 |
-
from transformers.models.siglip.modeling_siglip import (np)
|
| 100 |
-
|
| 101 |
-
def forward(self, input: Tensor) -> Tensor:
|
| 102 |
-
original_dtype = input.dtype
|
| 103 |
-
input = input.to(self.weight.dtype)
|
| 104 |
-
return self._conv_forward(input, self.weight, self.bias).to(original_dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/Conv2d.py
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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 sys
|
| 28 |
-
import torch
|
| 29 |
-
import importlib.util
|
| 30 |
-
import math
|
| 31 |
-
if importlib.util.find_spec("unsloth_studio") is None:
|
| 32 |
-
UNSLOTH_STUDIO_ENABLED = False
|
| 33 |
-
else:
|
| 34 |
-
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
| 35 |
-
pass
|
| 36 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 37 |
-
import math
|
| 38 |
-
|
| 39 |
-
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
| 40 |
-
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
| 41 |
-
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
| 42 |
-
UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache")
|
| 43 |
-
if UNSLOTH_COMPILE_LOCATION not in sys.path:
|
| 44 |
-
sys.path.insert(0, UNSLOTH_COMPILE_LOCATION)
|
| 45 |
-
|
| 46 |
-
import logging
|
| 47 |
-
logger_compiler = logging.getLogger(__name__)
|
| 48 |
-
if UNSLOTH_ENABLE_LOGGING:
|
| 49 |
-
logger_compiler.setLevel(logging.DEBUG)
|
| 50 |
-
|
| 51 |
-
global INFERENCE_RUNS
|
| 52 |
-
INFERENCE_RUNS = 0
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
| 56 |
-
torch_dynamo_eval_frame._stance.stance
|
| 57 |
-
torch_compiler_set_stance = torch.compiler.set_stance
|
| 58 |
-
except:
|
| 59 |
-
torch_dynamo_eval_frame = None
|
| 60 |
-
torch_compiler_set_stance = None
|
| 61 |
-
pass
|
| 62 |
-
|
| 63 |
-
# The stance is process wide, so whether Unsloth owns it lives in unsloth_zoo, shared by
|
| 64 |
-
# every generated module: inference in one model's module, training in another's.
|
| 65 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_EAGER_STANCE_OWNED, unsloth_claim_eager_stance, unsloth_owns_stance, unsloth_release_stance
|
| 66 |
-
|
| 67 |
-
def unsloth_training_stance():
|
| 68 |
-
# eager_on_recompile is global: left on by generate() or eval forwards, every recompile
|
| 69 |
-
# in a later training step (new sequence length, model.train() without for_training)
|
| 70 |
-
# would silently run the eager body. Training forwards restore the default stance,
|
| 71 |
-
# unless the user chose eager_on_recompile themselves. Every set_stance call installs a
|
| 72 |
-
# fresh stance object, so ours is still active only if the current one `is` it; a user
|
| 73 |
-
# set_stance since then (even to eager_on_recompile again) is theirs and stays.
|
| 74 |
-
global INFERENCE_RUNS
|
| 75 |
-
INFERENCE_RUNS = 0
|
| 76 |
-
if len(UNSLOTH_EAGER_STANCE_OWNED) != 0 and torch_dynamo_eval_frame is not None:
|
| 77 |
-
current = torch_dynamo_eval_frame._stance
|
| 78 |
-
# Ownership is only dropped once ours is reset: a temporary stance scope's exit restores
|
| 79 |
-
# one of our exact objects, which a later training forward must still recognise.
|
| 80 |
-
if current.stance == "eager_on_recompile" and unsloth_owns_stance(current):
|
| 81 |
-
# Only the reset object: an outer scope may still restore another one of ours.
|
| 82 |
-
# Put back what the caller had before Unsloth switched (force_eager, a backend, ...).
|
| 83 |
-
previous = unsloth_release_stance(current)
|
| 84 |
-
if previous is not None and hasattr(torch_dynamo_eval_frame, "_set_stance"):
|
| 85 |
-
torch_dynamo_eval_frame._set_stance(previous)
|
| 86 |
-
else:
|
| 87 |
-
torch_compiler_set_stance(stance = "default", skip_guard_eval_unsafe = False)
|
| 88 |
-
pass
|
| 89 |
-
|
| 90 |
-
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
| 91 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_DECODE_COMPILE
|
| 92 |
-
|
| 93 |
-
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': False, '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}
|
| 94 |
-
from torch import Tensor
|
| 95 |
-
import torch
|
| 96 |
-
import torch.nn as nn
|
| 97 |
-
from torch.nn import functional as F
|
| 98 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 99 |
-
from transformers.models.siglip.modeling_siglip import (np)
|
| 100 |
-
|
| 101 |
-
def forward(self, input: Tensor) -> Tensor:
|
| 102 |
-
original_dtype = input.dtype
|
| 103 |
-
input = input.to(self.weight.dtype)
|
| 104 |
-
return self._conv_forward(input, self.weight, self.bias).to(original_dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/Conv3d.py
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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 sys
|
| 28 |
-
import torch
|
| 29 |
-
import importlib.util
|
| 30 |
-
import math
|
| 31 |
-
if importlib.util.find_spec("unsloth_studio") is None:
|
| 32 |
-
UNSLOTH_STUDIO_ENABLED = False
|
| 33 |
-
else:
|
| 34 |
-
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
| 35 |
-
pass
|
| 36 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 37 |
-
import math
|
| 38 |
-
|
| 39 |
-
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
| 40 |
-
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
| 41 |
-
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
| 42 |
-
UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache")
|
| 43 |
-
if UNSLOTH_COMPILE_LOCATION not in sys.path:
|
| 44 |
-
sys.path.insert(0, UNSLOTH_COMPILE_LOCATION)
|
| 45 |
-
|
| 46 |
-
import logging
|
| 47 |
-
logger_compiler = logging.getLogger(__name__)
|
| 48 |
-
if UNSLOTH_ENABLE_LOGGING:
|
| 49 |
-
logger_compiler.setLevel(logging.DEBUG)
|
| 50 |
-
|
| 51 |
-
global INFERENCE_RUNS
|
| 52 |
-
INFERENCE_RUNS = 0
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
| 56 |
-
torch_dynamo_eval_frame._stance.stance
|
| 57 |
-
torch_compiler_set_stance = torch.compiler.set_stance
|
| 58 |
-
except:
|
| 59 |
-
torch_dynamo_eval_frame = None
|
| 60 |
-
torch_compiler_set_stance = None
|
| 61 |
-
pass
|
| 62 |
-
|
| 63 |
-
# The stance is process wide, so whether Unsloth owns it lives in unsloth_zoo, shared by
|
| 64 |
-
# every generated module: inference in one model's module, training in another's.
|
| 65 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_EAGER_STANCE_OWNED, unsloth_claim_eager_stance, unsloth_owns_stance, unsloth_release_stance
|
| 66 |
-
|
| 67 |
-
def unsloth_training_stance():
|
| 68 |
-
# eager_on_recompile is global: left on by generate() or eval forwards, every recompile
|
| 69 |
-
# in a later training step (new sequence length, model.train() without for_training)
|
| 70 |
-
# would silently run the eager body. Training forwards restore the default stance,
|
| 71 |
-
# unless the user chose eager_on_recompile themselves. Every set_stance call installs a
|
| 72 |
-
# fresh stance object, so ours is still active only if the current one `is` it; a user
|
| 73 |
-
# set_stance since then (even to eager_on_recompile again) is theirs and stays.
|
| 74 |
-
global INFERENCE_RUNS
|
| 75 |
-
INFERENCE_RUNS = 0
|
| 76 |
-
if len(UNSLOTH_EAGER_STANCE_OWNED) != 0 and torch_dynamo_eval_frame is not None:
|
| 77 |
-
current = torch_dynamo_eval_frame._stance
|
| 78 |
-
# Ownership is only dropped once ours is reset: a temporary stance scope's exit restores
|
| 79 |
-
# one of our exact objects, which a later training forward must still recognise.
|
| 80 |
-
if current.stance == "eager_on_recompile" and unsloth_owns_stance(current):
|
| 81 |
-
# Only the reset object: an outer scope may still restore another one of ours.
|
| 82 |
-
# Put back what the caller had before Unsloth switched (force_eager, a backend, ...).
|
| 83 |
-
previous = unsloth_release_stance(current)
|
| 84 |
-
if previous is not None and hasattr(torch_dynamo_eval_frame, "_set_stance"):
|
| 85 |
-
torch_dynamo_eval_frame._set_stance(previous)
|
| 86 |
-
else:
|
| 87 |
-
torch_compiler_set_stance(stance = "default", skip_guard_eval_unsafe = False)
|
| 88 |
-
pass
|
| 89 |
-
|
| 90 |
-
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
| 91 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_DECODE_COMPILE
|
| 92 |
-
|
| 93 |
-
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': False, '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}
|
| 94 |
-
from torch import Tensor
|
| 95 |
-
import torch
|
| 96 |
-
import torch.nn as nn
|
| 97 |
-
from torch.nn import functional as F
|
| 98 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 99 |
-
from transformers.models.siglip.modeling_siglip import (np)
|
| 100 |
-
|
| 101 |
-
def forward(self, input: Tensor) -> Tensor:
|
| 102 |
-
original_dtype = input.dtype
|
| 103 |
-
input = input.to(self.weight.dtype)
|
| 104 |
-
return self._conv_forward(input, self.weight, self.bias).to(original_dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/ConvTranspose1d.py
DELETED
|
@@ -1,132 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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 sys
|
| 28 |
-
import torch
|
| 29 |
-
import importlib.util
|
| 30 |
-
import math
|
| 31 |
-
if importlib.util.find_spec("unsloth_studio") is None:
|
| 32 |
-
UNSLOTH_STUDIO_ENABLED = False
|
| 33 |
-
else:
|
| 34 |
-
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
| 35 |
-
pass
|
| 36 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 37 |
-
import math
|
| 38 |
-
|
| 39 |
-
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
| 40 |
-
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
| 41 |
-
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
| 42 |
-
UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache")
|
| 43 |
-
if UNSLOTH_COMPILE_LOCATION not in sys.path:
|
| 44 |
-
sys.path.insert(0, UNSLOTH_COMPILE_LOCATION)
|
| 45 |
-
|
| 46 |
-
import logging
|
| 47 |
-
logger_compiler = logging.getLogger(__name__)
|
| 48 |
-
if UNSLOTH_ENABLE_LOGGING:
|
| 49 |
-
logger_compiler.setLevel(logging.DEBUG)
|
| 50 |
-
|
| 51 |
-
global INFERENCE_RUNS
|
| 52 |
-
INFERENCE_RUNS = 0
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
| 56 |
-
torch_dynamo_eval_frame._stance.stance
|
| 57 |
-
torch_compiler_set_stance = torch.compiler.set_stance
|
| 58 |
-
except:
|
| 59 |
-
torch_dynamo_eval_frame = None
|
| 60 |
-
torch_compiler_set_stance = None
|
| 61 |
-
pass
|
| 62 |
-
|
| 63 |
-
# The stance is process wide, so whether Unsloth owns it lives in unsloth_zoo, shared by
|
| 64 |
-
# every generated module: inference in one model's module, training in another's.
|
| 65 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_EAGER_STANCE_OWNED, unsloth_claim_eager_stance, unsloth_owns_stance, unsloth_release_stance
|
| 66 |
-
|
| 67 |
-
def unsloth_training_stance():
|
| 68 |
-
# eager_on_recompile is global: left on by generate() or eval forwards, every recompile
|
| 69 |
-
# in a later training step (new sequence length, model.train() without for_training)
|
| 70 |
-
# would silently run the eager body. Training forwards restore the default stance,
|
| 71 |
-
# unless the user chose eager_on_recompile themselves. Every set_stance call installs a
|
| 72 |
-
# fresh stance object, so ours is still active only if the current one `is` it; a user
|
| 73 |
-
# set_stance since then (even to eager_on_recompile again) is theirs and stays.
|
| 74 |
-
global INFERENCE_RUNS
|
| 75 |
-
INFERENCE_RUNS = 0
|
| 76 |
-
if len(UNSLOTH_EAGER_STANCE_OWNED) != 0 and torch_dynamo_eval_frame is not None:
|
| 77 |
-
current = torch_dynamo_eval_frame._stance
|
| 78 |
-
# Ownership is only dropped once ours is reset: a temporary stance scope's exit restores
|
| 79 |
-
# one of our exact objects, which a later training forward must still recognise.
|
| 80 |
-
if current.stance == "eager_on_recompile" and unsloth_owns_stance(current):
|
| 81 |
-
# Only the reset object: an outer scope may still restore another one of ours.
|
| 82 |
-
# Put back what the caller had before Unsloth switched (force_eager, a backend, ...).
|
| 83 |
-
previous = unsloth_release_stance(current)
|
| 84 |
-
if previous is not None and hasattr(torch_dynamo_eval_frame, "_set_stance"):
|
| 85 |
-
torch_dynamo_eval_frame._set_stance(previous)
|
| 86 |
-
else:
|
| 87 |
-
torch_compiler_set_stance(stance = "default", skip_guard_eval_unsafe = False)
|
| 88 |
-
pass
|
| 89 |
-
|
| 90 |
-
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
| 91 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_DECODE_COMPILE
|
| 92 |
-
|
| 93 |
-
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': False, '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}
|
| 94 |
-
from torch import Tensor
|
| 95 |
-
import torch
|
| 96 |
-
import torch.nn as nn
|
| 97 |
-
from torch.nn import functional as F
|
| 98 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 99 |
-
from transformers.models.siglip.modeling_siglip import (np, nn)
|
| 100 |
-
|
| 101 |
-
def forward(self, input: Tensor, output_size: list[int] | None = None) -> Tensor:
|
| 102 |
-
original_dtype = input.dtype
|
| 103 |
-
input = input.to(self.weight.dtype)
|
| 104 |
-
if self.padding_mode != "zeros":
|
| 105 |
-
raise ValueError(
|
| 106 |
-
"Only `zeros` padding mode is supported for ConvTranspose1d"
|
| 107 |
-
)
|
| 108 |
-
|
| 109 |
-
if not isinstance(self.padding, tuple):
|
| 110 |
-
raise AssertionError("self.padding must be a tuple")
|
| 111 |
-
# One cannot replace List by Tuple or Sequence in "_output_padding" because
|
| 112 |
-
# TorchScript does not support `Sequence[T]` or `Tuple[T, ...]`.
|
| 113 |
-
num_spatial_dims = 1
|
| 114 |
-
output_padding = self._output_padding(
|
| 115 |
-
input,
|
| 116 |
-
output_size,
|
| 117 |
-
self.stride, # type: ignore[arg-type]
|
| 118 |
-
self.padding, # type: ignore[arg-type]
|
| 119 |
-
self.kernel_size, # type: ignore[arg-type]
|
| 120 |
-
num_spatial_dims,
|
| 121 |
-
self.dilation, # type: ignore[arg-type]
|
| 122 |
-
)
|
| 123 |
-
return F.conv_transpose1d(
|
| 124 |
-
input,
|
| 125 |
-
self.weight,
|
| 126 |
-
self.bias,
|
| 127 |
-
self.stride,
|
| 128 |
-
self.padding,
|
| 129 |
-
output_padding,
|
| 130 |
-
self.groups,
|
| 131 |
-
self.dilation,
|
| 132 |
-
).to(original_dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/ConvTranspose2d.py
DELETED
|
@@ -1,141 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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 sys
|
| 28 |
-
import torch
|
| 29 |
-
import importlib.util
|
| 30 |
-
import math
|
| 31 |
-
if importlib.util.find_spec("unsloth_studio") is None:
|
| 32 |
-
UNSLOTH_STUDIO_ENABLED = False
|
| 33 |
-
else:
|
| 34 |
-
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
| 35 |
-
pass
|
| 36 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 37 |
-
import math
|
| 38 |
-
|
| 39 |
-
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
| 40 |
-
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
| 41 |
-
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
| 42 |
-
UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache")
|
| 43 |
-
if UNSLOTH_COMPILE_LOCATION not in sys.path:
|
| 44 |
-
sys.path.insert(0, UNSLOTH_COMPILE_LOCATION)
|
| 45 |
-
|
| 46 |
-
import logging
|
| 47 |
-
logger_compiler = logging.getLogger(__name__)
|
| 48 |
-
if UNSLOTH_ENABLE_LOGGING:
|
| 49 |
-
logger_compiler.setLevel(logging.DEBUG)
|
| 50 |
-
|
| 51 |
-
global INFERENCE_RUNS
|
| 52 |
-
INFERENCE_RUNS = 0
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
| 56 |
-
torch_dynamo_eval_frame._stance.stance
|
| 57 |
-
torch_compiler_set_stance = torch.compiler.set_stance
|
| 58 |
-
except:
|
| 59 |
-
torch_dynamo_eval_frame = None
|
| 60 |
-
torch_compiler_set_stance = None
|
| 61 |
-
pass
|
| 62 |
-
|
| 63 |
-
# The stance is process wide, so whether Unsloth owns it lives in unsloth_zoo, shared by
|
| 64 |
-
# every generated module: inference in one model's module, training in another's.
|
| 65 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_EAGER_STANCE_OWNED, unsloth_claim_eager_stance, unsloth_owns_stance, unsloth_release_stance
|
| 66 |
-
|
| 67 |
-
def unsloth_training_stance():
|
| 68 |
-
# eager_on_recompile is global: left on by generate() or eval forwards, every recompile
|
| 69 |
-
# in a later training step (new sequence length, model.train() without for_training)
|
| 70 |
-
# would silently run the eager body. Training forwards restore the default stance,
|
| 71 |
-
# unless the user chose eager_on_recompile themselves. Every set_stance call installs a
|
| 72 |
-
# fresh stance object, so ours is still active only if the current one `is` it; a user
|
| 73 |
-
# set_stance since then (even to eager_on_recompile again) is theirs and stays.
|
| 74 |
-
global INFERENCE_RUNS
|
| 75 |
-
INFERENCE_RUNS = 0
|
| 76 |
-
if len(UNSLOTH_EAGER_STANCE_OWNED) != 0 and torch_dynamo_eval_frame is not None:
|
| 77 |
-
current = torch_dynamo_eval_frame._stance
|
| 78 |
-
# Ownership is only dropped once ours is reset: a temporary stance scope's exit restores
|
| 79 |
-
# one of our exact objects, which a later training forward must still recognise.
|
| 80 |
-
if current.stance == "eager_on_recompile" and unsloth_owns_stance(current):
|
| 81 |
-
# Only the reset object: an outer scope may still restore another one of ours.
|
| 82 |
-
# Put back what the caller had before Unsloth switched (force_eager, a backend, ...).
|
| 83 |
-
previous = unsloth_release_stance(current)
|
| 84 |
-
if previous is not None and hasattr(torch_dynamo_eval_frame, "_set_stance"):
|
| 85 |
-
torch_dynamo_eval_frame._set_stance(previous)
|
| 86 |
-
else:
|
| 87 |
-
torch_compiler_set_stance(stance = "default", skip_guard_eval_unsafe = False)
|
| 88 |
-
pass
|
| 89 |
-
|
| 90 |
-
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
| 91 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_DECODE_COMPILE
|
| 92 |
-
|
| 93 |
-
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': False, '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}
|
| 94 |
-
from torch import Tensor
|
| 95 |
-
import torch
|
| 96 |
-
import torch.nn as nn
|
| 97 |
-
from torch.nn import functional as F
|
| 98 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 99 |
-
from transformers.models.siglip.modeling_siglip import (np, nn)
|
| 100 |
-
|
| 101 |
-
def forward(self, input: Tensor, output_size: list[int] | None = None) -> Tensor:
|
| 102 |
-
original_dtype = input.dtype
|
| 103 |
-
input = input.to(self.weight.dtype)
|
| 104 |
-
"""
|
| 105 |
-
Performs the forward pass.
|
| 106 |
-
|
| 107 |
-
Attributes:
|
| 108 |
-
input (Tensor): The input tensor.
|
| 109 |
-
output_size (list[int], optional): A list of integers representing
|
| 110 |
-
the size of the output tensor. Default is None.
|
| 111 |
-
"""
|
| 112 |
-
if self.padding_mode != "zeros":
|
| 113 |
-
raise ValueError(
|
| 114 |
-
"Only `zeros` padding mode is supported for ConvTranspose2d"
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
if not isinstance(self.padding, tuple):
|
| 118 |
-
raise AssertionError("self.padding must be a tuple")
|
| 119 |
-
# One cannot replace List by Tuple or Sequence in "_output_padding" because
|
| 120 |
-
# TorchScript does not support `Sequence[T]` or `Tuple[T, ...]`.
|
| 121 |
-
num_spatial_dims = 2
|
| 122 |
-
output_padding = self._output_padding(
|
| 123 |
-
input,
|
| 124 |
-
output_size,
|
| 125 |
-
self.stride, # type: ignore[arg-type]
|
| 126 |
-
self.padding, # type: ignore[arg-type]
|
| 127 |
-
self.kernel_size, # type: ignore[arg-type]
|
| 128 |
-
num_spatial_dims,
|
| 129 |
-
self.dilation, # type: ignore[arg-type]
|
| 130 |
-
)
|
| 131 |
-
|
| 132 |
-
return F.conv_transpose2d(
|
| 133 |
-
input,
|
| 134 |
-
self.weight,
|
| 135 |
-
self.bias,
|
| 136 |
-
self.stride,
|
| 137 |
-
self.padding,
|
| 138 |
-
output_padding,
|
| 139 |
-
self.groups,
|
| 140 |
-
self.dilation,
|
| 141 |
-
).to(original_dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/ConvTranspose3d.py
DELETED
|
@@ -1,133 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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 sys
|
| 28 |
-
import torch
|
| 29 |
-
import importlib.util
|
| 30 |
-
import math
|
| 31 |
-
if importlib.util.find_spec("unsloth_studio") is None:
|
| 32 |
-
UNSLOTH_STUDIO_ENABLED = False
|
| 33 |
-
else:
|
| 34 |
-
UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0"
|
| 35 |
-
pass
|
| 36 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 37 |
-
import math
|
| 38 |
-
|
| 39 |
-
UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1"
|
| 40 |
-
UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1"
|
| 41 |
-
UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",)
|
| 42 |
-
UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache")
|
| 43 |
-
if UNSLOTH_COMPILE_LOCATION not in sys.path:
|
| 44 |
-
sys.path.insert(0, UNSLOTH_COMPILE_LOCATION)
|
| 45 |
-
|
| 46 |
-
import logging
|
| 47 |
-
logger_compiler = logging.getLogger(__name__)
|
| 48 |
-
if UNSLOTH_ENABLE_LOGGING:
|
| 49 |
-
logger_compiler.setLevel(logging.DEBUG)
|
| 50 |
-
|
| 51 |
-
global INFERENCE_RUNS
|
| 52 |
-
INFERENCE_RUNS = 0
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
import torch._dynamo.eval_frame as torch_dynamo_eval_frame
|
| 56 |
-
torch_dynamo_eval_frame._stance.stance
|
| 57 |
-
torch_compiler_set_stance = torch.compiler.set_stance
|
| 58 |
-
except:
|
| 59 |
-
torch_dynamo_eval_frame = None
|
| 60 |
-
torch_compiler_set_stance = None
|
| 61 |
-
pass
|
| 62 |
-
|
| 63 |
-
# The stance is process wide, so whether Unsloth owns it lives in unsloth_zoo, shared by
|
| 64 |
-
# every generated module: inference in one model's module, training in another's.
|
| 65 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_EAGER_STANCE_OWNED, unsloth_claim_eager_stance, unsloth_owns_stance, unsloth_release_stance
|
| 66 |
-
|
| 67 |
-
def unsloth_training_stance():
|
| 68 |
-
# eager_on_recompile is global: left on by generate() or eval forwards, every recompile
|
| 69 |
-
# in a later training step (new sequence length, model.train() without for_training)
|
| 70 |
-
# would silently run the eager body. Training forwards restore the default stance,
|
| 71 |
-
# unless the user chose eager_on_recompile themselves. Every set_stance call installs a
|
| 72 |
-
# fresh stance object, so ours is still active only if the current one `is` it; a user
|
| 73 |
-
# set_stance since then (even to eager_on_recompile again) is theirs and stays.
|
| 74 |
-
global INFERENCE_RUNS
|
| 75 |
-
INFERENCE_RUNS = 0
|
| 76 |
-
if len(UNSLOTH_EAGER_STANCE_OWNED) != 0 and torch_dynamo_eval_frame is not None:
|
| 77 |
-
current = torch_dynamo_eval_frame._stance
|
| 78 |
-
# Ownership is only dropped once ours is reset: a temporary stance scope's exit restores
|
| 79 |
-
# one of our exact objects, which a later training forward must still recognise.
|
| 80 |
-
if current.stance == "eager_on_recompile" and unsloth_owns_stance(current):
|
| 81 |
-
# Only the reset object: an outer scope may still restore another one of ours.
|
| 82 |
-
# Put back what the caller had before Unsloth switched (force_eager, a backend, ...).
|
| 83 |
-
previous = unsloth_release_stance(current)
|
| 84 |
-
if previous is not None and hasattr(torch_dynamo_eval_frame, "_set_stance"):
|
| 85 |
-
torch_dynamo_eval_frame._set_stance(previous)
|
| 86 |
-
else:
|
| 87 |
-
torch_compiler_set_stance(stance = "default", skip_guard_eval_unsafe = False)
|
| 88 |
-
pass
|
| 89 |
-
|
| 90 |
-
from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT
|
| 91 |
-
from unsloth_zoo.temporary_patches.utils import UNSLOTH_DECODE_COMPILE
|
| 92 |
-
|
| 93 |
-
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': False, '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}
|
| 94 |
-
from torch import Tensor
|
| 95 |
-
import torch
|
| 96 |
-
import torch.nn as nn
|
| 97 |
-
from torch.nn import functional as F
|
| 98 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 99 |
-
from transformers.models.siglip.modeling_siglip import (np, nn)
|
| 100 |
-
|
| 101 |
-
def forward(self, input: Tensor, output_size: list[int] | None = None) -> Tensor:
|
| 102 |
-
original_dtype = input.dtype
|
| 103 |
-
input = input.to(self.weight.dtype)
|
| 104 |
-
if self.padding_mode != "zeros":
|
| 105 |
-
raise ValueError(
|
| 106 |
-
"Only `zeros` padding mode is supported for ConvTranspose3d"
|
| 107 |
-
)
|
| 108 |
-
|
| 109 |
-
if not isinstance(self.padding, tuple):
|
| 110 |
-
raise AssertionError("self.padding must be a tuple")
|
| 111 |
-
# One cannot replace List by Tuple or Sequence in "_output_padding" because
|
| 112 |
-
# TorchScript does not support `Sequence[T]` or `Tuple[T, ...]`.
|
| 113 |
-
num_spatial_dims = 3
|
| 114 |
-
output_padding = self._output_padding(
|
| 115 |
-
input,
|
| 116 |
-
output_size,
|
| 117 |
-
self.stride, # type: ignore[arg-type]
|
| 118 |
-
self.padding, # type: ignore[arg-type]
|
| 119 |
-
self.kernel_size, # type: ignore[arg-type]
|
| 120 |
-
num_spatial_dims,
|
| 121 |
-
self.dilation, # type: ignore[arg-type]
|
| 122 |
-
)
|
| 123 |
-
|
| 124 |
-
return F.conv_transpose3d(
|
| 125 |
-
input,
|
| 126 |
-
self.weight,
|
| 127 |
-
self.bias,
|
| 128 |
-
self.stride,
|
| 129 |
-
self.padding,
|
| 130 |
-
output_padding,
|
| 131 |
-
self.groups,
|
| 132 |
-
self.dilation,
|
| 133 |
-
).to(original_dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
training/unsloth_compiled_cache/GPTQLoraLinear_peft_forward.py
DELETED
|
@@ -1,106 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
2026.10.9
|
| 3 |
-
2026.10.9
|
| 4 |
-
5.5.0
|
| 5 |
-
1.15.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': False, '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 unsloth_zoo.temporary_patches.common import torch_compile
|
| 32 |
-
from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable
|
| 33 |
-
from peft.tuners.lora.gptq import (torch)
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
torch_addmm = torch.addmm
|
| 37 |
-
torch_add = torch.add
|
| 38 |
-
torch_is_compiling = torch.compiler.is_compiling
|
| 39 |
-
# torch 2.8 / 2.9 inductor miscompiles addmm(alpha = scaling, beta = 1) traced inside a
|
| 40 |
-
# compiled block (e.g. the VLM decoder MLP), forward and backward; fixed in 2.10 (unsloth#3271).
|
| 41 |
-
torch_lora_no_compiled_addmm = tuple(int(v) for v in torch.__version__.split(".")[:2]) < (2, 10)
|
| 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 |
-
if torch_lora_no_compiled_addmm and torch_is_compiling():
|
| 49 |
-
output = result + scaling * (xA @ lora_B.weight.to(target_dtype).t())
|
| 50 |
-
bias = lora_B.bias
|
| 51 |
-
if bias is not None:
|
| 52 |
-
output = output + scaling * bias.to(target_dtype)
|
| 53 |
-
return output
|
| 54 |
-
# output = result + scaling * xA @ lora_B.weight.t()
|
| 55 |
-
shape = result.shape
|
| 56 |
-
output = torch_addmm(
|
| 57 |
-
result.view(-1, shape[-1]),
|
| 58 |
-
xA.view(-1, xA.shape[-1]),
|
| 59 |
-
lora_B.weight.to(target_dtype).t(),
|
| 60 |
-
alpha = scaling,
|
| 61 |
-
beta = 1,
|
| 62 |
-
).view(shape)
|
| 63 |
-
|
| 64 |
-
bias = lora_B.bias
|
| 65 |
-
if bias is not None:
|
| 66 |
-
output = torch_add(
|
| 67 |
-
output,
|
| 68 |
-
bias.to(target_dtype),
|
| 69 |
-
alpha = scaling,
|
| 70 |
-
)
|
| 71 |
-
return output
|
| 72 |
-
pass
|
| 73 |
-
|
| 74 |
-
def unsloth_forward(self, x: torch.Tensor):
|
| 75 |
-
# note: logic differs from default Linear because merging is not supported
|
| 76 |
-
result = self.quant_linear_module(x)
|
| 77 |
-
|
| 78 |
-
if self.disable_adapters:
|
| 79 |
-
return result
|
| 80 |
-
|
| 81 |
-
lora_A_keys = self.lora_A.keys()
|
| 82 |
-
|
| 83 |
-
for active_adapter in self.active_adapters:
|
| 84 |
-
if active_adapter not in lora_A_keys:
|
| 85 |
-
continue
|
| 86 |
-
torch_result_dtype = result.dtype
|
| 87 |
-
|
| 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 |
-
if not torch.is_autocast_enabled(): result, x = result.to(lora_A.weight.dtype), x.to(lora_A.weight.dtype)
|
| 94 |
-
|
| 95 |
-
if active_adapter not in self.lora_variant: # vanilla LoRA
|
| 96 |
-
return lora_forward(result, lora_A, lora_B, dropout, x, scaling).to(torch_result_dtype)
|
| 97 |
-
else:
|
| 98 |
-
result = self.lora_variant[active_adapter].forward(
|
| 99 |
-
self,
|
| 100 |
-
active_adapter=active_adapter,
|
| 101 |
-
x=x,
|
| 102 |
-
result=result,
|
| 103 |
-
)
|
| 104 |
-
|
| 105 |
-
result = result.to(torch_result_dtype)
|
| 106 |
-
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|