---
title: bert
---

<div class="python-reference">
<a id="fastvideo.models.encoders.bert-classes"></a>
<a id="fastvideo.models.encoders.bert"></a>

<h2 id="fastvideo.models.encoders.bert.HunyuanClip"><code>fastvideo.models.encoders.bert.HunyuanClip</code></h2>
<pre class="doc-signature"><code>HunyuanClip(model_dir, max_length = 77)</code></pre>
<p>Hunyuan clip code copied from https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py
hunyuan's clip used BertModel and BertTokenizer, so we copy it.</p>

<details><summary>Source</summary><pre><code>class HunyuanClip(nn.Module):
    &quot;&quot;&quot;
        Hunyuan clip code copied from https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py
        hunyuan&#x27;s clip used BertModel and BertTokenizer, so we copy it.
    &quot;&quot;&quot;

    def __init__(self, model_dir, max_length=77):
        super().__init__()

        self.max_length = max_length
        self.tokenizer = BertTokenizer.from_pretrained(os.path.join(model_dir, &#x27;tokenizer&#x27;))
        self.text_encoder = BertModel.from_pretrained(os.path.join(model_dir, &#x27;clip_text_encoder&#x27;))

    @torch.no_grad
    def forward(self, prompts, with_mask=True):
        self.device = next(self.text_encoder.parameters()).device
        text_inputs = self.tokenizer(
            prompts,
            padding=&quot;max_length&quot;,
            max_length=self.max_length,
            truncation=True,
            return_attention_mask=True,
            return_tensors=&quot;pt&quot;,
        )
        prompt_embeds = self.text_encoder(
            text_inputs.input_ids.to(self.device),
            attention_mask=text_inputs.attention_mask.to(self.device) if with_mask else None,
        )
        return prompt_embeds.last_hidden_state, prompt_embeds.pooler_output</code></pre></details>
<h3 id="fastvideo.models.encoders.bert.HunyuanClip.forward"><code>fastvideo.models.encoders.bert.HunyuanClip.forward</code></h3>
<pre class="doc-signature"><code>forward(prompts, with_mask = True)</code></pre>

<details><summary>Source</summary><pre><code>@torch.no_grad
def forward(self, prompts, with_mask=True):
    self.device = next(self.text_encoder.parameters()).device
    text_inputs = self.tokenizer(
        prompts,
        padding=&quot;max_length&quot;,
        max_length=self.max_length,
        truncation=True,
        return_attention_mask=True,
        return_tensors=&quot;pt&quot;,
    )
    prompt_embeds = self.text_encoder(
        text_inputs.input_ids.to(self.device),
        attention_mask=text_inputs.attention_mask.to(self.device) if with_mask else None,
    )
    return prompt_embeds.last_hidden_state, prompt_embeds.pooler_output</code></pre></details>
</div>
