Skip to content

Commit f2e6fae

Browse files
committed
update docs and skills
1 parent d4bfe56 commit f2e6fae

3 files changed

Lines changed: 58 additions & 23 deletions

File tree

‎docs/contributing/components.md‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ The quiet band under every H1. You never write this markup; it is rendered from
326326
models: [gemma-4] # what the page is about
327327
frameworks: [ollama] # primary tools the page teaches, linked to their home pages
328328
requires: audio # narrows the selector to models that accept audio
329+
colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/tutorial-gemma-4-e2b-it.ipynb # opens in Colab
329330
```
330331
331332
Two kinds of item sit on the line, and keeping them apart is the design:
@@ -335,6 +336,7 @@ Two kinds of item sit on the line, and keeping them apart is the design:
335336
| `Models` | `models` frontmatter | What the page is **about**. Links to the local model page. |
336337
| `Uses` | `frameworks` frontmatter | Primary tools the page teaches. Links out to each project. |
337338
| `Examples` | the page's own code | What **you** want the commands to target. A preference. |
339+
| `Colab` | `colab` frontmatter | Direct link to Colab notebook; dynamically updates to target the selected model. |
338340

339341
Pairs are separated by a 1px rule, values all share one weight, and labels are muted — 16px of
340342
space alone was not enough to stop `Frameworks Sentence Transformers` reading as a single run
@@ -367,6 +369,8 @@ every tag while the `pull` command above it follows the selector.
367369

368370
A model is only offered if it has a published id for **every** engine appearing in the page's
369371
marked blocks, so switching can never rewrite some snippets and silently leave others behind.
372+
If a page specifies a `requires:` modality in frontmatter (such as `requires: audio`), the picker
373+
and exported notebooks are additionally filtered to models supporting that modality.
370374
If an intentionally separate example lacks one size—such as a QAT checkpoint—mark it
371375
`{ .model-fixed }` and explain the limitation beside it instead of unnecessarily narrowing the
372376
page's primary examples.
@@ -389,23 +393,32 @@ should become executable cells in the generated notebook:
389393

390394
````markdown
391395
```python { .notebook-cell .model-swap }
392-
print("This becomes a code cell; the authored model is retained.")
396+
model_id = "google/gemma-4-E2B-it"
393397
```
394398
````
395399

396400
Unmarked fences remain part of a Markdown cell, and `{ .output }` blocks are omitted because a
397-
notebook recreates them when it runs. Add the generated notebook's Colab URL to frontmatter to
398-
show a quiet, accessible Colab icon in the page context strip:
401+
notebook recreates them when it runs.
402+
403+
When a tutorial uses `{ .model-swap }`, `scripts/notebooks.py` exports separate model-specific
404+
notebooks named `<page>-gemma-4-<size>-it.ipynb` (e.g., `thinking-gemma-4-e2b-it.ipynb`,
405+
`thinking-gemma-4-12b-it.ipynb`) for every candidate model supported by the page's engines and
406+
`requires:` modality constraint. Tutorials without `.model-swap` export a single `<page>.ipynb`.
407+
408+
Add the default model notebook's Colab URL to frontmatter to show a quiet, accessible Colab icon
409+
in the page context strip:
399410

400411
```yaml
401-
colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/tutorial.ipynb
412+
colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/tutorial-gemma-4-e2b-it.ipynb
402413
```
403414

415+
When readers select another model in the page context dropdown, the model switcher dynamically
416+
updates the Colab button's destination to match the selected model notebook.
417+
404418
Wrap any other site-only controls in `<!-- notebook:skip-start -->` and
405-
`<!-- notebook:skip-end -->`. Register the source and output in `scripts/notebooks.py`, then
419+
`<!-- notebook:skip-end -->`. Register the source page in `SOURCES` in `scripts/notebooks.py`, then
406420
generate every registered notebook with `uv run python scripts/notebooks.py`; use `--check`
407-
during verification. Do not edit the generated `.ipynb`
408-
directly.
421+
during verification. Do not edit the generated `.ipynb` directly.
409422

410423
## Engine grid
411424

‎docs/contributing/conventions.md‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Nothing in this list should ever be edited by hand. Each has a generator, and
4545
| `docs/javascripts/model-data.js` | `generate_model_names.py` | `models.yml`, `frameworks.yml` |
4646
| `snippets/links.md`, `snippets/glossary.md` | `generate_snippets.py` | `links.yml`, `glossary.yml` |
4747
| `docs/llms.txt` and the raw `.md` routes | `agent_docs.py` | Page frontmatter and the nav |
48-
| `docs/notebooks/*.ipynb` | `notebooks.py` | The ten registered tutorial pages |
48+
| `docs/notebooks/*.ipynb` | `notebooks.py` | Registered tutorial pages (model-adapted variants for swappable pages) |
4949
| `overrides/.icons/**.svg` | `vendor_icons.py` | The icons pages actually reference |
5050

5151
Icons are the one entry checked by `--check icons` rather than `--check generated`, because
@@ -75,7 +75,7 @@ upstream source is still findable.
7575
distinction it draws matters:
7676

7777
- **Authored** keys are facts only a person knows — `title`, `description`, `models`,
78-
`frameworks`, `prerequisites`.
78+
`frameworks`, `prerequisites`, `requires` (modality constraints), `colab` (direct notebook link).
7979
- **Computed** keys are derivable from the file. Writing one by hand is an *error*, because a
8080
hand-written token count is wrong the moment the page is edited.
8181

@@ -110,13 +110,22 @@ one, and marking it up buries the links that do need revisiting.
110110

111111
## Markdown is the source, notebooks are output
112112

113-
Ten pages are exported to Jupyter. Markdown owns every subsequent edit; the `.ipynb` is a build
114-
artifact.
113+
Ten tutorial pages in `SOURCES` are exported to Jupyter. Markdown owns every subsequent edit; the
114+
`.ipynb` files are build artifacts.
115115

116-
Only fences marked `.notebook-cell` become executable cells. Everything else in the page is
117-
site chrome, and `notebooks.py` strips what Jupyter cannot render — `attr_list` annotations,
118-
card grids, snippet includes and abbreviation definitions. **Anything added to the authoring
119-
vocabulary needs a matching strip**, or it lands in the notebook as literal text.
116+
Only fences marked `.notebook-cell` become executable cells. When a tutorial contains
117+
`{ .model-swap }` code blocks, `notebooks.py` exports separate model-specific notebooks named
118+
`<stem>-gemma-4-<size>-it.ipynb` (e.g., `thinking-gemma-4-e2b-it.ipynb`) for all candidate models
119+
matching the tutorial's engines and `requires:` modality constraint. Non-swappable tutorials
120+
export a single `<stem>.ipynb`.
121+
122+
For swappable tutorials, frontmatter specifies the default model notebook in `colab:`, and the
123+
page context switcher dynamically updates the link when readers select a different model.
124+
125+
Everything else in the page is site chrome, and `notebooks.py` strips what Jupyter cannot render —
126+
`attr_list` annotations, card grids, `{ .output }` blocks, snippet includes, abbreviation definitions,
127+
and skip blocks (`<!-- notebook:skip-start -->` ... `<!-- notebook:skip-end -->`). **Anything added
128+
to the authoring vocabulary needs a matching strip**, or it lands in the notebook as literal text.
120129

121130
## Verification
122131

‎skills/gemma-docs/SKILL.md‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ This skill guides coding agents and contributors in maintaining and authoring do
5757

5858
| Data File | Governs | Generator / Consumer |
5959
|---|---|---|
60-
| `data/models.yml` | Model families, parameter sizes, context lengths, memory requirements, framework-specific checkpoint IDs | `scripts/generate_model_names.py` -> `docs/javascripts/model-data.js` and `overrides/partials/model-names.html` |
60+
| `data/models.yml` | Model families, parameter sizes, context lengths, memory requirements, framework-specific checkpoint IDs | `scripts/generate_model_names.py` -> `docs/javascripts/model-data.js` and `overrides/partials/model-names.html`; `scripts/notebooks.py` -> `docs/notebooks/*.ipynb` |
6161
| `data/frameworks.yml` | Engine metadata, blurbs, icons, URLs, `tuning_paths` | Rendered by Jinja macros (`{{ engines(...) }}`, `{{ paths(...) }}`) in pages |
6262
| `data/links.yml` | URLs used on more than one page, model version tags | `scripts/generate_snippets.py` -> `snippets/links.md` (auto-appended to all pages) |
6363
| `data/glossary.yml` | Acronyms and term definitions | `scripts/generate_snippets.py` -> `snippets/glossary.md` (opt-in via `--8<-- "glossary.md"`) |
@@ -68,6 +68,7 @@ Whenever editing files in `data/`, run:
6868
uv run --frozen python scripts/generate_model_names.py
6969
uv run --frozen python scripts/generate_snippets.py
7070
uv run --frozen python scripts/agent_docs.py
71+
uv run --frozen python scripts/notebooks.py
7172
```
7273
`scripts/lint_docs.py --check generated` will fail if generated files are out of sync with `data/`.
7374

@@ -83,14 +84,18 @@ Every page must have valid YAML frontmatter matching `scripts/frontmatter_schema
8384
title: Page Title
8485
description: Concise 1-2 sentence description for search and previews.
8586
models: [gemma-4] # Optional: list of relevant model family IDs
86-
frameworks: [ollama, vllm] # Optional: list of relevant framework IDs
87+
frameworks: [transformers] # Optional: list of relevant framework IDs
88+
requires: audio # Optional: required input modality (e.g. audio, vision)
89+
colab: https://colab.research.google.com/github/google-gemma/docs/blob/main/docs/notebooks/tutorial-gemma-4-e2b-it.ipynb # Optional: Colab link
8790
prerequisites: # Optional: list of prerequisite topics
8891
- get-started/index.md
8992
source_url: "https://..." # Mandatory on imported pages; omitted on original pages
9093
---
9194
```
9295
- **Authored keys only**: Do NOT add computed keys (e.g. token counts).
9396
- **Vocabularies**: Model and framework identifiers must exist in `data/models.yml` and `data/frameworks.yml`.
97+
- **Modality gating**: Use `requires:` to restrict model selection and notebook export to models supporting that modality (e.g., `audio` excludes 26B/31B).
98+
- **Colab link**: For swappable tutorials, link to the default model notebook (`-gemma-4-e2b-it.ipynb`). The model switcher updates the link dynamically when readers select other models.
9499

95100
### Headings and Anchor Links
96101
- Use standard markdown headings (`# H1`, `## 1. Step`, `### Substep`).
@@ -101,7 +106,7 @@ source_url: "https://..." # Mandatory on imported pages; omitted on original pa
101106
To enable interactive model switching in code examples:
102107
```python { .model-swap }
103108
# Use default model name in authoring; the JS switcher replaces it dynamically:
104-
model_id = "google/gemma-4-it"
109+
model_id = "google/gemma-4-E2B-it"
105110
```
106111

107112
### Shared Links & Citations
@@ -124,16 +129,24 @@ To create or edit a tutorial that exports to a Jupyter notebook:
124129
from transformers import AutoModelForCausalLM
125130
```
126131
````
127-
2. **Display-Only Code**: Normal fences (without `.notebook-cell`) stay in Markdown and become text cells in notebooks.
128-
3. **Outputs**: Fences marked `{ .output }` are omitted during notebook export.
129-
4. **Site-Only Blocks**: Wrap web-only elements (such as interactive widgets or card grids) in skip comments:
132+
2. **Model-Swappable Cells**: Combine with `{ .model-swap }` to export multi-model notebooks:
133+
````markdown
134+
```python { .notebook-cell .model-swap }
135+
model_id = "google/gemma-4-E2B-it"
136+
```
137+
````
138+
During export, `scripts/notebooks.py` detects swappable engines in marked blocks and candidate models matching any `requires:` frontmatter. For swappable tutorials, it generates model-specific notebooks named `<stem>-gemma-4-<size>-it.ipynb` (e.g., `thinking-gemma-4-e2b-it.ipynb`, `thinking-gemma-4-12b-it.ipynb`). Non-swappable tutorials generate a single `<stem>.ipynb`.
139+
3. **Display-Only Code**: Normal fences (without `.notebook-cell`) stay in Markdown and become text cells in notebooks.
140+
4. **Outputs**: Fences marked `{ .output }` are omitted during notebook export.
141+
5. **Site-Only Blocks**: Wrap web-only elements (such as interactive widgets or card grids) in skip comments:
130142
```markdown
131143
<!-- notebook:skip-start -->
132144
{{ engines(["ollama", "vllm"]) }}
133145
<!-- notebook:skip-end -->
134146
```
135-
5. **Registration**: Register new notebook tutorials in `NOTEBOOKS` in `scripts/notebooks.py`.
136-
6. **Export**: Run `uv run --frozen python scripts/notebooks.py` to regenerate `docs/notebooks/*.ipynb`.
147+
6. **Registration**: Register new notebook source tutorials in `SOURCES` in `scripts/notebooks.py`.
148+
7. **Colab Link**: For swappable tutorials, add the default model notebook's Colab URL to frontmatter (`colab: .../<stem>-gemma-4-e2b-it.ipynb`). The page context switcher dynamically updates the link when readers select a different model.
149+
8. **Export & Verify**: Run `uv run --frozen python scripts/notebooks.py` to regenerate `docs/notebooks/*.ipynb`, and verify with `uv run --frozen python scripts/notebooks.py --check`.
137150

138151
---
139152

0 commit comments

Comments
 (0)