| """ |
| 2026.4.9 |
| 2026.4.8 |
| 5.5.0 |
| 0.24.0 |
| __UNSLOTH_VERSIONING__ |
| """ |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| import os |
| import sys |
| import torch |
| import importlib.util |
| import math |
| if importlib.util.find_spec("unsloth_studio") is None: |
| UNSLOTH_STUDIO_ENABLED = False |
| else: |
| UNSLOTH_STUDIO_ENABLED = os.environ.get("UNSLOTH_STUDIO_DISABLED", "0") == "0" |
| pass |
| from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable |
| import math |
|
|
| UNSLOTH_ENABLE_LOGGING = os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") == "1" |
| UNSLOTH_ENABLE_CCE = os.environ.get("UNSLOTH_ENABLE_CCE", "1") == "1" |
| UNSLOTH_COMPILE_DISABLE = os.environ.get("UNSLOTH_COMPILE_DISABLE", "0") in ("1", "partial",) |
| UNSLOTH_COMPILE_LOCATION = os.environ.get("UNSLOTH_COMPILE_LOCATION", "unsloth_compiled_cache") |
| if UNSLOTH_COMPILE_LOCATION not in sys.path: |
| sys.path.insert(0, UNSLOTH_COMPILE_LOCATION) |
|
|
| import logging |
| logger_compiler = logging.getLogger(__name__) |
| if UNSLOTH_ENABLE_LOGGING: |
| logger_compiler.setLevel(logging.DEBUG) |
|
|
| global INFERENCE_RUNS |
| INFERENCE_RUNS = 0 |
|
|
| try: |
| import torch._dynamo.eval_frame as torch_dynamo_eval_frame |
| torch_dynamo_eval_frame._stance.stance |
| torch_compiler_set_stance = torch.compiler.set_stance |
| except: |
| torch_dynamo_eval_frame = None |
| torch_compiler_set_stance = None |
| pass |
|
|
| from unsloth_zoo import DEVICE_TYPE_TORCH, DEVICE_COUNT |
|
|
| torch_compile_options = {'epilogue_fusion': True, 'max_autotune': False, 'shape_padding': True, 'trace.enabled': False, 'triton.cudagraphs': False, 'debug': False, 'dce': True, 'memory_planning': True, 'coordinate_descent_tuning': False, 'trace.graph_diagram': False, 'compile_threads': 32, 'group_fusion': True, 'disable_progress': True, 'verbose_progress': False, 'triton.multi_kernel': 0, 'triton.use_block_ptr': False, 'triton.enable_persistent_tma_matmul': True, 'triton.autotune_at_compile_time': False, 'triton.cooperative_reductions': False, 'cuda.compile_opt_level': '-O2', 'cuda.enable_cuda_lto': True, 'combo_kernels': False, 'benchmark_combo_kernel': True, 'combo_kernel_foreach_dynamic_shapes': True} |
| from torch import Tensor |
| import torch |
| import torch.nn as nn |
| from torch.nn import functional as F |
| from typing import Any, List, Optional, Tuple, Union, Dict, Set, Callable |
| from transformers.models.gemma4.modeling_gemma4 import (F, torch) |
|
|
| def forward(self, x: torch.Tensor) -> torch.Tensor: |
| """ |
| Runs the forward pass. |
| """ |
| return F.rms_norm(x, self.normalized_shape, self.weight, self.eps).to(x.dtype).to(x.dtype) |
|
|