Skip to content

fix: gemma3 patch vocab_size not found#2741

Closed
NanoCode012 wants to merge 1 commit into
mainfrom
fix/gemma-patch
Closed

fix: gemma3 patch vocab_size not found#2741
NanoCode012 wants to merge 1 commit into
mainfrom
fix/gemma-patch

Conversation

@NanoCode012

@NanoCode012 NanoCode012 commented May 29, 2025

Copy link
Copy Markdown
Collaborator

Description

Fixes: https://github.com/axolotl-ai-cloud/axolotl/actions/runs/15310334187/job/43075132418

Motivation and Context

How has this been tested?

Screenshots (if appropriate)

Types of changes

Social Handles (Optional)

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of image token indexing to ensure more accurate processing in certain scenarios.

@coderabbitai

coderabbitai Bot commented May 29, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

A conditional check in the code was updated to compare the image token index against the vocabulary size from the text configuration, rather than the model's general vocabulary size. No changes were made to public interfaces or function signatures.

Changes

File Change Summary
src/axolotl/monkeypatch/gemma3.py Updated condition to use text_config.vocab_size for comparison.

Poem

In the world of tokens, a check was revised,
Now text config’s vocab size is properly prized.
No signatures shifted, no functions anew,
Just a sharper condition—less muddle, more true.
With a hop and a patch, the code’s on its way,
Hooray for precision—hip hip, hooray!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec4ebfd and ff44939.

📒 Files selected for processing (1)
  • src/axolotl/monkeypatch/gemma3.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: PyTest from Source Dist (3.11, 2.5.1)
  • GitHub Check: PyTest from Source Dist (3.11, 2.7.0)
  • GitHub Check: PyTest from Source Dist (3.11, 2.6.0)
  • GitHub Check: pre-commit
  • GitHub Check: PyTest (3.11, 2.5.1)
  • GitHub Check: PyTest (3.11, 2.7.0)
  • GitHub Check: PyTest (3.11, 2.6.0)
  • GitHub Check: pre-commit

Comment on lines +95 to +98
if (
input_ids is not None
and self.config.image_token_index >= self.config.text_config.vocab_size
):

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.

💡 Verification agent

🧩 Analysis chain

Fix for AttributeError looks correct and consistent.

The change from self.vocab_size to self.config.text_config.vocab_size properly resolves the "vocab_size not found" issue mentioned in the PR. This change is consistent with:

  1. The function's docstring (lines 41-42) which references config.text_config.vocab_size
  2. Other usage in the same function (lines 203, 211) where self.config.text_config.vocab_size is used for the loss function
  3. Standard transformers library structure where vocabulary size is typically accessed through the text configuration

To ensure this fix works as expected, please verify that the patched model handles image tokens correctly:


🏁 Script executed:

#!/bin/bash
# Description: Search for other usages of vocab_size in gemma3 related files to ensure consistency

# Search for vocab_size usage patterns in gemma3 files
rg -A 3 -B 3 "vocab_size" --type py | grep -i gemma

# Search for text_config.vocab_size usage patterns
rg -A 2 -B 2 "text_config\.vocab_size" --type py

Length of output: 12135


Ensure consistent use of config.text_config.vocab_size across all Gemma3 patches.

The fix in src/axolotl/monkeypatch/gemma3.py is correct and aligns with other usages. However, the integration patch under src/axolotl/integrations/cut_cross_entropy/monkeypatch/gemma3.py still references self.vocab_size in the image‐token check. Update it as well:

Locations to update:

  • src/axolotl/integrations/cut_cross_entropy/monkeypatch/gemma3.py
    - if input_ids is not None and self.config.image_token_index >= self.vocab_size:
    + if input_ids is not None and self.config.image_token_index >= self.config.text_config.vocab_size:

After applying, verify end‐to‐end that image tokens are handled without index errors.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/axolotl/integrations/cut_cross_entropy/monkeypatch/gemma3.py, locate the
image-token index check where self.vocab_size is referenced and update it to use
self.config.text_config.vocab_size instead. This change ensures consistency with
the fix applied in src/axolotl/monkeypatch/gemma3.py and aligns with the
standard way vocabulary size is accessed. After making this update, run
end-to-end tests to confirm image tokens are handled correctly without index
errors.

@codecov

codecov Bot commented May 29, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/axolotl/monkeypatch/gemma3.py 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@winglian

Copy link
Copy Markdown
Collaborator

looks like it may not be needed anymore. I've removed this patch in the #2735 PR and the loss is still stable for the test

@NanoCode012

Copy link
Copy Markdown
Collaborator Author

Thanks!

@NanoCode012 NanoCode012 deleted the fix/gemma-patch branch September 26, 2025 08:20
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