From 326daf095f832f90ada22c417a73df381e37e6c1 Mon Sep 17 00:00:00 2001 From: Dattu Sharma Date: Mon, 28 Apr 2025 18:41:23 +0000 Subject: [PATCH] fixup qwen3 Signed-off-by: Dattu Sharma --- unsloth/models/_utils.py | 2 +- unsloth/models/llama.py | 2 ++ unsloth/models/qwen3.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index e60881fa9c..282aa99334 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -248,7 +248,7 @@ model_architectures = ["llama", "mistral", "gemma", "gemma2", "qwen2", "granite" for model_name in model_architectures: config_filepath = f"transformers.models.{model_name}.configuration_{model_name}" model_filepath = f"transformers.models.{model_name}.modeling_{model_name}" - config_filename = f"{model_name.title()}Config" + config_filename = f"{model_name.title().replace('_','')}Config" # qwen3 arch folder is qwen3_moe but config is Qwen3Config. Need to remove underscore(_) for now exec(f"from {config_filepath} import {config_filename}", globals()) try: diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py index 722b50d27a..9c218d3e7d 100644 --- a/unsloth/models/llama.py +++ b/unsloth/models/llama.py @@ -2487,6 +2487,8 @@ class FastLlamaModel: elif model_type == "gemma2": apply_lora_mlp = apply_lora_mlp_geglu_approx elif model_type == "cohere": apply_lora_mlp = apply_lora_mlp_swiglu elif model_type == "granite": apply_lora_mlp = apply_lora_mlp_swiglu + elif model_type == "qwen3": apply_lora_mlp = apply_lora_mlp_swiglu + elif model_type == "qwen3moe": apply_lora_mlp = apply_lora_mlp_swiglu else: raise NotImplementedError(f"Unsloth: {model_type} is not yet implemented!") pass diff --git a/unsloth/models/qwen3.py b/unsloth/models/qwen3.py index aa99aa88db..9d658cf849 100644 --- a/unsloth/models/qwen3.py +++ b/unsloth/models/qwen3.py @@ -216,7 +216,7 @@ class FastQwen3Model(FastLlamaModel): # https://github.com/huggingface/transformers/pull/27931 # https://github.com/huggingface/transformers/blob/v4.37.2/src/transformers/models/llama/modeling_llama.py import transformers.models.qwen3.modeling_qwen3 - transformers.models.Qwen3.modeling_qwen3.Qwen3RotaryEmbedding = LlamaRotaryEmbedding + transformers.models.qwen3.modeling_qwen3.Qwen3RotaryEmbedding = LlamaRotaryEmbedding return pass