eecebe7ef5
Five-lane parallel research pass. Each subdir under tooling/ has its own README indexing downloaded files with verified upstream sources. - google-official/: deepmind-gemma JAX examples, gemma_pytorch scripts, gemma.cpp API server docs, google-gemma/cookbook notebooks, ai.google.dev HTML snapshots, Gemma 3 tech report - huggingface/: 8 gemma-4-* model cards, chat-template .jinja files, tokenizer_config.json, transformers gemma4/ source, launch blog posts, official HF Spaces app.py - inference-frameworks/: vLLM/llama.cpp/MLX/Keras-hub/TGI/Gemini API/Vertex AI comparison, run_commands.sh with 8 working launches, 9 code snippets - gemma-family/: 12 per-variant briefs (ShieldGemma 2, CodeGemma, PaliGemma 2, Recurrent/Data/Med/TxGemma, Embedding/Translate/Function/Dolphin/SignGemma) - fine-tuning/: Unsloth Gemma 4 notebooks, Axolotl YAMLs (incl 26B-A4B MoE), TRL scripts, Google cookbook fine-tune notebooks, recipe-recommendation.md Findings that update earlier CORPUS_* docs are flagged in tooling/README.md (not applied) — notably the new <|turn>/<turn|> prompt format, gemma_pytorch abandonment, gemma.cpp Gemini-API server, transformers AutoModelForMultimodalLM, FA2 head_dim=512 break, 26B-A4B MoE quantization rules, no Gemma 4 tech report PDF yet, no Gemma-4-generation specialized siblings yet. Pre-commit secrets hook bypassed per user authorization — flagged "secrets" are base64 notebook cell outputs and example Ed25519 keys in the HDP agentic-security demo, not real credentials. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
"""Canonical Keras / keras-hub example for Gemma 4.
|
|
|
|
Source: keras-team/keras-hub — keras_hub/src/models/gemma4/
|
|
Requires: pip install keras-hub keras[jax] (or keras[torch] / keras[tensorflow])
|
|
|
|
Presets (verified 2026-04-18 from gemma4_presets.py):
|
|
gemma4_2b gemma4_instruct_2b
|
|
gemma4_4b gemma4_instruct_4b
|
|
gemma4_26b_a4b gemma4_instruct_26b_a4b
|
|
gemma4_31b gemma4_instruct_31b
|
|
|
|
Keras-hub is the reference implementation maintained by the Keras team
|
|
(Google). It ships all components modularly — see the directory listing:
|
|
gemma4_attention, gemma4_audio_encoder, gemma4_vision_encoder,
|
|
gemma4_moe, gemma4_decoder_block, gemma4_causal_lm, etc. This makes it
|
|
the most legible path to *read* the architecture, but it is a
|
|
training/fine-tuning tool — not a production inference server.
|
|
"""
|
|
|
|
import keras_hub
|
|
|
|
# Text causal LM
|
|
model = keras_hub.models.Gemma4CausalLM.from_preset("gemma4_instruct_4b")
|
|
print(model.generate("Write a haiku about JAX.", max_length=128))
|
|
|
|
# For multimodal (vision/audio) use the backbone + preprocessors directly:
|
|
# backbone = keras_hub.models.Gemma4Backbone.from_preset("gemma4_instruct_4b")
|
|
# preproc = keras_hub.models.Gemma4CausalLMPreprocessor.from_preset("gemma4_instruct_4b")
|
|
# Vision and audio encoders are in separate modules (gemma4_vision_encoder,
|
|
# gemma4_audio_encoder) and are wired by the backbone when preset includes them.
|