T5Gemma2Backbone classkeras_hub.models.T5Gemma2Backbone(
vocabulary_size,
encoder_hidden_dim,
encoder_intermediate_dim,
encoder_num_layers,
encoder_num_attention_heads,
encoder_num_key_value_heads,
encoder_head_dim,
encoder_layer_types,
decoder_hidden_dim,
decoder_intermediate_dim,
decoder_num_layers,
decoder_num_attention_heads,
decoder_num_key_value_heads,
decoder_head_dim,
decoder_layer_types,
dropout_rate=0.0,
rms_norm_eps=1e-06,
query_pre_attn_scalar=1.0,
attention_bias=False,
hidden_activation="gelu_approximate",
tie_word_embeddings=True,
initializer_range=0.02,
attention_dropout=0.0,
sliding_window=None,
cross_attention_hidden_size=None,
attn_logit_softcapping=None,
final_logit_softcapping=None,
rope_max_wavelength=10000.0,
global_rope_scaling_factor=1.0,
encoder_rope_max_wavelength=None,
encoder_global_rope_scaling_factor=None,
use_query_key_norm=True,
vision_encoder=None,
eoi_token_index=256000,
dtype=None,
**kwargs
)
T5Gemma2 backbone model.
This class implements the encoder-decoder backbone of the T5Gemma2 model. T5Gemma2 is based on Gemma3 and features merged self+cross attention in the decoder (unlike T5Gemma which used separate attention sublayers), Gemma3-style Q/K normalization, and per-layer-type sliding window attention patterns.
When a vision_encoder is provided, the model also accepts image
inputs. Images are processed by the vision encoder and the resulting
embeddings are interleaved into the encoder text embeddings at
positions marked by image placeholder tokens.
Arguments
"full_attention" or
"sliding_attention").0.0.1e-6.1.0.False."gelu_approximate".True.0.02.0.0.encoder_hidden_dim.10000.0.1.0.True.Gemma3VisionEncoder instance for
multimodal inputs. When None, the model is text-only.256000.None.Examples
import numpy as np
from keras_hub.models import T5Gemma2Backbone
input_data = {
"encoder_token_ids": np.ones(shape=(1, 12), dtype="int32"),
"encoder_padding_mask": np.array(
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0]], dtype="int32"
),
"decoder_token_ids": np.ones(shape=(1, 8), dtype="int32"),
"decoder_padding_mask": np.array(
[[1, 1, 1, 1, 1, 1, 1, 1]], dtype="int32"
),
}
model = T5Gemma2Backbone(
vocabulary_size=32000,
encoder_hidden_dim=256,
encoder_intermediate_dim=512,
encoder_num_layers=4,
encoder_num_attention_heads=4,
encoder_num_key_value_heads=2,
encoder_head_dim=64,
encoder_layer_types=["full_attention"] * 4,
decoder_hidden_dim=256,
decoder_intermediate_dim=512,
decoder_num_layers=4,
decoder_num_attention_heads=4,
decoder_num_key_value_heads=2,
decoder_head_dim=64,
decoder_layer_types=["full_attention"] * 4,
dropout_rate=0.1,
rms_norm_eps=1e-6,
query_pre_attn_scalar=1.0,
attention_bias=False,
hidden_activation="gelu_approximate",
)
output = model(input_data)
from_preset methodT5Gemma2Backbone.from_preset(preset, load_weights=True, **kwargs)
Instantiate a keras_hub.models.Backbone 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 a
one of:
'bert_base_en''kaggle://user/bert/keras/bert_base_en''hf://user/bert_base_en''modelscope://user/bert_base_en''./bert_base_en'This constructor can be called in one of two ways. Either from the base
class like keras_hub.models.Backbone.from_preset(), or from
a model class like keras_hub.models.GemmaBackbone.from_preset().
If calling from the base class, the subclass of the returning object
will be inferred from the config in the preset directory.
For any Backbone subclass, you can run cls.presets.keys() to list
all built-in presets available on the class.
Arguments
True, the weights will be loaded into the
model architecture. If False, the weights will be randomly
initialized.Examples
# Load a Gemma backbone with pre-trained weights.
model = keras_hub.models.Backbone.from_preset(
"gemma_2b_en",
)
# Load a Bert backbone with a pre-trained config and random weights.
model = keras_hub.models.Backbone.from_preset(
"bert_base_en",
load_weights=False,
)
| Preset | Parameters | Description |
|---|---|---|
| t5gemma2_270m_270m | 953.80M | Encoder–decoder (T5-style) based out of Gemma3 model with 270M encoder + 270M decoder parameters, supporting text generation, multilingual tasks and long-context inputs. |
| t5gemma2_1b_1b | 2.42B | Encoder–decoder (T5-style) based out of Gemma3 model with 1B encoder + 1B decoder parameters, supporting text generation, multilingual tasks and long-context inputs. |
| t5gemma2_4b_4b | 8.18B | Encoder–decoder (T5-style) based out of Gemma3 model with 4B encoder + 4B decoder parameters, supporting text generation, multilingual tasks and long-context inputs. |
token_embedding propertykeras_hub.models.T5Gemma2Backbone.token_embedding
A keras.layers.Embedding instance for embedding token ids.
This layer embeds integer token ids to the hidden dim of the model.