Fix Gemma3N notebook loading by forcing eager attention#196
Fix Gemma3N notebook loading by forcing eager attention#196danielhanchen wants to merge 1 commit intomainfrom
Conversation
Summary of ChangesHello @danielhanchen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an incompatibility issue where Gemma3N's vision components conflict with Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses an incompatibility issue with Gemma3N models by forcing eager attention. The fix is applied consistently across all relevant notebooks. My review includes a few minor suggestions to improve comment clarity in the conversational notebooks for better maintainability, and one suggestion for code style consistency.
| " dtype = None, # None for auto detection\n", | ||
| " max_seq_length = 1024, # Choose any for long context!\n", | ||
| " load_in_4bit = True, # 4 bit quantization to reduce memory\n", | ||
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", |
There was a problem hiding this comment.
The comment mentions a "vision tower", which might be confusing in a conversational notebook. For clarity, consider a more general comment about the incompatibility with flex_attention.
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", | |
| " attn_implementation = \"eager\", # Force eager attention due to Gemma3N incompatibility with flex_attention\n", |
| " model_name = \"gemma_3n_lora\", # YOUR MODEL YOU USED FOR TRAINING\n", | ||
| " max_seq_length = 2048,\n", | ||
| " load_in_4bit = True,\n", | ||
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", |
There was a problem hiding this comment.
The comment mentions a "vision tower", which might be confusing in a conversational notebook. For clarity, consider a more general comment about the incompatibility with flex_attention.
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", | |
| " attn_implementation = \"eager\", # Force eager attention due to Gemma3N incompatibility with flex_attention\n", |
| " dtype = None, # None for auto detection\n", | ||
| " max_seq_length = 1024, # Choose any for long context!\n", | ||
| " load_in_4bit = True, # 4 bit quantization to reduce memory\n", | ||
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", |
There was a problem hiding this comment.
The comment mentions a "vision tower", which might be confusing in a conversational notebook. For clarity, consider a more general comment about the incompatibility with flex_attention.
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", | |
| " attn_implementation = \"eager\", # Force eager attention due to Gemma3N incompatibility with flex_attention\n", |
| " model_name = \"gemma_3n_lora\", # YOUR MODEL YOU USED FOR TRAINING\n", | ||
| " max_seq_length = 2048,\n", | ||
| " load_in_4bit = True,\n", | ||
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", |
There was a problem hiding this comment.
The comment mentions a "vision tower", which might be confusing in a conversational notebook. For clarity, consider a more general comment about the incompatibility with flex_attention.
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", | |
| " attn_implementation = \"eager\", # Force eager attention due to Gemma3N incompatibility with flex_attention\n", |
| " dtype = None, # None for auto detection\n", | ||
| " max_seq_length = 1024, # Choose any for long context!\n", | ||
| " load_in_4bit = True, # 4 bit quantization to reduce memory\n", | ||
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", |
There was a problem hiding this comment.
The comment mentions a "vision tower", which might be confusing in a conversational notebook. For clarity, consider a more general comment about the incompatibility with flex_attention.
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", | |
| " attn_implementation = \"eager\", # Force eager attention due to Gemma3N incompatibility with flex_attention\n", |
| " model_name = \"gemma-3n\", # YOUR MODEL YOU USED FOR TRAINING\n", | ||
| " max_seq_length = 2048,\n", | ||
| " load_in_4bit = True,\n", | ||
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", |
There was a problem hiding this comment.
The comment mentions a "vision tower", which might be confusing in a conversational notebook. For clarity, consider a more general comment about the incompatibility with flex_attention.
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", | |
| " attn_implementation = \"eager\", # Force eager attention due to Gemma3N incompatibility with flex_attention\n", |
| " model, processor = FastVisionModel.from_pretrained(\n", | ||
| " model_name=\"lora_model\", # YOUR MODEL YOU USED FOR TRAINING\n", | ||
| " load_in_4bit=True, # Set to False for 16bit LoRA\n", | ||
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", |
There was a problem hiding this comment.
For consistency with the surrounding code (e.g., model_name=\"lora_model\", load_in_4bit=True), consider removing the spaces around the = operator.
| " attn_implementation = \"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", | |
| " attn_implementation=\"eager\", # Gemma 3N vision tower is incompatible with flex_attention\n", |
Summary
attn_implementation = "eager"to Gemma3Nfrom_pretrained(...)calls in the conversational and vision notebooks.nb/,nb/Kaggle-, andoriginal_template/variants.Root cause
Gemma3N can initialize timm-based vision components that are not compatible with
flex_attentionin current Transformers paths. For notebook reliability, these Gemma3N loaders should request eager attention explicitly.Files changed
nb/Gemma3N_(4B)-Conversational.ipynbnb/Gemma3N_(4B)-Vision.ipynbnb/Kaggle-Gemma3N_(4B)-Conversational.ipynbnb/Kaggle-Gemma3N_(4B)-Vision.ipynboriginal_template/Gemma3N_(4B)-Conversational.ipynboriginal_template/Gemma3N_(4B)-Vision.ipynbValidation
from_pretrained(...)callsites withattn_implementation = "eager".