---
title: lingbotworld2_t5
---

<div class="python-reference">
<a id="fastvideo.models.encoders.lingbotworld2_t5-classes"></a>
<a id="fastvideo.models.encoders.lingbotworld2_t5-functions"></a>
<a id="fastvideo.models.encoders.lingbotworld2_t5.GELU-functions"></a>
<a id="fastvideo.models.encoders.lingbotworld2_t5.LingBotWorld2T5EncoderModel-functions"></a>
<a id="fastvideo.models.encoders.lingbotworld2_t5.T5Attention-functions"></a>
<a id="fastvideo.models.encoders.lingbotworld2_t5.T5FeedForward-functions"></a>
<a id="fastvideo.models.encoders.lingbotworld2_t5.T5LayerNorm-functions"></a>
<a id="fastvideo.models.encoders.lingbotworld2_t5.T5RelativeEmbedding-functions"></a>
<a id="fastvideo.models.encoders.lingbotworld2_t5.T5SelfAttention-functions"></a>
<a id="fastvideo.models.encoders.lingbotworld2_t5"></a>
<p>LingBot World 2 UMT5 encoder with the released checkpoint's module names.</p>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.BaseEncoderOutput"><code>fastvideo.models.encoders.lingbotworld2_t5.BaseEncoderOutput</code></h2>
<pre class="doc-signature"><code>BaseEncoderOutput(last_hidden_state: torch.FloatTensor | None = None, pooler_output: torch.FloatTensor | None = None, hidden_states: tuple&#91;torch.FloatTensor, ...&#93; | None = None, attentions: tuple&#91;torch.FloatTensor, ...&#93; | None = None, attention_mask: torch.Tensor | None = None)</code></pre>


<h2 id="fastvideo.models.encoders.lingbotworld2_t5.LingBotWorld2UMT5Config"><code>fastvideo.models.encoders.lingbotworld2_t5.LingBotWorld2UMT5Config</code></h2>
<pre class="doc-signature"><code>LingBotWorld2UMT5Config(arch_config: TextEncoderArchConfig = LingBotWorld2UMT5ArchConfig(), prefix: str = &#x27;text_encoder&#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.models.encoders.lingbotworld2_t5.TextEncoder"><code>fastvideo.models.encoders.lingbotworld2_t5.TextEncoder</code></h2>
<pre class="doc-signature"><code>TextEncoder(config: TextEncoderConfig)</code></pre>
<p>Base for native encoders with a model-specific forward output contract.</p>

<h3 id="fastvideo.models.encoders.lingbotworld2_t5.TextEncoder.forward"><code>fastvideo.models.encoders.lingbotworld2_t5.TextEncoder.forward</code></h3>
<pre class="doc-signature"><code>forward(*args: Any, **kwargs: Any) -&gt; TextEncoderOutputT</code></pre>

<h2 id="fastvideo.models.encoders.lingbotworld2_t5.default_weight_loader"><code>fastvideo.models.encoders.lingbotworld2_t5.default_weight_loader</code></h2>
<pre class="doc-signature"><code>default_weight_loader(param: torch.Tensor, loaded_weight: torch.Tensor) -&gt; None</code></pre>
<p>Default weight loader.</p>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.basic_clean"><code>fastvideo.models.encoders.lingbotworld2_t5.basic_clean</code></h2>
<pre class="doc-signature"><code>basic_clean(text: str) -&gt; str</code></pre>
<p>Apply LingBot World 2's ftfy/html cleanup before tokenization.</p>
<details><summary>Source</summary><pre><code>def basic_clean(text: str) -&gt; str:
    &quot;&quot;&quot;Apply LingBot World 2&#x27;s ftfy/html cleanup before tokenization.&quot;&quot;&quot;
    text = ftfy.fix_text(text)
    text = html.unescape(html.unescape(text))
    return text.strip()</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.whitespace_clean"><code>fastvideo.models.encoders.lingbotworld2_t5.whitespace_clean</code></h2>
<pre class="doc-signature"><code>whitespace_clean(text: str) -&gt; str</code></pre>
<p>Collapse all whitespace runs to single spaces.</p>
<details><summary>Source</summary><pre><code>def whitespace_clean(text: str) -&gt; str:
    &quot;&quot;&quot;Collapse all whitespace runs to single spaces.&quot;&quot;&quot;
    return &quot; &quot;.join(text.split())</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.canonicalize"><code>fastvideo.models.encoders.lingbotworld2_t5.canonicalize</code></h2>
<pre class="doc-signature"><code>canonicalize(text: str, keep_punctuation_exact_string: str | None = None) -&gt; str</code></pre>
<p>Normalize prompts with LingBot World 2's optional punctuation handling.</p>
<details><summary>Source</summary><pre><code>def canonicalize(text: str, keep_punctuation_exact_string: str | None = None) -&gt; str:
    &quot;&quot;&quot;Normalize prompts with LingBot World 2&#x27;s optional punctuation handling.&quot;&quot;&quot;
    text = text.replace(&quot;_&quot;, &quot; &quot;)
    if keep_punctuation_exact_string:
        text = keep_punctuation_exact_string.join(
            part.translate(str.maketrans(&quot;&quot;, &quot;&quot;, string.punctuation))
            for part in text.split(keep_punctuation_exact_string))
    else:
        text = text.translate(str.maketrans(&quot;&quot;, &quot;&quot;, string.punctuation))
    return &quot; &quot;.join(text.lower().split())</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.lingbotworld2_whitespace_preprocess"><code>fastvideo.models.encoders.lingbotworld2_t5.lingbotworld2_whitespace_preprocess</code></h2>
<pre class="doc-signature"><code>lingbotworld2_whitespace_preprocess(prompt: str) -&gt; str</code></pre>
<p>Match the LingBot World 2 source tokenizer's <code>clean='whitespace'</code> behavior.</p>
<details><summary>Source</summary><pre><code>def lingbotworld2_whitespace_preprocess(prompt: str) -&gt; str:
    &quot;&quot;&quot;Match the LingBot World 2 source tokenizer&#x27;s `clean=&#x27;whitespace&#x27;` behavior.&quot;&quot;&quot;
    return whitespace_clean(basic_clean(prompt))</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.GELU"><code>fastvideo.models.encoders.lingbotworld2_t5.GELU</code></h2>
<pre class="doc-signature"><code>GELU()</code></pre>
<p>T5 gated GELU approximation used by the source checkpoint.</p>
<details><summary>Source</summary><pre><code>class GELU(nn.Module):
    &quot;&quot;&quot;T5 gated GELU approximation used by the source checkpoint.&quot;&quot;&quot;

    def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
        &quot;&quot;&quot;Apply the tanh GELU approximation.&quot;&quot;&quot;
        return 0.5 * x * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi) * (x + 0.044715 * torch.pow(x, 3.0))))</code></pre></details>
<h3 id="fastvideo.models.encoders.lingbotworld2_t5.GELU.forward"><code>fastvideo.models.encoders.lingbotworld2_t5.GELU.forward</code></h3>
<pre class="doc-signature"><code>forward(x: torch.Tensor) -&gt; torch.Tensor</code></pre>
<p>Apply the tanh GELU approximation.</p>
<details><summary>Source</summary><pre><code>def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
    &quot;&quot;&quot;Apply the tanh GELU approximation.&quot;&quot;&quot;
    return 0.5 * x * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi) * (x + 0.044715 * torch.pow(x, 3.0))))</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.T5LayerNorm"><code>fastvideo.models.encoders.lingbotworld2_t5.T5LayerNorm</code></h2>
<pre class="doc-signature"><code>T5LayerNorm(dim: int, eps: float = 1e-06)</code></pre>
<p>T5 RMS-style layer norm with source-compatible parameter name.</p>

<details><summary>Source</summary><pre><code>class T5LayerNorm(nn.Module):
    &quot;&quot;&quot;T5 RMS-style layer norm with source-compatible parameter name.&quot;&quot;&quot;

    def __init__(self, dim: int, eps: float = 1e-6):
        super().__init__()
        self.dim = dim
        self.eps = eps
        self.weight = nn.Parameter(torch.ones(dim))

    def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
        &quot;&quot;&quot;Normalize in fp32 and apply the learned scale.&quot;&quot;&quot;
        x = x * torch.rsqrt(x.float().pow(2).mean(dim=-1, keepdim=True) + self.eps)
        if self.weight.dtype in (torch.float16, torch.bfloat16):
            x = x.type_as(self.weight)
        return self.weight * x</code></pre></details>
<h3 id="fastvideo.models.encoders.lingbotworld2_t5.T5LayerNorm.forward"><code>fastvideo.models.encoders.lingbotworld2_t5.T5LayerNorm.forward</code></h3>
<pre class="doc-signature"><code>forward(x: torch.Tensor) -&gt; torch.Tensor</code></pre>
<p>Normalize in fp32 and apply the learned scale.</p>
<details><summary>Source</summary><pre><code>def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
    &quot;&quot;&quot;Normalize in fp32 and apply the learned scale.&quot;&quot;&quot;
    x = x * torch.rsqrt(x.float().pow(2).mean(dim=-1, keepdim=True) + self.eps)
    if self.weight.dtype in (torch.float16, torch.bfloat16):
        x = x.type_as(self.weight)
    return self.weight * x</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.T5Attention"><code>fastvideo.models.encoders.lingbotworld2_t5.T5Attention</code></h2>
<pre class="doc-signature"><code>T5Attention(dim: int, dim_attn: int, num_heads: int, dropout: float = 0.1)</code></pre>
<p>LingBot World 2 source T5 attention block.</p>

<details><summary>Source</summary><pre><code>class T5Attention(nn.Module):
    &quot;&quot;&quot;LingBot World 2 source T5 attention block.&quot;&quot;&quot;

    def __init__(self, dim: int, dim_attn: int, num_heads: int, dropout: float = 0.1):
        super().__init__()
        assert dim_attn % num_heads == 0
        self.dim = dim
        self.dim_attn = dim_attn
        self.num_heads = num_heads
        self.head_dim = dim_attn // num_heads
        self.q = nn.Linear(dim, dim_attn, bias=False)
        self.k = nn.Linear(dim, dim_attn, bias=False)
        self.v = nn.Linear(dim, dim_attn, bias=False)
        self.o = nn.Linear(dim_attn, dim, bias=False)
        self.dropout = nn.Dropout(dropout)

    def forward(
        self,
        x: torch.Tensor,
        context: torch.Tensor | None = None,
        mask: torch.Tensor | None = None,
        pos_bias: torch.Tensor | None = None,
    ) -&gt; torch.Tensor:
        &quot;&quot;&quot;Project QKV, add relative bias/mask, and return attended states.&quot;&quot;&quot;
        context = x if context is None else context
        b, n, c = x.size(0), self.num_heads, self.head_dim
        q = self.q(x).view(b, -1, n, c)
        k = self.k(context).view(b, -1, n, c)
        v = self.v(context).view(b, -1, n, c)
        attn_bias = x.new_zeros(b, n, q.size(1), k.size(1))
        if pos_bias is not None:
            attn_bias += pos_bias
        if mask is not None:
            assert mask.ndim in (2, 3)
            mask = mask.view(b, 1, 1, -1) if mask.ndim == 2 else mask.unsqueeze(1)
            attn_bias.masked_fill_(mask == 0, torch.finfo(x.dtype).min)
        attn = torch.einsum(&quot;binc,bjnc-&gt;bnij&quot;, q, k) + attn_bias
        attn = F.softmax(attn.float(), dim=-1).type_as(attn)
        x = torch.einsum(&quot;bnij,bjnc-&gt;binc&quot;, attn, v)
        return self.dropout(self.o(x.reshape(b, -1, n * c)))</code></pre></details>
<h3 id="fastvideo.models.encoders.lingbotworld2_t5.T5Attention.forward"><code>fastvideo.models.encoders.lingbotworld2_t5.T5Attention.forward</code></h3>
<pre class="doc-signature"><code>forward(x: torch.Tensor, context: torch.Tensor | None = None, mask: torch.Tensor | None = None, pos_bias: torch.Tensor | None = None) -&gt; torch.Tensor</code></pre>
<p>Project QKV, add relative bias/mask, and return attended states.</p>
<details><summary>Source</summary><pre><code>def forward(
    self,
    x: torch.Tensor,
    context: torch.Tensor | None = None,
    mask: torch.Tensor | None = None,
    pos_bias: torch.Tensor | None = None,
) -&gt; torch.Tensor:
    &quot;&quot;&quot;Project QKV, add relative bias/mask, and return attended states.&quot;&quot;&quot;
    context = x if context is None else context
    b, n, c = x.size(0), self.num_heads, self.head_dim
    q = self.q(x).view(b, -1, n, c)
    k = self.k(context).view(b, -1, n, c)
    v = self.v(context).view(b, -1, n, c)
    attn_bias = x.new_zeros(b, n, q.size(1), k.size(1))
    if pos_bias is not None:
        attn_bias += pos_bias
    if mask is not None:
        assert mask.ndim in (2, 3)
        mask = mask.view(b, 1, 1, -1) if mask.ndim == 2 else mask.unsqueeze(1)
        attn_bias.masked_fill_(mask == 0, torch.finfo(x.dtype).min)
    attn = torch.einsum(&quot;binc,bjnc-&gt;bnij&quot;, q, k) + attn_bias
    attn = F.softmax(attn.float(), dim=-1).type_as(attn)
    x = torch.einsum(&quot;bnij,bjnc-&gt;binc&quot;, attn, v)
    return self.dropout(self.o(x.reshape(b, -1, n * c)))</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.T5FeedForward"><code>fastvideo.models.encoders.lingbotworld2_t5.T5FeedForward</code></h2>
<pre class="doc-signature"><code>T5FeedForward(dim: int, dim_ffn: int, dropout: float = 0.1)</code></pre>
<p>LingBot World 2 source T5 gated feed-forward block.</p>

<details><summary>Source</summary><pre><code>class T5FeedForward(nn.Module):
    &quot;&quot;&quot;LingBot World 2 source T5 gated feed-forward block.&quot;&quot;&quot;

    def __init__(self, dim: int, dim_ffn: int, dropout: float = 0.1):
        super().__init__()
        self.dim = dim
        self.dim_ffn = dim_ffn
        self.gate = nn.Sequential(nn.Linear(dim, dim_ffn, bias=False), GELU())
        self.fc1 = nn.Linear(dim, dim_ffn, bias=False)
        self.fc2 = nn.Linear(dim_ffn, dim, bias=False)
        self.dropout = nn.Dropout(dropout)

    def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
        &quot;&quot;&quot;Apply the gated feed-forward projection.&quot;&quot;&quot;
        x = self.fc1(x) * self.gate(x)
        x = self.dropout(x)
        x = self.fc2(x)
        return self.dropout(x)</code></pre></details>
<h3 id="fastvideo.models.encoders.lingbotworld2_t5.T5FeedForward.forward"><code>fastvideo.models.encoders.lingbotworld2_t5.T5FeedForward.forward</code></h3>
<pre class="doc-signature"><code>forward(x: torch.Tensor) -&gt; torch.Tensor</code></pre>
<p>Apply the gated feed-forward projection.</p>
<details><summary>Source</summary><pre><code>def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
    &quot;&quot;&quot;Apply the gated feed-forward projection.&quot;&quot;&quot;
    x = self.fc1(x) * self.gate(x)
    x = self.dropout(x)
    x = self.fc2(x)
    return self.dropout(x)</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.T5RelativeEmbedding"><code>fastvideo.models.encoders.lingbotworld2_t5.T5RelativeEmbedding</code></h2>
<pre class="doc-signature"><code>T5RelativeEmbedding(num_buckets: int, num_heads: int, bidirectional: bool, max_dist: int = 128)</code></pre>
<p>Per-block relative position embedding used by LingBot World 2 UMT5.</p>

<details><summary>Source</summary><pre><code>class T5RelativeEmbedding(nn.Module):
    &quot;&quot;&quot;Per-block relative position embedding used by LingBot World 2 UMT5.&quot;&quot;&quot;

    def __init__(self, num_buckets: int, num_heads: int, bidirectional: bool, max_dist: int = 128):
        super().__init__()
        self.num_buckets = num_buckets
        self.num_heads = num_heads
        self.bidirectional = bidirectional
        self.max_dist = max_dist
        self.embedding = nn.Embedding(num_buckets, num_heads)

    def forward(self, lq: int, lk: int) -&gt; torch.Tensor:
        &quot;&quot;&quot;Build a relative-position bias tensor for attention logits.&quot;&quot;&quot;
        device = self.embedding.weight.device
        rel_pos = torch.arange(lk, device=device).unsqueeze(0) - torch.arange(lq, device=device).unsqueeze(1)
        rel_pos = self._relative_position_bucket(rel_pos)
        rel_pos_embeds = self.embedding(rel_pos)
        return rel_pos_embeds.permute(2, 0, 1).unsqueeze(0).contiguous()

    def _relative_position_bucket(self, rel_pos: torch.Tensor) -&gt; torch.Tensor:
        &quot;&quot;&quot;Map token offsets to T5 relative-position buckets.&quot;&quot;&quot;
        if self.bidirectional:
            num_buckets = self.num_buckets // 2
            rel_buckets = (rel_pos &gt; 0).long() * num_buckets
            rel_pos = torch.abs(rel_pos)
        else:
            num_buckets = self.num_buckets
            rel_buckets = 0
            rel_pos = -torch.min(rel_pos, torch.zeros_like(rel_pos))
        max_exact = num_buckets // 2
        rel_pos_large = max_exact + (torch.log(rel_pos.float() / max_exact) / math.log(self.max_dist / max_exact) *
                                     (num_buckets - max_exact)).long()
        rel_pos_large = torch.min(rel_pos_large, torch.full_like(rel_pos_large, num_buckets - 1))
        rel_buckets += torch.where(rel_pos &lt; max_exact, rel_pos, rel_pos_large)
        return rel_buckets</code></pre></details>
<h3 id="fastvideo.models.encoders.lingbotworld2_t5.T5RelativeEmbedding.forward"><code>fastvideo.models.encoders.lingbotworld2_t5.T5RelativeEmbedding.forward</code></h3>
<pre class="doc-signature"><code>forward(lq: int, lk: int) -&gt; torch.Tensor</code></pre>
<p>Build a relative-position bias tensor for attention logits.</p>
<details><summary>Source</summary><pre><code>def forward(self, lq: int, lk: int) -&gt; torch.Tensor:
    &quot;&quot;&quot;Build a relative-position bias tensor for attention logits.&quot;&quot;&quot;
    device = self.embedding.weight.device
    rel_pos = torch.arange(lk, device=device).unsqueeze(0) - torch.arange(lq, device=device).unsqueeze(1)
    rel_pos = self._relative_position_bucket(rel_pos)
    rel_pos_embeds = self.embedding(rel_pos)
    return rel_pos_embeds.permute(2, 0, 1).unsqueeze(0).contiguous()</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.T5SelfAttention"><code>fastvideo.models.encoders.lingbotworld2_t5.T5SelfAttention</code></h2>
<pre class="doc-signature"><code>T5SelfAttention(dim: int, dim_attn: int, dim_ffn: int, num_heads: int, num_buckets: int, shared_pos: bool = False, dropout: float = 0.1)</code></pre>
<p>One source-compatible UMT5 encoder block.</p>

<details><summary>Source</summary><pre><code>class T5SelfAttention(nn.Module):
    &quot;&quot;&quot;One source-compatible UMT5 encoder block.&quot;&quot;&quot;

    def __init__(
        self,
        dim: int,
        dim_attn: int,
        dim_ffn: int,
        num_heads: int,
        num_buckets: int,
        shared_pos: bool = False,
        dropout: float = 0.1,
    ):
        super().__init__()
        self.norm1 = T5LayerNorm(dim)
        self.attn = T5Attention(dim, dim_attn, num_heads, dropout)
        self.norm2 = T5LayerNorm(dim)
        self.ffn = T5FeedForward(dim, dim_ffn, dropout)
        self.pos_embedding = None if shared_pos else T5RelativeEmbedding(num_buckets, num_heads, bidirectional=True)

    def forward(self,
                x: torch.Tensor,
                mask: torch.Tensor | None = None,
                pos_bias: torch.Tensor | None = None) -&gt; torch.Tensor:
        &quot;&quot;&quot;Run self-attention and feed-forward residual updates.&quot;&quot;&quot;
        e = pos_bias if self.pos_embedding is None else self.pos_embedding(x.size(1), x.size(1))
        x = self._fp16_clamp(x + self.attn(self.norm1(x), mask=mask, pos_bias=e))
        return self._fp16_clamp(x + self.ffn(self.norm2(x)))

    @staticmethod
    def _fp16_clamp(x: torch.Tensor) -&gt; torch.Tensor:
        if x.dtype == torch.float16 and torch.isinf(x).any():
            clamp = torch.finfo(x.dtype).max - 1000
            x = torch.clamp(x, min=-clamp, max=clamp)
        return x</code></pre></details>
<h3 id="fastvideo.models.encoders.lingbotworld2_t5.T5SelfAttention.forward"><code>fastvideo.models.encoders.lingbotworld2_t5.T5SelfAttention.forward</code></h3>
<pre class="doc-signature"><code>forward(x: torch.Tensor, mask: torch.Tensor | None = None, pos_bias: torch.Tensor | None = None) -&gt; torch.Tensor</code></pre>
<p>Run self-attention and feed-forward residual updates.</p>
<details><summary>Source</summary><pre><code>def forward(self,
            x: torch.Tensor,
            mask: torch.Tensor | None = None,
            pos_bias: torch.Tensor | None = None) -&gt; torch.Tensor:
    &quot;&quot;&quot;Run self-attention and feed-forward residual updates.&quot;&quot;&quot;
    e = pos_bias if self.pos_embedding is None else self.pos_embedding(x.size(1), x.size(1))
    x = self._fp16_clamp(x + self.attn(self.norm1(x), mask=mask, pos_bias=e))
    return self._fp16_clamp(x + self.ffn(self.norm2(x)))</code></pre></details>
<h2 id="fastvideo.models.encoders.lingbotworld2_t5.LingBotWorld2T5EncoderModel"><code>fastvideo.models.encoders.lingbotworld2_t5.LingBotWorld2T5EncoderModel</code></h2>
<pre class="doc-signature"><code>LingBotWorld2T5EncoderModel(config: LingBotWorld2UMT5Config, prefix: str = &#x27;&#x27;)</code></pre>
<p>FastVideo-native LingBot World 2 UMT5 encoder for the released <code>.pth</code> weights.</p>

<details><summary>Source</summary><pre><code>class LingBotWorld2T5EncoderModel(TextEncoder):
    &quot;&quot;&quot;FastVideo-native LingBot World 2 UMT5 encoder for the released `.pth` weights.&quot;&quot;&quot;

    fall_back_to_pt_during_load = True
    allow_patterns_overrides = &#91;&quot;*.pt&quot;&#93;

    def __init__(self, config: LingBotWorld2UMT5Config, prefix: str = &quot;&quot;):
        super().__init__(config)
        del prefix
        arch = config.arch_config
        self.token_embedding = nn.Embedding(arch.vocab_size, arch.dim)
        self.dropout = nn.Dropout(arch.dropout)
        self.blocks = nn.ModuleList(&#91;
            T5SelfAttention(
                arch.dim,
                arch.dim_attn,
                arch.dim_ffn,
                arch.num_heads,
                arch.num_buckets,
                shared_pos=False,
                dropout=arch.dropout,
            ) for _ in range(arch.num_layers)
        &#93;)
        self.norm = T5LayerNorm(arch.dim)

    def forward(
        self,
        input_ids: torch.Tensor | None,
        position_ids: torch.Tensor | None = None,
        attention_mask: torch.Tensor | None = None,
        inputs_embeds: torch.Tensor | None = None,
        output_hidden_states: bool | None = None,
        **kwargs,
    ) -&gt; BaseEncoderOutput:
        &quot;&quot;&quot;Encode token ids and return source-compatible hidden states.&quot;&quot;&quot;
        del position_ids, inputs_embeds, output_hidden_states, kwargs
        assert input_ids is not None
        x = self.dropout(self.token_embedding(input_ids))
        for block in self.blocks:
            x = block(x, attention_mask)
        x = self.dropout(self.norm(x))
        return BaseEncoderOutput(last_hidden_state=x, attention_mask=attention_mask)

    def load_weights(self, weights: Iterable&#91;tuple&#91;str, torch.Tensor&#93;&#93;) -&gt; set&#91;str&#93;:
        &quot;&quot;&quot;Load source `.pth` weights whose names already match this module.&quot;&quot;&quot;
        params_dict = dict(self.named_parameters())
        loaded_params: set&#91;str&#93; = set()
        for name, loaded_weight in weights:
            if name not in params_dict:
                continue
            param = params_dict&#91;name&#93;
            weight_loader = getattr(param, &quot;weight_loader&quot;, default_weight_loader)
            weight_loader(param, loaded_weight)
            loaded_params.add(name)
        return loaded_params</code></pre></details>
<h3 id="fastvideo.models.encoders.lingbotworld2_t5.LingBotWorld2T5EncoderModel.forward"><code>fastvideo.models.encoders.lingbotworld2_t5.LingBotWorld2T5EncoderModel.forward</code></h3>
<pre class="doc-signature"><code>forward(input_ids: torch.Tensor | None, position_ids: torch.Tensor | None = None, attention_mask: torch.Tensor | None = None, inputs_embeds: torch.Tensor | None = None, output_hidden_states: bool | None = None, **kwargs) -&gt; BaseEncoderOutput</code></pre>
<p>Encode token ids and return source-compatible hidden states.</p>
<details><summary>Source</summary><pre><code>def forward(
    self,
    input_ids: torch.Tensor | None,
    position_ids: torch.Tensor | None = None,
    attention_mask: torch.Tensor | None = None,
    inputs_embeds: torch.Tensor | None = None,
    output_hidden_states: bool | None = None,
    **kwargs,
) -&gt; BaseEncoderOutput:
    &quot;&quot;&quot;Encode token ids and return source-compatible hidden states.&quot;&quot;&quot;
    del position_ids, inputs_embeds, output_hidden_states, kwargs
    assert input_ids is not None
    x = self.dropout(self.token_embedding(input_ids))
    for block in self.blocks:
        x = block(x, attention_mask)
    x = self.dropout(self.norm(x))
    return BaseEncoderOutput(last_hidden_state=x, attention_mask=attention_mask)</code></pre></details>
<h3 id="fastvideo.models.encoders.lingbotworld2_t5.LingBotWorld2T5EncoderModel.load_weights"><code>fastvideo.models.encoders.lingbotworld2_t5.LingBotWorld2T5EncoderModel.load_weights</code></h3>
<pre class="doc-signature"><code>load_weights(weights: Iterable&#91;tuple&#91;str, torch.Tensor&#93;&#93;) -&gt; set&#91;str&#93;</code></pre>
<p>Load source <code>.pth</code> weights whose names already match this module.</p>
<details><summary>Source</summary><pre><code>def load_weights(self, weights: Iterable&#91;tuple&#91;str, torch.Tensor&#93;&#93;) -&gt; set&#91;str&#93;:
    &quot;&quot;&quot;Load source `.pth` weights whose names already match this module.&quot;&quot;&quot;
    params_dict = dict(self.named_parameters())
    loaded_params: set&#91;str&#93; = set()
    for name, loaded_weight in weights:
        if name not in params_dict:
            continue
        param = params_dict&#91;name&#93;
        weight_loader = getattr(param, &quot;weight_loader&quot;, default_weight_loader)
        weight_loader(param, loaded_weight)
        loaded_params.add(name)
    return loaded_params</code></pre></details>
</div>
