DiffusionGemmaBlockDiffusionLMPreprocessor classkeras_hub.models.DiffusionGemmaBlockDiffusionLMPreprocessor(
tokenizer,
image_converter=None,
sequence_length=1024,
canvas_length=256,
add_start_token=True,
add_end_token=True,
max_images_per_prompt=2,
num_vision_tokens_per_image=280,
stop_token_ids=None,
**kwargs
)
Preprocessing layer for DiffusionGemma diffusion language model tasks.
Tokenizes and packs prompt strings, optionally expanding image placeholders. The task model creates the canvas during generation.
This layer supports two operational modes:
- Text-only: no converters provided; plain string or dict with
"prompts" key accepted.
- Image: pass an image_converter; the prompt may contain
<|image|> placeholders that are expanded to per-patch soft tokens.
The preprocessor accepts input as plain strings or as dicts with the following keys:
"prompts" (required): string or batch of strings."responses" (optional): string or batch of strings used only during
training (the call() path)."images" (optional): image tensor(s) matching <|image|>
occurrences in the prompts.During generation (generate_preprocess()), only the packed prompt
tokens are returned. The canvas is initialised inside generate_step
via _init_canvas so that _encode_prompt always receives the prompt
alone, matching the HuggingFace encoder/decoder split.
Arguments
keras_hub.models.DiffusionGemmaTokenizer instance.keras_hub.layers.DiffusionGemmaImageConverter
instance. Defaults to None.1024.canvas_length sets the canvas size. Defaults to 256.True.True.2.280.generate_postprocess(), in addition to the
tokenizer's special tokens. Defaults to None.from_preset methodDiffusionGemmaBlockDiffusionLMPreprocessor.from_preset(
preset, config_file="preprocessor.json", **kwargs
)
Instantiate a keras_hub.models.Preprocessor from a model preset.
A preset is a directory of configs, weights and other file assets used
to save and load a pre-trained model. The preset can be passed as
one of:
'bert_base_en''kaggle://user/bert/keras/bert_base_en''hf://user/bert_base_en''./bert_base_en'For any Preprocessor subclass, you can run cls.presets.keys() to
list all built-in presets available on the class.
As there are usually multiple preprocessing classes for a given model,
this method should be called on a specific subclass like
keras_hub.models.BertTextClassifierPreprocessor.from_preset().
Arguments
Examples
# Load a preprocessor for Gemma generation.
preprocessor = keras_hub.models.CausalLMPreprocessor.from_preset(
"gemma_2b_en",
)
# Load a preprocessor for Bert classification.
preprocessor = keras_hub.models.TextClassifierPreprocessor.from_preset(
"bert_base_en",
)
| Preset | Parameters | Description |
|---|---|---|
| diffusion_gemma_26b_a4b_it | 25.82B | DiffusionGemma 26B MoE instruction-tuned model. 25.8B total parameters (3.8B active), 30 layers, 128 experts. |
tokenizer propertykeras_hub.models.DiffusionGemmaBlockDiffusionLMPreprocessor.tokenizer
The tokenizer used to tokenize strings.
image_converter propertykeras_hub.models.DiffusionGemmaBlockDiffusionLMPreprocessor.image_converter
The image converter used to preprocess image data.