-
Notifications
You must be signed in to change notification settings - Fork 574
Add Gemma phone deployment notebook #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @glee2429, 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 introduces a comprehensive Jupyter notebook that guides users through the process of preparing, training, and deploying the Gemma3 language model for mobile phone environments. It leverages Unsloth for efficient fine-tuning and integrates with Optimum Executorch for model export, demonstrating a practical workflow for on-device AI. The notebook also addresses specific considerations like Quantization Aware Training and data formatting for Gemma3. 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. 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.
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 adds a new Jupyter notebook for deploying a Gemma3 model on a phone. The notebook demonstrates fine-tuning and exporting the model using Unsloth and Optimum Executorch. My review focuses on improving the correctness and clarity of the notebook. I've identified an incorrect parameter in the model export command which could cause issues, suggested removing unused code, and recommended renaming variables for better readability. Overall, it's a great addition, and with these changes, it will be even more robust and easier to follow.
|
Hey @glee2429 I tried running your notebook. It runs fine. The export too works fine. |
|
Hey @Datta0! Thanks for the catch. Previously, the export script didn't compress the embeddings or weights. This was causing the file size balloon because the Gemma 3 model has a massive vocabulary size of 256k tokens, which is nearly 10x larger than comparable models like Llama 3 (128k) or Phi (32k). This results in a huge embedding matrix that takes up ~1GB on its own in fp32. In the newest code change, I used the --qlinear 8da4w and --qembedding 8w flags in Optimum to handle this. The final size is now roughly 300MB, which is much more suitable for mobile deployment. Here is the updated cell: (CC: @danielhanchen) |
|
/gemini review |
There was a problem hiding this 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 adds a new Jupyter notebook for demonstrating phone deployment with Gemma3. The notebook is well-structured and provides a clear walkthrough from data preparation to model export. I've found a critical bug in one of the code cells that would prevent it from running, and a minor issue with some dead code. My suggestions address these points to ensure the notebook runs correctly and is maintainable.
|
/gemini review |
There was a problem hiding this 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 adds a new Jupyter notebook demonstrating how to finetune a Gemma-3 model and deploy it to a phone using Unsloth and Executorch. The notebook is a great example, but I've found a few issues. The main concern is with the package installation steps, which use versions that don't seem to be publicly available, making the notebook difficult to reproduce. I've also noticed that the training loss is not converging, and I've suggested a potential fix. Additionally, there are some minor issues with variable naming, incorrect memory usage calculation, and a few missing outputs and typos in the markdown cells. Addressing these points will significantly improve the quality and usability of the notebook.
Hey @unslothai, I updated the notebook to use Gemma3 for phone deployment. A main difference in model export is using Optimum (https://github.com/huggingface/optimum-executorch/blob/main/optimum/exporters/executorch/README.md.) Unfortunately I wasn't able to reduce the loss below 17, so I cut the training short.