CINXE.COM
Get started with Gemma on Ray on Vertex AI - Google Developers Blog
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title> Get started with Gemma on Ray on Vertex AI - Google Developers Blog </title> <meta property="og:title" content="Get started with Gemma on Ray on Vertex AI- Google Developers Blog" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="description" content="Use Gemma Supervised tuning on Ray on Vertex AI to train and serve machine learning models efficiently and effectively." /> <meta content="summary_large_image" name="twitter:card"/> <meta content="Google for Developers Blog - News about Web, Mobile, AI and Cloud" property="twitter:title"/> <meta property="og:title" content="Get started with Gemma on Ray on Vertex AI" /> <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{ "@type": "ListItem", "position": 1, "name": "Google for Developers Blog", "item": "https://developers.googleblog.com/" },{ "@type": "ListItem", "position": 2, "name": "Get started with Gemma on Ray on Vertex AI", "item": "http://developers.googleblog.com/en/get-started-with-gemma-on-ray-on-vertex-ai/" }] } </script> <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Article", "headline": "Get started with Gemma on Ray on Vertex AI", "description": "Use Gemma Supervised tuning on Ray on Vertex AI to train and serve machine learning models efficiently and effectively.", "image": "https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Copy_of_Wagtail_Gemma_Blog_social_.2e16d0ba.fill-800x400.png", "datePublished": "2024-07-09", "author": [ { "@type": "Person", "name": "Ju-yeong Ji", "url": "/en/search/?author=Ju-yeong+Ji" }, { "@type": "Person", "name": "Ivan Nardini", "url": "/en/search/?author=Ivan+Nardini" } ] } </script> <meta content="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Copy_of_Wagtail_Gemma_Blog_social.2e16d0ba.fill-1200x600.png" property="og:image"/> <!-- Google Tag Manager --> <script type="text/javascript" src="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/js/analytics.js"></script> <!-- End Google Tag Manager --> <link href="//www.gstatic.com/glue/v27_1/glue.min.css" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/css/dgc_blog.css"> <link rel="icon" href="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/images/favicon.ico" type="image/x-icon"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preload" href="https://fonts.googleapis.com/css2?family=Product+Sans&family=Google+Sans+Display:ital@0;1&family=Google+Sans:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&family=Google+Sans+Text:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap" as="style"> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Product+Sans&family=Google+Sans+Display:ital@0;1&family=Google+Sans:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&family=Google+Sans+Text:ital,wght@0,400;0,500;0,700;1,400;1,500;1,700&display=swap"> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap"> <link href="https://www.gstatic.com/glue/cookienotificationbar/cookienotificationbar.min.css" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/css/blog_detail.css" /> <link rel="stylesheet" href="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/pygmentify/css/default.min.css"> </head> <body id="main-content" class="glue-body "> <!-- Google Tag Manager (noscript) --> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WVTLDSL " height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) --> <!-- HTML --> <header class="dgc-header"> <div class="dgc-header-inner"> <button class="hamburger" aria-haspopup="true" aria-expanded="false" aria-label="Open Menu"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#menu"></use> </svg> </button> <div class="product-name-wrapper"> <a href="https://developers.google.com/" class="site-logo-link" data-label="Site logo"> <img src="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/images/g-dev.svg" class="site-logo" alt="Google for Developers"> </a> </div> <div class="desktop-nav-wrapper"> <div class="upper-tabs-wrapper"> <div class="upper-tabs"> <nav class="tabs" aria-label="Upper Tabs"> <div class="tab" dropdown> <a href="//developers.google.com/products" class="top-nav-title"> Products </a> <a href="#" role="button" aria-haspopup="true" aria-expanded="true" aria-label="Dropdown menu for Products" class="dropdown-toggle"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#arrow-drop-down"></use> </svg> </a> <div class="tabs-dropdown" aria-label="Submenu"> <div class="tabs-dropdown-content"> <div class="tabs-dropdown-column"> <ul class="tabs-dropdown-section"> <li class="nav-title" aria-label="Develop Menu">Develop</li> <li class="nav-item"> <a href="//developer.android.com"> <div class="nav-item-title"> Android </div> </a> </li> <li class="nav-item"> <a href="//developer.chrome.com"> <div class="nav-item-title"> Chrome </div> </a> </li> <li class="nav-item"> <a href="//chromeos.dev/"> <div class="nav-item-title"> ChromeOS </div> </a> </li> <li class="nav-item"> <a href="//cloud.google.com"> <div class="nav-item-title"> Cloud </div> </a> </li> <li class="nav-item"> <a href="//firebase.google.com"> <div class="nav-item-title"> Firebase </div> </a> </li> <li class="nav-item"> <a href="//flutter.dev"> <div class="nav-item-title"> Flutter </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/assistant"> <div class="nav-item-title"> Google Assistant </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/maps"> <div class="nav-item-title"> Google Maps Platform </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/workspace"> <div class="nav-item-title"> Google Workspace </div> </a> </li> <li class="nav-item"> <a href="//www.tensorflow.org"> <div class="nav-item-title"> TensorFlow </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/youtube"> <div class="nav-item-title"> YouTube </div> </a> </li> </ul> </div> <div class="tabs-dropdown-column"> <ul class="tabs-dropdown-section"> <li class="nav-title" aria-label="Grow Menu">Grow</li> <li class="nav-item"> <a href="//firebase.google.com"> <div class="nav-item-title"> Firebase </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/google-ads"> <div class="nav-item-title"> Google Ads </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/analytics"> <div class="nav-item-title"> Google Analytics </div> </a> </li> <li class="nav-item"> <a href="//developer.android.com/distribute"> <div class="nav-item-title"> Google Play </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/search"> <div class="nav-item-title"> Search </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/web/fundamentals/engage-and-retain/push-notifications"> <div class="nav-item-title"> Web Push and Notification APIs </div> </a> </li> </ul> </div> <div class="tabs-dropdown-column"> <ul class="tabs-dropdown-section"> <li class="nav-title" aria-label="Earn Menu">Earn</li> <li class="nav-item"> <a href="//developers.google.com/admob"> <div class="nav-item-title"> AdMob </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/google-ads/api"> <div class="nav-item-title"> Google Ads API </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/pay"> <div class="nav-item-title"> Google Pay </div> </a> </li> <li class="nav-item"> <a href="//developer.android.com/google/play/billing/"> <div class="nav-item-title"> Google Play Billing </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/interactive-media-ads"> <div class="nav-item-title"> Interactive Media Ads </div> </a> </li> </ul> </div> </div> </div> </div> <div class="tab"> <a href="//developers.google.com/solutions/catalog" class="top-nav-title"> Solutions </a> </div> <div class="tab"> <a href="//developers.google.com/events" class="top-nav-title"> Events </a> </div> <div class="tab"> <a href="//developers.google.com/learn" class="top-nav-title"> Learn </a> </div> <div class="tab" dropdown> <a href="//developers.google.com/community" class="top-nav-title"> Community </a> <a href="#" role="button" aria-haspopup="true" aria-expanded="true" aria-label="Dropdown menu for Community" class="dropdown-toggle"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#arrow-drop-down"></use> </svg> </a> <div class="tabs-dropdown" aria-label="Submenu"> <div class="tabs-dropdown-content"> <div class="tabs-dropdown-column"> <ul class="tabs-dropdown-section"> <li class="nav-title" aria-label="Groups Menu">Groups</li> <li class="nav-item"> <a href="//developers.google.com/community/gdg"> <div class="nav-item-title"> Google Developer Groups </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/community/gdsc"> <div class="nav-item-title"> Google Developer Student Clubs </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/womentechmakers"> <div class="nav-item-title"> Woman Techmakers </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/community/experts"> <div class="nav-item-title"> Google Developer Experts </div> </a> </li> <li class="nav-item"> <a href="//www.techequitycollective.com/"> <div class="nav-item-title"> Tech Equity Collective </div> </a> </li> </ul> </div> <div class="tabs-dropdown-column"> <ul class="tabs-dropdown-section"> <li class="nav-title" aria-label="Programs Menu">Programs</li> <li class="nav-item"> <a href="//developers.google.com/community/accelerators"> <div class="nav-item-title"> Accelerator </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/community/gdsc-solution-challenge"> <div class="nav-item-title"> Solution Challenge </div> </a> </li> <li class="nav-item"> <a href="//developers.google.com/community/devfest"> <div class="nav-item-title"> DevFest </div> </a> </li> </ul> </div> <div class="tabs-dropdown-column"> <ul class="tabs-dropdown-section"> <li class="nav-title" aria-label="Stories Menu">Stories</li> <li class="nav-item"> <a href="//developers.google.com/community/stories"> <div class="nav-item-title"> All Stories </div> </a> </li> </ul> </div> </div> </div> </div> <div class="tab"> <a href="//developers.google.com/profile/u/me" class="top-nav-title"> Developer Program </a> </div> <div class="tab"> <a href="//developers.googleblog.com/" class="top-nav-title"> Blog </a> </div> </nav> </div> </div> </div> </div> <div class="dgc-header-search"> <div class="search-wrapper glue-page"> <div class="glue-grid"> <form id="search-form" action="/en/search/" method="get" class="search-content glue-grid__col glue-grid__col--span-4-sm glue-grid__col--span-9-md glue-grid__col--span-7-lg"> <div class="search-input-wrapper"> <svg role="presentation" aria-hidden="true" class="glue-icon search-icon"> <use href="/glue-icon/#search"></use> </svg> <input type="text" name="query" placeholder="Search all articles..." aria-label="Search" class="search-input-field" /> </div> <button class="glue-button glue-button--high-emphasis"> Search </button> </form> <div class="language-selector glue-grid__col glue-grid__col--span-4-sm glue-grid__col--span-3-md glue-grid__col--span-5-lg" aria-label="Select your language preference"> <button type="button" aria-controls="lang-menu-header" aria-haspopup="true"> <svg role="presentation" aria-hidden="true" class="glue-icon lang-icon"> <use href="/glue-icon/#language"></use> </svg> <span class="lang-label">English</span> <svg role="presentation" aria-hidden="true" class="glue-icon lang-icon"> <use href="/glue-icon/#arrow-drop-down"></use> </svg> </button> <div id="lang-menu-header" class="lang-menu hidden" role="menu"> <ul role="presentation"> <li role="presentation"> <a role="menuitem" lang="en" aria-current="true" href="/en/get-started-with-gemma-on-ray-on-vertex-ai/">English</a> </li> <li role="presentation"> <a role="menuitem" lang="es" href="/es/get-started-with-gemma-on-ray-on-vertex-ai/">Español (Latam)</a> </li> <li role="presentation"> <a role="menuitem" lang="id" href="/id/get-started-with-gemma-on-ray-on-vertex-ai/">Bahasa Indonesia</a> </li> <li role="presentation"> <a role="menuitem" lang="ja" href="/ja/get-started-with-gemma-on-ray-on-vertex-ai/">日本語</a> </li> <li role="presentation"> <a role="menuitem" lang="ko" href="/ko/get-started-with-gemma-on-ray-on-vertex-ai/">한국어</a> </li> <li role="presentation"> <a role="menuitem" lang="pt-br" href="/pt-br/get-started-with-gemma-on-ray-on-vertex-ai/">Português (Brasil)</a> </li> <li role="presentation"> <a role="menuitem" lang="zh-hans" href="/zh-hans/get-started-with-gemma-on-ray-on-vertex-ai/">简体中文</a> </li> </ul> </div> </div> </div> </div> </div> </header> <div class="mobile-drawer" top-level-nav> <nav class="nav-content" aria-label="Side menu"> <div class="mobile-header"> <button class="nav-close-btn nav-btn" aria-label="Close navigation"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#close"></use> </svg> </button> <button class="nav-back-btn nav-btn hidden" aria-label="Back to Menu"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#arrow-back"></use> </svg> </button> <div class="product-name-wrapper"> <a href="https://developers.google.com/" class="site-logo-link" data-label="Site logo"> <img src="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/images/g-dev.svg" class="site-logo" alt="Google for Developers"> </a> </div> </div> <div class="nav-wrapper"> <div class="mobile-nav-top"> <ul class="nav-list"> <li class="nav-item"> <a href="//developers.google.com/products" class="nav-title" data-label="Tab: Products"> <span class="nav-text" tooltip=""> Products </span> </a> <ul class="nav-responsive-tabs"> <li class="nav-item"> <span tabindex="0" class="nav-title products-btn" data-label="More Products"> <span class="nav-text" menu="Products"> More </span> <span class="nav-icon" menu="Products"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#arrow-forward"></use> </svg> </span> </span> </li> </ul> </li> <li class="nav-item"> <a href="//developers.google.com/solutions/catalog" class="nav-title" data-label="Tab: Solutions"> <span class="nav-text" tooltip=""> Solutions </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/events" class="nav-title" data-label="Tab: Events"> <span class="nav-text" tooltip=""> Events </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/learn" class="nav-title" data-label="Tab: Learn"> <span class="nav-text" tooltip=""> Learn </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/community" class="nav-title" data-label="Tab: Community"> <span class="nav-text" tooltip=""> Community </span> </a> <ul class="nav-responsive-tabs"> <li class="nav-item"> <span tabindex="0" class="nav-title community-btn" data-label="More Community"> <span class="nav-text" menu="Community"> More </span> <span class="nav-icon" menu="Community"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#arrow-forward"></use> </svg> </span> </span> </li> </ul> </li> <li class="nav-item"> <a href="//developers.google.com/profile/u/me" class="nav-title" data-label="Tab: Developer Program"> <span class="nav-text" tooltip=""> Developer Program </span> </a> </li> <li class="nav-item"> <a href="//developers.googleblog.com/" class="nav-title" data-label="Tab: Blog"> <span class="nav-text" tooltip=""> Blog </span> </a> </li> </ul> </div> <div class="mobile-nav-bottom"> <ul class="nav-list products-submenu" menu="Products" aria-label="Side menu"> <li class="nav-item nav-heading"> <span class="nav-title"> <span class="nav-text"> Develop </span> </span> </li> <li class="nav-item"> <a href="//developer.android.com" class="nav-title"> <span class="nav-text"> Android </span> </a> </li> <li class="nav-item"> <a href="//developer.chrome.com" class="nav-title"> <span class="nav-text"> Chrome </span> </a> </li> <li class="nav-item"> <a href="//chromeos.dev/" class="nav-title"> <span class="nav-text"> ChromeOS </span> </a> </li> <li class="nav-item"> <a href="//cloud.google.com" class="nav-title"> <span class="nav-text"> Cloud </span> </a> </li> <li class="nav-item"> <a href="//firebase.google.com" class="nav-title"> <span class="nav-text"> Firebase </span> </a> </li> <li class="nav-item"> <a href="//flutter.dev" class="nav-title"> <span class="nav-text"> Flutter </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/assistant" class="nav-title"> <span class="nav-text"> Google Assistant </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/maps" class="nav-title"> <span class="nav-text"> Google Maps Platform </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/workspace" class="nav-title"> <span class="nav-text"> Google Workspace </span> </a> </li> <li class="nav-item"> <a href="//www.tensorflow.org" class="nav-title"> <span class="nav-text"> TensorFlow </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/youtube" class="nav-title"> <span class="nav-text"> YouTube </span> </a> </li> <li class="nav-item nav-heading"> <span class="nav-title"> <span class="nav-text"> Grow </span> </span> </li> <li class="nav-item"> <a href="//firebase.google.com" class="nav-title"> <span class="nav-text"> Firebase </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/google-ads" class="nav-title"> <span class="nav-text"> Google Ads </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/analytics" class="nav-title"> <span class="nav-text"> Google Analytics </span> </a> </li> <li class="nav-item"> <a href="//developer.android.com/distribute" class="nav-title"> <span class="nav-text"> Google Play </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/search" class="nav-title"> <span class="nav-text"> Search </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/web/fundamentals/engage-and-retain/push-notifications" class="nav-title"> <span class="nav-text"> Web Push and Notification APIs </span> </a> </li> <li class="nav-item nav-heading"> <span class="nav-title"> <span class="nav-text"> Earn </span> </span> </li> <li class="nav-item"> <a href="//developers.google.com/admob" class="nav-title"> <span class="nav-text"> AdMob </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/google-ads/api" class="nav-title"> <span class="nav-text"> Google Ads API </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/pay" class="nav-title"> <span class="nav-text"> Google Pay </span> </a> </li> <li class="nav-item"> <a href="//developer.android.com/google/play/billing/" class="nav-title"> <span class="nav-text"> Google Play Billing </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/interactive-media-ads" class="nav-title"> <span class="nav-text"> Interactive Media Ads </span> </a> </li> </ul> <ul class="nav-list community-submenu hidden" menu="Community" aria-label="Side menu"> <li class="nav-item nav-heading"> <span class="nav-title"> <span class="nav-text"> Groups </span> </span> </li> <li class="nav-item"> <a href="//developers.google.com/community/gdg" class="nav-title"> <span class="nav-text"> Google Developer Groups </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/community/gdsc" class="nav-title"> <span class="nav-text"> Google Developer Student Clubs </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/womentechmakers" class="nav-title"> <span class="nav-text"> Woman Techmakers </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/community/experts" class="nav-title"> <span class="nav-text"> Google Developer Experts </span> </a> </li> <li class="nav-item"> <a href="//www.techequitycollective.com/" class="nav-title"> <span class="nav-text"> Tech Equity Collective </span> </a> </li> <li class="nav-item nav-heading"> <span class="nav-title"> <span class="nav-text"> Programs </span> </span> </li> <li class="nav-item"> <a href="//developers.google.com/community/accelerators" class="nav-title"> <span class="nav-text"> Accelerator </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/community/gdsc-solution-challenge" class="nav-title"> <span class="nav-text"> Solution Challenge </span> </a> </li> <li class="nav-item"> <a href="//developers.google.com/community/devfest" class="nav-title"> <span class="nav-text"> DevFest </span> </a> </li> <li class="nav-item nav-heading"> <span class="nav-title"> <span class="nav-text"> Stories </span> </span> </li> <li class="nav-item"> <a href="//developers.google.com/community/stories" class="nav-title" aria-label="All Stories"> <span class="nav-text"> All Stories </span> </a> </li> </ul> </div> </div> </nav> <select aria-label="Change language" name="lang-selector" id="lang-selector-nav" class="glue-form__dropdown glue-mobile-nav__lang-dropdown" onchange="window.location.href=this.value" > <option value="/en/get-started-with-gemma-on-ray-on-vertex-ai/" lang="en" selected > English </option> <option value="/es/get-started-with-gemma-on-ray-on-vertex-ai/" lang="es" > Español (Latam) </option> <option value="/id/get-started-with-gemma-on-ray-on-vertex-ai/" lang="id" > Bahasa Indonesia </option> <option value="/ja/get-started-with-gemma-on-ray-on-vertex-ai/" lang="ja" > 日本語 </option> <option value="/ko/get-started-with-gemma-on-ray-on-vertex-ai/" lang="ko" > 한국어 </option> <option value="/pt-br/get-started-with-gemma-on-ray-on-vertex-ai/" lang="pt-br" > Português (Brasil) </option> <option value="/zh-hans/get-started-with-gemma-on-ray-on-vertex-ai/" lang="zh-hans" > 简体中文 </option> </select> </div> <div class="backdrop"></div> <div class="blog-detail-container"> <section class="tags-container glue-page glue-spacer-5-top"> <div class="glue-eyebrow"><a href="/en/search/?product_categories=Gemma">Gemma</a></div> </section> <section class="heading-container glue-page glue-spacer-1-top"> <h1 class="glue-headline glue-headline--headline-1">Get started with Gemma on Ray on Vertex AI</h1> </section> <section class="summary-container glue-page glue-spacer-4-top"> <div class="date-time"> <div class="published-date glue-font-weight-medium">JUL 09, 2024</div> </div> </section> <section class="glue-page glue-grid glue-spacer-1-top"> <section class="author-container glue-grid__col glue-grid__col--span-4-sm glue-grid__col--span-10-md"> <div class="author-obj"> <a class="glue-font-weight-medium" href="/en/search/?author=Ju-yeong+Ji">Ju-yeong Ji</a> <span class="glue-font-weight-medium role">Gemma DevRel</span> </div> <div class="author-obj"> <a class="glue-font-weight-medium" href="/en/search/?author=Ivan+Nardini">Ivan Nardini</a> <span class="glue-font-weight-medium role">Customer Engineer</span> <span class="glue-font-weight-medium team">Google Cloud</span> </div> </section> <section class="social-container glue-grid__col glue-grid__col--span-4-sm glue-grid__col--span-2-md"> <button id="social-button" class="glue-button glue-button--low-emphasis glue-button--icon" aria-haspopup="true" aria-expanded="false"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#share"></use> </svg> <span>Share</span> </button> <ul id="social-menu" class="glue-elevation-level-1" role="menu" aria-labelledby="social-button"> <li> <a href="https://www.facebook.com/sharer/sharer.php?u={url}" title="Share on Facebook" target="_blank" rel="noopener"> <svg role="presentation" aria-hidden="true" class="glue-icon glue-icon--social glue-icon--32px"> <use href="/glue-icon/#post-facebook"></use> </svg> <span>Facebook</span> </a> </li> <li> <a href="https://twitter.com/intent/tweet?text={url}" title="Share on Twitter" target="_blank" rel="noopener"> <svg role="presentation" aria-hidden="true" class="glue-icon glue-icon--social glue-icon--32px"> <use href="/glue-icon/#twitter-x"></use> </svg> <span>Twitter</span> </a> </li> <li> <a href="https://www.linkedin.com/shareArticle?url={url}&mini=true" title="Share on LinkedIn" target="_blank" rel="noopener"> <svg role="presentation" aria-hidden="true" class="glue-icon glue-icon--social glue-icon--32px"> <use href="/glue-icon/#post-linkedin"></use> </svg> <span>LinkedIn</span> </a> </li> <li> <a href="mailto:name@example.com?subject=Check%20out%20this%20site&body=Check%20out%20{url}" title="Send via Email"> <svg role="presentation" aria-hidden="true" class="glue-icon glue-icon--social glue-icon--32px"> <use href="/glue-icon/#email"></use> </svg> <span>Mail</span> </a> </li> <li> <a href="#" title="Get shareable link" data-link="" data-copy-text="Copy Link" data-copied-text="Copied!"> <svg role="presentation" aria-hidden="true" class="glue-icon glue-icon--social glue-icon--32px"> <use href="/glue-icon/#link"></use> </svg> <span></span> </a> </li> </ul> </section> </section> <section class="blocks-container glue-page glue-spacer-3-top"> <div class="block"> <img class="banner-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Blog_Hero_-_Logo.original.png" alt="Gemma blog hero" /> <div class="inner-block-content rich-content"> <p data-block-key="vn49f"><a href="https://ai.google.dev/gemma"><b>Gemma</b></a> is a family of open models built from the same research and technology used to create the Gemini models. Gemma models are capable of performing a wide range of tasks, including text generation, code completion and generation, fine-tuning for specific tasks, and running on various devices.</p><p data-block-key="kauu"><a href="https://docs.ray.io/en/latest/index.html"><b>Ray</b></a> is an open-source framework for scaling AI and Python applications. Ray provides the infrastructure to perform distributed computing and parallel processing for your machine learning (ML) workflow.</p><p data-block-key="f3o14">By the end of this tutorial, you'll have a solid understanding of how to use Gemma Supervised tuning on Ray on Vertex AI to train and serve machine learning models efficiently and effectively.</p><p data-block-key="eisns">You can explore the "<a href="https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks%2Fcommunity%2Fmodel_garden%2Fmodel_garden_gemma_fine_tuning_batch_deployment_on_rov.ipynb">Get started with Gemma on Ray on Vertex AI</a>" tutorial notebook on GitHub to learn more about Gemma on Ray. All the code below is on this notebook to make your journey easier.</p><h2 data-block-key="26fr7"><br/><b>Prerequisite</b></h2><p data-block-key="ccgp5">The following steps are required, regardless of your environment.</p><p data-block-key="t744"></p><ol><li data-block-key="76s7a"><a href="https://colab.research.google.com/corgiredirector?site=https%3A%2F%2Fconsole.cloud.google.com%2Fcloud-resource-manager">Select or create a Google Cloud project</a>.</li></ol><p data-block-key="8412p"></p><p data-block-key="6kal5">2. <a href="https://colab.research.google.com/corgiredirector?site=https%3A%2F%2Fcloud.google.com%2Fbilling%2Fdocs%2Fhow-to%2Fmodify-project">Make sure that billing is enabled for your project</a>.</p><p data-block-key="35rm"></p><p data-block-key="6one7">3. <a href="https://colab.research.google.com/corgiredirector?site=https%3A%2F%2Fconsole.cloud.google.com%2Fflows%2Fenableapi%3Fapiid%3Daiplatform.googleapis.com%2Cartifactregistry.googleapis.com%2Ccloudbuild.googleapis.com">Enable APIs</a>.</p><p data-block-key="7n20b"></p><p data-block-key="ci7cp">If you’re running this tutorial locally, you need to install the <a href="https://colab.research.google.com/corgiredirector?site=https%3A%2F%2Fcloud.google.com%2Fsdk">Cloud SDK</a>.</p><h3 data-block-key="83otv"><br/><b>Costs</b></h3><p data-block-key="2qjf2">This tutorial uses billable components of Google Cloud:</p><p data-block-key="973h0"></p><ul><li data-block-key="c0e1u">Vertex AI</li></ul><p data-block-key="230po"></p><ul><li data-block-key="fb6ku">Cloud Build</li></ul><p data-block-key="1cbaf"></p><ul><li data-block-key="7e8p4">Artifact Registry</li></ul><p data-block-key="2bleq"></p><ul><li data-block-key="frmi8">Cloud Storage</li></ul><p data-block-key="fgn39"></p><p data-block-key="3odq3">Learn about pricing, use the <a href="https://cloud.google.com/products/calculator/">Pricing Calculator</a> to generate a cost estimate based on your projected usage.</p><h2 data-block-key="26c4h"><b><br/>What you need</b></h2><h3 data-block-key="ddphc"><b>Dataset</b></h3><p data-block-key="2lbvi">We’ll use the <a href="https://huggingface.co/datasets/EdinburghNLP/xsum">Extreme Summarization (XSum) dataset</a>, which is a dataset about abstractive single-document summarization systems.</p><h3 data-block-key="68amr"><br/><b>Cloud Storage Bucket</b></h3><p data-block-key="7mosj">You have to create <a href="https://console.cloud.google.com/storage">a storage bucket</a> to store intermediate artifacts such as datasets.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/image6_VAOPymp.original.png" alt="Create a storage bucket to store intermediate artifacts" /> </div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Or with Google Cloud CLI</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">gsutil</span> <span class="n">mb</span> <span class="o">-</span><span class="n">l</span> <span class="p">{</span><span class="n">REGION</span><span class="p">}</span> <span class="o">-</span><span class="n">p</span> <span class="p">{</span><span class="n">PROJECT_ID</span><span class="p">}</span> <span class="p">{</span><span class="n">BUCKET_URI</span><span class="p">}</span> <span class="c1"># for example: gsutil mb -l asia-northeast1 -p test-bebechien gs://test-bebechien-ray-bucket</span> </pre></div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="vn49f"><b>Docker Image Repository</b></h2><p data-block-key="1auja">To store the custom cluster image, create a Docker repository in the <a href="https://console.cloud.google.com/artifacts">Artifact Registry</a>.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/image1_OTNw0dv.original.png" alt="Create a Docker repository in the Artifact Registry." /> </div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Or with Google Cloud CLI</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">gcloud</span> <span class="n">artifacts</span> <span class="n">repositories</span> <span class="n">create</span> <span class="n">your</span><span class="o">-</span><span class="n">repo</span> <span class="o">--</span><span class="n">repository</span><span class="o">-</span><span class="nb">format</span><span class="o">=</span><span class="n">docker</span> <span class="o">--</span><span class="n">location</span><span class="o">=</span><span class="n">your</span><span class="o">-</span><span class="n">region</span> <span class="o">--</span><span class="n">description</span><span class="o">=</span><span class="s2">"Tutorial repository"</span> </pre></div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="vn49f"><b>Vertex AI TensorBoard Instance</b></h2><p data-block-key="63uh2">A TensorBoard instance is for tracking and monitoring your tuning jobs. You can create one from <a href="https://console.cloud.google.com/vertex-ai/experiments/tensorboard-instances">Experiments</a>.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/image3_Gtok2lm.original.png" alt="Create a TensorBoard instance from Experiments" /> </div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Or with Google Cloud CLI</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">gcloud</span> <span class="n">ai</span> <span class="n">tensorboards</span> <span class="n">create</span> <span class="o">--</span><span class="n">display</span><span class="o">-</span><span class="n">name</span> <span class="n">your</span><span class="o">-</span><span class="n">tensorboard</span> <span class="o">--</span><span class="n">project</span> <span class="n">your</span><span class="o">-</span><span class="n">project</span> <span class="o">--</span><span class="n">region</span> <span class="n">your</span><span class="o">-</span><span class="n">region</span> </pre></div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="vn49f"><b>How to set a Ray cluster on Vertex AI</b></h2><h3 data-block-key="ba96t"><b>Build the custom cluster image</b></h3><p data-block-key="7pgrh">To get started with Ray on Vertex AI, you can choose to either create a Dockerfile for a custom image from scratch or utilize one of the pre-built Ray base images. One such base image is available <a href="http://us-docker.pkg.dev/vertex-ai/training/ray-gpu.2-9.py310:latest">here</a>.</p><p data-block-key="enoss">First, prepare the requirements file that includes the dependencies your Ray application needs to run.</p><ul><li data-block-key="8o9ke"><a href="https://github.com/bebechien/gemma/blob/main/ray/tutorial/build/requirements.txt"><code>tutorial/build/requirements.txt</code></a></li></ul><p data-block-key="213b0">Then, create the Dockerfile for the custom image by leveraging one of the prebuilt Ray on Vertex AI base images.</p><ul><li data-block-key="cb0a4"><a href="https://github.com/bebechien/gemma/blob/main/ray/tutorial/build/Dockerfile"><code>tutorial/build/Dockerfile</code></a></li></ul><p data-block-key="2ie3p">Finally, build the Ray cluster custom image using Cloud Build.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">gcloud</span> <span class="n">builds</span> <span class="n">submit</span> <span class="o">--</span><span class="n">region</span><span class="o">=</span><span class="n">your</span><span class="o">-</span><span class="n">region</span> <span class="o">--</span><span class="n">tag</span><span class="o">=</span><span class="n">your</span><span class="o">-</span><span class="n">region</span><span class="o">-</span><span class="n">docker</span><span class="o">.</span><span class="n">pkg</span><span class="o">.</span><span class="n">dev</span><span class="o">/</span><span class="n">your</span><span class="o">-</span><span class="n">project</span><span class="o">/</span><span class="n">your</span><span class="o">-</span><span class="n">repo</span><span class="o">/</span><span class="n">train</span> <span class="o">--</span><span class="n">machine</span><span class="o">-</span><span class="nb">type</span><span class="o">=</span><span class="n">E2_HIGHCPU_32</span> <span class="o">./</span><span class="n">dockerfile</span><span class="o">-</span><span class="n">path</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">If everything goes well, you’ll see the custom image has been successfully pushed to your docker image repository.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/image4_DbF7N1n.original.png" alt="The custom image has been successfully pushed to your docker image repository." /> </div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Also on your <a href="https://console.cloud.google.com/artifacts">Artifact Registry</a></p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/image7_mRT491c.original.png" alt="The custom image has been successfully pushed to your artifact registry" /> </div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="vn49f"><b>Create the Ray Cluster</b></h2><p data-block-key="cdbvo">You can create the ray cluster from <a href="https://console.cloud.google.com/vertex-ai/ray">Ray on Vertex AI</a>.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/image9_iW9j9bT.original.png" alt="Ray on Vertex AI" /> </div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Or use the Vertex AI Python SDK to create a Ray cluster with a custom image and to customize the cluster configuration. To learn more about the cluster configuration, see the <a href="https://cloud.google.com/vertex-ai/docs/open-source/ray-on-vertex-ai/create-cluster#ray-on-vertex-ai-sdk">documentation</a>.</p><p data-block-key="5012j">Below is an example Python code to create the Ray cluster with the predefined custom configuration.</p><p data-block-key="5iob5"><b>NOTE: Creating a cluster can take several minutes, depending on its configuration.</b></p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="c1"># Set up Ray on Vertex AI</span> <span class="kn">import</span> <span class="nn">vertex_ray</span> <span class="kn">from</span> <span class="nn">google.cloud</span> <span class="kn">import</span> <span class="n">aiplatform</span> <span class="k">as</span> <span class="n">vertex_ai</span> <span class="kn">from</span> <span class="nn">vertex_ray</span> <span class="kn">import</span> <span class="n">NodeImages</span><span class="p">,</span> <span class="n">Resources</span> <span class="c1"># Retrieves an existing managed tensorboard given a tensorboard ID</span> <span class="n">tensorboard</span> <span class="o">=</span> <span class="n">vertex_ai</span><span class="o">.</span><span class="n">Tensorboard</span><span class="p">(</span><span class="n">your</span><span class="o">-</span><span class="n">tensorboard</span><span class="o">-</span><span class="nb">id</span><span class="p">,</span> <span class="n">project</span><span class="o">=</span><span class="n">your</span><span class="o">-</span><span class="n">project</span><span class="p">,</span> <span class="n">location</span><span class="o">=</span><span class="n">your</span><span class="o">-</span><span class="n">region</span><span class="p">)</span> <span class="c1"># Initialize the Vertex AI SDK for Python for your project</span> <span class="n">vertex_ai</span><span class="o">.</span><span class="n">init</span><span class="p">(</span><span class="n">project</span><span class="o">=</span><span class="n">your</span><span class="o">-</span><span class="n">project</span><span class="p">,</span> <span class="n">location</span><span class="o">=</span><span class="n">your</span><span class="o">-</span><span class="n">region</span><span class="p">,</span> <span class="n">staging_bucket</span><span class="o">=</span><span class="n">your</span><span class="o">-</span><span class="n">bucket</span><span class="o">-</span><span class="n">uri</span><span class="p">,</span> <span class="n">experiment_tensorboard</span><span class="o">=</span><span class="n">tensorboard</span><span class="p">)</span> <span class="n">HEAD_NODE_TYPE</span> <span class="o">=</span> <span class="n">Resources</span><span class="p">(</span> <span class="n">machine_type</span><span class="o">=</span> <span class="s2">"n1-standard-16"</span><span class="p">,</span> <span class="n">node_count</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="p">)</span> <span class="n">WORKER_NODE_TYPES</span> <span class="o">=</span> <span class="p">[</span> <span class="n">Resources</span><span class="p">(</span> <span class="n">machine_type</span><span class="o">=</span><span class="s2">"n1-standard-16"</span><span class="p">,</span> <span class="n">node_count</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">accelerator_type</span><span class="o">=</span><span class="s2">"NVIDIA_TESLA_T4"</span><span class="p">,</span> <span class="n">accelerator_count</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="p">)</span> <span class="p">]</span> <span class="n">CUSTOM_IMAGES</span> <span class="o">=</span> <span class="n">NodeImages</span><span class="p">(</span> <span class="n">head</span><span class="o">=</span><span class="s2">"your-region-docker.pkg.dev/your-project/your-repo/train"</span><span class="p">,</span> <span class="n">worker</span><span class="o">=</span><span class="s2">"your-region-docker.pkg.dev/your-project/your-repo/train"</span><span class="p">,</span> <span class="p">)</span> <span class="n">ray_cluster_name</span> <span class="o">=</span> <span class="n">vertex_ray</span><span class="o">.</span><span class="n">create_ray_cluster</span><span class="p">(</span> <span class="n">head_node_type</span><span class="o">=</span><span class="n">HEAD_NODE_TYPE</span><span class="p">,</span> <span class="n">worker_node_types</span><span class="o">=</span><span class="n">WORKER_NODE_TYPES</span><span class="p">,</span> <span class="n">custom_images</span><span class="o">=</span><span class="n">CUSTOM_IMAGES</span><span class="p">,</span> <span class="n">cluster_name</span><span class="o">=</span><span class="err">”</span><span class="n">your</span><span class="o">-</span><span class="n">cluster</span><span class="o">-</span><span class="n">name</span><span class="err">”</span><span class="p">,</span> <span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Now you can get the Ray cluster with <code>get_ray_cluster()</code>. Use <a href="https://github.com/googleapis/python-aiplatform/blob/cd85d8f74d3922de3f871415bacf77c594f0c547/google/cloud/aiplatform/preview/vertex_ray/cluster_init.py#L340"><code>list_ray_clusters()</code></a> if you want to see all clusters associated with your project.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">ray_clusters</span> <span class="o">=</span> <span class="n">vertex_ray</span><span class="o">.</span><span class="n">list_ray_clusters</span><span class="p">()</span> <span class="n">ray_cluster_resource_name</span> <span class="o">=</span> <span class="n">ray_clusters</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">cluster_resource_name</span> <span class="n">ray_cluster</span> <span class="o">=</span> <span class="n">vertex_ray</span><span class="o">.</span><span class="n">get_ray_cluster</span><span class="p">(</span><span class="n">ray_cluster_resource_name</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Ray cluster on Vertex AI:"</span><span class="p">,</span> <span class="n">ray_cluster_resource_name</span><span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="vn49f"><b>Fine-Tune Gemma with Ray on Vertex AI</b></h2><p data-block-key="3d3bv">To fine-tune Gemma with Ray on Vertex AI, you can use <a href="https://docs.ray.io/en/latest/train/train.html">Ray Train</a> for distributing HuggingFace Transformers with PyTorch training, as you can see below.</p><p data-block-key="4smvi">With Ray Train, you define a training function which contains your HuggingFace Transformers code for tuning Gemma that you want to distribute. Next, you define the scaling configuration to specify the desired number of workers and indicate whether the distributed training process requires GPUs. Additionally, you can define a runtime configuration to specify checkpointing and synchronization behaviors. Finally, you submit the fine-tuning by initiating a TorchTrainer and run it using its fit method.</p><p data-block-key="cfqon">In this tutorial, we’ll fine-tune Gemma 2B (<code>gemma-2b-it</code>) for summarizing newspaper articles using HuggingFace Transformer on Ray on Vertex AI. We wrote a simple Python <code>trainer.py</code> script and will submit it to the Ray cluster.</p><h3 data-block-key="8tphm"><br/><b>Prepare Python Scripts</b></h3><p data-block-key="a6pbm">Let’s prepare the train script, below is an example Python script for initializing Gemma fine-tuning using HuggingFace TRL library.</p><ul><li data-block-key="uith"><a href="https://github.com/bebechien/gemma/blob/main/ray/tutorial/src/train.py"><code>tutorial/src/train.py</code></a></li></ul><p data-block-key="fs3ki">Next, prepare the distributed training script. Below is an example Python script for executing the Ray distributed training job.</p><ul><li data-block-key="5214n"><a href="https://github.com/bebechien/gemma/blob/main/ray/tutorial/src/trainer.py"><code>tutorial/src/trainer.py</code></a></li></ul><p data-block-key="cssci">Now we submit the script to the Ray cluster using the Ray Jobs API via the Ray dashboard address. You can also find the dashboard address on the <a href="https://console.cloud.google.com/vertex-ai/ray">Cluster details page</a> like below.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/image5_dlnlzMZ.original.png" alt="Cluster details page showing the dashboard address" /> </div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">First, initiate the client to submit the job.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="kn">import</span> <span class="nn">ray</span> <span class="kn">from</span> <span class="nn">ray.job_submission</span> <span class="kn">import</span> <span class="n">JobSubmissionClient</span> <span class="n">client</span> <span class="o">=</span> <span class="n">JobSubmissionClient</span><span class="p">(</span> <span class="n">address</span><span class="o">=</span><span class="s2">"vertex_ray://</span><span class="si">{}</span><span class="s2">"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ray_cluster</span><span class="o">.</span><span class="n">dashboard_address</span><span class="p">)</span> <span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Let’s set some job configuration including model path, job id, prediction entrypoint, and more.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="kn">import</span> <span class="nn">random</span><span class="o">,</span> <span class="nn">string</span><span class="o">,</span> <span class="nn">datasets</span><span class="o">,</span> <span class="nn">transformers</span> <span class="kn">from</span> <span class="nn">etils</span> <span class="kn">import</span> <span class="n">epath</span> <span class="kn">from</span> <span class="nn">huggingface_hub</span> <span class="kn">import</span> <span class="n">login</span> <span class="c1"># Initialize some libraries settings</span> <span class="n">login</span><span class="p">(</span><span class="n">token</span><span class="o">=</span><span class="err">”</span><span class="n">your</span><span class="o">-</span><span class="n">hf</span><span class="o">-</span><span class="n">token</span><span class="err">”</span><span class="p">)</span> <span class="n">datasets</span><span class="o">.</span><span class="n">disable_progress_bar</span><span class="p">()</span> <span class="n">transformers</span><span class="o">.</span><span class="n">set_seed</span><span class="p">(</span><span class="mi">8</span><span class="p">)</span> <span class="n">train_experiment_name</span> <span class="o">=</span> <span class="err">“</span><span class="n">your</span><span class="o">-</span><span class="n">experiment</span><span class="o">-</span><span class="n">name</span><span class="err">”</span> <span class="n">train_submission_id</span> <span class="o">=</span> <span class="err">“</span><span class="n">your</span><span class="o">-</span><span class="n">submission</span><span class="o">-</span><span class="nb">id</span><span class="err">”</span> <span class="n">train_entrypoint</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"python3 trainer.py --experiment-name=</span><span class="si">{</span><span class="n">train_experiment_name</span><span class="si">}</span><span class="s2"> --logging-dir=”your-bucket-uri/logs” --num-workers=2 --use-gpu"</span> <span class="n">train_runtime_env</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">"working_dir"</span><span class="p">:</span> <span class="s2">"your-working-dir"</span><span class="p">,</span> <span class="s2">"env_vars"</span><span class="p">:</span> <span class="p">{</span><span class="s2">"HF_TOKEN"</span><span class="p">:</span> <span class="err">”</span><span class="n">your</span><span class="o">-</span><span class="n">hf</span><span class="o">-</span><span class="n">token</span><span class="err">”</span><span class="p">,</span> <span class="s2">"TORCH_NCCL_ASYNC_ERROR_HANDLING"</span><span class="p">:</span> <span class="s2">"3"</span><span class="p">},</span> <span class="p">}</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Submit the job</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">train_job_id</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">submit_job</span><span class="p">(</span> <span class="n">submission_id</span><span class="o">=</span><span class="n">train_submission_id</span><span class="p">,</span> <span class="n">entrypoint</span><span class="o">=</span><span class="n">train_entrypoint</span><span class="p">,</span> <span class="n">runtime_env</span><span class="o">=</span><span class="n">train_runtime_env</span><span class="p">,</span> <span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="ouabo">Check the status of the job from the OSS dashboard.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/image8_XHfJIXp.original.png" alt="OSS dashboard showing job status" /> </div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="vn49f"><b>Check training artifacts and monitor the training</b></h2><p data-block-key="ec5cc">Using Ray on Vertex AI for developing AI/ML applications offers various benefits. In this scenario, you can use Cloud storage to conveniently store model checkpoints, metrics, and more. This allows you to quickly consume the model for AI/ML downstreaming tasks including monitoring the training process using Vertex AI TensorBoard or generating batch predictions using Ray Data.</p><p data-block-key="3ja1o">While the Ray training job is running and after it has completed, you see the model artifacts in the Cloud Storage location with Google Cloud CLI.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">gsutil</span> <span class="n">ls</span> <span class="o">-</span><span class="n">l</span> <span class="n">your</span><span class="o">-</span><span class="n">bucket</span><span class="o">-</span><span class="n">uri</span><span class="o">/</span><span class="n">your</span><span class="o">-</span><span class="n">experiments</span><span class="o">/</span><span class="n">your</span><span class="o">-</span><span class="n">experiment</span><span class="o">-</span><span class="n">name</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">You can use Vertex AI TensorBoard for validating your training job by logging resulting metrics.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">vertex_ai</span><span class="o">.</span><span class="n">upload_tb_log</span><span class="p">(</span> <span class="n">tensorboard_id</span><span class="o">=</span><span class="n">tensorboard</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">tensorboard_experiment_name</span><span class="o">=</span><span class="n">train_experiment_name</span><span class="p">,</span> <span class="n">logdir</span><span class="o">=./</span><span class="n">experiments</span><span class="p">,</span> <span class="p">)</span> </pre></div> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/image10_Bv17gCb.original.png" alt="Vertex AI TensorBoard" /> </div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="vn49f"><b>Validate Gemma training on Vertex AI</b></h2><p data-block-key="efkb2">Assuming that your training runs successfully, you can generate predictions locally to validate the tuned model.</p><p data-block-key="2kddg">First, download all resulting checkpoints from Ray job with Google Cloud CLI.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="c1"># copy all artifacts</span> <span class="n">gsutil</span> <span class="n">ls</span> <span class="o">-</span><span class="n">l</span> <span class="n">your</span><span class="o">-</span><span class="n">bucket</span><span class="o">-</span><span class="n">uri</span><span class="o">/</span><span class="n">your</span><span class="o">-</span><span class="n">experiments</span><span class="o">/</span><span class="n">your</span><span class="o">-</span><span class="n">experiment</span><span class="o">-</span><span class="n">name</span> <span class="o">./</span><span class="n">your</span><span class="o">-</span><span class="n">experiment</span><span class="o">-</span><span class="n">path</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Use the <code>ExperimentAnalysis</code> method to retrieve the best checkpoint according to relevant metrics and mode.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="kn">import</span> <span class="nn">ray</span> <span class="kn">from</span> <span class="nn">ray.tune</span> <span class="kn">import</span> <span class="n">ExperimentAnalysis</span> <span class="n">experiment_analysis</span> <span class="o">=</span> <span class="n">ExperimentAnalysis</span><span class="p">(</span><span class="err">“</span><span class="o">./</span><span class="n">your</span><span class="o">-</span><span class="n">experiment</span><span class="o">-</span><span class="n">path</span><span class="err">”</span><span class="p">)</span> <span class="n">log_path</span> <span class="o">=</span> <span class="n">experiment_analysis</span><span class="o">.</span><span class="n">get_best_trial</span><span class="p">(</span><span class="n">metric</span><span class="o">=</span><span class="s2">"eval_rougeLsum"</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s2">"max"</span><span class="p">)</span> <span class="n">best_checkpoint</span> <span class="o">=</span> <span class="n">experiment_analysis</span><span class="o">.</span><span class="n">get_best_checkpoint</span><span class="p">(</span> <span class="n">log_path</span><span class="p">,</span> <span class="n">metric</span><span class="o">=</span><span class="s2">"eval_rougeLsum"</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s2">"max"</span> <span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Now you know which one is the best checkpoint. Below is an example output.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Screenshot_2024-06-18_at_5.10.47PM.original.png" alt="example output - code snippet" /> </div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">And load the fine-tuned model as described in the Hugging Face <a href="https://huggingface.co/docs/trl/use_model#use-adapters-peft">documentation</a>.</p><p data-block-key="2iamh">Below is an example Python code to load the base model and merge the adapters into the base model so you can use the model like a normal transformers model. You can find the saved tuned model at <b><code>tuned_model_path</code></b>. For example, “<code>tutorial/models/xsum-tuned-gemma-it</code>”</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="kn">import</span> <span class="nn">torch</span> <span class="kn">from</span> <span class="nn">etils</span> <span class="kn">import</span> <span class="n">epath</span> <span class="kn">from</span> <span class="nn">transformers</span> <span class="kn">import</span> <span class="n">AutoModelForCausalLM</span><span class="p">,</span> <span class="n">AutoTokenizer</span> <span class="kn">from</span> <span class="nn">peft</span> <span class="kn">import</span> <span class="n">PeftModel</span> <span class="n">base_model_path</span> <span class="o">=</span> <span class="s2">"google/gemma-2b-it"</span> <span class="n">peft_model_path</span> <span class="o">=</span> <span class="n">epath</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="n">best_checkpoint</span><span class="o">.</span><span class="n">path</span><span class="p">)</span> <span class="o">/</span> <span class="s2">"checkpoint"</span> <span class="n">tuned_model_path</span> <span class="o">=</span> <span class="n">models_path</span> <span class="o">/</span> <span class="s2">"xsum-tuned-gemma-it"</span> <span class="n">tokenizer</span> <span class="o">=</span> <span class="n">AutoTokenizer</span><span class="o">.</span><span class="n">from_pretrained</span><span class="p">(</span><span class="n">base_model_path</span><span class="p">)</span> <span class="n">tokenizer</span><span class="o">.</span><span class="n">padding_side</span> <span class="o">=</span> <span class="s2">"right"</span> <span class="n">base_model</span> <span class="o">=</span> <span class="n">AutoModelForCausalLM</span><span class="o">.</span><span class="n">from_pretrained</span><span class="p">(</span> <span class="n">base_model_path</span><span class="p">,</span> <span class="n">device_map</span><span class="o">=</span><span class="s2">"auto"</span><span class="p">,</span> <span class="n">torch_dtype</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">float16</span> <span class="p">)</span> <span class="n">peft_model</span> <span class="o">=</span> <span class="n">PeftModel</span><span class="o">.</span><span class="n">from_pretrained</span><span class="p">(</span> <span class="n">base_model</span><span class="p">,</span> <span class="n">peft_model_path</span><span class="p">,</span> <span class="n">device_map</span><span class="o">=</span><span class="s2">"auto"</span><span class="p">,</span> <span class="n">torch_dtype</span><span class="o">=</span><span class="n">torch</span><span class="o">.</span><span class="n">bfloat16</span><span class="p">,</span> <span class="n">is_trainable</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="p">)</span> <span class="n">tuned_model</span> <span class="o">=</span> <span class="n">peft_model</span><span class="o">.</span><span class="n">merge_and_unload</span><span class="p">()</span> <span class="n">tuned_model</span><span class="o">.</span><span class="n">save_pretrained</span><span class="p">(</span><span class="n">tuned_model_path</span><span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f"><i>Tidbit: Since you fine tuned a model, you can also publish it to the Hugging Face Hub by using this single line of code.</i></p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">tuned_model</span><span class="o">.</span><span class="n">push_to_hub</span><span class="p">(</span><span class="s2">"my-awesome-model"</span><span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">To generate summaries with the tuned model, let’s use the validation set of the tutorial dataset.</p><p data-block-key="euctf">The following Python code example demonstrates how to sample one article from a dataset to summarize. It then generates the associated summary and prints both the reference summary from the dataset and the generated summary side by side.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="kn">import</span> <span class="nn">random</span><span class="o">,</span> <span class="nn">datasets</span> <span class="kn">from</span> <span class="nn">transformers</span> <span class="kn">import</span> <span class="n">pipeline</span> <span class="n">dataset</span> <span class="o">=</span> <span class="n">datasets</span><span class="o">.</span><span class="n">load_dataset</span><span class="p">(</span> <span class="s2">"xsum"</span><span class="p">,</span> <span class="n">split</span><span class="o">=</span><span class="s2">"validation"</span><span class="p">,</span> <span class="n">cache_dir</span><span class="o">=</span><span class="err">”</span><span class="o">./</span><span class="n">data</span><span class="err">”</span><span class="p">,</span> <span class="n">trust_remote_code</span><span class="o">=</span><span class="kc">True</span> <span class="p">)</span> <span class="n">sample</span> <span class="o">=</span> <span class="n">dataset</span><span class="o">.</span><span class="n">select</span><span class="p">([</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">dataset</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)])</span> <span class="n">document</span> <span class="o">=</span> <span class="n">sample</span><span class="p">[</span><span class="s2">"document"</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="n">reference_summary</span> <span class="o">=</span> <span class="n">sample</span><span class="p">[</span><span class="s2">"summary"</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="n">messages</span> <span class="o">=</span> <span class="p">[</span> <span class="p">{</span> <span class="s2">"role"</span><span class="p">:</span> <span class="s2">"user"</span><span class="p">,</span> <span class="s2">"content"</span><span class="p">:</span> <span class="sa">f</span><span class="s2">"Summarize the following ARTICLE in one sentence.</span><span class="se">\n</span><span class="s2">###ARTICLE: </span><span class="si">{</span><span class="n">document</span><span class="si">}</span><span class="s2">"</span><span class="p">,</span> <span class="p">},</span> <span class="p">]</span> <span class="n">prompt</span> <span class="o">=</span> <span class="n">tokenizer</span><span class="o">.</span><span class="n">apply_chat_template</span><span class="p">(</span> <span class="n">messages</span><span class="p">,</span> <span class="n">tokenize</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">add_generation_prompt</span><span class="o">=</span><span class="kc">True</span> <span class="p">)</span> <span class="n">tuned_gemma_pipeline</span> <span class="o">=</span> <span class="n">pipeline</span><span class="p">(</span> <span class="s2">"text-generation"</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="n">tuned_model</span><span class="p">,</span> <span class="n">tokenizer</span><span class="o">=</span><span class="n">tokenizer</span><span class="p">,</span> <span class="n">max_new_tokens</span><span class="o">=</span><span class="mi">50</span> <span class="p">)</span> <span class="n">generated_tuned_gemma_summary</span> <span class="o">=</span> <span class="n">tuned_gemma_pipeline</span><span class="p">(</span> <span class="n">prompt</span><span class="p">,</span> <span class="n">do_sample</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">temperature</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">add_special_tokens</span><span class="o">=</span><span class="kc">True</span> <span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="s2">"generated_text"</span><span class="p">][</span><span class="nb">len</span><span class="p">(</span><span class="n">prompt</span><span class="p">)</span> <span class="p">:]</span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Reference summary: </span><span class="si">{</span><span class="n">reference_summary</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"-"</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Tuned generated summary: </span><span class="si">{</span><span class="n">generated_tuned_gemma_summary</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Below is an example output from the tuned model. Note that the tuned result might require further refinement. To achieve optimal quality, it's necessary to iterate through the process several times, adjusting factors such as the learning rate and the number of training steps.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Screenshot_2024-06-18_at_5.14.57PM.original.png" alt="Example of output from the tuned model" /> </div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="589pj"><b>Evaluate the tuned model</b></h2><p data-block-key="87qis">As an additional step, you can evaluate the tuned model. To evaluate the model you compare models qualitatively and quantitatively.</p><p data-block-key="84fqg">In one case, you compare responses generated by the base Gemma model with the ones generated by the tuned Gemma model. In the other case, you calculate ROUGE metrics and its improvements which gives you an idea of how well the tuned model is able to reproduce the reference summaries correctly with respect to the base model.</p><p data-block-key="aionf">Below is a Python code to evaluate models by comparing generated summaries.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">gemma_pipeline</span> <span class="o">=</span> <span class="n">pipeline</span><span class="p">(</span> <span class="s2">"text-generation"</span><span class="p">,</span> <span class="n">model</span><span class="o">=</span><span class="n">base_model</span><span class="p">,</span> <span class="n">tokenizer</span><span class="o">=</span><span class="n">tokenizer</span><span class="p">,</span> <span class="n">max_new_tokens</span><span class="o">=</span><span class="mi">50</span> <span class="p">)</span> <span class="n">generated_gemma_summary</span> <span class="o">=</span> <span class="n">gemma_pipeline</span><span class="p">(</span> <span class="n">prompt</span><span class="p">,</span> <span class="n">do_sample</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">temperature</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">add_special_tokens</span><span class="o">=</span><span class="kc">True</span> <span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="s2">"generated_text"</span><span class="p">][</span><span class="nb">len</span><span class="p">(</span><span class="n">prompt</span><span class="p">)</span> <span class="p">:]</span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Reference summary: </span><span class="si">{</span><span class="n">reference_summary</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"-"</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Base generated summary: </span><span class="si">{</span><span class="n">generated_gemma_summary</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"-"</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Tuned generated summary: </span><span class="si">{</span><span class="n">generated_tuned_gemma_summary</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="0mqga">Below is an example output from the base model and tuned model.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Screenshot_2024-06-18_at_5.16.55PM.original.png" alt="Example output from the base model and tuned model." /> </div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">And below is a code to evaluate models by computing <a href="https://en.wikipedia.org/wiki/ROUGE_(metric)">ROUGE metrics</a> and its improvements.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="kn">import</span> <span class="nn">evaluate</span> <span class="n">rouge</span> <span class="o">=</span> <span class="n">evaluate</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="s2">"rouge"</span><span class="p">)</span> <span class="n">gemma_results</span> <span class="o">=</span> <span class="n">rouge</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span> <span class="n">predictions</span><span class="o">=</span><span class="p">[</span><span class="n">generated_gemma_summary</span><span class="p">],</span> <span class="n">references</span><span class="o">=</span><span class="p">[</span><span class="n">reference_summary</span><span class="p">],</span> <span class="n">rouge_types</span><span class="o">=</span><span class="p">[</span><span class="s2">"rouge1"</span><span class="p">,</span> <span class="s2">"rouge2"</span><span class="p">,</span> <span class="s2">"rougeL"</span><span class="p">,</span> <span class="s2">"rougeLsum"</span><span class="p">],</span> <span class="n">use_aggregator</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">use_stemmer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="p">)</span> <span class="n">tuned_gemma_results</span> <span class="o">=</span> <span class="n">rouge</span><span class="o">.</span><span class="n">compute</span><span class="p">(</span> <span class="n">predictions</span><span class="o">=</span><span class="p">[</span><span class="n">generated_tuned_gemma_summary</span><span class="p">],</span> <span class="n">references</span><span class="o">=</span><span class="p">[</span><span class="n">reference_summary</span><span class="p">],</span> <span class="n">rouge_types</span><span class="o">=</span><span class="p">[</span><span class="s2">"rouge1"</span><span class="p">,</span> <span class="s2">"rouge2"</span><span class="p">,</span> <span class="s2">"rougeL"</span><span class="p">,</span> <span class="s2">"rougeLsum"</span><span class="p">],</span> <span class="n">use_aggregator</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">use_stemmer</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="p">)</span> <span class="n">improvements</span> <span class="o">=</span> <span class="p">{}</span> <span class="k">for</span> <span class="n">rouge_metric</span><span class="p">,</span> <span class="n">gemma_rouge</span> <span class="ow">in</span> <span class="n">gemma_results</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> <span class="n">tuned_gemma_rouge</span> <span class="o">=</span> <span class="n">tuned_gemma_results</span><span class="p">[</span><span class="n">rouge_metric</span><span class="p">]</span> <span class="k">if</span> <span class="n">gemma_rouge</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span> <span class="n">improvement</span> <span class="o">=</span> <span class="p">((</span><span class="n">tuned_gemma_rouge</span> <span class="o">-</span> <span class="n">gemma_rouge</span><span class="p">)</span> <span class="o">/</span> <span class="n">gemma_rouge</span><span class="p">)</span> <span class="o">*</span> <span class="mi">100</span> <span class="k">else</span><span class="p">:</span> <span class="n">improvement</span> <span class="o">=</span> <span class="kc">None</span> <span class="n">improvements</span><span class="p">[</span><span class="n">rouge_metric</span><span class="p">]</span> <span class="o">=</span> <span class="n">improvement</span> <span class="nb">print</span><span class="p">(</span><span class="s2">"Base Gemma vs Tuned Gemma - ROUGE improvements"</span><span class="p">)</span> <span class="k">for</span> <span class="n">rouge_metric</span><span class="p">,</span> <span class="n">improvement</span> <span class="ow">in</span> <span class="n">improvements</span><span class="o">.</span><span class="n">items</span><span class="p">():</span> <span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">rouge_metric</span><span class="si">}</span><span class="s2">: </span><span class="si">{</span><span class="n">improvement</span><span class="si">:</span><span class="s2">.3f</span><span class="si">}</span><span class="s2">%"</span><span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">And the example output for the evaluation.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Screenshot_2024-06-18_at_5.18.58PM.original.png" alt="Base Gemma v Tuned Gemma - Rouge improvements" /> </div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="vn49f"><b>Serving tuned Gemma model with Ray Data for offline predictions</b></h2><p data-block-key="bs3v4">To generate offline predictions at scale with the tuned Gemma on Ray on Vertex AI, you can use Ray Data, a scalable data processing library for ML workloads.</p><p data-block-key="dnvck">Using Ray Data for generating offline predictions with Gemma, you need to define a Python class to load the tuned model in Hugging Face Pipeline. Then, depending on your data source and its format, you use Ray Data to perform distributed data reading and you use a Ray dataset method to apply the Python class for performing predictions in parallel to multiple batches of data.</p><h3 data-block-key="bpn6r"><br/><b>Batch prediction with Ray Data</b></h3><p data-block-key="2hvc7">To generate batch prediction with the tuned model using Ray Data on Vertex AI, you need a dataset to generate predictions and the tuned model stored in the Cloud bucket.</p><p data-block-key="csfbr">Then, you can leverage Ray Data which provides an easy-to-use API for offline batch inference.</p><p data-block-key="foat8">First, upload the tuned model on the Cloud storage with Google Cloud CLI</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">gsutil</span> <span class="o">-</span><span class="n">q</span> <span class="n">cp</span> <span class="o">-</span><span class="n">r</span> <span class="err">“</span><span class="o">./</span><span class="n">models</span><span class="err">”</span> <span class="err">“</span><span class="n">your</span><span class="o">-</span><span class="n">bucket</span><span class="o">-</span><span class="n">uri</span><span class="o">/</span><span class="n">models</span><span class="err">”</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Prepare the batch prediction training script file for executing the Ray batch prediction job.</p><ul><li data-block-key="vo87"><a href="https://github.com/bebechien/gemma/blob/main/ray/tutorial/src/batch_predictor.py"><code>tutorial/src/batch_predictor.py</code></a></li></ul><p data-block-key="3j36v">Again, you can initiate the client to submit the job like below with the Ray Jobs API via the Ray dashboard address.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="kn">import</span> <span class="nn">ray</span> <span class="kn">from</span> <span class="nn">ray.job_submission</span> <span class="kn">import</span> <span class="n">JobSubmissionClient</span> <span class="n">client</span> <span class="o">=</span> <span class="n">JobSubmissionClient</span><span class="p">(</span> <span class="n">address</span><span class="o">=</span><span class="s2">"vertex_ray://</span><span class="si">{}</span><span class="s2">"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">ray_cluster</span><span class="o">.</span><span class="n">dashboard_address</span><span class="p">)</span> <span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Let’s set some job configuration including model path, job id, prediction entrypoint and more.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="kn">import</span> <span class="nn">random</span><span class="o">,</span> <span class="nn">string</span> <span class="n">batch_predict_submission_id</span> <span class="o">=</span> <span class="s2">"your-batch-prediction-job"</span> <span class="n">tuned_model_uri_path</span> <span class="o">=</span> <span class="s2">"/gcs/your-bucket-uri/models"</span> <span class="n">batch_predict_entrypoint</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"python3 batch_predictor.py --tuned_model_path=</span><span class="si">{</span><span class="n">tuned_model_uri_path</span><span class="si">}</span><span class="s2"> --num_gpus=1 --output_dir=”your-bucket-uri/predictions”"</span> <span class="n">batch_predict_runtime_env</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">"working_dir"</span><span class="p">:</span> <span class="s2">"tutorial/src"</span><span class="p">,</span> <span class="s2">"env_vars"</span><span class="p">:</span> <span class="p">{</span><span class="s2">"HF_TOKEN"</span><span class="p">:</span> <span class="err">“</span><span class="n">your</span><span class="o">-</span><span class="n">hf</span><span class="o">-</span><span class="n">token</span><span class="err">”</span><span class="p">},</span> <span class="p">}</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">You can specify the number of GPUs to use with the "--num_gpus" argument. This should be a value that is equal to or less than the number of GPUs available in your Ray cluster.</p><p data-block-key="lbfd">And submit the job.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="n">batch_predict_job_id</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">submit_job</span><span class="p">(</span> <span class="n">submission_id</span><span class="o">=</span><span class="n">batch_predict_submission_id</span><span class="p">,</span> <span class="n">entrypoint</span><span class="o">=</span><span class="n">batch_predict_entrypoint</span><span class="p">,</span> <span class="n">runtime_env</span><span class="o">=</span><span class="n">batch_predict_runtime_env</span><span class="p">,</span> <span class="p">)</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Let’s have a quick view of generated summaries using a Pandas DataFrame.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="kn">import</span> <span class="nn">io</span> <span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span> <span class="kn">from</span> <span class="nn">google.cloud</span> <span class="kn">import</span> <span class="n">storage</span> <span class="k">def</span> <span class="nf">read_json_files</span><span class="p">(</span><span class="n">bucket_name</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> <span class="w"> </span><span class="sd">"""Reads JSON files from a cloud storage bucket and returns a Pandas DataFrame"""</span> <span class="c1"># Set up storage client</span> <span class="n">storage_client</span> <span class="o">=</span> <span class="n">storage</span><span class="o">.</span><span class="n">Client</span><span class="p">()</span> <span class="n">bucket</span> <span class="o">=</span> <span class="n">storage_client</span><span class="o">.</span><span class="n">bucket</span><span class="p">(</span><span class="n">bucket_name</span><span class="p">)</span> <span class="n">blobs</span> <span class="o">=</span> <span class="n">bucket</span><span class="o">.</span><span class="n">list_blobs</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="n">prefix</span><span class="p">)</span> <span class="n">dfs</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">blob</span> <span class="ow">in</span> <span class="n">blobs</span><span class="p">:</span> <span class="k">if</span> <span class="n">blob</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">".json"</span><span class="p">):</span> <span class="n">file_bytes</span> <span class="o">=</span> <span class="n">blob</span><span class="o">.</span><span class="n">download_as_bytes</span><span class="p">()</span> <span class="n">file_string</span> <span class="o">=</span> <span class="n">file_bytes</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">"utf-8"</span><span class="p">)</span> <span class="k">with</span> <span class="n">io</span><span class="o">.</span><span class="n">StringIO</span><span class="p">(</span><span class="n">file_string</span><span class="p">)</span> <span class="k">as</span> <span class="n">json_file</span><span class="p">:</span> <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_json</span><span class="p">(</span><span class="n">json_file</span><span class="p">,</span> <span class="n">lines</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="n">dfs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">df</span><span class="p">)</span> <span class="k">return</span> <span class="n">pd</span><span class="o">.</span><span class="n">concat</span><span class="p">(</span><span class="n">dfs</span><span class="p">,</span> <span class="n">ignore_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> <span class="n">predictions_df</span> <span class="o">=</span> <span class="n">read_json_files</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">"predictions/"</span><span class="p">,</span> <span class="n">bucket_name</span><span class="o">=</span><span class="err">”</span><span class="n">your</span><span class="o">-</span><span class="n">bucket</span><span class="o">-</span><span class="n">uri</span><span class="err">”</span><span class="p">)</span> <span class="n">predictions_df</span> <span class="o">=</span> <span class="n">predictions_df</span><span class="p">[</span> <span class="p">[</span><span class="s2">"id"</span><span class="p">,</span> <span class="s2">"document"</span><span class="p">,</span> <span class="s2">"prompt"</span><span class="p">,</span> <span class="s2">"summary"</span><span class="p">,</span> <span class="s2">"generated_summary"</span><span class="p">]</span> <span class="p">]</span> <span class="n">predictions_df</span><span class="o">.</span><span class="n">head</span><span class="p">()</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">And below is an example output. The default number of articles to summarize is 20. You can specify the number with the “--sample_size” argument.</p> </div> <div class="inner-block-content"> <div class="image-wrapper"> <img class="regular-image" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Screenshot_2024-06-18_at_5.25.12PM.original.png" alt="Example output of summaries" /> </div> </div> <div class="inner-block-content rich-content"> <h2 data-block-key="vn49f"><b>Summary</b></h2><p data-block-key="sh23">Now you have learned many things including:</p><p data-block-key="7bog4"></p><ul><li data-block-key="5p456">How to create a Ray cluster on Vertex AI</li></ul><p data-block-key="20h14"></p><ul><li data-block-key="qu2s">How to tune Gemma with Ray Train on Vertex AI</li></ul><p data-block-key="cr3bl"></p><ul><li data-block-key="cjbmj">How to validate Gemma training on Vertex AI</li></ul><p data-block-key="2q02l"></p><ul><li data-block-key="4g9oj">How to evaluate tuned Gemma model</li></ul><p data-block-key="ag5n8"></p><ul><li data-block-key="borh2">How to serve Gemma with Ray Data for offline predictions</li></ul><p data-block-key="bphg4"></p><p data-block-key="71j89">We hope that this tutorial has been enlightening and provided you with valuable insights.</p><p data-block-key="5n863">Consider joining the <a href="https://discord.gg/google-dev-community">Google Developer Community</a> Discord server. It offers an opportunity to share your projects, connect with other developers, and engage in collaborative discussions.</p><p data-block-key="7ora">And don’t forget to clean up all Google Cloud resources used in this project. You can simply <a href="https://cloud.google.com/resource-manager/docs/creating-managing-projects#shutting_down_projects">delete the Google Cloud project</a> that you used for the tutorial. Otherwise, you can delete the individual resources that you created.</p> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="c1"># Delete tensorboard</span> <span class="n">tensorboard_list</span> <span class="o">=</span> <span class="n">vertex_ai</span><span class="o">.</span><span class="n">Tensorboard</span><span class="o">.</span><span class="n">list</span><span class="p">()</span> <span class="k">for</span> <span class="n">tensorboard</span> <span class="ow">in</span> <span class="n">tensorboard_list</span><span class="p">:</span> <span class="n">tensorboard</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span> <span class="c1"># Delete experiments</span> <span class="n">experiment_list</span> <span class="o">=</span> <span class="n">vertex_ai</span><span class="o">.</span><span class="n">Experiment</span><span class="o">.</span><span class="n">list</span><span class="p">()</span> <span class="k">for</span> <span class="n">experiment</span> <span class="ow">in</span> <span class="n">experiment_list</span><span class="p">:</span> <span class="n">experiment</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span> <span class="c1"># Delete ray on vertex cluster</span> <span class="n">ray_cluster_list</span> <span class="o">=</span> <span class="n">vertex_ray</span><span class="o">.</span><span class="n">list_ray_clusters</span><span class="p">()</span> <span class="k">for</span> <span class="n">ray_cluster</span> <span class="ow">in</span> <span class="n">ray_cluster_list</span><span class="p">:</span> <span class="n">vertex_ray</span><span class="o">.</span><span class="n">delete_ray_cluster</span><span class="p">(</span><span class="n">ray_cluster</span><span class="o">.</span><span class="n">cluster_resource_name</span><span class="p">)</span> </pre></div> </div> <div class="inner-block-content code-block"> <div class="highlight"><pre class="python"><span></span><span class="c1"># Delete artifacts repo</span> <span class="n">gcloud</span> <span class="n">artifacts</span> <span class="n">repositories</span> <span class="n">delete</span> <span class="err">“</span><span class="n">your</span><span class="o">-</span><span class="n">repo</span><span class="err">”</span> <span class="o">-</span><span class="n">q</span> <span class="c1"># Delete Cloud Storage objects that were created</span> <span class="n">gsutil</span> <span class="o">-</span><span class="n">q</span> <span class="o">-</span><span class="n">m</span> <span class="n">rm</span> <span class="o">-</span><span class="n">r</span> <span class="err">“</span><span class="n">your</span><span class="o">-</span><span class="n">bucker</span><span class="o">-</span><span class="n">uri</span><span class="err">”</span> </pre></div> </div> <div class="inner-block-content rich-content"> <p data-block-key="vn49f">Thanks for reading!</p><h2 data-block-key="6gs0p"><br/><b>References</b></h2><ul><li data-block-key="8oohv"><a href="https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/model_garden/model_garden_gemma_fine_tuning_batch_deployment_on_rov.ipynb">https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/model_garden/model_garden_gemma_fine_tuning_batch_deployment_on_rov.ipynb</a></li></ul><p data-block-key="55i03"></p><ul><li data-block-key="d8flq"><a href="https://cloud.google.com/vertex-ai/docs/open-source/ray-on-vertex-ai/overview">https://cloud.google.com/vertex-ai/docs/open-source/ray-on-vertex-ai/overview</a></li></ul><p data-block-key="fn4mp"></p><ul><li data-block-key="5pp6i"><a href="https://github.com/googleapis/python-aiplatform/tree/main/google/cloud/aiplatform/preview/vertex_ray">https://github.com/googleapis/python-aiplatform/tree/main/google/cloud/aiplatform/preview/vertex_ray</a></li></ul><p data-block-key="euld8"></p><ul><li data-block-key="ced0k"><a href="https://github.com/bebechien/gemma/tree/main/ray/tutorial">https://github.com/bebechien/gemma/tree/main/ray/tutorial</a></li></ul> </div> </div> </section> <section class="navigation-container glue-page glue-spacer-6-top"> <div class="posted-in-section"> <div class="posted-in-section__heading"> <span class="glue-caption"> posted in: </span> </div> <div class="posted-in-section__tags"> <ul> <li> <a href="/en/search/?product_categories=Gemma" class="glue-caption">Gemma</a> </li> <li> <a href="/en/search/?technology_categories=AI" class="glue-caption">AI</a> </li> <li> <a href="/en/search/?technology_categories=Cloud" class="glue-caption">Cloud</a> </li> <li> <a href="/en/search/?content_type_categories=Tutorials" class="glue-caption">Tutorials</a> </li> <li> <a href="/en/search/?content_type_categories=How-To+Guides" class="glue-caption">How-To Guides</a> </li> <li> <a href="/en/search/?tag=Learn" class="glue-caption">Learn</a> </li> </ul> </div> </div> <div class="buttons-section"> <div class="buttons-section__left"> <a href="/en/model-explorer-simplifying-ml-models-for-edge-devices/" class="glue-button--icon glue-elevation-level-1 " aria-label="Previous"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#chevron-left"></use> </svg> </a> <span class="caption ">Previous</span> </div> <div class="buttons-section__right"> <span class="caption ">Next</span> <a href="/en/how-its-made-ai-roadtrip-a-pixel-campaign-powered-by-generative-ai-and-fans/" class="glue-button--icon glue-elevation-level-1 " aria-label="Next"> <svg role="presentation" aria-hidden="true" class="glue-icon"> <use href="/glue-icon/#chevron-right"></use> </svg> </a> </div> </div> </section> <section class="related-posts-container glue-page glue-spacer-6-top glue-spacer-3-bottom"> <span class="glue-headline glue-headline--headline-3">Related Posts</span> <div class="related-posts-container__carousel glue-page glue-spacer-5-top"> <div class="glue-carousel glue-carousel--cards glue-carousel-related-posts" aria-label="Related Posts"> <!-- Previous --> <button class="glue-carousel__button glue-carousel__button--prev" aria-label="Go to the previous slide"> <svg role="presentation" aria-hidden="true" class="glue-icon glue-icon--32px"> <use href="/glue-icon/#chevron-left"></use> </svg> </button> <!-- Next --> <button class="glue-carousel__button glue-carousel__button--next" aria-label="Go to the next slide"> <svg role="presentation" aria-hidden="true" class="glue-icon glue-icon--32px"> <use href="/glue-icon/#chevron-right"></use> </svg> </button> <!-- List --> <div class="glue-carousel__viewport"> <div class="glue-carousel__list"> <a class="glue-card glue-carousel__item" href="/en/firebase-demo-day-24/"> <div aria-label="Learn to build and run AI powered apps at Firebase Demo Day ‘24" class="glue-card__inner"> <picture class="glue-card__asset"> <img alt="Learn to build and run AI powered apps at Firebase Demo Day ‘24" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Newletter_DayOf.2e16d0ba.fill-800x400.jpg"> </picture> <div class="glue-card__content"> <div class="glue-card__tags glue-spacer-2-top"> <span class="glue-label">Firebase</span> <span class="glue-label">Mobile</span> <span class="glue-label">Web</span> <span class="glue-label">Tutorials</span> <span class="glue-label">How-To Guides</span> </div> <p class="glue-headline glue-headline--headline-5">Learn to build and run AI powered apps at Firebase Demo Day ‘24</p> <div class="glue-card__cta-custom glue-spacer-3-top"> <span class="glue-cta">Nov. 19, 2024</span> <svg aria-hidden="true" class="glue-icon glue-icon--24px" role="presentation"> <use href="/glue-icon/#arrow-forward"></use> </svg> </div> </div> </div> </a> <a class="glue-card glue-carousel__item" href="/en/inference-with-gemma-using-dataflow-and-vllm/"> <div aria-label="Inference with Gemma using Dataflow and vLLM" class="glue-card__inner"> <picture class="glue-card__asset"> <img alt="Inference with Gemma using Dataflow and vLLM" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Gemma-Dataflow-ML-vLLM.2e16d0ba.fill-800x400.png"> </picture> <div class="glue-card__content"> <div class="glue-card__tags glue-spacer-2-top"> <span class="glue-label">Gemma</span> <span class="glue-label">AI</span> <span class="glue-label">Cloud</span> <span class="glue-label">How-To Guides</span> <span class="glue-label">Problem-Solving</span> </div> <p class="glue-headline glue-headline--headline-5">Inference with Gemma using Dataflow and vLLM</p> <div class="glue-card__cta-custom glue-spacer-3-top"> <span class="glue-cta">Nov. 13, 2024</span> <svg aria-hidden="true" class="glue-icon glue-icon--24px" role="presentation"> <use href="/glue-icon/#arrow-forward"></use> </svg> </div> </div> </div> </a> <a class="glue-card glue-carousel__item" href="/en/gemini-is-now-accessible-from-the-openai-library/"> <div aria-label="Gemini is now accessible from the OpenAI Library" class="glue-card__inner"> <picture class="glue-card__asset"> <img alt="Gemini is now accessible from the OpenAI Library" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Gemini-Social-2_1.2e16d0ba.fill-800x400.png"> </picture> <div class="glue-card__content"> <div class="glue-card__tags glue-spacer-2-top"> <span class="glue-label">Gemini</span> <span class="glue-label">AI</span> <span class="glue-label">Tutorials</span> <span class="glue-label">How-To Guides</span> </div> <p class="glue-headline glue-headline--headline-5">Gemini is now accessible from the OpenAI Library</p> <div class="glue-card__cta-custom glue-spacer-3-top"> <span class="glue-cta">Nov. 8, 2024</span> <svg aria-hidden="true" class="glue-icon glue-icon--24px" role="presentation"> <use href="/glue-icon/#arrow-forward"></use> </svg> </div> </div> </div> </a> <a class="glue-card glue-carousel__item" href="/en/announcing-the-winners-of-the-gemini-api-developer-competition/"> <div aria-label="Announcing the Winners of the Gemini API Developer Competition!" class="glue-card__inner"> <picture class="glue-card__asset"> <img alt="Announcing the Winners of the Gemini API Developer Competition!" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Gemini_Competition_G4D_-_meta.2e16d0ba.fill-800x400.png"> </picture> <div class="glue-card__content"> <div class="glue-card__tags glue-spacer-2-top"> <span class="glue-label">Mobile</span> <span class="glue-label">Web</span> <span class="glue-label">Case Studies</span> <span class="glue-label">Community</span> </div> <p class="glue-headline glue-headline--headline-5">Announcing the Winners of the Gemini API Developer Competition!</p> <div class="glue-card__cta-custom glue-spacer-3-top"> <span class="glue-cta">Nov. 21, 2024</span> <svg aria-hidden="true" class="glue-icon glue-icon--24px" role="presentation"> <use href="/glue-icon/#arrow-forward"></use> </svg> </div> </div> </div> </a> <a class="glue-card glue-carousel__item" href="/en/introducing-keras-hub-for-pretrained-models/"> <div aria-label="Introducing Keras Hub: Your one-stop shop for pretrained models" class="glue-card__inner"> <picture class="glue-card__asset"> <img alt="Introducing Keras Hub: Your one-stop shop for pretrained models" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/Keras-GfD.2e16d0ba.fill-800x400.png"> </picture> <div class="glue-card__content"> <div class="glue-card__tags glue-spacer-2-top"> <span class="glue-label">Gemma</span> <span class="glue-label">AI</span> <span class="glue-label">Announcements</span> <span class="glue-label">Best Practices</span> </div> <p class="glue-headline glue-headline--headline-5">Introducing Keras Hub: Your one-stop shop for pretrained models</p> <div class="glue-card__cta-custom glue-spacer-3-top"> <span class="glue-cta">Oct. 22, 2024</span> <svg aria-hidden="true" class="glue-icon glue-icon--24px" role="presentation"> <use href="/glue-icon/#arrow-forward"></use> </svg> </div> </div> </div> </a> <a class="glue-card glue-carousel__item" href="/en/join-us-at-the-women-in-ai-summit-2024/"> <div aria-label="Join us at the Women in AI Summit 2024!" class="glue-card__inner"> <picture class="glue-card__asset"> <img alt="Join us at the Women in AI Summit 2024!" src="https://storage.googleapis.com/gweb-developer-goog-blog-assets/images/WAI-2024-Feature.2e16d0ba.fill-800x400.png"> </picture> <div class="glue-card__content"> <div class="glue-card__tags glue-spacer-2-top"> <span class="glue-label">AI</span> <span class="glue-label">Community</span> <span class="glue-label">Events</span> </div> <p class="glue-headline glue-headline--headline-5">Join us at the Women in AI Summit 2024!</p> <div class="glue-card__cta-custom glue-spacer-3-top"> <span class="glue-cta">Nov. 22, 2024</span> <svg aria-hidden="true" class="glue-icon glue-icon--24px" role="presentation"> <use href="/glue-icon/#arrow-forward"></use> </svg> </div> </div> </div> </a> </div> </div> <!-- Navigation dots --> <div class="glue-carousel__navigation" aria-label="Choose a page" data-glue-carousel-navigation-label="Selected tab $glue_carousel_page_number$ of $glue_carousel_page_total$"> </div> </div> </div> </section> </div> <div class="footer-linkboxes__wrapper"> <nav class="footer-linkboxes" aria-label="Footer links"> <ul class="footer-linkboxes__list"> <li class="footer-linkbox"> <span class="footer-linkbox-heading"> Connect </span> <ul class="footer-linkbox-list"> <li class="footer-linkbox-list__item"> <a href="//googledevelopers.blogspot.com" class="footer-linkbox-list__link"> Blog </a> </li> <li class="footer-linkbox-list__item"> <a href="https://goo.gle/googlefordevs" class="footer-linkbox-list__link"> Instagram </a> </li> <li class="footer-linkbox-list__item"> <a href="https://goo.gle/gdevs-li" class="footer-linkbox-list__link"> LinkedIn </a> </li> <li class="footer-linkbox-list__item"> <a href="https://goo.gle/gdevs-tw" class="footer-linkbox-list__link"> Twitter </a> </li> <li class="footer-linkbox-list__item"> <a href="https://goo.gle/developers" class="footer-linkbox-list__link"> YouTube </a> </li> </ul> </li> <li class="footer-linkbox"> <span class="footer-linkbox-heading"> Programs </span> <ul class="footer-linkbox-list"> <li class="footer-linkbox-list__item"> <a href="//www.womentechmakers.com" class="footer-linkbox-list__link"> Women Techmakers </a> </li> <li class="footer-linkbox-list__item"> <a href="//developers.google.com/community/gdg" class="footer-linkbox-list__link"> Google Developer Groups </a> </li> <li class="footer-linkbox-list__item"> <a href="//developers.google.com/community/experts" class="footer-linkbox-list__link"> Google Developer Experts </a> </li> <li class="footer-linkbox-list__item"> <a href="//developers.google.com/community/accelerators" class="footer-linkbox-list__link"> Accelerators </a> </li> <li class="footer-linkbox-list__item"> <a href="//developers.google.com/community/gdsc" class="footer-linkbox-list__link"> Google Developer Student Clubs </a> </li> </ul> </li> <li class="footer-linkbox"> <span class="footer-linkbox-heading"> Developer consoles </span> <ul class="footer-linkbox-list"> <li class="footer-linkbox-list__item"> <a href="//console.developers.google.com" class="footer-linkbox-list__link"> Google API Console </a> </li> <li class="footer-linkbox-list__item"> <a href="//console.cloud.google.com" class="footer-linkbox-list__link"> Google Cloud Platform Console </a> </li> <li class="footer-linkbox-list__item"> <a href="//play.google.com/apps/publish" class="footer-linkbox-list__link"> Google Play Console </a> </li> <li class="footer-linkbox-list__item"> <a href="//console.firebase.google.com" class="footer-linkbox-list__link"> Firebase Console </a> </li> <li class="footer-linkbox-list__item"> <a href="//console.actions.google.com" class="footer-linkbox-list__link"> Actions on Google Console </a> </li> <li class="footer-linkbox-list__item"> <a href="//cast.google.com/publish" class="footer-linkbox-list__link"> Cast SDK Developer Console </a> </li> <li class="footer-linkbox-list__item"> <a href="//chrome.google.com/webstore/developer/dashboard" class="footer-linkbox-list__link"> Chrome Web Store Dashboard </a> </li> </ul> </li> </ul> </nav> </div> <div class="footer-utility__wrapper"> <div> <nav class="footer-sites" aria-label="Other Google Developers websites"> <a href="https://developers.google.com/" class="site-logo-link" data-label="Site logo"> <img src="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/images/g-dev.svg" class="site-logo" alt="Google for Developers"> </a> <ul class="footer-sites-list"> <li class="footer-sites-item"> <a href="//developer.android.com" class="footer-sites-link"> Android </a> </li> <li class="footer-sites-item"> <a href="//developer.chrome.com/home" class="footer-sites-link"> Chrome </a> </li> <li class="footer-sites-item"> <a href="//firebase.google.com" class="footer-sites-link"> Firebase </a> </li> <li class="footer-sites-item"> <a href="//cloud.google.com" class="footer-sites-link"> Google Cloud Platform </a> </li> <li class="footer-sites-item"> <a href="//developers.google.com/products" class="footer-sites-link"> All products </a> </li> <li class="footer-sites-item"> <button aria-hidden="true" class="glue-cookie-notification-bar-control footer-sites-link"> Manage cookies </button> </li> </ul> </nav> <nav class="footer-utility-links"> <ul class="footer-utility-list"> <li class="footer-utility-item"> <a href="//developers.google.com/terms/site-terms" class="footer-utility-link"> Terms </a> </li> <li class="footer-utility-item"> <a href="//policies.google.com/privacy" class="footer-utility-link"> Privacy </a> </li> </ul> <div class="language-selector footer" aria-label="Select your language preference"> <button type="button" aria-controls="lang-selector-footer" aria-haspopup="true"> <svg role="presentation" aria-hidden="true" class="glue-icon lang-icon"> <use href="/glue-icon/#language"></use> </svg> <span class="lang-label">English</span> <svg role="presentation" aria-hidden="true" class="glue-icon lang-icon"> <use href="/glue-icon/#arrow-drop-down"></use> </svg> </button> <div id="lang-selector-footer" class="lang-menu hidden" role="menu"> <ul role="presentation"> <li role="presentation"> <a role="menuitem" lang="en" aria-current="true" href="/en/get-started-with-gemma-on-ray-on-vertex-ai/">English</a> </li> <li role="presentation"> <a role="menuitem" lang="es" href="/es/get-started-with-gemma-on-ray-on-vertex-ai/">Español (Latam)</a> </li> <li role="presentation"> <a role="menuitem" lang="id" href="/id/get-started-with-gemma-on-ray-on-vertex-ai/">Bahasa Indonesia</a> </li> <li role="presentation"> <a role="menuitem" lang="ja" href="/ja/get-started-with-gemma-on-ray-on-vertex-ai/">日本語</a> </li> <li role="presentation"> <a role="menuitem" lang="ko" href="/ko/get-started-with-gemma-on-ray-on-vertex-ai/">한국어</a> </li> <li role="presentation"> <a role="menuitem" lang="pt-br" href="/pt-br/get-started-with-gemma-on-ray-on-vertex-ai/">Português (Brasil)</a> </li> <li role="presentation"> <a role="menuitem" lang="zh-hans" href="/zh-hans/get-started-with-gemma-on-ray-on-vertex-ai/">简体中文</a> </li> </ul> </div> </div> </nav> </div> </div> <script src="https://www.youtube.com/player_api"></script> <script src="//www.gstatic.com/glue/v27_1/glue.min.js"></script> <script type="text/javascript" src="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/js/dgc_blog.js"></script> <script src="https://www.gstatic.com/glue/cookienotificationbar/cookienotificationbar.min.js" data-glue-cookie-notification-bar-category="2A" data-glue-cookie-notification-bar-site-id="developers.googleblog.com"> </script> <script src="https://storage.googleapis.com/gweb-developer-goog-blog-cms-assets/f677f1b8-8552-4a23-83cc-57c36dbaf782/js/blog_detail.js"></script> </body> </html>