Skip to content

fix: initialize Gemma embeddings with std 0.02 - #206

Merged
aaishwarymishra merged 1 commit into
mainfrom
fix/gemma4-embedding-init
Oct 25, 2026
Merged

aaishwarymishra merged 1 commit into
mainfrom
fix/gemma4-embedding-init

Conversation

@aaishwarymishra

@aaishwarymishra aaishwarymishra commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

Gemma scales embeddings by sqrt(hidden_size). PyTorch's default N(0, 1) initialization then makes tied logits predict the input token with near-100% probability in an untrained model.

Initialize embeddings with N(0, 0.02), matching Gemma's initializer_range, and keep the padding row zeroed.

@netlify

netlify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for trainite canceled.

Name Link
🔨 Latest commit 773b33d
🔍 Latest deploy log https://app.netlify.com/projects/trainite/deploys/6adcec583a07673c4dfc2b83

@aaishwarymishra
aaishwarymishra force-pushed the fix/gemma4-embedding-init branch from 4a68eab to f215cd6 Compare October 24, 2026 17:30
PyTorch's default N(0, 1) initialization becomes too large after Gemma's sqrt(hidden_size) embedding scale. With tied output weights, untrained models assign almost all probability to the input token. Use Gemma's initializer_range (0.02) and keep the padding row zeroed.
@aaishwarymishra
aaishwarymishra force-pushed the fix/gemma4-embedding-init branch from f215cd6 to 773b33d Compare October 24, 2026 17:35
@aaishwarymishra aaishwarymishra changed the title fix: initialize Gemma token embeddings with Gemma's scale fix: initialize Gemma embeddings with std 0.02 Oct 24, 2026
@aaishwarymishra
aaishwarymishra merged commit 507cb91 into main Oct 25, 2026
11 checks passed
@aaishwarymishra
aaishwarymishra deleted the fix/gemma4-embedding-init branch October 25, 2026 15:35
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.

2 participants