gm#

[[Source]]

from gemma import gm

Kauldron API for Gemma.

All symbols#

Module#

gm

Kauldron API for Gemma.

gm.ckpts

Checkpoints API.

gm.data

Data pipeline ops.

gm.evals

Evaluators for Gemma.

gm.losses

Losses.

gm.math

Math utils (attention masks, positional embeddings, …).

gm.nn

Gemma models.

gm.nn.config

Symbols needed to build new TransformerConfig.

gm.sharding

Sharding utilities.

gm.testing

Testing utilities (dummy models, tokenizer,…).

gm.text

Text processing utilities.

gm.tools

Tools.

gm.typing

Common types for Gemma.

Class#

gm.ckpts.AnchoredPolicyLoader

Loader for gm.nn.AnchoredPolicy models.

gm.ckpts.CheckpointPath

Hardcoded paths to Gemma checkpoints.

gm.ckpts.LoadCheckpoint

Loads weights from a Gemma checkpoint.

gm.ckpts.SkipLoRA

Wraps a partial loader to not restore the LoRA weights.

gm.data.AddSeq2SeqFields

Adds the model input, target and loss_mask.

gm.data.ContrastiveTask

Creates the contrastive model inputs for DPO-like loss.

gm.data.DecodeBytes

Decode bytes to str.

gm.data.FormatText

Equivalent to template.format(text=my_string).

gm.data.MapInts

Replace each int by a new value.

gm.data.Pad

Add zeros to the end of the sequence to reach the max length.

gm.data.Parquet

Parquet(*, _fake_refs: ‘type[_FakeRefsUnset]

gm.data.Seq2SeqTask

Sequence-to-sequence task.

gm.data.Tokenize

Tokenize a string to ids.

gm.evals.SamplerEvaluator

Sampling evaluator.

gm.losses.DpoLoss

DPO loss.

gm.losses.NpoLoss

NPO loss.

gm.nn.AnchoredPolicy

Wrapper around a model to compute policy and anchor outputs.

gm.nn.AnchoredPolicyOutput

Output of the gm.nn.AnchoredPolicy.

gm.nn.Attention

Attention module.

gm.nn.AttentionType

gm.nn.Block

Transformer block.

gm.nn.Einsum

Einsum is a convenience module for parameterized tensor multiplication.

gm.nn.Embedder

Embedder module.

gm.nn.FeedForward

Feed forward module.

gm.nn.Gemma2_27B

Gemma2 transformer architecture.

gm.nn.Gemma2_2B

Gemma2 transformer architecture.

gm.nn.Gemma2_9B

Gemma2 transformer architecture.

gm.nn.Gemma3_12B

Gemma3 transformer architecture.

gm.nn.Gemma3_1B

Gemma3 transformer architecture.

gm.nn.Gemma3_270M

Gemma3 transformer architecture.

gm.nn.Gemma3_27B

Gemma3 transformer architecture.

gm.nn.Gemma3_4B

Gemma3 transformer architecture.

gm.nn.Gemma3n_E2B

Gemma3n E2B transformer architecture.

gm.nn.Gemma3n_E4B

Gemma3n E4B transformer architecture.

gm.nn.Gemma4_26B_A4B

Gemma 4 26B_A4B MoE model.

gm.nn.Gemma4_31B

Gemma 4 31B model.

gm.nn.Gemma4_E2B

Gemma 4 E2B model.

gm.nn.Gemma4_E4B

Gemma 4 E4B model.

gm.nn.IntWrapper

Wrapper around a Gemma model to enable int4 inference.

gm.nn.LoRA

Wrapper around a Gemma model to enable LoRA.

gm.nn.Output

Output of the Gemma model.

gm.nn.QuantizationAwareWrapper

Wrapper around a Gemma model to enable quantization aware training.

gm.nn.RMSNorm

RMSNorm layer.

gm.nn.SigLiPFromPatches

SigLIP vision encoder forward pass from PatchifiedMedia.

gm.nn.Transformer

Base transformer class.

gm.nn.TransformerLike

Protocol for a transformer model to be used with a Sampler.

gm.testing.DummyGemma

Dummy transformer architecture, for testing.

gm.testing.DummyTokenizer

Dummy tokenizer.

gm.text.ChatSampler

Chat sampler.

gm.text.Gemma2Tokenizer

Tokenizer for Gemma 2.

gm.text.Gemma3Tokenizer

Tokenizer for Gemma 3.

gm.text.Gemma3nTokenizer

Tokenizer for Gemma3n.

gm.text.Gemma4Sampler

Stateless sampler for Gemma4 with variable-aspect-ratio image support.

gm.text.Gemma4Tokenizer

Tokenizer for Gemma 4.

gm.text.Greedy

Greedy sampling.

gm.text.RandomSampling

Simple random sampling.

gm.text.Sampler

Sampler.

gm.text.SamplingMethod

Base class for sampling methods.

gm.text.SpecialTokens

Special tokens ids.

gm.text.Tokenizer

Base class for tokenizers.

gm.text.ToolSampler

Sampler with tool support.

gm.text.TopPSampling

Top-p (Nucleus) Sampling.

gm.text.TopkSampling

Top-k sampling.

gm.tools.McpToolHandler

Mcp tool handler.

gm.tools.ToolHandlerBase

Base class to orchestrate tools.

Function#

gm.ckpts.load_params

Restore the params from a checkpoint.

gm.ckpts.save_params

Save the params to a checkpoint.

gm.data.make_seq2seq_fields

Create the model input, target and loss_mask.

gm.data.pad

Add zeros to the end of the sequence to reach the max length.

gm.math.apply_rope

Applies RoPE.

gm.math.count_consecutive

Counts consecutive identical elements in a list.

gm.testing.use_hermetic_tokenizer

Use the local tokenizer, to avoid TFHub calls.

Typing#