Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Gemma3 Compatibility #965

Open
wns823 opened this issue Mar 13, 2025 · 2 comments
Open

[BUG] Gemma3 Compatibility #965

wns823 opened this issue Mar 13, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@wns823
Copy link

wns823 commented Mar 13, 2025

Description

I encountered an error when using gemma3 models with the smolagents library.

  • AttributeError: 'Gemma3Config' object has no attribute 'vocab_size'

The Issue

In src/smolagents/models.py,

try:
    self.model = AutoModelForCausalLM.from_pretrained(
        model_id,
        device_map=device_map,
        torch_dtype=torch_dtype,
        trust_remote_code=trust_remote_code,
    )
    self.tokenizer = AutoTokenizer.from_pretrained(model_id)
except ValueError as e:
    if "Unrecognized configuration class" in str(e):
        self.model = AutoModelForImageTextToText.from_pretrained(model_id, device_map=device_map)
        self.processor = AutoProcessor.from_pretrained(model_id)
        self._is_vlm = True
    else:
        raise e

I recommend adding an appropriate exception block, as shown in the example below.

except AttributeError as e:
    if "'Gemma3Config' object has no attribute 'vocab_size'" in str(e) :
        self.model = AutoModelForImageTextToText.from_pretrained(model_id, device_map=device_map)
        self.processor = AutoProcessor.from_pretrained(model_id)
        self._is_vlm = True
@wns823 wns823 added the bug Something isn't working label Mar 13, 2025
@aymeric-roucher
Copy link
Collaborator

Maybe the solution is just to switch line:

try:
    self.model = AutoModelForCausalLM.from_pretrained(

to:

try:
    self.model = AutoModel.from_pretrained(

Could you try that @wns823 ? And if it solves the issue, open a PR?

@Sakalya100
Copy link

Hi @aymeric-roucher

I have worked on this issue and tried the changes as suggested by you. This change works and it solves the issue.
Have opened a PR #1023 for the same

This is my first contribution to this repo and I have started contributing to open source recently. Please let me know if I am missing anything or something needs to be improved.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants