Skip to content

Sync FORCE_FLOAT32 fallback with unsloth-zoo (gemma4, glm4_moe, qwen3_moe) - #6865

Merged
danielhanchen merged 2 commits into
mainfrom
fp16-moe-force-float32-fallback
Jul 6, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fp16-moe-force-float32-fallback

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Keeps the FORCE_FLOAT32 fallback list in unsloth/models/loader.py in sync with unsloth_zoo/model_lists.py (unslothai/unsloth-zoo#866), which adds gemma4, glm4_moe and qwen3_moe.

Loaded with dtype=torch.float16, these MoE architectures keep a finite loss but NaN the grad_norm (a backward gradient overflow along the residual stream; bf16 is fully finite). Being in FORCE_FLOAT32 makes a float16 request load bf16 and run finite, the same as gpt_oss / qwen3_5 / gemma3. The targeted per-module float32 patches for gemma4 / qwen3_moe live in unsloth-zoo (#866).

This list is only the fallback used if from unsloth_zoo import FORCE_FLOAT32 fails; the authoritative list is in unsloth-zoo. Updating it keeps the two consistent.

Keeps the fallback list (used only if the unsloth_zoo import fails) in sync with
unsloth_zoo/model_lists.py, which now force-float32s these MoE archs so a float16
request loads bf16 and trains finite instead of NaNing the grad_norm.

@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 updates unsloth/models/loader.py to add several new model identifiers (gemma4, glm4_moe, and qwen3_moe) to the list of models that experience float16 NaN gradient norms during backward passes. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

/gemini review

@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 updates unsloth/models/loader.py to add several new model architectures ('gemma4', 'glm4_moe', and 'qwen3_moe') to the list of models that experience float16 NaN gradient norms during backward passes. There are no review comments, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@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: cb371110fb

ℹ️ 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 thread unsloth/models/loader.py Outdated
"gemma3,", # Add comma bc gemma3 will match gemma3n
"gemma3text", # Gemma3TextModel (EmbeddingGemma, standalone text-only Gemma3)
"gemma3n",
"gemma4", # Gemma4 (gemma4 / gemma4_text): float16 NaNs grad norms in the backward

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 Merge new fallbacks when zoo import succeeds

Adding gemma4 only to the except ImportError fallback does not cover the stale-unsloth_zoo case described in the commit: if the installed zoo package already exports FORCE_FLOAT32 but predates the entries from unsloth-zoo#866, the import at line 116 succeeds and this fallback list is bypassed, so Gemma 4 / GLM-4 MoE / Qwen3-MoE fp16 loads still will not be coerced. Please append/merge these required names into the imported list when they are missing, rather than only defining them in the import-failure path.

Useful? React with 👍 / 👎.

@danielhanchen

Copy link
Copy Markdown
Member Author

The fallback list is now unioned into whatever unsloth_zoo exports, so a newer unsloth still forces float32 for gemma4 / glm4_moe / qwen3_moe even when paired with an older unsloth_zoo that predates those entries.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: bf7afc4972

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: bf7afc4972

ℹ️ 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".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 6, 2026
@danielhanchen
danielhanchen merged commit efcaffb into main Jul 6, 2026
51 checks passed
@danielhanchen
danielhanchen deleted the fp16-moe-force-float32-fallback branch July 6, 2026 12:48
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.

1 participant