Skip to content

updated models template mappers. added lfm2.5vl450m to transformers 5… - #4939

Merged
rolandtannous merged 2 commits into
mainfrom
feature/update-models-template-mapping
Apr 9, 2026
Merged

rolandtannous merged 2 commits into
mainfrom
feature/update-models-template-mapping

Conversation

@rolandtannous

Copy link
Copy Markdown
Contributor

updated models template mappers for:

  • gemma4 models (thinking and non thinking)
  • lfm2 models
  • lfm2.5 models

added lfm2.5vl450m to transformers 5.3.0 white list

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60c2246109

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1981 to +1983
"unsloth/gemma-4-E2B-it-unsloth-bnb-4bit",
"unsloth/gemma-4-E4B-it",
"unsloth/gemma-4-E4B",
"unsloth/gemma-4-E4B-it-unsloth-bnb-4bit",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore Gemma-4 base aliases in Ollama mapper

Replacing the Gemma-4 base IDs with only -it/4-bit IDs removes template resolution for checkpoints whose base_model_name is unsloth/gemma-4-E2B, unsloth/gemma-4-E4B, unsloth/gemma-4-31B, or unsloth/gemma-4-26B-A4B. In create_ollama_modelfile, those names now miss MODEL_TO_OLLAMA_TEMPLATE_MAPPER and immediately skip Modelfile generation, which is a regression from the previous mapping and breaks Ollama export for adapters trained from those base models.

Useful? React with 👍 / 👎.

"LiquidAI/LFM2-1.2B",
"unsloth/LFM2-1.2B-unsloth-bnb-4bit",
),
"lfm-2.5": ("unsloth/LFM2.5-1.2B-Instruct",),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Map LFM2.5 to an existing chat template key

This adds unsloth/LFM2.5-1.2B-Instruct under template name lfm-2.5, but unsloth.chat_templates.CHAT_TEMPLATES has lfm-2 and no lfm-2.5. As a result, Studio now always takes the direct-match path, calls get_chat_template(..., chat_template='lfm-2.5'), hits a KeyError, and falls back without applying a known Unsloth template; this makes template setup for LFM2.5 unreliable and can disable expected formatting/masking behavior.

Useful? React with 👍 / 👎.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for several new models, including the Gemma-4 family and LiquidAI LFM-2/2.5 models, by updating model mappings, template configurations, and versioning utilities. I have reviewed the changes and identified a redundant entry in the gemma4 template mapper within unsloth/ollama_template_mappers.py that should be removed.

"gemma4": (
"unsloth/gemma-4-E2B-it",
"unsloth/gemma-4-E2B",
"unsloth/gemma-4-E2B-it-unsloth-bnb-4bit",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The model name 'unsloth/gemma-4-E2B-it-unsloth-bnb-4bit' is already included in the gemma4 template mapper. This duplicate entry is redundant and should be removed to maintain clean configuration.

Suggested change
"unsloth/gemma-4-E2B-it-unsloth-bnb-4bit",
"unsloth/gemma-4-E2B-it",
"unsloth/gemma-4-E4B-it",
"unsloth/gemma-4-E4B-it-unsloth-bnb-4bit",
"unsloth/gemma-4-31B-it",
"unsloth/gemma-4-26B-A4B-it",

@isaac-mcfadyen

isaac-mcfadyen commented Apr 9, 2026 •

Copy link
Copy Markdown

This commit just broke FastModel.from_pretrained("unsloth/gemma-4-E4B-it"), which was working before this was merged (~1h ago).

With unsloth>=2026.4.4 and transformers>=5.5.0:

NotImplementedError: Unsloth: unsloth/gemma-4-E4B-it is not supported in your current Unsloth version! Please update Unsloth via:

pip uninstall unsloth unsloth_zoo -y
pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
pip install --upgrade --no-cache-dir "git+https://github.com/unslothai/unsloth-zoo.git"

Can we see about getting this reverted?

EDIT: investigating further, it seems because Gemma 4 is now in the mapper.py file, and the logic is "any models in the GItHub mapper.py and not in local mapper.py must need a new Unsloth version", things break, even though Gemma 4 is supported in unsloth==2026.4.4.


Side note: bit unfortunate that it relies on fetching from HEAD on GitHub since it means things like this can happen even without upgrading unsloth or unsloth-zoo

@SmartestWashingMachine

Copy link
Copy Markdown

I'm facing the exact same issue as @isaac-mcfadyen

For now this hack seems to work for me (apply before loading a model with .from_pretrained):

from unsloth.models import loader_utils
def _get_new_mapper_patched():
    # upgraded_model_name always resolves to None now, so no version mismatch check for model loading.
    # Thankfully this util doesn't seem to be used anywhere else apart from unit tests.
    return {}, {}, {}

loader_utils._get_new_mapper = _get_new_mapper_patched

danielhanchen added a commit that referenced this pull request Apr 15, 2026
* Reapply "updated models template mappers. added lfm2.5vl450m to transformers 5…" (#4945)

This reverts commit 33503ea.

* Add missing gemma-4-31B-it bnb-4bit mapper entry and LFM2.5 upstream namespace for PR #4950

- Add unsloth/gemma-4-31B-it-unsloth-bnb-4bit to __INT_TO_FLOAT_MAPPER so
  the int-to-float resolution works for this model (already listed in
  TEMPLATE_TO_MODEL_MAPPER but had no mapper entry).
- Add LiquidAI/LFM2.5-1.2B-Instruct to lfm-2.5 TEMPLATE_TO_MODEL_MAPPER
  entry so the canonical upstream namespace is mapped consistently with lfm-2.

* Add missing gemma-4-31B-it bnb-4bit Ollama mapping and lfm-2.5 chat template alias

- Add unsloth/gemma-4-31B-it-unsloth-bnb-4bit to OLLAMA_TEMPLATE_TO_MODEL_MAPPER
  so Ollama export works for this model (E2B-it and E4B-it bnb-4bit variants were
  already present, 31B-it was inconsistently omitted)
- Register CHAT_TEMPLATES["lfm-2.5"] as alias of the lfm-2 template to prevent
  KeyError when Studio resolves LFM2.5 models through MODEL_TO_TEMPLATE_MAPPER

* Add missing LFM2 bnb-4bit INT_TO_FLOAT_MAPPER entry

unsloth/LFM2-1.2B-unsloth-bnb-4bit is referenced in model_mappings.py
but had no mapper.py entry, so model resolution would fail when users
load that variant with load_in_4bit=False or when the float name is
used with load_in_4bit=True.

* Fix review findings for PR #16

1. ollama_template_mappers.py: Restore dropped Gemma-4 base model IDs
   (E2B, E4B, 31B, 26B-A4B) and add missing google/ upstream IDs to
   the gemma4 Ollama mapper for consistency with other gemma entries.

2. mapper.py: Remove self-mapping non-bnb-4bit entries from
   __INT_TO_FLOAT_MAPPER that were polluting FLOAT_TO_INT_MAPPER with
   lowercase 16-bit names, causing load_in_4bit=True to return bad
   model names. Add direct MAP_TO_UNSLOTH_16bit entries to preserve
   the google->unsloth 16-bit redirects.

3. mapper.py: Add LFM2.5 MAP_TO_UNSLOTH_16bit redirect so
   LiquidAI/LFM2.5-1.2B-Instruct resolves to its unsloth mirror.

* Add review tests for PR #4950

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove top-level test files

These test_*.py files were added at the repo root rather than under tests/.
Removing them from this PR; the production mapper changes remain.

* Add gemma-4-26B-A4B-it mapping

Adds unsloth/gemma-4-26B-A4B-it to __INT_TO_FLOAT_MAPPER as a 2-tuple so
google/gemma-4-26B-A4B-it routes to unsloth/gemma-4-26B-A4B-it across
INT_TO_FLOAT_MAPPER, FLOAT_TO_INT_MAPPER, and MAP_TO_UNSLOTH_16bit.

The 26B-A4B (MoE) model has no bnb-4bit variant, so the key uses the
plain unsloth name rather than the -unsloth-bnb-4bit suffix.

Removes the now-redundant standalone _add_with_lower call for the -it
variant; the 16bit mapping is registered via the dict loop.

* Add unsloth-bnb-4bit mappings for gemma-4 base (non-it) models

Adds E2B, E4B, 31B base unsloth-bnb-4bit entries to __INT_TO_FLOAT_MAPPER.
The 26B-A4B (MoE) base has no bnb-4bit variant on HF, so it stays on the
standalone _add_with_lower line for the 16bit-only routing.

Removes the redundant _add_with_lower lines for E2B, E4B, 31B base since
the dict loop now registers the same google->unsloth route through the
2-tuple entries, plus full FLOAT_TO_INT and INT_TO_FLOAT coverage.

---------

Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants