Using and fine-tuning Gemma 3

Google for Developers · Advanced ·🎨 Image & Video AI ·1y ago

Key Takeaways

Using and fine-tuning Gemma 3 with techniques like LoRA and model sharding for tailored language models

Full Transcript

With the release of Gemma 3, we really wanted to significantly increase the user experience for you all. And this is why we are introducing a new uh JMA Python library. Uh I'm going to in this talk I'm going to like demonstrate some of the features that this library provide. The first thing you probably want to do is to just chat with the model. So let's look at an example. Um you start by importing the library. Uh choose uh one of the Gemma architecture, load the parameters. So each of the Gemma models come in two flavor, the pre-trained version or the instruction tuned. And then uh with our sampler interface you can start quering the model about your last u programming problem or in this case this beautiful poem about open weight LLMs. Um and I'm sure you also want to try the multi-turn capability of u our models. So you activate the multi-turn in the sampler and then the model will remember uh the context of your query and automatically handle the caching for you. So it only um only computes the last queries and um similarly with a multimodel um you only need to specify those special uh token inside your prompt and then provide the images uh like the raw images to the chat interface. And uh in this case Jas3 will help me choose where I will spend my next holidays. and um train like fine tune like inference is only part of the problem. Um you also want to be able like because our model are open weight. Uh you want to be able to customize them for your custom use case and your custom data and this is why we um make it as easy as possible for you by integrating Gemma with Cauldron. Cauldron is a open-source library actively used at Google and that is designed to train any arbitrary model on any arbitrary u modalities. If we look at example, I'm sure this API will look very um familiar with a lot of you. You import the library, you create the trainer and then you call the train method um like that will uh launch the training and return the final parameters. Um for the data set side we support uh we're not bound to any data set provider and we support out of the box standard provider like face tensorflow data set um or simpler format like JSON and if you have a custom format or custom data set it's also very easy to create your own wrapper uh to integrate it with our data set. Uh then we have this uh transform API that allow you to apply specific transformation to the individual element of your data set. For example, to apply tokenizing or padding with the GMA library, we provide highle transformation for the common task that you want to use like a supervised fine tuning. So in this case it will take a pair of question and answer from your data set and uh convert them into the input tokens that will be fed to the model and loss. Uh then you can pass this data set to your trainer um and then you connect uh your data set to your model and loss using the special string key. We think that this system is very flexible because then we are not bound to any particular data set structure and um um if for example you want to switch uh to train on multi model data the only thing you need to do is to one add some uh like have a data set that will return images and then with a single line of code you indicate to your model that oh it should also use those image from this data set and the rest of the training is completely identical and uh will work out of the box. For the optimizer uh we use of tags that provide all the standard optimizer um out of the box but also uh have a more advanced capability for like gradient clipping YDK or complex learning rate schedules. So once you have your trainer, you often want to customize specific fields uh from it. And in most programming codebase, what you will do is then you will duplicate the this field inside your config. And then like try to propagate the field uh inside your codebase until the place it is actually used. And uh here we want to remove all indirection and your code. So uh this is why you can just uh add your trainer definition inside a config file and all the field from the trainer will be automatically configurable through the command line. So in this case you indicate um with config you want to launch and then you can override arbitrary fields from this config and this support uh any Python code and any function. You don't need to modify anything about uh uh your class. If you have like a custom loss or custom thing, you can just plug them inside the trainer and things will work uh out of the box. And uh if you go to our GitHub, we provide some of those default trainer configs for the most common use cases like supervised fine tuning, multimodel, uh classification, DPO and more. Uh we also have a bunch of collabs uh that explore more into details some specific uh features of the libraries. Uh and now I'm going to talk about some more advanced features. So if you have access to multiple GPU often it's quite complicated to uh implement the sharding directly in our codebase. But uh with our library when you restore the parameters you just specified uh this sharding uh field uh with some of the default sharding strategy that we provide and uh your model gets automatically uh sharded and similarly during training you can have this sharding uh property to specify the sharding from your data set or optimizer. Yeah. And uh if you don't have access to multiple uh GPU uh you can still try those sharding features uh with our public collab runtime and just choose the uh collab to use TPU v28 that has eight TPU cars and this allow you to try for free or bigger model uh in collab and on the other end of the spectrum we know many of you only have a single GPU maybe with a low memory footprint and we want Gemma to be for everyone. So that's why we also support Lora or Lorank adaptation that is a method uh used to reduce the memory footprint during training. Uh so here you can take any of our GMA model and just wrap it inside our Laura wrapper for the optimizer. You also need to wrap it in the partial update. so that only the Laura rates are optimized and not the full network. And with those two change, everything else work out of the box. Um and finally once your model is trained, uh we have some weight surgery util that allow you to extract the lower rates or fuse them back to the uh model. So I talk about like some of the features of the library but if you go on our website we have more like for example about the quantization or some DPU examples and this is just the beginning. So um very soon we also plan to add like streaming decoding tool use uh model merging so you can fine-tune multiple GMA expert and then uh merge their capability together which was one of the features explained earlier today and more contisation. So if you're interested uh you can check out our GitHub. Thank you. [Music]

Original Description

Explore how you can use and fine-tune Gemma 3 with techniques like LoRA and model sharding to taylor Gemma for your specific needs. Subscribe to Google for Developers → https://goo.gle/developers #Gemma #GemmaDeveloperDay Speaker: Etienne Pot Products Mentioned: Gemma
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Google for Developers · Google for Developers · 0 of 60

← Previous Next →
1 Developer Journey - Sunnyvale DSC Summit ‘19
Developer Journey - Sunnyvale DSC Summit ‘19
Google for Developers
2 How Google is working with students - Sunnyvale DSC Summit ‘19
How Google is working with students - Sunnyvale DSC Summit ‘19
Google for Developers
3 Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Google for Developers
4 The Solution Challenge  - Sunnyvale DSC Summit ‘19
The Solution Challenge - Sunnyvale DSC Summit ‘19
Google for Developers
5 Firebase - Sunnyvale DSC Summit ‘19
Firebase - Sunnyvale DSC Summit ‘19
Google for Developers
6 Cloud Hero - Sunnyvale DSC Summit ‘19
Cloud Hero - Sunnyvale DSC Summit ‘19
Google for Developers
7 Panel discussion  - Sunnyvale DSC Summit ‘19
Panel discussion - Sunnyvale DSC Summit ‘19
Google for Developers
8 The art of negotiation - Sunnyvale DSC Summit ‘19
The art of negotiation - Sunnyvale DSC Summit ‘19
Google for Developers
9 Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Google for Developers
10 Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Google for Developers
11 [DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
[DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
Google for Developers
12 Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Google for Developers
13 Why Podcast.app chose a .app domain name
Why Podcast.app chose a .app domain name
Google for Developers
14 Machine Learning Bootcamp Jakarta 2019
Machine Learning Bootcamp Jakarta 2019
Google for Developers
15 Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Google for Developers
16 [DEPRECATING]  Importance of community (Assistant on Air)
[DEPRECATING] Importance of community (Assistant on Air)
Google for Developers
17 Why the Flutter team switched from .io to a .dev domain name
Why the Flutter team switched from .io to a .dev domain name
Google for Developers
18 3 website-building tips from .dev creators
3 website-building tips from .dev creators
Google for Developers
19 Why NimbleDroid chose a .app domain name
Why NimbleDroid chose a .app domain name
Google for Developers
20 Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Google for Developers
21 Google for Games Developer Summit: A free, digital experience for game developers
Google for Games Developer Summit: A free, digital experience for game developers
Google for Developers
22 Inspecting Home Graph (Assistant for Developers Pro Tips)
Inspecting Home Graph (Assistant for Developers Pro Tips)
Google for Developers
23 Google for Games Developer Summit Keynote
Google for Games Developer Summit Keynote
Google for Developers
24 Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Google for Developers
25 Empowering game developers with Stadia R&D (Google Games Dev Summit)
Empowering game developers with Stadia R&D (Google Games Dev Summit)
Google for Developers
26 Supercharging discoverability with Stadia (Google Games Dev Summit)
Supercharging discoverability with Stadia (Google Games Dev Summit)
Google for Developers
27 Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Google for Developers
28 Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Google for Developers
29 Live Captioning in Google Slides
Live Captioning in Google Slides
Google for Developers
30 [DEPRECATING]  User engagement for the Google Assistant
[DEPRECATING] User engagement for the Google Assistant
Google for Developers
31 TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
Google for Developers
32 Top 5 from the TensorFlow Dev Summit 2020
Top 5 from the TensorFlow Dev Summit 2020
Google for Developers
33 Developer Student Clubs 2019 Turkey Leads Summit
Developer Student Clubs 2019 Turkey Leads Summit
Google for Developers
34 Building simpler payment experiences | Google Pay Plugin for Magento 2
Building simpler payment experiences | Google Pay Plugin for Magento 2
Google for Developers
35 Become A Developer Student Club Lead
Become A Developer Student Club Lead
Google for Developers
36 Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Google for Developers
37 Test suite for Smart Home (Assistant for Developers Pro Tips)
Test suite for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
38 Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google for Developers
39 How to use error logs (Assistant for Developers Pro Tips)
How to use error logs (Assistant for Developers Pro Tips)
Google for Developers
40 Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Google for Developers
41 WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
Google for Developers
42 Offline handling for Smart Home (Assistant for Developers Pro Tips)
Offline handling for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
43 Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Google for Developers
44 Machine Learning Foundations: Ep #1 - What is ML?
Machine Learning Foundations: Ep #1 - What is ML?
Google for Developers
45 Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Google for Developers
46 Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Google for Developers
47 Machine Learning Foundations: Ep #3 - Convolutions and pooling
Machine Learning Foundations: Ep #3 - Convolutions and pooling
Google for Developers
48 Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Google for Developers
49 Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Google for Developers
50 Google Developers ML Summit
Google Developers ML Summit
Google for Developers
51 Real-world image classification using convolutional neural networks | Machine Learning Foundations
Real-world image classification using convolutional neural networks | Machine Learning Foundations
Google for Developers
52 Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Google for Developers
53 Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Google for Developers
54 Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Google for Developers
55 Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Google for Developers
56 Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Google for Developers
57 Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Google for Developers
58 Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Google for Developers
59 Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Google for Developers
60 AR Realism with the ARCore Depth API
AR Realism with the ARCore Depth API
Google for Developers

Related Reads

📰
How AI Head Swap Works: The Technology Behind Realistic AI Image Replacement
Learn how AI head swap technology works and its applications in image editing
Dev.to AI
📰
How I Built an AI Pet Portrait Generator That Turns Photos Into Art
Learn how to build an AI pet portrait generator that turns photos into art using deep learning techniques and Python libraries
Dev.to · William Li
📰
I Put Google’s Squoosh Codecs in the Browser — and Cut My Image Bill Before the Upload Even…
Learn how to use Google's Squoosh codecs in the browser to compress images before upload and reduce costs
Medium · Programming
📰
I Put Google’s Squoosh Codecs in the Browser — and Cut My Image Bill Before the Upload Even…
Learn how to use Google's Squoosh codecs in the browser to compress images before upload, reducing costs and improving performance
Medium · JavaScript
Up next
Short.ai Review 2025: Turn Long Videos into Viral Shorts in One Click! 🔥
DroidCrunch
Watch →