Gemma3 is Torch Exportable
Author: guangy10
Pull request: yes

# What does this PR do?

Initial effort to add `torch.expport` support for the Gemma3 model! 
Gemma3 provides a 1b variant that is suitable for `ExecuTorch` to bring it for on-device use-case. This PR is focusing on creating the export recipe and validate the exported model can produce same output as eager.

Expand support to other models that utilize HybridCache as well including gemma2 and cohere2.

### End2end Test Validation with Exported Graph
`RUN_SLOW=1 pytest tests/models/gemma3/test_modeling_gemma3.py -s -v -k test_export_text_only_with_hybrid_cache`
```
Export generated texts: 'What is the capital of France?

The capital of France is Paris.

Final Answer: The final answer is $\boxed{Paris'


Eager generated texts: 'What is the capital of France?

The capital of France is Paris.

Final Answer: The final answer is $\boxed{Paris'

PASSED
======================================================= 1 passed, 319 deselected, 108 warnings in 26.95s =======================================================
```

### Ene2end Validation in Optimum-ExecuTorch
 
<img width="1579" alt="Screenshot 2025-04-24 at 2 01 49 PM" src="https://github.com/user-attachments/assets/f6b135d8-bf58-449a-8d66-38c868a221db" />



## Before submitting
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case. https://github.com/huggingface/transformers/issues/37727
- [x] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@ArthurZucker @gante @qubvel


Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers and trigger CI.

CC: @tugsbayasgalan for review as well

removed unused buffer

Fixed in the ExportableModule to make gemma3 lowerable to ExecuTorch

I've ran `make fixup` but it doesn't fixed the linter.

Hey @guangy10! Thanks for the PR! The changes LGTM, however the gemma3 change should be reflected in `modular_gemma3.py`, which is the source of `modeling_gemma3.py`! 🤗
Any way you could downstream the small change to other models using Hybridcache as well? They should be the models that were changed in https://github.com/huggingface/transformers/pull/37447 👌

It's the source of the issue in `check_repo_consistency` 😉

cc @gante as well for viz!

> Hey @guangy10! Thanks for the PR! The changes LGTM, however the gemma3 change should be reflected in `modular_gemma3.py`, which is the source of `modeling_gemma3.py`! 🤗 Any way you could downstream the small change to other models using Hybridcache as well? They should be the models that were changed in #37447 👌

Done. Could you take another look?