Skip to content

Commit 2cdcf61

Browse files
danielhanchenjeromekujackswlshimmyshimmer
authored
Gemma 3N (#2809)
* Add QLoRA Train and Merge16bit Test (#2130) * add reference and unsloth lora merging tests * add test / dataset printing to test scripts * allow running tests from repo root * add qlora test readme * more readme edits * ruff formatting * additional readme comments * forgot to add actual tests * add apache license * Update pyproject.toml * Update vision.py * Update vision.py * Update vision.py * Update vision.py * Update loader.py * Update loader.py * Revert * Update vision.py * Update vision.py * Update vision.py * Update vision.py * Update vision.py * Bug fix * Update mapper.py * check SDPA for Mistral 3, Pixtral * Update vision.py * Versioning * Update rl_replacements.py * Update README.md * add model registry * move hf hub utils to unsloth/utils * refactor global model info dicts to dataclasses * fix dataclass init * fix llama registration * remove deprecated key function * start registry reog * add llama vision * quant types -> Enum * remap literal quant types to QuantType Enum * add llama model registration * fix quant tag mapping * add qwen2.5 models to registry * add option to include original model in registry * handle quant types per model size * separate registration of base and instruct llama3.2 * add QwenQVQ to registry * add gemma3 to registry * add phi * add deepseek v3 * add deepseek r1 base * add deepseek r1 zero * add deepseek distill llama * add deepseek distill models * remove redundant code when constructing model names * add mistral small to registry * rename model registration methods * rename deepseek registration methods * refactor naming for mistral and phi * add global register models * refactor model registration tests for new registry apis * add model search method * remove deprecated registration api * add quant type test * add registry readme * make llama registration more specific * clear registry when executing individual model registration file * more registry readme updates * Update _auto_install.py * Llama4 * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Synthetic data * Update mapper.py * Xet and Synthetic * Update synthetic.py * Update loader.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update pyproject.toml * Delete .gitignore * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update _utils.py * Update pyproject.toml * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update synthetic.py * Update chat_templates.py * Seasame force float16 / float32 * Fix Seasame * Update loader.py * Update vision.py * Update vision.py * Update vision.py * Update loader.py * is_multimodal * Update loader.py * Update loader.py * Update loader.py * Update loader.py * Update vision.py * Update vision.py * Update vision.py * UNSLOTH_DISABLE_STATIC_GENERATION * Update vision.py * Auto vision detection * Sesame * Whisper * Update loader.py * Update loader.py * Update loader.py * Update mapper.py * Update vision.py * Update vision.py * Update vision.py * Update vision.py * Update vision.py * Update vision.py * Update loader.py * Update loader.py * Update loader.py * Update loader.py * Update _utils.py * Update rl.py * versioning * Update rl.py * Update rl.py * Update rl.py * Update rl.py * Update rl.py * logging * Update pyproject.toml * Update rl.py * versioning * Update rl.py * Update rl.py * Update rl_replacements.py * Update rl_replacements.py * Update rl.py * Update rl_replacements.py * Update rl_replacements.py * logits / temperature * Update rl_replacements.py * Update pyproject.toml * Update rl_replacements.py * Update rl_replacements.py * Debugging only * Update llama.py * Update llama.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Update rl_replacements.py * Generic efficient GRPO * Update rl_replacements.py * Update rl_replacements.py * Remove debugging * Update rl_replacements.py * Update rl_replacements.py * Update vision.py * Update llama.py * Update rl_replacements.py * versioning * Update _utils.py * Update vision.py * Update mapper.py * Update loader.py * Update mapper.py * Update vision.py * Update loader.py * Update vision.py * Update loader.py * Update _utils.py --------- Co-authored-by: jeromeku <jerome.ku@gmail.com> Co-authored-by: Jack Shi Wei Lun <87535974+jackswl@users.noreply.github.com> Co-authored-by: Michael Han <107991372+shimmyshimmer@users.noreply.github.com>
1 parent 425ae4d commit 2cdcf61

3 files changed

Lines changed: 35 additions & 8 deletions

File tree

unsloth/models/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "2025.6.6"
15+
__version__ = "2025.6.7"
1616

1717
__all__ = [
1818
"SUPPORTS_BFLOAT16",

unsloth/models/loader.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@
4848
# https://github.com/huggingface/transformers/pull/26037 allows 4 bit loading!
4949
from unsloth_zoo.utils import Version, _get_dtype
5050
transformers_version = Version(transformers_version)
51-
SUPPORTS_FOURBIT = transformers_version >= Version("4.37")
52-
SUPPORTS_GEMMA = transformers_version >= Version("4.38")
53-
SUPPORTS_GEMMA2 = transformers_version >= Version("4.42")
54-
SUPPORTS_LLAMA31 = transformers_version >= Version("4.43.2")
55-
SUPPORTS_LLAMA32 = transformers_version > Version("4.45.0")
56-
SUPPORTS_GRANITE = transformers_version >= Version("4.46.0")
57-
SUPPORTS_QWEN3 = transformers_version >= Version("4.50.3")
51+
SUPPORTS_FOURBIT = transformers_version >= Version("4.37")
52+
SUPPORTS_GEMMA = transformers_version >= Version("4.38")
53+
SUPPORTS_GEMMA2 = transformers_version >= Version("4.42")
54+
SUPPORTS_LLAMA31 = transformers_version >= Version("4.43.2")
55+
SUPPORTS_LLAMA32 = transformers_version > Version("4.45.0")
56+
SUPPORTS_GRANITE = transformers_version >= Version("4.46.0")
57+
SUPPORTS_QWEN3 = transformers_version >= Version("4.50.3")
5858
SUPPORTS_QWEN3_MOE = transformers_version >= Version("4.50.3")
59+
SUPPORTS_GEMMA3N = transformers_version >= Version("4.53.0")
5960
if SUPPORTS_GEMMA:
6061
from .gemma import FastGemmaModel
6162
if SUPPORTS_GEMMA2:
@@ -543,6 +544,8 @@ def from_pretrained(
543544
os.environ["UNSLOTH_FORCE_CUSTOM_DTYPE"] = "torch.float16;if name.endswith(('_proj', 'fc1', 'fc2', 'codebook', 'head')): module.to(torch.float16)"
544545
elif "olmo-2" in lowered_model_name and transformers_version < Version("4.50.0.dev0"):
545546
raise RuntimeError("Unsloth: OLMo-2 only works on transformers >= 4.50.0." + NIGHTLY)
547+
elif "gemma-3n" in lowered_model_name and transformers_version < Version("4.53.0"):
548+
raise RuntimeError("Unsloth: Gemma 3N only works on transformers >= 4.53.0" + LATEST)
546549
else:
547550
for check_model_name in DISABLE_COMPILE_MODEL_NAMES:
548551
if check_model_name in lowered_model_name:
@@ -727,6 +730,10 @@ def from_pretrained(
727730
unsloth_force_compile = unsloth_force_compile,
728731
)
729732
pass
733+
# Fix SDPA
734+
if "gemma-3n" in lowered_model_name:
735+
supports_sdpa = False
736+
pass
730737

731738
# Check if this is local model since the tokenizer gets overwritten
732739
if os.path.exists(os.path.join(old_model_name, "tokenizer_config.json")) and \

unsloth/models/mapper.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,26 @@
879879
"mistralai/Mistral-Small-3.2-24B-Instruct-2506",
880880
"unsloth/Mistral-Small-3.2-24B-Instruct-2506-bnb-4bit",
881881
),
882+
"unsloth/gemma-3n-E4B-it-unsloth-bnb-4bit" : (
883+
"unsloth/gemma-3n-E4B-it",
884+
"google/gemma-3n-E4B-it",
885+
"unsloth/gemma-3n-E4B-it-unsloth-bnb-4bit",
886+
),
887+
"unsloth/gemma-3n-E2B-it-unsloth-bnb-4bit" : (
888+
"unsloth/gemma-3n-E2B-it",
889+
"google/gemma-3n-E2B-it",
890+
"unsloth/gemma-3n-E2B-it-unsloth-bnb-4bit",
891+
),
892+
"unsloth/gemma-3n-E4B-unsloth-bnb-4bit" : (
893+
"unsloth/gemma-3n-E4B",
894+
"google/gemma-3n-E4B",
895+
"unsloth/gemma-3n-E4B-unsloth-bnb-4bit",
896+
),
897+
"unsloth/gemma-3n-E2B-unsloth-bnb-4bit" : (
898+
"unsloth/gemma-3n-E2B",
899+
"google/gemma-3n-E2B",
900+
"unsloth/gemma-3n-E2B-unsloth-bnb-4bit",
901+
),
882902
}
883903

884904
INT_TO_FLOAT_MAPPER = {}

0 commit comments

Comments
 (0)