diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index 34a61e250d..9bd0fc17ad 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "2025.6.6" +__version__ = "2025.6.7" __all__ = [ "SUPPORTS_BFLOAT16", diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index 8a49026984..184be83539 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -48,14 +48,15 @@ import importlib.util # https://github.com/huggingface/transformers/pull/26037 allows 4 bit loading! from unsloth_zoo.utils import Version, _get_dtype transformers_version = Version(transformers_version) -SUPPORTS_FOURBIT = transformers_version >= Version("4.37") -SUPPORTS_GEMMA = transformers_version >= Version("4.38") -SUPPORTS_GEMMA2 = transformers_version >= Version("4.42") -SUPPORTS_LLAMA31 = transformers_version >= Version("4.43.2") -SUPPORTS_LLAMA32 = transformers_version > Version("4.45.0") -SUPPORTS_GRANITE = transformers_version >= Version("4.46.0") -SUPPORTS_QWEN3 = transformers_version >= Version("4.50.3") +SUPPORTS_FOURBIT = transformers_version >= Version("4.37") +SUPPORTS_GEMMA = transformers_version >= Version("4.38") +SUPPORTS_GEMMA2 = transformers_version >= Version("4.42") +SUPPORTS_LLAMA31 = transformers_version >= Version("4.43.2") +SUPPORTS_LLAMA32 = transformers_version > Version("4.45.0") +SUPPORTS_GRANITE = transformers_version >= Version("4.46.0") +SUPPORTS_QWEN3 = transformers_version >= Version("4.50.3") SUPPORTS_QWEN3_MOE = transformers_version >= Version("4.50.3") +SUPPORTS_GEMMA3N = transformers_version >= Version("4.53.0") if SUPPORTS_GEMMA: from .gemma import FastGemmaModel if SUPPORTS_GEMMA2: @@ -543,6 +544,8 @@ class FastModel(FastBaseModel): os.environ["UNSLOTH_FORCE_CUSTOM_DTYPE"] = "torch.float16;if name.endswith(('_proj', 'fc1', 'fc2', 'codebook', 'head')): module.to(torch.float16)" elif "olmo-2" in lowered_model_name and transformers_version < Version("4.50.0.dev0"): raise RuntimeError("Unsloth: OLMo-2 only works on transformers >= 4.50.0." + NIGHTLY) + elif "gemma-3n" in lowered_model_name and transformers_version < Version("4.53.0"): + raise RuntimeError("Unsloth: Gemma 3N only works on transformers >= 4.53.0" + LATEST) else: for check_model_name in DISABLE_COMPILE_MODEL_NAMES: if check_model_name in lowered_model_name: @@ -727,6 +730,10 @@ class FastModel(FastBaseModel): unsloth_force_compile = unsloth_force_compile, ) pass + # Fix SDPA + if "gemma-3n" in lowered_model_name: + supports_sdpa = False + pass # Check if this is local model since the tokenizer gets overwritten if os.path.exists(os.path.join(old_model_name, "tokenizer_config.json")) and \ diff --git a/unsloth/models/mapper.py b/unsloth/models/mapper.py index fdf95691a9..62259841c5 100644 --- a/unsloth/models/mapper.py +++ b/unsloth/models/mapper.py @@ -879,6 +879,26 @@ __INT_TO_FLOAT_MAPPER = \ "mistralai/Mistral-Small-3.2-24B-Instruct-2506", "unsloth/Mistral-Small-3.2-24B-Instruct-2506-bnb-4bit", ), + "unsloth/gemma-3n-E4B-it-unsloth-bnb-4bit" : ( + "unsloth/gemma-3n-E4B-it", + "google/gemma-3n-E4B-it", + "unsloth/gemma-3n-E4B-it-unsloth-bnb-4bit", + ), + "unsloth/gemma-3n-E2B-it-unsloth-bnb-4bit" : ( + "unsloth/gemma-3n-E2B-it", + "google/gemma-3n-E2B-it", + "unsloth/gemma-3n-E2B-it-unsloth-bnb-4bit", + ), + "unsloth/gemma-3n-E4B-unsloth-bnb-4bit" : ( + "unsloth/gemma-3n-E4B", + "google/gemma-3n-E4B", + "unsloth/gemma-3n-E4B-unsloth-bnb-4bit", + ), + "unsloth/gemma-3n-E2B-unsloth-bnb-4bit" : ( + "unsloth/gemma-3n-E2B", + "google/gemma-3n-E2B", + "unsloth/gemma-3n-E2B-unsloth-bnb-4bit", + ), } INT_TO_FLOAT_MAPPER = {}