From 9c565580fbcc6bf95ca9d775e83f0c863eab9f1e Mon Sep 17 00:00:00 2001 From: Daniel Han-Chen Date: Sat, 24 Feb 2024 17:09:03 +1100 Subject: [PATCH] Update gemma.py --- unsloth/models/gemma.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/unsloth/models/gemma.py b/unsloth/models/gemma.py index d896d5a080..5bfc885dc0 100644 --- a/unsloth/models/gemma.py +++ b/unsloth/models/gemma.py @@ -89,7 +89,7 @@ def GemmaDecoderLayer_fast_forward( hidden_states += residual else: residual = hidden_states - hidden_states = self.input_layernorm(hidden_states) + hidden_states = fast_rms_layernorm(self.input_layernorm, hidden_states) hidden_states, self_attn_weights, present_key_value = self.self_attn( hidden_states=hidden_states, causal_mask=causal_mask, @@ -104,7 +104,7 @@ def GemmaDecoderLayer_fast_forward( # Fully Connected residual = hidden_states - hidden_states = self.post_attention_layernorm(hidden_states) + hidden_states = fast_rms_layernorm(self.post_attention_layernorm, hidden_states) hidden_states = self.mlp(hidden_states) hidden_states = residual + hidden_states pass @@ -350,7 +350,7 @@ def GemmaModel_fast_forward( all_self_attns += (layer_outputs[1],) pass - hidden_states = self.norm(hidden_states) + hidden_states = fast_rms_layernorm(self.norm, hidden_states) # add hidden states from the last decoder layer if output_hidden_states: @@ -531,12 +531,12 @@ class FastGemmaModel(FastLlamaModel): pass print("Unsloth: Patching Gemma RMS Layernorm + 1") - # for name, module in model.named_modules(): - # if isinstance(module, GemmaRMSNorm): - # module.weight += 1.0 # return output * (1 + self.weight) - # if not hasattr(module, "variance_epsilon"): - # module.variance_epsilon = module.eps # Gemma doesn't use variance_epsilon - # pass + for name, module in model.named_modules(): + if isinstance(module, GemmaRMSNorm): + module.weight += 1.0 # return output * (1 + self.weight) + if not hasattr(module, "variance_epsilon"): + module.variance_epsilon = module.eps # Gemma doesn't use variance_epsilon + pass # Clear deleted GPU items import gc