---
title: t5gemma
---

<div class="python-reference">

<a id="fastvideo.configs.models.encoders.t5gemma"></a>
<p>Config for the T5-Gemma encoder used by daVinci-MagiHuman.</p>
<p>The reference pipeline uses <code>transformers.models.t5gemma.T5GemmaEncoderModel</code>
on <code>google/t5gemma-9b-9b-ul2</code>. That is a gated Google repository, so the
encoder weights are not bundled inside GAIR/daVinci-MagiHuman; they are
loaded from the T5-Gemma HF repo directly.</p>
<p>Encoder shape (verified from google/t5gemma-9b-9b-ul2/config.json):
    layers=42, hidden=3584, heads=16, kv_heads=8, head_dim=256,
    intermediate=14336, rope_theta=10000.0, max_pos=8192,
    layer_types alternate sliding_attention / full_attention.</p>
<h2 id="fastvideo.configs.models.encoders.t5gemma.TextEncoderArchConfig"><code>fastvideo.configs.models.encoders.t5gemma.TextEncoderArchConfig</code></h2>
<pre class="doc-signature"><code>TextEncoderArchConfig(stacked_params_mapping: list&#91;tuple&#91;str, str, str&#93;&#93; = list(), architectures: list&#91;str&#93; = (lambda: &#91;&#93;)(), _supported_attention_backends: tuple&#91;AttentionBackendEnum, ...&#93; = (AttentionBackendEnum.FLASH_ATTN, AttentionBackendEnum.TORCH_SDPA), output_hidden_states: bool = False, use_return_dict: bool = True, vocab_size: int = 0, hidden_size: int = 0, num_hidden_layers: int = 0, num_attention_heads: int = 0, pad_token_id: int = 0, eos_token_id: int = 0, text_len: int = 0, hidden_state_skip_layer: int = 0, decoder_start_token_id: int = 0, output_past: bool = True, scalable_attention: bool = True, tie_word_embeddings: bool = False, tokenizer_kwargs: dict&#91;str, Any&#93; = dict(), _fsdp_shard_conditions: list = (lambda: &#91;&#93;)(), require_processor: bool = False)</code></pre>


<h2 id="fastvideo.configs.models.encoders.t5gemma.TextEncoderConfig"><code>fastvideo.configs.models.encoders.t5gemma.TextEncoderConfig</code></h2>
<pre class="doc-signature"><code>TextEncoderConfig(arch_config: ArchConfig = TextEncoderArchConfig(), prefix: str = &#x27;&#x27;, quant_config: QuantizationConfig | None = None, lora_config: Any | None = None, is_chat_model: bool = False, treat_empty_as_dot: bool = False, *, _resolved_attention_backend: AttentionBackendEnum | None = None, chat_template_enable_thinking: bool = False)</code></pre>


<h2 id="fastvideo.configs.models.encoders.t5gemma.T5GemmaEncoderArchConfig"><code>fastvideo.configs.models.encoders.t5gemma.T5GemmaEncoderArchConfig</code></h2>
<pre class="doc-signature"><code>T5GemmaEncoderArchConfig(stacked_params_mapping: list&#91;tuple&#91;str, str, str&#93;&#93; = list(), architectures: list&#91;str&#93; = (lambda: &#91;&#x27;T5GemmaEncoderModel&#x27;&#93;)(), _supported_attention_backends: tuple&#91;AttentionBackendEnum, ...&#93; = (AttentionBackendEnum.FLASH_ATTN, AttentionBackendEnum.TORCH_SDPA), output_hidden_states: bool = False, use_return_dict: bool = True, vocab_size: int = 256000, hidden_size: int = 3584, num_hidden_layers: int = 42, num_attention_heads: int = 16, pad_token_id: int = 0, eos_token_id: int = 1, text_len: int = 640, hidden_state_skip_layer: int = 0, decoder_start_token_id: int = 0, output_past: bool = True, scalable_attention: bool = True, tie_word_embeddings: bool = False, tokenizer_kwargs: dict&#91;str, Any&#93; = dict(), _fsdp_shard_conditions: list = list(), require_processor: bool = False, num_key_value_heads: int = 8, head_dim: int = 256, intermediate_size: int = 14336, max_position_embeddings: int = 8192, rope_theta: float = 10000.0, t5gemma_model_path: str = &#x27;google/t5gemma-9b-9b-ul2&#x27;, t5gemma_dtype: str = &#x27;bfloat16&#x27;)</code></pre>


<details><summary>Source</summary><pre><code>@dataclass
class T5GemmaEncoderArchConfig(TextEncoderArchConfig):
    architectures: list&#91;str&#93; = field(default_factory=lambda: &#91;&quot;T5GemmaEncoderModel&quot;&#93;)

    hidden_size: int = 3584
    num_hidden_layers: int = 42
    num_attention_heads: int = 16
    num_key_value_heads: int = 8
    head_dim: int = 256
    intermediate_size: int = 14336
    max_position_embeddings: int = 8192
    rope_theta: float = 10000.0
    vocab_size: int = 256000

    # MagiHuman fixes prompt embed length at 640 via pad_or_trim.
    text_len: int = 640

    pad_token_id: int = 0
    eos_token_id: int = 1

    # Path to the upstream gated repo. When set, the FastVideo loader will
    # pull the encoder directly via `T5GemmaEncoderModel.from_pretrained`.
    t5gemma_model_path: str = &quot;google/t5gemma-9b-9b-ul2&quot;
    t5gemma_dtype: str = &quot;bfloat16&quot;

    # The HF T5-Gemma encoder is lazy-loaded on first forward (see
    # `fastvideo/models/encoders/t5gemma.py`), so no FastVideo-owned
    # submodules exist at FSDP-apply time. An empty list makes
    # `shard_model()` log a warning and return cleanly instead of raising
    # &quot;No layer modules were sharded&quot; — sharding of the lazy HF model is
    # the activation pipeline&#x27;s responsibility.
    _fsdp_shard_conditions: list = field(default_factory=list)

    def __post_init__(self) -&gt; None:
        super().__post_init__()
        # WHY: upstream `t5_gemma_model.py:25` tokenizes without
        # padding/max_length, then `prompt_process.py` pad_or_trim-s the
        # encoded states. Keep only tensor return here so
        # MagiHumanLatentPreparationStage can pad/trim post-encode while
        # preserving the real original prompt length.
        self.tokenizer_kwargs.pop(&quot;truncation&quot;, None)
        self.tokenizer_kwargs.pop(&quot;max_length&quot;, None)
        self.tokenizer_kwargs.pop(&quot;padding&quot;, None)</code></pre></details>
<h2 id="fastvideo.configs.models.encoders.t5gemma.T5GemmaEncoderConfig"><code>fastvideo.configs.models.encoders.t5gemma.T5GemmaEncoderConfig</code></h2>
<pre class="doc-signature"><code>T5GemmaEncoderConfig(arch_config: TextEncoderArchConfig = T5GemmaEncoderArchConfig(), prefix: str = &#x27;t5gemma&#x27;, quant_config: QuantizationConfig | None = None, lora_config: Any | None = None, is_chat_model: bool = False, treat_empty_as_dot: bool = False, *, _resolved_attention_backend: AttentionBackendEnum | None = None, chat_template_enable_thinking: bool = False)</code></pre>


<details><summary>Source</summary><pre><code>@dataclass
class T5GemmaEncoderConfig(TextEncoderConfig):
    arch_config: TextEncoderArchConfig = field(default_factory=T5GemmaEncoderArchConfig)

    prefix: str = &quot;t5gemma&quot;</code></pre></details>
</div>
