Skip to content

Changes to get transformers Gemma working, as well as bug fixes#25

Merged
samuela merged 1 commit into
samuela:mainfrom
adconner:push-lqozvsrpzprx
Sep 2, 2025
Merged

Changes to get transformers Gemma working, as well as bug fixes#25
samuela merged 1 commit into
samuela:mainfrom
adconner:push-lqozvsrpzprx

Conversation

@adconner

Copy link
Copy Markdown
Contributor

Some additions to get Gemma-2b working, as implemented by transformers, as well as some bug fixes in the in-place versions of sum, mean, etc.

One divergence with torch semantics with this change is I make no attempt to support the torch.no_grad context (arising as the implementation of torch._C._set_grad_enabled). In the context of Gemma it was used for pure efficiency reasons to mark tensors independent of the input; this optimization is unneeded in the jax autograd context. I am supposing the heuristic that such efficiency is the typical reason for this context, and torch tensors will usually be explicitly detached when this is required for the correctness of the model (already supported by torch2jax). If we wish to support the no_grad context, it can be done by tracking this state ourselves and wrapping the result of all operators in stop_gradient if on.

@samuela

samuela commented Aug 15, 2025

Copy link
Copy Markdown
Owner

hi @adconner, thanks for submitting this! it would be super cool to get gemma working. there's some existing, in-flight PRs to be aware of for some of these issues:

i propose that we get those merged first since there already in the works and then rebase from there

@samuela

samuela commented Aug 15, 2025

Copy link
Copy Markdown
Owner

also would be cool to add this to the readme or some kind of examples docs somewhere once it's all working!

Comment thread torch2jax/__init__.py Outdated
@samuela

samuela commented Aug 21, 2025

Copy link
Copy Markdown
Owner

ok #19 and #21 are merged! so we should be in a pretty good place after rebasing

@adconner

Copy link
Copy Markdown
Contributor Author

I've rebased @samuela

@samuela samuela left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

thanks @adconner !

Comment thread torch2jax/__init__.py Outdated
Comment thread torch2jax/__init__.py
Comment thread torch2jax/__init__.py Outdated
Comment thread torch2jax/__init__.py Outdated
Comment thread torch2jax/__init__.py Outdated
@samuela

samuela commented Aug 30, 2025

Copy link
Copy Markdown
Owner

just ooc gemma is already implemented in jax, no? https://github.com/google-deepmind/gemma just out of curiosity what's your use case look like?

@adconner

Copy link
Copy Markdown
Contributor Author

My use case involves possibly collaborating with torch users in the future, and potentially wanting to run experiments with other models aside from gemma.

@samuela samuela left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

lgtm, thanks @adconner !

@samuela
samuela merged commit 8f70a0b into samuela:main Sep 2, 2025
1 check passed
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.

3 participants