Skip to content

Fix Gemma3N notebook loading by forcing eager attention#196

Open
danielhanchen wants to merge 1 commit intomainfrom
fix-gemma3n-eager-attn-loaders
Open

Fix Gemma3N notebook loading by forcing eager attention#196
danielhanchen wants to merge 1 commit intomainfrom
fix-gemma3n-eager-attn-loaders

Conversation

@danielhanchen
Copy link
Copy Markdown
Contributor

Summary

  • Add attn_implementation = "eager" to Gemma3N from_pretrained(...) calls in the conversational and vision notebooks.
  • Apply the same change in nb/, nb/Kaggle-, and original_template/ variants.
  • Update both the primary model load cell and the optional reload cell in each notebook for consistency.

Root cause

Gemma3N can initialize timm-based vision components that are not compatible with flex_attention in current Transformers paths. For notebook reliability, these Gemma3N loaders should request eager attention explicitly.

Files changed

  • nb/Gemma3N_(4B)-Conversational.ipynb
  • nb/Gemma3N_(4B)-Vision.ipynb
  • nb/Kaggle-Gemma3N_(4B)-Conversational.ipynb
  • nb/Kaggle-Gemma3N_(4B)-Vision.ipynb
  • original_template/Gemma3N_(4B)-Conversational.ipynb
  • original_template/Gemma3N_(4B)-Vision.ipynb

Validation

  • Verified each notebook has 2/2 Gemma3N from_pretrained(...) callsites with attn_implementation = "eager".
  • Diff footprint is minimal: 6 files changed, 12 insertions.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 flex_attention in current Transformers paths. By explicitly setting the attention implementation to 'eager' during model loading in all relevant notebooks, it ensures reliable operation and prevents potential loading failures for Gemma3N models.

Highlights

  • Attention Implementation: Forced 'eager' attention implementation in all Gemma3N from_pretrained(...) calls across conversational and vision notebooks.
  • Notebook Variants: Applied the attention implementation change consistently to nb/, nb/Kaggle-, and original_template/ notebook variants.
  • Callsite Consistency: Ensured both the primary model load cell and the optional reload cell in each affected notebook were updated for uniform behavior.

🧠 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
  • nb/Gemma3N_(4B)-Conversational.ipynb
    • Added attn_implementation = "eager" to two from_pretrained calls.
  • nb/Gemma3N_(4B)-Vision.ipynb
    • Added attn_implementation = "eager" to two from_pretrained calls.
  • nb/Kaggle-Gemma3N_(4B)-Conversational.ipynb
    • Added attn_implementation = "eager" to two from_pretrained calls.
  • nb/Kaggle-Gemma3N_(4B)-Vision.ipynb
    • Added attn_implementation = "eager" to two from_pretrained calls.
  • original_template/Gemma3N_(4B)-Conversational.ipynb
    • Added attn_implementation = "eager" to two from_pretrained calls.
  • original_template/Gemma3N_(4B)-Vision.ipynb
    • Added attn_implementation = "eager" to two from_pretrained calls.
Activity
  • The author verified that each affected notebook now includes attn_implementation = "eager" in both from_pretrained calls.
  • The changes involved 6 files and resulted in 12 insertions, indicating a minimal diff footprint.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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",
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.

medium

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.

Suggested change
" 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",
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.

medium

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.

Suggested change
" 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",
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.

medium

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.

Suggested change
" 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",
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.

medium

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.

Suggested change
" 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",
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.

medium

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.

Suggested change
" 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",
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.

medium

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.

Suggested change
" 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",
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.

medium

For consistency with the surrounding code (e.g., model_name=\"lora_model\", load_in_4bit=True), consider removing the spaces around the = operator.

Suggested change
" 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",

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.

1 participant