ml-explore / ml-explore/mlx-examples

Gemma issues identified by the Unsloth team / impact on mlx code? (shared on our discord as well)

Open
#579 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
9k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

posted this in the discord (https://discord.gg/pEPVK6gGfW)

but thanks to the awesome work of the unsloth team, they've identified some bugs in gemma implementations across the ecosystem: https://unsloth.ai/blog/gemma-bugs

i think these are the potential fixes to the mlx-lm examples repo, but would love a second pair of eyes -

token issues:
handle the addition of the token during finetuning
prefix to the input?

RMSNorm:
fp32 at the beginning and result back down at the end to the weight's dtype
set dtype of weight in RMSNorm class to fp32

rope issues:
unsloth guys say it needs to be int32 and not bfloat, but i dont see gemma.py in mlx examples handling it explicitly - maybe not an issue? cant tell. same with "RoPE is sensitive to a*(1/x) vs a/x"

gelu needs to be approx tanh
looking at mlx.nn, looks like it defaults to exact when you dont pass in a param. gemma.py does this:
return self.down_proj(nn.gelu(self.gate_proj(x)) * self.up_proj(x))
which I assume means it's using exact, and needs to pass in 'precise'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Unsloth Gemma bug report and the Gemma implementation in gemma.py, then inspect mlx.nn behavior for token handling, RMSNorm, RoPE, and GELU. Compare each reported issue with the current implementation and document or implement only the applicable fixes; done means the affected Gemma behaviors match the intended specification.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.