Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

hack for rotary

Daniel Hand587ce218da6
diff --git a/unsloth/models/gemma.py b/unsloth/models/gemma.py
index ce89ad3be69..6c9a57abf71 100644
--- a/unsloth/models/gemma.py
+++ b/unsloth/models/gemma.py
@@ -205,7 +205,9 @@ class GemmaFixedRotaryEmbedding(torch.nn.Module):
# Fixes https://github.com/huggingface/transformers/pull/28837
# https://github.com/microsoft/DeepSpeed/issues/4932
# The precision of RoPE buffers is not correct, so we cast to int64.
- def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None,
+ config = None, # [TODO] Hack to pass in config - need to remove later
+ ):
super().__init__()
self.dim = dim
self.max_position_embeddings = max_position_embeddings
@@ -264,7 +266,9 @@ class GemmaFixedLinearScalingRotaryEmbedding(GemmaFixedRotaryEmbedding):
# Fixes https://github.com/huggingface/transformers/pull/28837
# https://github.com/microsoft/DeepSpeed/issues/4932
# The precision of RoPE buffers is not correct, so we cast to int64.
- def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0,
+ config = None, # [TODO] Hack to pass in config - need to remove later
+ ):
self.scaling_factor = scaling_factor
super().__init__(dim, max_position_embeddings, base, device)
pass
diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py
index 830b345d794..929c324966c 100644
--- a/unsloth/models/llama.py
+++ b/unsloth/models/llama.py
@@ -977,7 +977,9 @@ class LlamaRotaryEmbedding(torch.nn.Module):
# Fixes https://github.com/huggingface/transformers/pull/28837
# https://github.com/microsoft/DeepSpeed/issues/4932
# The precision of RoPE buffers is not correct, so we cast to int64.
- def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None,
+ config = None, # [TODO] Hack to pass in config - need to remove later
+ ):
super().__init__()
self.dim = dim
self.max_position_embeddings = max_position_embeddings
@@ -1030,7 +1032,9 @@ class LlamaLinearScalingRotaryEmbedding(LlamaRotaryEmbedding):
# Fixes https://github.com/huggingface/transformers/pull/28837
# https://github.com/microsoft/DeepSpeed/issues/4932
# The precision of RoPE buffers is not correct, so we cast to int64.
- def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0):
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None, scaling_factor=1.0,
+ config = None, # [TODO] Hack to pass in config - need to remove later
+ ):
self.scaling_factor = scaling_factor
super().__init__(dim, max_position_embeddings, base, device)
pass
@@ -1055,7 +1059,9 @@ pass
# See https://github.com/vllm-project/vllm/blob/main/vllm/model_executor/layers/rotary_embedding.py#L736
# For Llama 3.1
class LlamaExtendedRotaryEmbedding(torch.nn.Module):
- def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None,
+ config = None, # [TODO] Hack to pass in config - need to remove later
+ ):
super().__init__()
self.dim = dim
self.max_position_embeddings = max_position_embeddings