From cd9cae3eda48176f861199b4608335a6b308ff4a Mon Sep 17 00:00:00 2001 From: yash solanki Date: Wed, 13 Aug 2025 12:01:53 +0530 Subject: [PATCH] chore(review): remove unused GeLU exports, dedupe fast_layernorm_inference import; minor cleanup --- unsloth/kernels/__init__.py | 2 +- unsloth/kernels/gelu.py | 26 ++++---------------------- unsloth/models/cohere.py | 1 + 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/unsloth/kernels/__init__.py b/unsloth/kernels/__init__.py index 5b906b6cfa..de8b0666cf 100644 --- a/unsloth/kernels/__init__.py +++ b/unsloth/kernels/__init__.py @@ -29,7 +29,7 @@ from .layernorm import ( ) from .rope_embedding import fast_rope_embedding, inplace_rope_embedding from .dropout import DeterministicDropout, seeded_dropout -from .gelu import fast_gelu, FastGELU +# GeLU acceleration reserved; currently unused from .swiglu import swiglu_fg_kernel, swiglu_DWf_DW_dfg_kernel from .geglu import ( geglu_exact_forward_kernel, diff --git a/unsloth/kernels/gelu.py b/unsloth/kernels/gelu.py index c3b0499c3b..1cd209e5fa 100644 --- a/unsloth/kernels/gelu.py +++ b/unsloth/kernels/gelu.py @@ -12,27 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import torch -import torch.nn.functional as F - - -@torch.compiler.disable -def fast_gelu(x: torch.Tensor, approximate: str | None = None) -> torch.Tensor: - """Fast GeLU wrapper. Uses torch.nn.functional.gelu with optional approximation. - - approximate: None | "tanh" - """ - if approximate is None: - return F.gelu(x) - return F.gelu(x, approximate=approximate) - - -class FastGELU(torch.nn.Module): - def __init__(self, approximate: str | None = None): - super().__init__() - self.approximate = approximate - - def forward(self, x: torch.Tensor) -> torch.Tensor: - return fast_gelu(x, self.approximate) +""" +Reserved module for optional GeLU acceleration. Currently unused. +Left intentionally minimal to address reviewer feedback. +""" diff --git a/unsloth/models/cohere.py b/unsloth/models/cohere.py index 4251f3acd9..eb6a1accfc 100644 --- a/unsloth/models/cohere.py +++ b/unsloth/models/cohere.py @@ -13,6 +13,7 @@ # limitations under the License. from .llama import * +from ..kernels import fast_layernorm_inference from ._utils import __version__ from unsloth_zoo.hf_utils import dtype_from_config from unsloth_zoo.utils import _get_dtype, Version