Przeprowadzanie generowania treści i wyciągania wniosków przez Gemma
Jeśli chcesz uruchomić model Gemma, musisz podjąć 2 kluczowe decyzje:
1) jaki wariant Gemma chcesz uruchomić i 2) jakiego frameworku AI chcesz użyć do jego uruchomienia. Kluczowym czynnikiem przy podejmowaniu tych decyzji jest sprzęt, który Ty i Twoi użytkownicy macie do dyspozycji na potrzeby uruchamiania modelu.
Ten przegląd pomoże Ci podjąć te decyzje i rozpocząć pracę z modelami Gemma. Ogólne czynności związane z uruchamianiem modelu Gemma:
Modele Gemma są zgodne z różnymi frameworkami generatywnej AI. Jednym z kluczowych czynników wpływających na decyzję o wykorzystaniu modelu Gemma jest to, jakie zasoby obliczeniowe masz (lub będziesz mieć) dostępne do jego uruchamiania. Większość kompatybilnych platform AI wymaga sprzętu specjalistycznego, takiego jak GPU lub TPU, aby skutecznie uruchamiać model Gemma. Narzędzie takie jak Google Colab może udostępniać te wyspecjalizowane zasoby obliczeniowe w ograniczonym zakresie. Niektóre frameworki do wykonywania AI, takie jak Ollama i Gemma.cpp, umożliwiają uruchamianie Gemma na bardziej popularnych procesorach z architekturą zgodną z x86 lub ARM.
Oto przewodniki dotyczące uruchamiania modeli Gemma w różnych środowiskach wykonawczych AI:
Upewnij się, że wybrany format modelu Gemma, np. format natywny Keras, Safetensors lub GGUF, jest obsługiwany przez wybraną platformę.
Wybierz wariant Gemma
Modele Gemma są dostępne w różnych wersjach i rozmiarach, w tym podstawowe modele Gemma i podstawowe modele Gemma oraz bardziej wyspecjalizowane wersje modeli, takie jak PaliGemma i DataGemma, a także wiele wersji stworzonych przez społeczność programistów AI na stronach takich jak Kaggle i Hugging Face. Jeśli nie masz pewności, od którego wariantu zacząć, wybierz najnowszy model Gemma core z instrukcjami (IT) o najmniejszej liczbie parametrów. Ten typ modelu Gemma ma niskie wymagania dotyczące zasobów obliczeniowych i może odpowiadać na wiele różnych promptów bez konieczności dodatkowego rozwoju.
Wybierając wariant Gemma, weź pod uwagę te czynniki:
Gemma core i inne rodziny wariantów, takie jak PaliGemma czy CodeGemma:zalecamy Gemma (core). Wersje Gemma inne niż główna mają tę samą architekturę co model główny i są trenowane, aby lepiej wykonywać określone zadania. Jeśli Twoje aplikacje lub cele nie pasują do specjalizacji konkretnego wariantu Gemma, najlepiej zacząć od podstawowego modelu Gemma.
Instruction-tuned (IT), pre-trained (PT), fine-tuned (FT), mixed
(mix): Recommend IT.
Dostrojone pod kątem instrukcji (IT) warianty Gemma to modele, które zostały wytrenowane do reagowania na różne instrukcje lub żądania w języku naturalnym. Te warianty modelu są najlepszym punktem wyjścia, ponieważ mogą odpowiadać na prompty bez dalszego trenowania.
Gotowe (PT) warianty modelu Gemma to modele, które zostały wytrenowane do wyciągania wniosków na podstawie języka lub innych danych, ale nie zostały wytrenowane do wykonywania poleceń wydawanych przez człowieka. Modele te wymagają dodatkowego trenowania lub dostosowania, aby mogły skutecznie wykonywać zadania. Są przeznaczone dla badaczy lub programistów, którzy chcą badać możliwości modelu i jego architektury lub je rozwijać.
Dostrojone (FT) warianty Gemma można uznać za warianty IT, ale są one zwykle trenowane do wykonywania określonego zadania lub osiągania dobrych wyników w ramach konkretnego benchmarku generatywnej AI. Rodzina wariantów PaliGemma obejmuje kilka wariantów FT.
Zróżnicowane (mix) warianty modelu Gemma to wersje modeli PaliGemma, które zostały dostosowane do różnych instrukcji i są odpowiednie do ogólnego użytku.
Parametry:polec najmniejszą liczbę dostępnych opcji. Zasadniczo im więcej parametrów ma model, tym jest on bardziej zaawansowany. Jednak uruchamianie większych modeli wymaga większych i bardziej złożonych zasobów obliczeniowych, co spowalnia rozwój aplikacji AI. Jeśli nie masz pewności, że mniejszy model Gemma nie spełni Twoich potrzeb, wybierz model z małą liczbą parametrów.
Poziomy kwantowania:zalecamy użycie precyzji połowy (16-bitowej), z wyjątkiem strojenia. Kwantyzacja to złożony temat, który sprowadza się do rozmiaru i dokładności danych, a w konsekwencji do ilości pamięci, której model generatywnej AI używa do obliczeń i generowania odpowiedzi. Po wytrenowaniu modelu za pomocą danych o wysokiej precyzji, czyli zwykle 32-bitowych danych zmiennoprzecinkowych, modele takie jak Gemma można zmodyfikować, aby używały danych o niższej precyzji, np. 16-, 8- lub 4-bitowych. Te skonwertowane modele Gemma mogą nadal dobrze działać, w zależności od złożoności zadań, przy znacznie mniejszym wykorzystaniu zasobów obliczeniowych i pamięci. Narzędzia do dostrajania skwantyzowanych modeli są jednak ograniczone i mogą nie być dostępne w wybranym przez Ciebie frameworku do tworzenia AI. Zwykle trzeba dostroić model, taki jak Gemma, z pełną dokładnością, a potem zastosować kwantyzację.
Listę najważniejszych modeli Gemma opublikowanych przez Google znajdziesz w artykule Pierwsze kroki z modelami Gemma oraz na liście modeli Gemma.
Przetwarzanie żądań generowania i wnioskowania
Po wybraniu platformy do wykonywania AI i wersji Gemma możesz rozpocząć uruchamianie modelu i poprosić go o wygenerowanie treści lub wykonanie zadań.
Więcej informacji o uruchamianiu Gemma z konkretną platformą znajdziesz w przewodniku dostępnym w sekcji Wybieranie platformy.
Formatowanie prompta
Wszystkie warianty Gemma z dostosowaniem instrukcji mają określone wymagania dotyczące formatowania promptów. Niektóre z tych wymagań dotyczących formatowania są obsługiwane automatycznie przez framework używany do uruchamiania modeli Gemma, ale gdy wysyłasz dane prompta bezpośrednio do tokenizera, musisz dodać określone tagi. Wymagania dotyczące tagowania mogą się zmieniać w zależności od używanej wersji Gemma. Aby uzyskać informacje o formatowaniu promptów i instrukcjach dotyczących systemu Gemma, zapoznaj się z tymi przewodnikami:
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-06-11 UTC."],[],[],null,["# Run Gemma content generation and inferences\n\nThere are two key decisions to make when you want to run a Gemma model:\n1) what Gemma variant you want to run, and 2) what AI execution framework you\nare going to use to run it? A key issue in making both these decisions has to do\nwith what are hardware you and your users have available to run the model.\n\nThis overview helps you navigate these decisions and start working with Gemma\nmodels. The general steps for running a Gemma model are as follows:\n\n- [Choose a framework for running](#choose-a-framework)\n- [Select a Gemma variant](#select-a-variant)\n- [Run generation and inference requests](#run-generation)\n\nChoose a framework\n------------------\n\nGemma models are compatible with a variety of generative AI execution\nframeworks. One of the key decision making factors in running a Gemma model is\nwhat computing resources you have (or will have) available to you to run the\nmodel. Most compatible AI frameworks require specialized hardware, such as GPUs\nor TPUs, to run a Gemma model effectively. Tools such as\n[Google Colab](https://colab.research.google.com/) can provide these specialized\ncompute resources on a limited basis. Some AI execution frameworks, such as\n[Ollama](/gemma/docs/integrations/ollama) and\n[Gemma.cpp](/gemma/docs/gemma_cpp), allow you to run Gemma on more common CPUs\nusing x86-compatible or ARM architectures.\n\nHere are guides for running Gemma models with various AI runtime frameworks:\n\n- [Ollama](/gemma/docs/integrations/ollama)\n- [Hugging Face Transformers](https://huggingface.co/docs/transformers/en/model_doc/gemma2)\n- [Gemma library for JAX](https://gemma-llm.readthedocs.io)\n- [Keras](/gemma/docs/keras_inference)\n- [PyTorch](/gemma/docs/pytorch_gemma)\n- [MediaPipe LLM Inference API](/edge/mediapipe/solutions/genai/llm_inference)\n- [Hugging Face Transformers](https://huggingface.co/docs/transformers/en/model_doc/gemma2)\n- [Gemma.cpp](/gemma/docs/gemma_cpp)\n- [vLLM](https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/%5BGemma_2%5DDeploy_with_vLLM.ipynb)\n- Google Cloud [Vertex AI](https://cloud.google.com/vertex-ai/generative-ai/docs/open-models/use-gemma)\n- [Google Cloud Kubernetes Engine (GKE)](/gemma/docs/code/gke)\n- [Google Cloud Run](/gemma/docs/core/deploy_to_cloud_run_from_ai_studio)\n\n| **Note:** The JAX inference run guide has been replaced by the [Gemma library sampling](https://gemma-llm.readthedocs.io/en/latest/colab_sampling.html) guide.\n\nMake sure your intended deployment Gemma model format, such as Keras native\nformat, Safetensors, or GGUF, is supported by your chosen framework.\n\nSelect a Gemma variant\n----------------------\n\nGemma models are available in several variants and sizes, including the\nfoundation or [core](/gemma/docs/core) Gemma models, and more\nspecialized model variants such as\n[PaliGemma](/gemma/docs/paligemma) and\n[DataGemma](/gemma/docs/datagemma), and many variants\ncreated by the AI developer community on sites such as\n[Kaggle](https://www.kaggle.com/models?query=gemma) and\n[Hugging Face](https://huggingface.co/models?search=gemma). If you are unsure\nabout what variant you should start with, select the latest Gemma\n[core](/gemma/docs/core) instruction-tuned (IT) model with\nthe lowest number of parameters. This type of Gemma model has low compute\nrequirements and be able to respond to a wide variety of prompts without\nrequiring additional development.\n\nConsider the following factors when choosing a Gemma variant:\n\n- **Gemma core, and other variant families such as PaliGemma, CodeGemma** : *Recommend Gemma (core).* Gemma variants beyond the core version have the same architecture as the core model, and are trained to perform better at specific tasks. Unless your application or goals align with the specialization of a specific Gemma variant, it is best to start with a Gemma core, or base, model.\n- **Instruction-tuned (IT), pre-trained (PT), fine-tuned (FT), mixed\n (mix)** : *Recommend IT.*\n - *Instruction-tuned* (IT) Gemma variants are models that have been trained to respond to a variety of instructions or requests in human language. These model variants are the best place to start because they can respond to prompts without further model training.\n - *Pre-trained* (PT) Gemma variants are models that have been trained to make inferences about language or other data, but have not been trained to follow human instructions. These models require additional training or tuning to be able to perform tasks effectively, and are meant for researchers or developers who want to study or develop the capabilities of the model and its architecture.\n - *Fine-tuned* (FT) Gemma variants can be considered IT variants, but are typically trained to perform a specific task, or perform well on a specific generative AI benchmark. The PaliGemma variant family includes a number of FT variants.\n - *Mixed* (mix) Gemma variants are versions of PaliGemma models that have been instruction tuned with a variety of instructions and are suitable for general use.\n- **Parameters** : *Recommend smallest number available*. In general, the more parameters a model has, the more capable it is. However, running larger models requires larger and more complex compute resources, and generally slows down development of an AI application. Unless you have already determined that a smaller Gemma model cannot meet your needs, choose a one with a small number of parameters.\n- **Quantization levels:** *Recommend half precision (16-bit), except for\n tuning*. Quantization is a complex topic that boils down to what size and precision of data, and consequently how much memory a generative AI model uses for calculations and generating responses. After a model is trained with high-precision data, which is typically 32-bit floating point data, models like Gemma can be modified to use lower precision data such as 16, 8 or 4-bit sizes. These quantized Gemma models can still perform well, depending on the complexity of the tasks, while using significantly less compute and memory resources. However, tools for tuning quantized models are limited and may not be available within your chosen AI development framework. Typically, you must fine-tune a model like Gemma at full precision, then quantize the resulting model.\n\nFor a list of key, Google-published Gemma models, see the\n[Getting started with Gemma models](/gemma/docs/get_started#models-list),\nGemma model list.\n\nRun generation and inference requests\n-------------------------------------\n\nAfter you have selected an AI execution framework and a Gemma variant, you can\nstart running the model, and prompting it to generate content or complete tasks.\nFor more information on how to run Gemma with a specific framework, see the\nguides linked in the [Choose a framework](#choose-a-framework) section.\n\n### Prompt formatting\n\nAll instruction-tuned Gemma variants have specific prompt formatting\nrequirements. Some of these formatting requirements are handled automatically by\nthe framework you use to run Gemma models, but when you are sending prompt data\ndirectly to a tokenizer, you must add specific tags, and the tagging\nrequirements can change depending on the Gemma variant you are using. See the\nfollowing guides for information on Gemma variant prompt formatting and system\ninstructions:\n\n- [Gemma prompt and system instructions](/gemma/docs/core/prompt-structure)\n- [PaliGemma prompt and system instructions](/gemma/docs/paligemma/prompt-system-instructions)\n- [CodeGemma prompt and system instructions](/gemma/docs/codegemma/prompt-structure)"]]