You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
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,
I recommend adding an appropriate exception block, as shown in the example below.
The text was updated successfully, but these errors were encountered: