Skip to content

fix(pi0-fast): don't apply embed scaling#3304

Open
zucchini-nlp wants to merge 2 commits intohuggingface:mainfrom
zucchini-nlp:pio-fast-embed-scaling
Open

fix(pi0-fast): don't apply embed scaling#3304
zucchini-nlp wants to merge 2 commits intohuggingface:mainfrom
zucchini-nlp:pio-fast-embed-scaling

Conversation

@zucchini-nlp
Copy link
Copy Markdown
Member

@zucchini-nlp zucchini-nlp commented Apr 7, 2026

From internal conversation, huggingface/transformers#44432 moved all the scaling to LM's embedding layer and now we shouldn't be manually apply or removing the scaling with gemma models. This fix is needed to pin transformers>= 5.4.0

Copilot AI review requested due to automatic review settings April 7, 2026 10:34
@github-actions github-actions bot added the policies Items related to robot policies label Apr 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates PI0/PI0Fast embedding logic to align with the upstream Transformers change that relocates Gemma/PaliGemma embedding scaling into the model’s embedding layer (so this code should no longer manually apply or remove scaling).

Changes:

  • Removed manual sqrt(hidden_size) scaling for image embeddings and language token embeddings.
  • Switched language-token embedding retrieval from direct embed_tokens(...) access to an embedding-layer accessor call.
  • Removed additional scaling when embedding incremental next-tokens during fast decoding paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/lerobot/policies/pi0/modeling_pi0.py Drops manual embedding scaling; updates language token embedding call site.
src/lerobot/policies/pi0_fast/modeling_pi0_fast.py Drops manual embedding scaling across prefix/FAST action/decoding paths; updates language token embedding call site.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 414 to +417
# Process language instruction tokens
def lang_embed_func(tokens):
lang_emb = self.paligemma_with_expert.embed_language_tokens(tokens)
lang_emb_dim = lang_emb.shape[-1]
return lang_emb * math.sqrt(lang_emb_dim)
return lang_emb
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

After removing the math.sqrt(...) scaling, this block no longer uses math; since the module is now unused in this file, the import math at the top should be removed to satisfy linters (ruff/flake8) and avoid dead imports.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

policies Items related to robot policies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants