diff --git a/data/links.yml b/data/links.yml index 2f54cb4..013746e 100644 --- a/data/links.yml +++ b/data/links.yml @@ -25,7 +25,7 @@ links: gemma-terms: url: /resources/terms prohibited-use: - url: /resources/prohibited_use_policy + url: /resources/prohibited-use # --- Weights and collections ----------------------------------------------------------- hf-gemma4: @@ -122,7 +122,7 @@ links: gemmaverse: url: https://deepmind.google/models/gemma/gemmaverse/ gemma-cookbook: - url: https://github.com/google-gemma/gemma-cookbook + url: https://github.com/google-gemma/cookbook gemma-skills-repo: url: https://github.com/google-gemma/gemma-skills awesome-gemma: diff --git a/data/models.yml b/data/models.yml index c5c12dd..c22dab7 100644 --- a/data/models.yml +++ b/data/models.yml @@ -304,8 +304,10 @@ gemma4: hf: google/gemma-4-E2B-it hf_base: google/gemma-4-E2B hf_qat: google/gemma-4-E2B-it-qat-w4a16-ct - gguf: google/gemma-4-E2B-it-qat-q4_0-gguf + gguf: ggml-org/gemma-4-E2B-it-GGUF gguf_qat: google/gemma-4-E2B-it-qat-q4_0-gguf + gguf_file: gemma-4-E2B-it-Q4_0.gguf + gguf_mmproj: mmproj-gemma-4-E2B-it-Q8_0.gguf ollama: gemma4:e2b mlx: mlx-community/gemma-4-E2B-it-qat-4bit lmstudio: google/gemma-4-e2b @@ -313,6 +315,7 @@ gemma4: keras_base: gemma4_2b keras_assistant: gemma4_instruct_2b_assistant litert: litert-community/gemma-4-E2B-it-litert-lm + litert_file: gemma-4-E2B-it.litertlm memory: # GB, static weights + ~20% overhead bf16: 11.4 sfp8: 5.7 @@ -335,8 +338,10 @@ gemma4: hf: google/gemma-4-E4B-it hf_base: google/gemma-4-E4B hf_qat: google/gemma-4-E4B-it-qat-w4a16-ct - gguf: google/gemma-4-E4B-it-qat-q4_0-gguf + gguf: ggml-org/gemma-4-E4B-it-GGUF gguf_qat: google/gemma-4-E4B-it-qat-q4_0-gguf + gguf_file: gemma-4-E4B-it-Q4_0.gguf + gguf_mmproj: mmproj-gemma-4-E4B-it-Q8_0.gguf ollama: gemma4:e4b mlx: mlx-community/gemma-4-E4B-it-qat-4bit lmstudio: google/gemma-4-e4b @@ -344,6 +349,7 @@ gemma4: keras_base: gemma4_4b keras_assistant: gemma4_instruct_4b_assistant litert: litert-community/gemma-4-E4B-it-litert-lm + litert_file: gemma-4-E4B-it.litertlm memory: bf16: 17.9 sfp8: 8.9 @@ -366,8 +372,10 @@ gemma4: hf: google/gemma-4-12B-it hf_base: google/gemma-4-12B hf_qat: google/gemma-4-12B-it-qat-w4a16-ct - gguf: google/gemma-4-12B-it-qat-q4_0-gguf + gguf: ggml-org/gemma-4-12B-it-GGUF gguf_qat: google/gemma-4-12B-it-qat-q4_0-gguf + gguf_file: gemma-4-12B-it-Q4_0.gguf + gguf_mmproj: mmproj-gemma-4-12B-it-Q8_0.gguf ollama: gemma4:12b mlx: mlx-community/gemma-4-12B-it-qat-4bit lmstudio: google/gemma-4-12b @@ -391,8 +399,10 @@ gemma4: ids: # verified repo/tag strings; see PLAN.md hf: google/gemma-4-26B-A4B-it hf_base: google/gemma-4-26B-A4B - gguf: google/gemma-4-26B-A4B-it-qat-q4_0-gguf + gguf: ggml-org/gemma-4-26B-A4B-it-GGUF gguf_qat: google/gemma-4-26B-A4B-it-qat-q4_0-gguf + gguf_file: gemma-4-26B-A4B-it-Q4_0.gguf + gguf_mmproj: mmproj-gemma-4-26B-A4B-it-Q8_0.gguf ollama: gemma4:26b mlx: mlx-community/gemma-4-26B-A4B-it-qat-4bit lmstudio: google/gemma-4-26b-a4b @@ -420,8 +430,10 @@ gemma4: hf: google/gemma-4-31B-it hf_base: google/gemma-4-31B hf_qat: google/gemma-4-31B-it-qat-w4a16-ct - gguf: google/gemma-4-31B-it-qat-q4_0-gguf + gguf: ggml-org/gemma-4-31B-it-GGUF gguf_qat: google/gemma-4-31B-it-qat-q4_0-gguf + gguf_file: gemma-4-31B-it-Q4_0.gguf + gguf_mmproj: mmproj-gemma-4-31B-it-Q8_0.gguf ollama: gemma4:31b mlx: mlx-community/gemma-4-31B-it-qat-4bit lmstudio: google/gemma-4-31b diff --git a/docs/deployment/huggingface.md b/docs/deployment/huggingface.md index 45c6cc7..7d9fd4f 100644 --- a/docs/deployment/huggingface.md +++ b/docs/deployment/huggingface.md @@ -12,7 +12,7 @@ colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs Generating text, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Hugging Face Transformers using both text and image input to generate text content. The Transformers Python library provides a API for accessing pre-trained generative AI models, including Gemma. For more information, see the [Transformers](https://huggingface.co/docs/transformers/en/index) documentation. !!! Note - Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md). + Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md). ### Install Python packages @@ -143,6 +143,7 @@ You can include multiple images in your prompt by including additional `"type": Do not use `<|image|>`{.token-multi}, ``{.token-multi} or ``{.token-multi} tokens in text portion of a prompt template as this approach creates redundant tokens and processing errors. + ## Generate text from audio data With [Gemma 4](../models/gemma-4/index.md) and [Gemma 3n](../models/gemma-3n/index.md), you can use audio data as part of your prompt. This section shows how to use the Transformers library to load and configure a Gemma model to use audio data and text input to generate text output. @@ -151,7 +152,7 @@ With [Gemma 4](../models/gemma-4/index.md) and [Gemma 3n](../models/gemma-3n/ind When generating content with audio, use a prompt template to structure your request. A prompt template allows you to specify input from specific roles, such as `user`{.token-role} or `model`{.token-role}, and is a required format for managing multi-turn chat interactions with Gemma models. The following example code shows how to constuct a prompt template for Gemma with audio data input: -```python { .notebook-cell } +```python { .notebook-cell data-requires="audio" } from transformers import GenerationConfig config = GenerationConfig.from_pretrained(MODEL_ID) config.max_new_tokens = 512 @@ -183,6 +184,7 @@ You can include multiple audio files in your prompt by including additional `"ty !!! Note Do not use `<|audio|>`{.token-multi} or ``{.token-multi} tokens in text portion of a prompt template as this approach creates redundant tokens and processing errors. + ## Next steps diff --git a/docs/deployment/keras.md b/docs/deployment/keras.md index a5ff282..8278b98 100644 --- a/docs/deployment/keras.md +++ b/docs/deployment/keras.md @@ -11,7 +11,7 @@ colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs Generating content, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Keras, including generating text content with text and image input. [Keras](https://keras.io/) provides implementations for running Gemma and other models using JAX, PyTorch, and TensorFlow. If you're new to Keras, you might want to read [Getting started with Keras](https://keras.io/getting_started/) before you begin. -Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md). +Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md). !!! Note This notebook won't run on T4 if you try with Gemma 4. Use L4 or higher GPUs. diff --git a/docs/deployment/llamacpp.md b/docs/deployment/llamacpp.md index 781101f..1c93499 100644 --- a/docs/deployment/llamacpp.md +++ b/docs/deployment/llamacpp.md @@ -13,41 +13,29 @@ most capable local runtime for Gemma 4 — **image, audio and video input all wo ## Install -=== "macOS / Linux" +=== "curl" ```bash - brew install llama.cpp + curl -LsSf https://llama.app/install.sh | sh ``` -=== "Windows" +=== "powershell" - ```bash - winget install llama.cpp - ``` - -=== "conda" - - ```bash - conda install -c conda-forge llama.cpp - ``` - -=== "Nix" - - ```bash - nix profile install nixpkgs#llama-cpp + ```powershell + irm https://llama.app/install.ps1 | iex ``` ## Run ```bash { .model-swap } -llama-cli -hf ggml-org/gemma-4-E2B-it-GGUF --prompt "Write a poem about the Kraken." +llama cli -hf ggml-org/gemma-4-E2B-it-GGUF --prompt "Write a poem about the Kraken." ``` `-hf` downloads the weights on first use, including the multimodal projector. With a system prompt: ```bash { .model-swap } -llama-cli -hf ggml-org/gemma-4-E2B-it-GGUF -sys "You are Hong Gildong." -p "Who are you?" +llama cli -hf ggml-org/gemma-4-E2B-it-GGUF -sys "You are Hong Gildong." -p "Who are you?" ``` ## Model repositories @@ -64,7 +52,7 @@ For 4-bit, prefer Google's [QAT](../get-started/qat.md) weights — trained with than compressed afterwards: ```bash { .model-swap } -llama-cli -hf google/gemma-4-12B-it-qat-q4_0-gguf -p "Explain PLE in one paragraph" +llama cli -hf google/gemma-4-E2B-it-qat-q4_0-gguf -p "Explain gravity in one paragraph" ``` Available as `google/gemma-4-{E2B,E4B,12B,26B-A4B,31B}-it-qat-q4_0-gguf`. @@ -72,13 +60,13 @@ Available as `google/gemma-4-{E2B,E4B,12B,26B-A4B,31B}-it-qat-q4_0-gguf`. ## Multimodal ```bash { .model-swap } -llama-mtmd-cli -hf ggml-org/gemma-4-E2B-it-GGUF +llama cli -hf ggml-org/gemma-4-E2B-it-GGUF --image "image.png" -p "Describe this image." ``` With local files, pass the projector explicitly: -```bash -llama-server -m gemma-4-12B-it-Q4_K_M.gguf --mmproj mmproj-gemma-4-12B-it.gguf +```bash { .model-swap } +llama cli -m gemma-4-E2B-it-Q4_0.gguf --mm mmproj-gemma-4-E2B-it-Q8_0.gguf ``` !!! note @@ -88,7 +76,7 @@ llama-server -m gemma-4-12B-it-Q4_K_M.gguf --mmproj mmproj-gemma-4-12B-it.gguf ## Server ```bash { .model-swap } -llama-server -hf ggml-org/gemma-4-E2B-it-GGUF +llama server -hf ggml-org/gemma-4-E2B-it-GGUF ``` Browser UI at `http://localhost:8080`, OpenAI-compatible API at `http://localhost:8080/v1`. diff --git a/docs/deployment/unsloth.md b/docs/deployment/unsloth.md index f527525..65280f7 100644 --- a/docs/deployment/unsloth.md +++ b/docs/deployment/unsloth.md @@ -86,17 +86,19 @@ and both GGUF and MLX files are supported. ## llama.cpp -Build `llama.cpp` first — set `-DGGML_CUDA=OFF` for CPU-only machines and for Apple silicon, -where Metal is on by default: +A few options to get `llama.cpp` installed on your machine: -```bash -git clone https://github.com/ggml-org/llama.cpp -cmake llama.cpp -B llama.cpp/build \ - -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON -cmake --build llama.cpp/build --config Release -j --clean-first \ - --target llama-cli llama-mtmd-cli llama-server llama-gguf-split -cp llama.cpp/build/bin/llama-* llama.cpp -``` +=== "curl" + + ```bash + curl -LsSf https://llama.app/install.sh | sh + ``` + +=== "powershell" + + ```powershell + irm https://llama.app/install.ps1 | iex + ``` Then pull and run a model straight from Hugging Face. There is no need to set a context length — llama.cpp uses exactly what is required. @@ -104,8 +106,7 @@ llama.cpp uses exactly what is required. === "E2B" ```bash - export LLAMA_CACHE="unsloth/gemma-4-E2B-it-GGUF" - ./llama.cpp/llama-cli \ + llama cli \ -hf unsloth/gemma-4-E2B-it-GGUF:Q8_0 \ --temp 1.0 --top-p 0.95 --top-k 64 ``` @@ -113,8 +114,7 @@ llama.cpp uses exactly what is required. === "E4B" ```bash - export LLAMA_CACHE="unsloth/gemma-4-E4B-it-GGUF" - ./llama.cpp/llama-cli \ + llama cli \ -hf unsloth/gemma-4-E4B-it-GGUF:Q8_0 \ --temp 1.0 --top-p 0.95 --top-k 64 ``` @@ -122,8 +122,7 @@ llama.cpp uses exactly what is required. === "12B" ```bash - export LLAMA_CACHE="unsloth/gemma-4-12B-it-GGUF" - ./llama.cpp/llama-cli \ + llama cli \ -hf unsloth/gemma-4-12b-it-GGUF:UD-Q4_K_XL \ --temp 1.0 --top-p 0.95 --top-k 64 ``` @@ -131,8 +130,7 @@ llama.cpp uses exactly what is required. === "26B A4B" ```bash - export LLAMA_CACHE="unsloth/gemma-4-26B-A4B-it-GGUF" - ./llama.cpp/llama-cli \ + llama cli \ -hf unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q4_K_XL \ --temp 1.0 --top-p 0.95 --top-k 64 ``` @@ -140,8 +138,7 @@ llama.cpp uses exactly what is required. === "31B" ```bash - export LLAMA_CACHE="unsloth/gemma-4-31B-it-GGUF" - ./llama.cpp/llama-cli \ + llama cli \ -hf unsloth/gemma-4-31B-it-GGUF:UD-Q4_K_XL \ --temp 1.0 --top-p 0.95 --top-k 64 ``` @@ -158,7 +155,7 @@ hf download unsloth/gemma-4-26B-A4B-it-GGUF \ ``` ```bash -./llama.cpp/llama-cli \ +llama cli \ --model unsloth/gemma-4-26B-A4B-it-GGUF/gemma-4-26B-A4B-it-UD-Q4_K_XL.gguf \ --mmproj unsloth/gemma-4-26B-A4B-it-GGUF/mmproj-BF16.gguf \ --temp 1.0 --top-p 0.95 --top-k 64 @@ -167,7 +164,7 @@ hf download unsloth/gemma-4-26B-A4B-it-GGUF \ ### Server ```bash -./llama.cpp/llama-server \ +llama server \ --model unsloth/gemma-4-26B-A4B-it-GGUF/gemma-4-26B-A4B-it-UD-Q4_K_XL.gguf \ --mmproj unsloth/gemma-4-26B-A4B-it-GGUF/mmproj-BF16.gguf \ --temp 1.0 --top-p 0.95 --top-k 64 \ diff --git a/docs/get-started/capabilities/function-calling.md b/docs/get-started/capabilities/function-calling.md index 6aa8366..4bcedf9 100644 --- a/docs/get-started/capabilities/function-calling.md +++ b/docs/get-started/capabilities/function-calling.md @@ -264,7 +264,7 @@ if calls: !!! Note For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|"|>sunny<|"|>}`). -```python { .notebook-cell } +```python "tool_responses": [ { "name": function_name, @@ -275,7 +275,7 @@ if calls: In case of multiple independent requests: -```python { .notebook-cell } +```python "tool_responses": [ { "name": function_name_1, diff --git a/docs/get-started/capabilities/image.md b/docs/get-started/capabilities/image.md index 5e72819..8ffc8ab 100644 --- a/docs/get-started/capabilities/image.md +++ b/docs/get-started/capabilities/image.md @@ -320,16 +320,16 @@ output = vqa_pipe(messages, return_full_text=False, generate_kwargs=gen_kwargs) print(output[0]['generated_text']) draw_results(output[0]['generated_text']) -``` +``` -```{ .no-copy .output } +```` { .no-copy .output } ```json [ {"box_2d": [243, 252, 956, 415], "label": "person"}, {"box_2d": [356, 606, 654, 802], "label": "cat"} ] ``` -``` +```` ![png](../../assets/capabilities/output_b041486b_1.png) @@ -409,14 +409,14 @@ print(output[0]['generated_text']) draw_results(output[0]['generated_text']) ``` -```{ .no-copy .output } +```` { .no-copy .output } ```json [ {"box_2d": [454, 871, 533, 923], "label": "person"}, {"box_2d": [551, 316, 665, 628], "label": "car"} ] ``` -``` +```` ![png](../../assets/capabilities/output_bc2920e6_1.png) @@ -506,7 +506,7 @@ plt.tight_layout() plt.show() ``` -```{ .no-copy .output } +```` { .no-copy .output } Budget Size: 70 # of Image Tokens: 64 [transformers] You seem to be using the pipelines sequentially on GPU. In order to maximize efficiency please use a dataset @@ -551,7 +551,7 @@ Budget Size: 560 {"box_2d": [404, 867, 520, 925], "label": "person"} ] ``` -``` +```` ![png](../../assets/capabilities/output_76f17518_3.png) diff --git a/docs/get-started/index.md b/docs/get-started/index.md index 5937f90..29d8865 100644 --- a/docs/get-started/index.md +++ b/docs/get-started/index.md @@ -40,7 +40,7 @@ and move up without rewriting anything. pipe = pipeline( "text-generation", - model="google/gemma-4-12B-it", + model="google/gemma-4-E2B-it", device_map="auto" ) output = pipe("Explain quantum computing simply:", max_new_tokens=150) @@ -51,14 +51,14 @@ and move up without rewriting anything. Install [`llama.cpp`](https://llama.app/), then run: ```bash { .model-swap } - llama-cli -hf google/gemma-4-12B-it-qat-q4_0-gguf --prompt "Write a poem about the Kraken." + llama cli -hf google/gemma-4-E2B-it-qat-q4_0-gguf --prompt "Write a poem about the Kraken." ``` === "Ollama" Install [`ollama`](https://ollama.com/download), then run: ```bash { .model-swap } - ollama run gemma4:12b "Explain quantum computing simply:" + ollama run gemma4:e2b "Explain quantum computing simply:" ``` === "Apple MLX" @@ -66,7 +66,7 @@ and move up without rewriting anything. Install [`MLX LM`](https://github.com/ml-explore/mlx-lm), then run: ```bash { .model-swap } - mlx_lm.generate --model mlx-community/gemma-4-12B-it-qat-4bit \ + mlx_lm.generate --model mlx-community/gemma-4-E2B-it-qat-4bit \ --prompt "Explain quantum computing simply:" ``` @@ -75,14 +75,14 @@ and move up without rewriting anything. Install [`vLLM`](https://docs.vllm.ai/en/latest/getting_started/installation/), then run: ```bash { .model-swap } - vllm serve google/gemma-4-26B-A4B-it + vllm serve google/gemma-4-E2B-it ``` === "LMStudio" Install [`LMStudio`](https://lmstudio.ai/), then run: ```bash { .model-swap } - lms chat google/gemma-4-12b + lms chat google/gemma-4-e2b ``` !!! example "Using a coding agent?" diff --git a/docs/get-started/qat.md b/docs/get-started/qat.md index 66de8a3..e4489e2 100644 --- a/docs/get-started/qat.md +++ b/docs/get-started/qat.md @@ -29,7 +29,7 @@ Names follow `google/gemma-4-{SIZE}-it{SUFFIX}`, for example: ```bash { .model-swap } # Local, via llama.cpp -llama-cli -hf google/gemma-4-12B-it-qat-q4_0-gguf +llama cli -hf google/gemma-4-12B-it-qat-q4_0-gguf ``` ```bash { .model-fixed } diff --git a/docs/javascripts/model-data.js b/docs/javascripts/model-data.js index 25f3798..8d69455 100644 --- a/docs/javascripts/model-data.js +++ b/docs/javascripts/model-data.js @@ -31,15 +31,18 @@ window.GEMMA_MODELS = { "hf": "google/gemma-4-E2B-it", "hf_base": "google/gemma-4-E2B", "hf_qat": "google/gemma-4-E2B-it-qat-w4a16-ct", - "gguf": "google/gemma-4-E2B-it-qat-q4_0-gguf", + "gguf": "ggml-org/gemma-4-E2B-it-GGUF", "gguf_qat": "google/gemma-4-E2B-it-qat-q4_0-gguf", + "gguf_file": "gemma-4-E2B-it-Q4_0.gguf", + "gguf_mmproj": "mmproj-gemma-4-E2B-it-Q8_0.gguf", "ollama": "gemma4:e2b", "mlx": "mlx-community/gemma-4-E2B-it-qat-4bit", "lmstudio": "google/gemma-4-e2b", "keras": "gemma4_instruct_2b", "keras_base": "gemma4_2b", "keras_assistant": "gemma4_instruct_2b_assistant", - "litert": "litert-community/gemma-4-E2B-it-litert-lm" + "litert": "litert-community/gemma-4-E2B-it-litert-lm", + "litert_file": "gemma-4-E2B-it.litertlm" }, "inputs": [ "text", @@ -57,15 +60,18 @@ window.GEMMA_MODELS = { "hf": "google/gemma-4-E4B-it", "hf_base": "google/gemma-4-E4B", "hf_qat": "google/gemma-4-E4B-it-qat-w4a16-ct", - "gguf": "google/gemma-4-E4B-it-qat-q4_0-gguf", + "gguf": "ggml-org/gemma-4-E4B-it-GGUF", "gguf_qat": "google/gemma-4-E4B-it-qat-q4_0-gguf", + "gguf_file": "gemma-4-E4B-it-Q4_0.gguf", + "gguf_mmproj": "mmproj-gemma-4-E4B-it-Q8_0.gguf", "ollama": "gemma4:e4b", "mlx": "mlx-community/gemma-4-E4B-it-qat-4bit", "lmstudio": "google/gemma-4-e4b", "keras": "gemma4_instruct_4b", "keras_base": "gemma4_4b", "keras_assistant": "gemma4_instruct_4b_assistant", - "litert": "litert-community/gemma-4-E4B-it-litert-lm" + "litert": "litert-community/gemma-4-E4B-it-litert-lm", + "litert_file": "gemma-4-E4B-it.litertlm" }, "inputs": [ "text", @@ -83,8 +89,10 @@ window.GEMMA_MODELS = { "hf": "google/gemma-4-12B-it", "hf_base": "google/gemma-4-12B", "hf_qat": "google/gemma-4-12B-it-qat-w4a16-ct", - "gguf": "google/gemma-4-12B-it-qat-q4_0-gguf", + "gguf": "ggml-org/gemma-4-12B-it-GGUF", "gguf_qat": "google/gemma-4-12B-it-qat-q4_0-gguf", + "gguf_file": "gemma-4-12B-it-Q4_0.gguf", + "gguf_mmproj": "mmproj-gemma-4-12B-it-Q8_0.gguf", "ollama": "gemma4:12b", "mlx": "mlx-community/gemma-4-12B-it-qat-4bit", "lmstudio": "google/gemma-4-12b" @@ -104,8 +112,10 @@ window.GEMMA_MODELS = { "ids": { "hf": "google/gemma-4-26B-A4B-it", "hf_base": "google/gemma-4-26B-A4B", - "gguf": "google/gemma-4-26B-A4B-it-qat-q4_0-gguf", + "gguf": "ggml-org/gemma-4-26B-A4B-it-GGUF", "gguf_qat": "google/gemma-4-26B-A4B-it-qat-q4_0-gguf", + "gguf_file": "gemma-4-26B-A4B-it-Q4_0.gguf", + "gguf_mmproj": "mmproj-gemma-4-26B-A4B-it-Q8_0.gguf", "ollama": "gemma4:26b", "mlx": "mlx-community/gemma-4-26B-A4B-it-qat-4bit", "lmstudio": "google/gemma-4-26b-a4b", @@ -129,8 +139,10 @@ window.GEMMA_MODELS = { "hf": "google/gemma-4-31B-it", "hf_base": "google/gemma-4-31B", "hf_qat": "google/gemma-4-31B-it-qat-w4a16-ct", - "gguf": "google/gemma-4-31B-it-qat-q4_0-gguf", + "gguf": "ggml-org/gemma-4-31B-it-GGUF", "gguf_qat": "google/gemma-4-31B-it-qat-q4_0-gguf", + "gguf_file": "gemma-4-31B-it-Q4_0.gguf", + "gguf_mmproj": "mmproj-gemma-4-31B-it-Q8_0.gguf", "ollama": "gemma4:31b", "mlx": "mlx-community/gemma-4-31B-it-qat-4bit", "lmstudio": "google/gemma-4-31b", diff --git a/docs/javascripts/model-switcher.js b/docs/javascripts/model-switcher.js index dd4209d..f4def15 100644 --- a/docs/javascripts/model-switcher.js +++ b/docs/javascripts/model-switcher.js @@ -29,6 +29,11 @@ } } index.sort((a, b) => b.text.length - a.text.length); + const byText = new Map(index.map((entry) => [entry.text, entry])); + const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + const pattern = index.length + ? new RegExp(index.map((entry) => escapeRegExp(entry.text)).join("|"), "g") + : null; const blocks = () => document.querySelectorAll(".model-swap code, code.model-swap"); const displayName = (id) => models[id]?.fullName || models[id]?.name || id; @@ -59,9 +64,11 @@ const enginesInUse = () => { const found = new Set(); + if (!pattern) return found; for (const block of blocks()) { - for (const entry of index) { - if (block.textContent.includes(entry.text)) found.add(entry.engine); + for (const [match] of block.textContent.matchAll(pattern)) { + const entry = byText.get(match); + if (entry) found.add(entry.engine); } } return found; @@ -78,26 +85,74 @@ }; const detect = () => { + if (!pattern) return null; for (const block of blocks()) { - const hit = index.find((entry) => block.textContent.includes(entry.text)); - if (hit) return hit.model; + for (const [match] of block.textContent.matchAll(pattern)) { + const entry = byText.get(match); + if (entry) return entry.model; + } } return null; }; const rewriteNode = (node, target) => { + if (!pattern) return; const original = node.__gemmaOriginal ?? node.nodeValue; - let next = original; - for (const entry of index) { - if (!next.includes(entry.text)) continue; - const replacement = models[target]?.ids?.[entry.engine]; - if (replacement) next = next.split(entry.text).join(replacement); - } + const next = original.replace(pattern, (match) => { + const entry = byText.get(match); + return (entry && models[target]?.ids?.[entry.engine]) || match; + }); if (next === node.nodeValue) return; node.__gemmaOriginal = original; node.nodeValue = next; }; + const applyRequires = (target) => { + const inputs = models[target]?.inputs || []; + const article = document.querySelector(".md-content__inner"); + if (article) { + const walker = document.createTreeWalker(article, NodeFilter.SHOW_COMMENT); + const startRe = /^\s*notebook:requires-start\s+([a-z0-9_-]+)\s*$/i; + const endRe = /^\s*notebook:requires-end\s*$/i; + const starts = []; + let comment; + while ((comment = walker.nextNode())) { + const match = comment.nodeValue.match(startRe); + if (match) starts.push({ node: comment, modality: match[1].toLowerCase() }); + } + for (const { node, modality } of starts) { + const supported = inputs.includes(modality); + let cur = node.nextSibling; + while (cur) { + if (cur.nodeType === Node.COMMENT_NODE && endRe.test(cur.nodeValue)) break; + if (cur.nodeType === Node.ELEMENT_NODE) { + cur.hidden = !supported; + cur.style.display = supported ? "" : "none"; + if (cur.id && /^H[1-6]$/.test(cur.tagName)) { + const targetHash = `#${cur.id}`; + for (const link of document.querySelectorAll(".md-nav--secondary a.md-nav__link")) { + if (link.hash !== targetHash) continue; + const item = link.closest(".md-nav__item"); + if (item) { + item.hidden = !supported; + item.style.display = supported ? "" : "none"; + } + } + } + } + cur = cur.nextSibling; + } + } + } + for (const el of document.querySelectorAll("[data-requires]:not(.page-context)")) { + const modality = el.dataset.requires?.trim().toLowerCase(); + if (!modality) continue; + const supported = inputs.includes(modality); + el.hidden = !supported; + el.style.display = supported ? "" : "none"; + } + }; + const apply = (target) => { if (!models[target]) return; for (const block of blocks()) { @@ -105,6 +160,31 @@ let node; while ((node = walker.nextNode())) rewriteNode(node, target); } + applyRequires(target); + }; + + const positionMenu = (picker) => { + const menu = picker.querySelector(".page-context__picker-menu"); + const strip = picker.closest(".page-context"); + if (!menu || menu.hidden || !strip) return; + menu.style.left = ""; + menu.style.right = ""; + const stripRect = strip.getBoundingClientRect(); + const pickerRect = picker.getBoundingClientRect(); + const menuRect = menu.getBoundingClientRect(); + if (menuRect.right > stripRect.right) { + if (pickerRect.right - menuRect.width >= stripRect.left) { + menu.style.left = "auto"; + menu.style.right = "0"; + } else { + const offset = Math.max( + stripRect.left - pickerRect.left, + stripRect.right - pickerRect.left - menuRect.width + ); + menu.style.left = `${offset}px`; + menu.style.right = "auto"; + } + } }; const closePicker = (picker, returnFocus = false) => { @@ -209,6 +289,7 @@ document.querySelectorAll(".page-context__picker").forEach((other) => closePicker(other)); menu.hidden = !opening; trigger.setAttribute("aria-expanded", String(opening)); + if (opening) positionMenu(picker); }); trigger.addEventListener("keydown", (event) => { if (event.key === "Escape") { @@ -220,6 +301,7 @@ event.preventDefault(); menu.hidden = false; trigger.setAttribute("aria-expanded", "true"); + positionMenu(picker); const options = [...menu.querySelectorAll("[role=option]")]; (event.key === "ArrowDown" ? options[0] : options.at(-1))?.focus(); }); @@ -255,7 +337,7 @@ : available[0]; buildControl(strip, available, initial, requested && !available.includes(requested) ? requested : null); - if (requested && available.includes(requested)) apply(requested); + apply(initial); }; let prevTabState = null; @@ -371,7 +453,10 @@ setTimeout(initSearchModalDefaults, 150); } }); - window.addEventListener("resize", syncTabIndicator); + window.addEventListener("resize", () => { + syncTabIndicator(); + document.querySelectorAll(".page-context__picker").forEach(positionMenu); + }); const DEFAULT_SEARCH_TOPICS = [ { diff --git a/docs/llms.txt b/docs/llms.txt index 6ce23a5..9869569 100644 --- a/docs/llms.txt +++ b/docs/llms.txt @@ -32,19 +32,19 @@ Follow the Markdown links below to read canonical page content without cloning t - [Gemma 3n model card](https://gemma.ai/models/gemma-3n/model-card.md): Model card for Gemma 3n: on-device inputs and outputs, training data, evaluation results, and intended use. - [DiffusionGemma model overview](https://gemma.ai/models/diffusiongemma.md): DiffusionGemma is an experimental open model that explores text diffusion, an exceptionally fast approach to text generation. - [DiffusionGemma model card](https://gemma.ai/models/diffusiongemma/model-card.md): DiffusionGemma is a generative model built by Google DeepMind. -- [Diffusion in Text Generation Explained](https://gemma.ai/models/diffusiongemma/explained.md): To understand DiffusionGemma, it helps to examine the core limitations of standard language models and how text-based diffusion differs. -- [Generate output](https://gemma.ai/models/diffusiongemma/inference.md): Generate text with DiffusionGemma using Hugging Face Transformers, including the GPU memory the model requires. +- [DiffusionGemma — Diffusion in Text Generation Explained](https://gemma.ai/models/diffusiongemma/explained.md): To understand DiffusionGemma, it helps to examine the core limitations of standard language models and how text-based diffusion differs. +- [DiffusionGemma — Generate output](https://gemma.ai/models/diffusiongemma/inference.md): Generate text with DiffusionGemma using Hugging Face Transformers, including the GPU memory the model requires. - [FunctionGemma model overview](https://gemma.ai/models/functiongemma.md): FunctionGemma is a specialized version of our Gemma 3 270M model tuned for function calling. - [FunctionGemma model card](https://gemma.ai/models/functiongemma/model-card.md): Model card for FunctionGemma: function-calling inputs and outputs, training data, evaluation results, and intended use. - [FunctionGemma formatting and best practices](https://gemma.ai/models/functiongemma/formatting.md): FunctionGemma is a specialized version of the Gemma 3 270M model, trained specifically for function calling (i.e., tool use). -- [Function calling with Hugging Face Transformers](https://gemma.ai/models/functiongemma/inference.md): Call functions with FunctionGemma in Hugging Face Transformers, passing tools as manual JSON schemas or as raw Python functions. +- [FunctionGemma — Function calling with Hugging Face Transformers](https://gemma.ai/models/functiongemma/inference.md): Call functions with FunctionGemma in Hugging Face Transformers, passing tools as manual JSON schemas or as raw Python functions. - [Full function calling sequence with FunctionGemma](https://gemma.ai/models/functiongemma/full-sequence.md): The complete FunctionGemma tool-calling cycle: the model's call, the developer's execution, and the final response built from the tool's output. - [Fine-tuning with FunctionGemma](https://gemma.ai/models/functiongemma/fine-tuning.md): This guide demonstrates how to fine-tune FunctionGemma for tool calling. - [EmbeddingGemma model overview](https://gemma.ai/models/embeddinggemma.md): EmbeddingGemma 2 is a lightweight, open-source 740M parameter model designed for unified multimodal embeddings. - [EmbeddingGemma model card](https://gemma.ai/models/embeddinggemma/model-card-v1.md): Model card for EmbeddingGemma: embedding inputs and outputs, training data, evaluation results, and intended use. - [EmbeddingGemma 2 model card](https://gemma.ai/models/embeddinggemma/model-card-v2.md): Model card for EmbeddingGemma 2: architecture, multimodal capabilities, benchmarks, best practices, training data, and intended use. -- [Generate Embeddings with Sentence Transformers](https://gemma.ai/models/embeddinggemma/inference.md): Generate text embeddings, compute semantic similarity, apply task prompts, and build RAG and zero-shot classifiers with EmbeddingGemma 2 and Sentence Transformers. -- [Multimodal Embeddings with Sentence Transformers](https://gemma.ai/models/embeddinggemma/multimodal.md): Generate unified image, audio, video, and interleaved multimodal embeddings with EmbeddingGemma 2 and Sentence Transformers. +- [EmbeddingGemma — Generate Embeddings with Sentence Transformers](https://gemma.ai/models/embeddinggemma/inference.md): Generate text embeddings, compute semantic similarity, apply task prompts, and build RAG and zero-shot classifiers with EmbeddingGemma 2 and Sentence Transformers. +- [EmbeddingGemma — Multimodal Embeddings with Sentence Transformers](https://gemma.ai/models/embeddinggemma/multimodal.md): Generate unified image, audio, video, and interleaved multimodal embeddings with EmbeddingGemma 2 and Sentence Transformers. - [Fine-tune EmbeddingGemma with Sentence Transformers](https://gemma.ai/models/embeddinggemma/fine-tuning.md): Adapt EmbeddingGemma 2 to specialized domain terminology using contrastive triplet fine-tuning with Sentence Transformers. - [Fine-Tune Multimodal EmbeddingGemma 2 with Sentence Transformers](https://gemma.ai/models/embeddinggemma/fine-tuning-multimodal.md): Adapt EmbeddingGemma 2 across text and visual inputs using contrastive multimodal triplet fine-tuning with Sentence Transformers. - [PaliGemma](https://gemma.ai/models/paligemma.md): PaliGemma 2 and PaliGemma are lightweight open vision-language models (VLM) inspired by PaLI-3, and based on open components like the SigLIP vision model and the Gemma language model. @@ -59,14 +59,14 @@ Follow the Markdown links below to read canonical page content without cloning t - [RecurrentGemma](https://gemma.ai/models/recurrentgemma.md): RecurrentGemma is an open model based on Griffin, a hybrid model architecture that mixes gated linear recurrences with local sliding window attention. - [RecurrentGemma model card](https://gemma.ai/models/recurrentgemma/model-card.md): RecurrentGemma is a family of open language models built on a novel recurrent architecture developed at Google. - [Inference with RecurrentGemma using JAX and Flax](https://gemma.ai/models/recurrentgemma/inference.md): Run sampling and inference with RecurrentGemma 2B Instruct using Google DeepMind's recurrentgemma library and JAX. -- [Fine-tuning using JAX and Flax](https://gemma.ai/models/recurrentgemma/fine-tuning.md): Fine-tune RecurrentGemma 2B Instruct for English-French translation using JAX, Flax, and the MTNT noisy-text dataset. +- [RecurrentGemma — Fine-tuning using JAX and Flax](https://gemma.ai/models/recurrentgemma/fine-tuning.md): Fine-tune RecurrentGemma 2B Instruct for English-French translation using JAX, Flax, and the MTNT noisy-text dataset. - [DataGemma](https://gemma.ai/models/datagemma.md): DataGemma is a research tool that lets users ask questions in plain language and receive answers based on publicly available statistical data in the Data Commons repository. - [Gemma Scope](https://gemma.ai/models/gemma-scope.md): Gemma Scope 2 is a comprehensive, open suite of interpretability tools designed for the Gemma 3 model collection. - [Gemma for abstractive proposition segmentation (APS)](https://gemma.ai/models/gemma-aps.md): Abstractive proposition segmentation (APS) is an analysis technique that breaks down text information into component parts. - [Releases](https://gemma.ai/models/releases.md): Dated release history for every Gemma model, from Gemma 1 through Gemma 4 and the specialized variants. ## Run -- [Gemma 4 — Overview](https://gemma.ai/deployment.md): Choose an execution framework and a Gemma variant for your hardware, then run your first generation request. +- [Overview](https://gemma.ai/deployment.md): Choose an execution framework and a Gemma variant for your hardware, then run your first generation request. - [Ollama](https://gemma.ai/deployment/ollama.md): Run Gemma 4 locally with Ollama — model tags, image input, and the OpenAI-compatible server. - [llama.cpp](https://gemma.ai/deployment/llamacpp.md): Run Gemma 4 with llama.cpp — GGUF repos for every size, image/audio/video input, and the OpenAI-compatible server. - [LM Studio](https://gemma.ai/deployment/lmstudio.md): Run Gemma 4 with LM Studio — desktop app, lms CLI, and the OpenAI-compatible local server. diff --git a/docs/models/datagemma/index.md b/docs/models/datagemma/index.md index 2a914cf..7b9c979 100644 --- a/docs/models/datagemma/index.md +++ b/docs/models/datagemma/index.md @@ -9,7 +9,7 @@ source_url: "https://ai.google.dev/gemma/docs/datagemma.md.txt" DataGemma is a research tool that lets users ask questions in plain language and receive answers based on publicly available statistical data in the [Data Commons](https://datacommons.org/) repository. The tool uses -specially built versions of [Gemma](../gemma-4/index.md), +specially built versions of [Gemma 2](../gemma-2/index.md), the [Gemini API](https://ai.google.dev/gemini-api) with Gemini 1.5 Pro, and a set of libraries specifically designed to work with Data Commons. diff --git a/docs/models/diffusiongemma/model-card.md b/docs/models/diffusiongemma/model-card.md index e7bb0bf..fed31be 100644 --- a/docs/models/diffusiongemma/model-card.md +++ b/docs/models/diffusiongemma/model-card.md @@ -12,7 +12,7 @@ source_url: "https://ai.google.dev/gemma/docs/diffusiongemma/model_card.md.txt" [Documentation](index.md) -**License** : [Apache 2.0](https://ai.google.dev/gemma/apache_2) \| **Authors** : [Google DeepMind](https://deepmind.google/models/gemma/) +**License** : [Apache 2.0](https://gemma.ai/resources/apache-2) \| **Authors** : [Google DeepMind](https://deepmind.google/models/gemma/) DiffusionGemma is a generative model built by Google DeepMind. Based on the 26B A4B Mixture-of-Experts (MoE) Gemma 4 architecture, DiffusionGemma generates diff --git a/docs/models/embeddinggemma/fine-tuning-multimodal.md b/docs/models/embeddinggemma/fine-tuning-multimodal.md index 026e64f..05ab8ce 100644 --- a/docs/models/embeddinggemma/fine-tuning-multimodal.md +++ b/docs/models/embeddinggemma/fine-tuning-multimodal.md @@ -1,7 +1,7 @@ --- title: Fine-Tune Multimodal EmbeddingGemma 2 with Sentence Transformers description: Adapt EmbeddingGemma 2 across text and visual inputs using contrastive multimodal triplet fine-tuning with Sentence Transformers. -models: [embeddinggemma] +models: [embeddinggemma-2] frameworks: [sentence-transformers, transformers] colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/embeddinggemma-fine-tuning-multimodal.ipynb source_url: "https://ai.google.dev/gemma/docs/embeddinggemma/fine-tuning-multimodal-embeddinggemma-with-sentence-transformers.md.txt" diff --git a/docs/models/embeddinggemma/fine-tuning.md b/docs/models/embeddinggemma/fine-tuning.md index 93428b5..5077709 100644 --- a/docs/models/embeddinggemma/fine-tuning.md +++ b/docs/models/embeddinggemma/fine-tuning.md @@ -1,7 +1,7 @@ --- title: Fine-tune EmbeddingGemma with Sentence Transformers description: Adapt EmbeddingGemma 2 to specialized domain terminology using contrastive triplet fine-tuning with Sentence Transformers. -models: [embeddinggemma] +models: [embeddinggemma-2] frameworks: [sentence-transformers, transformers] colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/embeddinggemma-fine-tuning.ipynb source_url: "https://ai.google.dev/gemma/docs/embeddinggemma/fine-tuning-embeddinggemma-with-sentence-transformers.md.txt" diff --git a/docs/models/embeddinggemma/index.md b/docs/models/embeddinggemma/index.md index a47af3d..5fcb391 100644 --- a/docs/models/embeddinggemma/index.md +++ b/docs/models/embeddinggemma/index.md @@ -1,7 +1,7 @@ --- title: EmbeddingGemma model overview description: EmbeddingGemma 2 is a lightweight, open-source 740M parameter model designed for unified multimodal embeddings. -models: [embeddinggemma] +models: [embeddinggemma-2, embeddinggemma] source_url: "https://ai.google.dev/gemma/docs/embeddinggemma.md.txt" --- # EmbeddingGemma model overview {: #hidden-title style="display: none;" } diff --git a/docs/models/embeddinggemma/inference.md b/docs/models/embeddinggemma/inference.md index 95a3fbc..b744e15 100644 --- a/docs/models/embeddinggemma/inference.md +++ b/docs/models/embeddinggemma/inference.md @@ -1,7 +1,7 @@ --- title: Generate Embeddings with Sentence Transformers description: Generate text embeddings, compute semantic similarity, apply task prompts, and build RAG and zero-shot classifiers with EmbeddingGemma 2 and Sentence Transformers. -models: [embeddinggemma] +models: [embeddinggemma-2] frameworks: [sentence-transformers, transformers] colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/embeddinggemma-inference.ipynb source_url: "https://ai.google.dev/gemma/docs/embeddinggemma/inference-embeddinggemma-with-sentence-transformers.md.txt" diff --git a/docs/models/embeddinggemma/model-card-v2.md b/docs/models/embeddinggemma/model-card-v2.md index fdaf7a6..c159207 100644 --- a/docs/models/embeddinggemma/model-card-v2.md +++ b/docs/models/embeddinggemma/model-card-v2.md @@ -1,7 +1,7 @@ --- title: EmbeddingGemma 2 model card description: "Model card for EmbeddingGemma 2: architecture, multimodal capabilities, benchmarks, best practices, training data, and intended use." -models: [embeddinggemma] +models: [embeddinggemma-2] source_url: "https://ai.google.dev/gemma/docs/embeddinggemma/model_card_2.md.txt" --- # EmbeddingGemma 2 model card diff --git a/docs/models/embeddinggemma/multimodal.md b/docs/models/embeddinggemma/multimodal.md index d8844d2..3418986 100644 --- a/docs/models/embeddinggemma/multimodal.md +++ b/docs/models/embeddinggemma/multimodal.md @@ -1,7 +1,7 @@ --- title: Multimodal Embeddings with Sentence Transformers description: Generate unified image, audio, video, and interleaved multimodal embeddings with EmbeddingGemma 2 and Sentence Transformers. -models: [embeddinggemma] +models: [embeddinggemma-2] frameworks: [sentence-transformers, transformers] colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/embeddinggemma-multimodal.ipynb source_url: "https://ai.google.dev/gemma/docs/embeddinggemma/multimodal-embeddinggemma-with-sentence-transformers.md.txt" diff --git a/docs/models/functiongemma/fine-tuning.md b/docs/models/functiongemma/fine-tuning.md index ccb1d20..34f7aa0 100644 --- a/docs/models/functiongemma/fine-tuning.md +++ b/docs/models/functiongemma/fine-tuning.md @@ -608,7 +608,7 @@ Now that you have a fine-tuned model, consider the following steps to move towar
Fine-tune Gemma

QLoRA, full fine-tunes and distributed training.

- +
Mobile Actions notebook ↗

Fine-tune FunctionGemma 270M for on-device actions.

diff --git a/docs/models/functiongemma/model-card.md b/docs/models/functiongemma/model-card.md index e6d2281..63043b0 100644 --- a/docs/models/functiongemma/model-card.md +++ b/docs/models/functiongemma/model-card.md @@ -128,7 +128,7 @@ capable of generalizing across multiple tasks. This is specially suitable for foundation models, including large language models like these ones. Together, JAX and ML Pathways are used as described in the [paper about the -Gemini family of models](https://goo.gle/gemma2report); *"the 'single +Gemini family of models](https://arxiv.org/abs/2312.11805); *"the 'single controller' programming model of Jax and Pathways allows a single Python process to orchestrate the entire training run, dramatically simplifying the development workflow."* diff --git a/docs/models/gemma-2/index.md b/docs/models/gemma-2/index.md index bcd7da6..3c984a6 100644 --- a/docs/models/gemma-2/index.md +++ b/docs/models/gemma-2/index.md @@ -111,7 +111,7 @@ capable of generalizing across multiple tasks. This is specially suitable for foundation models, including large language models like these ones. Together, JAX and ML Pathways are used as described in the -[paper about the Gemini family of models](https://goo.gle/gemma2report){ data-model="gemma-2" }; "the 'single +[paper about the Gemini family of models](https://arxiv.org/abs/2312.11805); "the 'single controller' programming model of Jax and Pathways allows a single Python process to orchestrate the entire training run, dramatically simplifying the development workflow." diff --git a/docs/models/gemma-3n/model-card.md b/docs/models/gemma-3n/model-card.md index 912d464..2c45758 100644 --- a/docs/models/gemma-3n/model-card.md +++ b/docs/models/gemma-3n/model-card.md @@ -124,7 +124,7 @@ capable of generalizing across multiple tasks. This is specially suitable for foundation models, including large language models like these ones. Together, JAX and ML Pathways are used as described in the -[paper about the Gemini family of models](https://goo.gle/gemma2report){ data-model="gemma-2" }: +[paper about the Gemini family of models](https://arxiv.org/abs/2312.11805): *"the 'single controller' programming model of Jax and Pathways allows a single Python process to orchestrate the entire training run, dramatically simplifying the development workflow."* diff --git a/docs/models/gemma-4/index.md b/docs/models/gemma-4/index.md index f24d342..b28757b 100644 --- a/docs/models/gemma-4/index.md +++ b/docs/models/gemma-4/index.md @@ -17,7 +17,7 @@ Gemma is a family of generative artificial intelligence models and you can use them in a wide variety of generation tasks, including question answering, summarization, and reasoning. Gemma models are provided with open weights and permit responsible -[commercial use][gemma-terms], +[commercial use](../../resources/apache-2.md), allowing you to tune and deploy them in your own projects and applications. Gemma 4 model family spans four distinct architectures tailored for specific diff --git a/docs/models/gemma-4/model-card.md b/docs/models/gemma-4/model-card.md index 5b36c73..42064f1 100644 --- a/docs/models/gemma-4/model-card.md +++ b/docs/models/gemma-4/model-card.md @@ -14,7 +14,7 @@ source_url: "https://ai.google.dev/gemma/docs/core/model_card_4.md.txt" [Documentation](index.md) \| [Technical Report](https://arxiv.org/abs/2607.02770) -**License** : [Apache 2.0](https://ai.google.dev/gemma/apache_2) \| **Authors** : [Google DeepMind](https://deepmind.google/models/gemma/) +**License** : [Apache 2.0](https://gemma.ai/resources/apache-2) \| **Authors** : [Google DeepMind](https://deepmind.google/models/gemma/) diff --git a/docs/models/gemma-scope/index.md b/docs/models/gemma-scope/index.md index 7c755a7..6b0b3db 100644 --- a/docs/models/gemma-scope/index.md +++ b/docs/models/gemma-scope/index.md @@ -38,7 +38,7 @@ Read about the new architecture, training data, and capabilities of Gemma Scope Access the weights, code, and documentation for the Gemma 3 interpretability suite. -### [Run in Colab](https://colab.sandbox.google.com/drive/1NhWjg7n0nhfW--CjtsOdw5A5J_-Bzn4r?usp=sharing) +### [Run in Colab](https://colab.research.google.com/drive/1NhWjg7n0nhfW--CjtsOdw5A5J_-Bzn4r?usp=sharing) Try the interactive tutorial to visualize features and modify model behavior. diff --git a/docs/models/paligemma/fine-tuning.md b/docs/models/paligemma/fine-tuning.md index e9ab5c3..3ebd446 100644 --- a/docs/models/paligemma/fine-tuning.md +++ b/docs/models/paligemma/fine-tuning.md @@ -1,7 +1,7 @@ --- title: Fine-tune PaliGemma with JAX and Flax description: This notebook shows how to fine-tune PaliGemma on a vision-language task with JAX. -models: [paligemma] +models: [paligemma-2, paligemma] frameworks: [jax] colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/paligemma-fine-tuning.ipynb source_url: "https://ai.google.dev/gemma/docs/paligemma/fine-tuning-paligemma.md.txt" diff --git a/docs/models/paligemma/index.md b/docs/models/paligemma/index.md index f89ced5..d558c79 100644 --- a/docs/models/paligemma/index.md +++ b/docs/models/paligemma/index.md @@ -1,7 +1,7 @@ --- title: PaliGemma description: PaliGemma 2 and PaliGemma are lightweight open vision-language models (VLM) inspired by PaLI-3, and based on open components like the SigLIP vision model and the Gemma language model. -models: [paligemma] +models: [paligemma-2, paligemma] source_url: "https://ai.google.dev/gemma/docs/paligemma.md.txt" --- # PaliGemma diff --git a/docs/models/paligemma/inference.md b/docs/models/paligemma/inference.md index cd81289..dd1d11f 100644 --- a/docs/models/paligemma/inference.md +++ b/docs/models/paligemma/inference.md @@ -1,7 +1,7 @@ --- title: Generate PaliGemma output with Keras description: PaliGemma models have multimodal capabilities, allowing you to generate output using both text and image input data. -models: [paligemma] +models: [paligemma-2] frameworks: [keras] colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/paligemma-inference.ipynb source_url: "https://ai.google.dev/gemma/docs/paligemma/inference-with-keras.md.txt" diff --git a/docs/models/paligemma/model-card-v2.md b/docs/models/paligemma/model-card-v2.md index dc69621..e5c6e9a 100644 --- a/docs/models/paligemma/model-card-v2.md +++ b/docs/models/paligemma/model-card-v2.md @@ -1,7 +1,7 @@ --- title: PaliGemma 2 model card description: PaliGemma 2 is an update of the PaliGemma vision-language model (VLM) which incorporates the capabilities of the Gemma 2 models. -models: [paligemma] +models: [paligemma-2] source_url: "https://ai.google.dev/gemma/docs/paligemma/model-card-2.md.txt" --- # Model card @@ -38,7 +38,7 @@ PaliGemma 2 is the composition of a [Transformer decoder](https://arxiv.org/abs/1706.03762) and a [Vision Transformer image encoder](https://arxiv.org/abs/2010.11929). The text decoder is initialized from -[Gemma 2](../gemma-4/index.md) in the 2B, 9B, and 27B +[Gemma 2](../gemma-2/index.md) in the 2B, 9B, and 27B parameter sizes. The image encoder is initialized from [SigLIP-So400m/14](https://colab.research.google.com/github/google-research/big_vision/blob/main/big_vision/configs/proj/image_text/SigLIP_demo.ipynb). Similar to the original PaliGemma model, PaliGemma 2 is trained following the diff --git a/docs/models/paligemma/prompting.md b/docs/models/paligemma/prompting.md index 7d29d07..dc550bf 100644 --- a/docs/models/paligemma/prompting.md +++ b/docs/models/paligemma/prompting.md @@ -1,7 +1,7 @@ --- title: PaliGemma prompt and system instructions description: This page describes prompt formatting and system instructions for PaliGemma models. -models: [paligemma] +models: [paligemma-2, paligemma] source_url: "https://ai.google.dev/gemma/docs/paligemma/prompt-system-instructions.md.txt" --- # PaliGemma prompt and system instructions diff --git a/docs/models/shieldgemma/index.md b/docs/models/shieldgemma/index.md index e4c668a..1fcc3ed 100644 --- a/docs/models/shieldgemma/index.md +++ b/docs/models/shieldgemma/index.md @@ -1,7 +1,7 @@ --- title: ShieldGemma description: ShieldGemma is a set of instruction tuned models for evaluating the safety of text and images against a set of defined safety policies. -models: [shieldgemma] +models: [shieldgemma-2, shieldgemma] source_url: "https://ai.google.dev/gemma/docs/shieldgemma.md.txt" --- # ShieldGemma {: #hidden-title style="display: none;" } @@ -21,7 +21,7 @@ for your specific use case. ShieldGemma 2 is a 4B parameter model built to label images for safety. -ShieldGemma 1 is built on [Gemma 2](../gemma-4/index.md) in 2B, 9B, and 27B parameter sizes. +ShieldGemma 1 is built on [Gemma 2](../gemma-2/index.md) in 2B, 9B, and 27B parameter sizes. - **Content safety evaluation** — Evaluate the safety of prompt input and output responses against a set of defined safety policies. diff --git a/docs/models/shieldgemma/model-card-v2.md b/docs/models/shieldgemma/model-card-v2.md index 0fb80ca..4de8bf7 100644 --- a/docs/models/shieldgemma/model-card-v2.md +++ b/docs/models/shieldgemma/model-card-v2.md @@ -1,7 +1,7 @@ --- title: ShieldGemma 2 model card description: ShieldGemma 2 is a model trained on Gemma 3's 4B IT checkpoint for image safety classification across key categories that takes in images and outputs safety labels per policy. -models: [shieldgemma] +models: [shieldgemma-2] source_url: "https://ai.google.dev/gemma/docs/shieldgemma/model_card_2.md.txt" --- # ShieldGemma model card @@ -11,8 +11,8 @@ source_url: "https://ai.google.dev/gemma/docs/shieldgemma/model_card_2.md.txt" **Resources and Technical Documentation**: - [Responsible Generative AI Toolkit][responsible-ai] -- [ShieldGemma on Kaggle](https://www.kaggle.com/models/google/shieldgemma){ data-model="shieldgemma" } -- [ShieldGemma on Hugging Face Hub](https://huggingface.co/models?search=shieldgemma){ data-model="shieldgemma" } +- [ShieldGemma on Kaggle](https://www.kaggle.com/models/google/shieldgemma-2){ data-model="shieldgemma-2" } +- [ShieldGemma on Hugging Face Hub](https://huggingface.co/models?search=shieldgemma){ data-model="shieldgemma-2" } **Terms of Use** : [Terms][gemma-terms] diff --git a/docs/notebooks/audio-qlora-gemma-4-12b.ipynb b/docs/notebooks/audio-qlora-gemma-4-12b.ipynb index 6f558c6..7ef1596 100644 --- a/docs/notebooks/audio-qlora-gemma-4-12b.ipynb +++ b/docs/notebooks/audio-qlora-gemma-4-12b.ipynb @@ -302,8 +302,8 @@ "\n", "To ensure the model learns strictly to transcribe the audio rather than memorizing prompt tokens:\n", "\n", - "- The following code parses <|turn>model\\n in each sequence.\n", - "- All tokens prior to <|turn>model\\n (including audio prefix markers and user instruction) are masked to `-100`.\n", + "- The following code parses <|turn>model\\n in each sequence.\n", + "- All tokens prior to <|turn>model\\n (including audio prefix markers and user instruction) are masked to `-100`.\n", "- Only assistant response tokens contribute to the cross-entropy loss." ] }, diff --git a/docs/notebooks/audio-qlora-gemma-4-e2b.ipynb b/docs/notebooks/audio-qlora-gemma-4-e2b.ipynb index dee25a9..fdb3675 100644 --- a/docs/notebooks/audio-qlora-gemma-4-e2b.ipynb +++ b/docs/notebooks/audio-qlora-gemma-4-e2b.ipynb @@ -302,8 +302,8 @@ "\n", "To ensure the model learns strictly to transcribe the audio rather than memorizing prompt tokens:\n", "\n", - "- The following code parses <|turn>model\\n in each sequence.\n", - "- All tokens prior to <|turn>model\\n (including audio prefix markers and user instruction) are masked to `-100`.\n", + "- The following code parses <|turn>model\\n in each sequence.\n", + "- All tokens prior to <|turn>model\\n (including audio prefix markers and user instruction) are masked to `-100`.\n", "- Only assistant response tokens contribute to the cross-entropy loss." ] }, diff --git a/docs/notebooks/audio-qlora-gemma-4-e4b.ipynb b/docs/notebooks/audio-qlora-gemma-4-e4b.ipynb index a322d82..7a51e66 100644 --- a/docs/notebooks/audio-qlora-gemma-4-e4b.ipynb +++ b/docs/notebooks/audio-qlora-gemma-4-e4b.ipynb @@ -302,8 +302,8 @@ "\n", "To ensure the model learns strictly to transcribe the audio rather than memorizing prompt tokens:\n", "\n", - "- The following code parses <|turn>model\\n in each sequence.\n", - "- All tokens prior to <|turn>model\\n (including audio prefix markers and user instruction) are masked to `-100`.\n", + "- The following code parses <|turn>model\\n in each sequence.\n", + "- All tokens prior to <|turn>model\\n (including audio prefix markers and user instruction) are masked to `-100`.\n", "- Only assistant response tokens contribute to the cross-entropy loss." ] }, diff --git a/docs/notebooks/function-calling-gemma-4-12b.ipynb b/docs/notebooks/function-calling-gemma-4-12b.ipynb index eb8e70a..f66acea 100644 --- a/docs/notebooks/function-calling-gemma-4-12b.ipynb +++ b/docs/notebooks/function-calling-gemma-4-12b.ipynb @@ -311,40 +311,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`).\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name,\n", " \"response\": function_response\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case of multiple independent requests:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "]\n", + "```\n", + "\n", + "In case of multiple independent requests:\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name_1,\n", @@ -354,13 +334,9 @@ " \"name\": function_name_2,\n", " \"response\": function_response_2\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "]\n", + "```\n", + "\n", "### Final Response\n", "\n", "Finally, Gemma reads the tool response and reply to the user." diff --git a/docs/notebooks/function-calling-gemma-4-26b-a4b.ipynb b/docs/notebooks/function-calling-gemma-4-26b-a4b.ipynb index d058323..031c575 100644 --- a/docs/notebooks/function-calling-gemma-4-26b-a4b.ipynb +++ b/docs/notebooks/function-calling-gemma-4-26b-a4b.ipynb @@ -311,40 +311,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`).\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name,\n", " \"response\": function_response\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case of multiple independent requests:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "]\n", + "```\n", + "\n", + "In case of multiple independent requests:\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name_1,\n", @@ -354,13 +334,9 @@ " \"name\": function_name_2,\n", " \"response\": function_response_2\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "]\n", + "```\n", + "\n", "### Final Response\n", "\n", "Finally, Gemma reads the tool response and reply to the user." diff --git a/docs/notebooks/function-calling-gemma-4-31b.ipynb b/docs/notebooks/function-calling-gemma-4-31b.ipynb index 73b8537..7308266 100644 --- a/docs/notebooks/function-calling-gemma-4-31b.ipynb +++ b/docs/notebooks/function-calling-gemma-4-31b.ipynb @@ -311,40 +311,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`).\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name,\n", " \"response\": function_response\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case of multiple independent requests:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "]\n", + "```\n", + "\n", + "In case of multiple independent requests:\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name_1,\n", @@ -354,13 +334,9 @@ " \"name\": function_name_2,\n", " \"response\": function_response_2\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "]\n", + "```\n", + "\n", "### Final Response\n", "\n", "Finally, Gemma reads the tool response and reply to the user." diff --git a/docs/notebooks/function-calling-gemma-4-e2b.ipynb b/docs/notebooks/function-calling-gemma-4-e2b.ipynb index 2995aec..8bf3348 100644 --- a/docs/notebooks/function-calling-gemma-4-e2b.ipynb +++ b/docs/notebooks/function-calling-gemma-4-e2b.ipynb @@ -311,40 +311,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`).\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name,\n", " \"response\": function_response\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case of multiple independent requests:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "]\n", + "```\n", + "\n", + "In case of multiple independent requests:\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name_1,\n", @@ -354,13 +334,9 @@ " \"name\": function_name_2,\n", " \"response\": function_response_2\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "]\n", + "```\n", + "\n", "### Final Response\n", "\n", "Finally, Gemma reads the tool response and reply to the user." diff --git a/docs/notebooks/function-calling-gemma-4-e4b.ipynb b/docs/notebooks/function-calling-gemma-4-e4b.ipynb index efe83e0..309ecdf 100644 --- a/docs/notebooks/function-calling-gemma-4-e4b.ipynb +++ b/docs/notebooks/function-calling-gemma-4-e4b.ipynb @@ -311,40 +311,20 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "> **Note:** For optimal results, append the tool execution result to your message history using the specific format below. This ensures the chat template correctly generates the required token structure (e.g., `response:get_current_weather{temperature:15,weather:<|\"|>sunny<|\"|>}`).\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name,\n", " \"response\": function_response\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In case of multiple independent requests:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ + "]\n", + "```\n", + "\n", + "In case of multiple independent requests:\n", + "\n", + "```python\n", "\"tool_responses\": [\n", " {\n", " \"name\": function_name_1,\n", @@ -354,13 +334,9 @@ " \"name\": function_name_2,\n", " \"response\": function_response_2\n", " }\n", - "]\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "]\n", + "```\n", + "\n", "### Final Response\n", "\n", "Finally, Gemma reads the tool response and reply to the user." diff --git a/docs/notebooks/run-gemma-with-hf-gemma-4-12b.ipynb b/docs/notebooks/run-gemma-with-hf-gemma-4-12b.ipynb index c42d8f0..d44474c 100644 --- a/docs/notebooks/run-gemma-with-hf-gemma-4-12b.ipynb +++ b/docs/notebooks/run-gemma-with-hf-gemma-4-12b.ipynb @@ -37,7 +37,7 @@ "\n", "Generating text, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Hugging Face Transformers using both text and image input to generate text content. The Transformers Python library provides a API for accessing pre-trained generative AI models, including Gemma. For more information, see the [Transformers](https://huggingface.co/docs/transformers/en/index) documentation.\n", "\n", - "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md).\n", + "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md).\n", "\n", "\n", "### Install Python packages\n", diff --git a/docs/notebooks/run-gemma-with-hf-gemma-4-26b-a4b.ipynb b/docs/notebooks/run-gemma-with-hf-gemma-4-26b-a4b.ipynb index 6c9aa38..72d6bdf 100644 --- a/docs/notebooks/run-gemma-with-hf-gemma-4-26b-a4b.ipynb +++ b/docs/notebooks/run-gemma-with-hf-gemma-4-26b-a4b.ipynb @@ -37,7 +37,7 @@ "\n", "Generating text, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Hugging Face Transformers using both text and image input to generate text content. The Transformers Python library provides a API for accessing pre-trained generative AI models, including Gemma. For more information, see the [Transformers](https://huggingface.co/docs/transformers/en/index) documentation.\n", "\n", - "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md).\n", + "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md).\n", "\n", "\n", "### Install Python packages\n", @@ -203,47 +203,6 @@ "You can include multiple images in your prompt by including additional `\"type\": \"image\",` entries in the `content` list.\n", "> **Note:** Do not use `<|image|>`, `` or `` tokens in text portion of a prompt template as this approach creates redundant tokens and processing errors.\n", "\n", - "## Generate text from audio data\n", - "\n", - "With [Gemma 4](../models/gemma-4/index.md) and [Gemma 3n](../models/gemma-3n/index.md), you can use audio data as part of your prompt. This section shows how to use the Transformers library to load and configure a Gemma model to use audio data and text input to generate text output.\n", - "\n", - "### Use a prompt template\n", - "\n", - "When generating content with audio, use a prompt template to structure your request. A prompt template allows you to specify input from specific roles, such as `user` or `model`, and is a required format for managing multi-turn chat interactions with Gemma models. The following example code shows how to constuct a prompt template for Gemma with audio data input:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ - "from transformers import GenerationConfig\n", - "config = GenerationConfig.from_pretrained(MODEL_ID)\n", - "config.max_new_tokens = 512\n", - "gen_kwargs = dict(generation_config=config)\n", - "\n", - "messages = [\n", - " {\n", - " \"role\": \"user\",\n", - " \"content\": [\n", - " {\"type\": \"text\", \"text\": \"Transcribe the following speech segment in its original language. Follow these specific instructions for formatting the answer:\\n* Only output the transcription, with no newlines.\\n* When transcribing numbers, write the digits, i.e. write 1.7 and not one point seven, and write 3 instead of three.\"},\n", - " {\"type\": \"audio\", \"audio\": \"https://ai.google.dev/gemma/docs/audio/roses-are.wav\"},\n", - " ]\n", - " }\n", - "]\n", - "\n", - "pipe(text=messages, return_full_text=False, generate_kwargs=gen_kwargs)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can include multiple audio files in your prompt by including additional `\"type\": \"audio\",` entries in the `content` list.\n", - "> **Note:** Do not use `<|audio|>` or `` tokens in text portion of a prompt template as this approach creates redundant tokens and processing errors.\n", "\n", "## Next steps\n", "\n", diff --git a/docs/notebooks/run-gemma-with-hf-gemma-4-31b.ipynb b/docs/notebooks/run-gemma-with-hf-gemma-4-31b.ipynb index 625ef6f..16c7d18 100644 --- a/docs/notebooks/run-gemma-with-hf-gemma-4-31b.ipynb +++ b/docs/notebooks/run-gemma-with-hf-gemma-4-31b.ipynb @@ -37,7 +37,7 @@ "\n", "Generating text, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Hugging Face Transformers using both text and image input to generate text content. The Transformers Python library provides a API for accessing pre-trained generative AI models, including Gemma. For more information, see the [Transformers](https://huggingface.co/docs/transformers/en/index) documentation.\n", "\n", - "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md).\n", + "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md).\n", "\n", "\n", "### Install Python packages\n", @@ -203,47 +203,6 @@ "You can include multiple images in your prompt by including additional `\"type\": \"image\",` entries in the `content` list.\n", "> **Note:** Do not use `<|image|>`, `` or `` tokens in text portion of a prompt template as this approach creates redundant tokens and processing errors.\n", "\n", - "## Generate text from audio data\n", - "\n", - "With [Gemma 4](../models/gemma-4/index.md) and [Gemma 3n](../models/gemma-3n/index.md), you can use audio data as part of your prompt. This section shows how to use the Transformers library to load and configure a Gemma model to use audio data and text input to generate text output.\n", - "\n", - "### Use a prompt template\n", - "\n", - "When generating content with audio, use a prompt template to structure your request. A prompt template allows you to specify input from specific roles, such as `user` or `model`, and is a required format for managing multi-turn chat interactions with Gemma models. The following example code shows how to constuct a prompt template for Gemma with audio data input:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "language": "python" - }, - "outputs": [], - "source": [ - "from transformers import GenerationConfig\n", - "config = GenerationConfig.from_pretrained(MODEL_ID)\n", - "config.max_new_tokens = 512\n", - "gen_kwargs = dict(generation_config=config)\n", - "\n", - "messages = [\n", - " {\n", - " \"role\": \"user\",\n", - " \"content\": [\n", - " {\"type\": \"text\", \"text\": \"Transcribe the following speech segment in its original language. Follow these specific instructions for formatting the answer:\\n* Only output the transcription, with no newlines.\\n* When transcribing numbers, write the digits, i.e. write 1.7 and not one point seven, and write 3 instead of three.\"},\n", - " {\"type\": \"audio\", \"audio\": \"https://ai.google.dev/gemma/docs/audio/roses-are.wav\"},\n", - " ]\n", - " }\n", - "]\n", - "\n", - "pipe(text=messages, return_full_text=False, generate_kwargs=gen_kwargs)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can include multiple audio files in your prompt by including additional `\"type\": \"audio\",` entries in the `content` list.\n", - "> **Note:** Do not use `<|audio|>` or `` tokens in text portion of a prompt template as this approach creates redundant tokens and processing errors.\n", "\n", "## Next steps\n", "\n", diff --git a/docs/notebooks/run-gemma-with-hf-gemma-4-e2b.ipynb b/docs/notebooks/run-gemma-with-hf-gemma-4-e2b.ipynb index d66809a..e911f28 100644 --- a/docs/notebooks/run-gemma-with-hf-gemma-4-e2b.ipynb +++ b/docs/notebooks/run-gemma-with-hf-gemma-4-e2b.ipynb @@ -37,7 +37,7 @@ "\n", "Generating text, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Hugging Face Transformers using both text and image input to generate text content. The Transformers Python library provides a API for accessing pre-trained generative AI models, including Gemma. For more information, see the [Transformers](https://huggingface.co/docs/transformers/en/index) documentation.\n", "\n", - "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md).\n", + "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md).\n", "\n", "\n", "### Install Python packages\n", diff --git a/docs/notebooks/run-gemma-with-hf-gemma-4-e4b.ipynb b/docs/notebooks/run-gemma-with-hf-gemma-4-e4b.ipynb index 5cc92e6..6ec1bcd 100644 --- a/docs/notebooks/run-gemma-with-hf-gemma-4-e4b.ipynb +++ b/docs/notebooks/run-gemma-with-hf-gemma-4-e4b.ipynb @@ -37,7 +37,7 @@ "\n", "Generating text, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Hugging Face Transformers using both text and image input to generate text content. The Transformers Python library provides a API for accessing pre-trained generative AI models, including Gemma. For more information, see the [Transformers](https://huggingface.co/docs/transformers/en/index) documentation.\n", "\n", - "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md).\n", + "> **Note:** Gemma 3 and later models support input of both images and text. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md).\n", "\n", "\n", "### Install Python packages\n", diff --git a/docs/notebooks/run-gemma-with-keras-gemma-4-26b-a4b.ipynb b/docs/notebooks/run-gemma-with-keras-gemma-4-26b-a4b.ipynb index e229a9c..1947409 100644 --- a/docs/notebooks/run-gemma-with-keras-gemma-4-26b-a4b.ipynb +++ b/docs/notebooks/run-gemma-with-keras-gemma-4-26b-a4b.ipynb @@ -37,7 +37,7 @@ "\n", "Generating content, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Keras, including generating text content with text and image input. [Keras](https://keras.io/) provides implementations for running Gemma and other models using JAX, PyTorch, and TensorFlow. If you're new to Keras, you might want to read [Getting started with Keras](https://keras.io/getting_started/) before you begin.\n", "\n", - "Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md).\n", + "Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md).\n", "> **Note:** This notebook won't run on T4 if you try with Gemma 4. Use L4 or higher GPUs.\n", "\n", "### Install Keras packages\n", diff --git a/docs/notebooks/run-gemma-with-keras-gemma-4-31b.ipynb b/docs/notebooks/run-gemma-with-keras-gemma-4-31b.ipynb index 6c492b3..59b592d 100644 --- a/docs/notebooks/run-gemma-with-keras-gemma-4-31b.ipynb +++ b/docs/notebooks/run-gemma-with-keras-gemma-4-31b.ipynb @@ -37,7 +37,7 @@ "\n", "Generating content, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Keras, including generating text content with text and image input. [Keras](https://keras.io/) provides implementations for running Gemma and other models using JAX, PyTorch, and TensorFlow. If you're new to Keras, you might want to read [Getting started with Keras](https://keras.io/getting_started/) before you begin.\n", "\n", - "Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md).\n", + "Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md).\n", "> **Note:** This notebook won't run on T4 if you try with Gemma 4. Use L4 or higher GPUs.\n", "\n", "### Install Keras packages\n", diff --git a/docs/notebooks/run-gemma-with-keras-gemma-4-e2b.ipynb b/docs/notebooks/run-gemma-with-keras-gemma-4-e2b.ipynb index 8840fd8..448098c 100644 --- a/docs/notebooks/run-gemma-with-keras-gemma-4-e2b.ipynb +++ b/docs/notebooks/run-gemma-with-keras-gemma-4-e2b.ipynb @@ -37,7 +37,7 @@ "\n", "Generating content, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Keras, including generating text content with text and image input. [Keras](https://keras.io/) provides implementations for running Gemma and other models using JAX, PyTorch, and TensorFlow. If you're new to Keras, you might want to read [Getting started with Keras](https://keras.io/getting_started/) before you begin.\n", "\n", - "Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md).\n", + "Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md).\n", "> **Note:** This notebook won't run on T4 if you try with Gemma 4. Use L4 or higher GPUs.\n", "\n", "### Install Keras packages\n", diff --git a/docs/notebooks/run-gemma-with-keras-gemma-4-e4b.ipynb b/docs/notebooks/run-gemma-with-keras-gemma-4-e4b.ipynb index 0a67c93..2cc75bf 100644 --- a/docs/notebooks/run-gemma-with-keras-gemma-4-e4b.ipynb +++ b/docs/notebooks/run-gemma-with-keras-gemma-4-e4b.ipynb @@ -37,7 +37,7 @@ "\n", "Generating content, summarizing, and analysing content are just some of the tasks you can accomplish with Gemma open models. This tutorial shows you how to get started running Gemma using Keras, including generating text content with text and image input. [Keras](https://keras.io/) provides implementations for running Gemma and other models using JAX, PyTorch, and TensorFlow. If you're new to Keras, you might want to read [Getting started with Keras](https://keras.io/getting_started/) before you begin.\n", "\n", - "Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../get-started/index.md).\n", + "Gemma 3 and later models support text and image input. Earlier versions of Gemma only support text input, except for some variants, including [PaliGemma](../models/paligemma/index.md).\n", "> **Note:** This notebook won't run on T4 if you try with Gemma 4. Use L4 or higher GPUs.\n", "\n", "### Install Keras packages\n", diff --git a/docs/resources/embedding-draw-challenge.md b/docs/resources/embedding-draw-challenge.md index c728eb8..a6fd4af 100644 --- a/docs/resources/embedding-draw-challenge.md +++ b/docs/resources/embedding-draw-challenge.md @@ -1,7 +1,7 @@ --- title: Embedding Draw Challenge description: Sketch target objects on an interactive canvas and see how EmbeddingGemma 2 scores cross-modal image-to-text similarity in real time. -models: [embeddinggemma] +models: [embeddinggemma-2] hide: - toc --- diff --git a/docs/stylesheets/motion.css b/docs/stylesheets/motion.css index 2526c0b..63c2074 100644 --- a/docs/stylesheets/motion.css +++ b/docs/stylesheets/motion.css @@ -44,11 +44,11 @@ .md-content__inner, .gemma-stage { - animation: gemmaPageReveal 260ms var(--gemma-ease) both; + animation: gemmaPageReveal 260ms var(--gemma-ease) backwards; } .md-sidebar--primary .md-nav--primary > .md-nav__list { - animation: gemmaPageReveal 220ms var(--gemma-ease) both; + animation: gemmaPageReveal 220ms var(--gemma-ease) backwards; } /* ------------------------------------------------------------------- diff --git a/docs/tuning/audio-qlora.md b/docs/tuning/audio-qlora.md index 6f02944..2c7d2d8 100644 --- a/docs/tuning/audio-qlora.md +++ b/docs/tuning/audio-qlora.md @@ -258,8 +258,8 @@ trainable params: 48,316,416 || all params: 5,152,613,920 || trainable%: 0.9377 To ensure the model learns strictly to transcribe the audio rather than memorizing prompt tokens: -- The following code parses <|turn>model\n in each sequence. -- All tokens prior to <|turn>model\n (including audio prefix markers and user instruction) are masked to `-100`. +- The following code parses <|turn>model\n in each sequence. +- All tokens prior to <|turn>model\n (including audio prefix markers and user instruction) are masked to `-100`. - Only assistant response tokens contribute to the cross-entropy loss. diff --git a/docs/tutorials/gemma-explained/paligemma.md b/docs/tutorials/gemma-explained/paligemma.md index cc9dc6e..dd67e8d 100644 --- a/docs/tutorials/gemma-explained/paligemma.md +++ b/docs/tutorials/gemma-explained/paligemma.md @@ -135,7 +135,7 @@ It takes as input the multi-modal representation from the projector and generate For the text input, each checkpoint was trained with various sequence lengths. For example, paligemma-3b-mix-224 was trained with sequence length 256 (input text + output text tokenized by Gemma’s tokenizer). -PaliGemma uses the Gemma tokenizer with 256000 tokens, but extends its vocabulary with 1024 entries that represent coordinates in normalized image-space (...), and another with 128 entries (...) that are codewords used by a lightweight referring-expression segmentation [vector-quantized variational auto-encoder (VQ-VAE)](https://arxiv.org/abs/2301.02229). (256000 + 1024 + 128 = 257216) +PaliGemma uses the Gemma tokenizer with 256000 tokens, but extends its vocabulary with 1024 entries that represent coordinates in normalized image-space (``...``), and another with 128 entries (``...``) that are codewords used by a lightweight referring-expression segmentation [vector-quantized variational auto-encoder (VQ-VAE)](https://arxiv.org/abs/2301.02229). (256000 + 1024 + 128 = 257216) ## Object Segmentation Example diff --git a/docs/tutorials/visual-guides/diffusiongemma.md b/docs/tutorials/visual-guides/diffusiongemma.md index b953f65..76f4396 100644 --- a/docs/tutorials/visual-guides/diffusiongemma.md +++ b/docs/tutorials/visual-guides/diffusiongemma.md @@ -11,7 +11,7 @@ source_url: https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-diffu Originally published on [Exploring Language Models](https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-diffusiongemma){ data-model="diffusiongemma" }. -Following the release of [Gemma 4 12B](https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-gemma-4-12b){ data-model="gemma-4" } there is yet another innovative model that I can introduce to you all, [DiffusionGemma](https://huggingface.co/google/diffusiongemma-26B-A4B-it){ data-model="diffusiongemma" }! +Following the release of [Gemma 4 12B](gemma-4-12b.md){ data-model="gemma-4" } there is yet another innovative model that I can introduce to you all, [DiffusionGemma](https://huggingface.co/google/diffusiongemma-26B-A4B-it){ data-model="diffusiongemma" }! This is one I’m especially excited about because it’s a different way of approaching text generation, yet uses many of the great things we have with existing “regular” LLMs. We are going to explore the old, the new, and how they live side-by-side. @@ -198,7 +198,7 @@ So how can we have the benefits of Uniform State Diffusion without the downsides ## Architecture of DiffusionGemma **DiffusionGemma** applies Uniform State Diffusion that we explore thus far. However, the downsides of training this entirely from scratch still remains. The solution was simply not to train from scratch but to use an existing checkpoint as a start instead, namely the Gemma 4 26B A4B model. -Gemma 4 26B A4B, as covered in [A Visual Guide to Gemma 4](https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-gemma-4){ data-model="gemma-4" }, is a Mixture of Experts (MoE) model that already went through extensive training and has great performance. There is one problem though… +Gemma 4 26B A4B, as covered in [A Visual Guide to Gemma 4](gemma-4.md){ data-model="gemma-4" }, is a Mixture of Experts (MoE) model that already went through extensive training and has great performance. There is one problem though… Gemma 4 26B A4B is a *decoder-only* model and meant to generate text one by one whilst diffusion generally needs an *encoder* and a *denoiser*. This is where an elegant solution comes in, the **Encoder-Denoiser** patch! diff --git a/docs/tutorials/visual-guides/gemma-4-12b.md b/docs/tutorials/visual-guides/gemma-4-12b.md index 326db90..58eff78 100644 --- a/docs/tutorials/visual-guides/gemma-4-12b.md +++ b/docs/tutorials/visual-guides/gemma-4-12b.md @@ -150,17 +150,17 @@ Gemma 4 12B is not just a model that fits nicely between E4B and 26B A4B, it doe ## What's next
- + {{ icon('lucide/book-open') }}
A Visual Guide to MTP

Drafter models and speculative decoding, illustrated.

- + {{ icon('lucide/book-open') }}
A Visual Guide to DiffusionGemma

How denoising produces text instead of pixels.

- + {{ icon('lucide/library') }}
Resources

Demos, tools and the repositories worth bookmarking.

diff --git a/scripts/agent_docs.py b/scripts/agent_docs.py index 81916f5..95ac43a 100644 --- a/scripts/agent_docs.py +++ b/scripts/agent_docs.py @@ -26,6 +26,7 @@ import re import sys import tomllib +from functools import lru_cache from pathlib import Path from typing import Iterable @@ -37,6 +38,7 @@ CONFIG_FILE = REPO_ROOT / "zensical.toml" MODELS_FILE = REPO_ROOT / "data" / "models.yml" FRAMEWORKS_FILE = REPO_ROOT / "data" / "frameworks.yml" +LINKS_FILE = REPO_ROOT / "data" / "links.yml" # Pages call `icon()`; the macros extension provides it during a Zensical build, but these raw # routes are rendered here, in a Jinja environment of our own. Same source, same output. @@ -56,6 +58,7 @@ RELATIVE_ASSET = re.compile( r"(?P\]\(|(?:\b(?:src|href)=[\"']))(?:\.\.?/|/)*(?Passets/[^)\s\"']+)" ) +REFERENCE_LINK = re.compile(r"\[([^\]]+)\]\[([a-z0-9][a-z0-9-]*)\]") def split_frontmatter(text: str) -> tuple[dict, str]: @@ -121,13 +124,24 @@ def markdown_route_for(relative: str) -> str: return "/index.md" if route == "/" else f"{route.rstrip('/')}.md" -def display_title(metadata: dict, family_names: dict[str, str]) -> str: +def display_title( + metadata: dict, + family_names: dict[str, str], + relative: str = "", +) -> str: title = str(metadata.get("title", "Untitled")) + if not relative.startswith("models/"): + return title models = metadata.get("models") or [] - if title.lower() in {"model card", "overview"} and len(models) == 1: - family = str(models[0]).split("/", 1)[0] - if family in family_names: - return f"{family_names[family]} — {title}" + parts = Path(relative).parts + family = ( + parts[1] + if len(parts) > 2 and parts[1] in family_names + else (str(models[0]).split("/", 1)[0] if len(models) == 1 else "") + ) + family_name = family_names.get(family) + if family_name and not all(part in title.lower() for part in family_name.lower().split()): + return f"{family_name} — {title}" return title @@ -139,6 +153,12 @@ def framework_data() -> dict: return yaml.safe_load(FRAMEWORKS_FILE.read_text(encoding="utf-8")) +@lru_cache(maxsize=1) +def shared_links() -> dict[str, str]: + data = yaml.safe_load(LINKS_FILE.read_text(encoding="utf-8")) + return {name: str(entry["url"]) for name, entry in (data.get("links") or {}).items()} + + def render_llms() -> str: pages = source_pages() data = model_data() @@ -159,7 +179,7 @@ def render_llms() -> str: for relative in entries: seen.add(relative) _path, metadata, _body = pages[relative] - title = display_title(metadata, family_names) + title = display_title(metadata, family_names, relative) description = " ".join(str(metadata.get("description", "")).split()) url = f"{SITE_URL}{markdown_route_for(relative)}" suffix = f": {description}" if description else "" @@ -185,6 +205,12 @@ def render_raw(relative: str, metadata: dict, body: str) -> str: context["frameworkdata"] = framework_data() context["icon"] = _icon rendered = environment.from_string(body).render(**context) + + def resolve_reference(match: re.Match) -> str: + url = shared_links().get(match.group(2)) + return f"[{match.group(1)}]({url})" if url else match.group(0) + + rendered = REFERENCE_LINK.sub(resolve_reference, rendered) rendered = WHATS_NEXT_SECTION.sub("", rendered) rendered = SNIPPET_INCLUDE.sub("", rendered).strip() + "\n" rendered = RELATIVE_ASSET.sub(rf"\g{SITE_URL}/\g", rendered) diff --git a/scripts/frontmatter_schema.py b/scripts/frontmatter_schema.py index b24c828..8153cf3 100644 --- a/scripts/frontmatter_schema.py +++ b/scripts/frontmatter_schema.py @@ -94,8 +94,9 @@ class Field: @cache def model_families() -> frozenset[str]: - """Every family id. Derived from `docs/models/`, so adding a model directory is enough.""" - return frozenset(p.name for p in (DOCS_DIR / "models").iterdir() if p.is_dir()) + """Every family id in data/models.yml.""" + data = yaml.safe_load(MODELS_DATA.read_text(encoding="utf-8")) + return frozenset(str(family["id"]) for family in data.get("families", [])) @cache diff --git a/scripts/lint_docs.py b/scripts/lint_docs.py index 01e81da..4a4a410 100644 --- a/scripts/lint_docs.py +++ b/scripts/lint_docs.py @@ -231,23 +231,26 @@ def load_context() -> Context: return Context(pages=load_pages(), nav_entries=list(walk_nav(nav)), config=config) +FENCE_OPEN = re.compile(r"^(\s*)(`{3,}|~{3,})(.*)$") + + def iter_code_blocks(page: Page) -> Iterator[tuple[int, str, str]]: """Yield (start line, info string, block content) for each fenced code block.""" - fence = re.compile(r"^(\s*)```(.*)$") open_at: int | None = None + active_fence = "" info = "" buf: list[str] = [] for lineno, line in page.body_lines(): - m = fence.match(line) - if not m: - if open_at is not None: - buf.append(line) - continue + m = FENCE_OPEN.match(line) if open_at is None: - open_at, info, buf = lineno, m.group(2).strip(), [] - else: + if m: + open_at, active_fence, info, buf = lineno, m.group(2), m.group(3).strip(), [] + continue + if m and m.group(2) == active_fence and not m.group(3).strip(): yield open_at, info, "\n".join(buf) open_at = None + else: + buf.append(line) INLINE_CODE = re.compile(r"`+[^`]*`+") @@ -264,13 +267,17 @@ def strip_inline_code(line: str) -> str: def outside_code(page: Page) -> Iterator[tuple[int, str]]: """Yield body lines that are not inside a fenced code block, with code spans blanked.""" - in_fence = False + active_fence: str | None = None for lineno, line in page.body_lines(): - if line.lstrip().startswith("```"): - in_fence = not in_fence - continue - if not in_fence: + m = FENCE_OPEN.match(line) + if active_fence is None: + if m: + active_fence = m.group(2) + continue yield lineno, strip_inline_code(line) + elif m and m.group(2) == active_fence and not m.group(3).strip(): + active_fence = None + continue # --- Checks ----------------------------------------------------------------------------------- @@ -558,9 +565,19 @@ def check_model_swap(ctx: Context) -> Iterable[Finding]: """A swappable engine must not also appear in unacknowledged static code blocks.""" data = yaml.safe_load((REPO_ROOT / "data" / "models.yml").read_text(encoding="utf-8")) engines: dict[str, set[str]] = {} + index: list[tuple[str, str, str]] = [] for size in data.get("gemma4", {}).get("sizes", []): + size_id = str(size["id"]) for engine, identifier in size.get("ids", {}).items(): engines.setdefault(str(engine), set()).add(str(identifier)) + index.append((str(identifier), str(engine), size_id)) + index.sort(key=lambda item: len(item[0]), reverse=True) + pattern = re.compile("|".join(re.escape(text) for text, _, _ in index)) + by_text = {text: (engine, size_id) for text, engine, size_id in index} + unrewritten_re = re.compile( + r"\bgemma[-_]?4[-_:(](?:e2b|e4b|12b|26b(?:[-_]a4b)?|31b)[\w.-]*", + re.IGNORECASE, + ) for page in ctx.pages: blocks = list(iter_code_blocks(page)) @@ -568,12 +585,40 @@ def check_model_swap(ctx: Context) -> Iterable[Finding]: if not marked: continue - active = { - engine - for _, _, code in marked - for engine, identifiers in engines.items() - if any(identifier in code for identifier in identifiers) - } + active: set[str] = set() + page_default_size: str | None = None + for line, _, code in marked: + matches = [m.group(0) for m in pattern.finditer(code)] + if not matches: + yield Finding( + "model-swap", + page.repo_rel, + line, + ".model-swap block contains no swappable model identifier from data/models.yml", + ) + continue + for match in matches: + engine, size_id = by_text[match] + active.add(engine) + if page_default_size is None: + page_default_size = size_id + elif size_id != page_default_size: + yield Finding( + "model-swap", + page.repo_rel, + line, + f".model-swap identifier '{match}' targets '{size_id}' " + f"but page default is '{page_default_size}'", + ) + remainder = pattern.sub("", code) + for leftover in unrewritten_re.finditer(remainder): + yield Finding( + "model-swap", + page.repo_rel, + line, + f"unrewritten model identifier '{leftover.group(0)}' inside .model-swap block", + ) + for line, info, code in blocks: if ".model-swap" in info or ".model-fixed" in info or ".output" in info: continue diff --git a/scripts/notebooks.py b/scripts/notebooks.py index bc88aa9..064fe19 100644 --- a/scripts/notebooks.py +++ b/scripts/notebooks.py @@ -73,6 +73,16 @@ r".*?", re.DOTALL, ) +REQUIRES_REGION = re.compile( + r"[ \t]*\n?" + r"(?P.*?)" + r"[ \t]*\n?", + re.DOTALL, +) +REQUIRES_COMMENT = re.compile( + r"[ \t]*\n?" +) +FENCE_REQUIRES = re.compile(r"\b(?:data-)?requires=[\"'](?P[a-z0-9_-]+)[\"']") ADMONITION = re.compile( r"^!!!\s+(?P