Skip to content

Fixed Gemma example using Gemma2 models#4830

Merged
copybara-service[bot] merged 2 commits into
mainfrom
fix-example-gemma2
Sep 18, 2025
Merged

Fixed Gemma example using Gemma2 models#4830
copybara-service[bot] merged 2 commits into
mainfrom
fix-example-gemma2

Conversation

@vfdev-5

@vfdev-5 vfdev-5 commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

What does this PR do?

This PR is based on #4587 (thanks to @mdda!) and adds more tests and fixes remaining incosistencies with the latest codebase.

Fixes #4567
Closes #4587

Checklist

  • This PR fixes a minor issue (e.g.: typo or small bug) or improves the docs (you can dismiss the other
    checks if that's the case).
  • This change is discussed in a Github issue/
    discussion (please add a
    link).
  • The documentation and docstrings adhere to the
    documentation guidelines.
  • This change includes necessary high-coverage tests.
    (No quality testing = no merge!)

Comment thread examples/gemma/layers.py Outdated
def __call__(self, x: Array) -> Array:
var = jnp.mean(jnp.square(x), axis=-1, keepdims=True)
normed_inputs = jnp.asarray(x * jnp.reciprocal(jnp.sqrt(var + 1e-06)))
normed_inputs = jnp.asarray(x * jax.lax.rsqrt(var + 1e-06))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

{"url": "google/gemma-2/flax/gemma2-2b"},
{"url": "google/gemma-3/flax/gemma3-1b"},
)
def test_models_from_kaggle(self, url):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@cgarciae I added this test to make sure that real models can work. By default this test is skipped and it can run locally if kagglehub is installed and env vars have creds.
Let me know if we want / do not want to keep this.

@vfdev-5 vfdev-5 requested a review from cgarciae July 22, 2025 17:06
@cgarciae

Copy link
Copy Markdown
Collaborator

Thanks @vfdev-5 (and @mdda)!

mdda and others added 2 commits August 27, 2025 08:42
gemma2-2b config added, others rationalised

Removed debugging prints...
@vfdev-5 vfdev-5 force-pushed the fix-example-gemma2 branch from 7ec08cf to 90a5d16 Compare August 27, 2025 08:42
@copybara-service copybara-service Bot merged commit 6a75a1d into main Sep 18, 2025
17 of 18 checks passed
@copybara-service copybara-service Bot deleted the fix-example-gemma2 branch September 18, 2025 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some surprises when adding Gemma2-2b to flax/examples/gemma

3 participants