---
title: hunyuan15
---

<div class="python-reference">
<a id="fastvideo.models.upsamplers.hunyuan15-classes"></a>
<a id="fastvideo.models.upsamplers.hunyuan15-functions"></a>
<a id="fastvideo.models.upsamplers.hunyuan15.SRTo1080pUpsampler-functions"></a>
<a id="fastvideo.models.upsamplers.hunyuan15"></a>

<h2 id="fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15CausalConv3d"><code>fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15CausalConv3d</code></h2>
<pre class="doc-signature"><code>HunyuanVideo15CausalConv3d(in_channels: int, out_channels: int, kernel_size: Union&#91;int, Tuple&#91;int, int, int&#93;&#93; = 3, stride: Union&#91;int, Tuple&#91;int, int, int&#93;&#93; = 1, padding: Union&#91;int, Tuple&#91;int, int, int&#93;&#93; = 0, dilation: Union&#91;int, Tuple&#91;int, int, int&#93;&#93; = 1, bias: bool = True, pad_mode: str = &#x27;replicate&#x27;)</code></pre>


<h3 id="fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15CausalConv3d.forward"><code>fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15CausalConv3d.forward</code></h3>
<pre class="doc-signature"><code>forward(hidden_states: torch.Tensor) -&gt; torch.Tensor</code></pre>

<h2 id="fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15RMS_norm"><code>fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15RMS_norm</code></h2>
<pre class="doc-signature"><code>HunyuanVideo15RMS_norm(dim: int, channel_first: bool = True, images: bool = True, bias: bool = False)</code></pre>
<p>A custom RMS normalization layer.</p>
<h3>Parameters</h3>
<dl>
<dt><code>dim: int</code></dt><dd><p>The number of dimensions to normalize over.</p></dd>
<dt><code>channel_first: bool</code></dt><dd><p>Whether the input tensor has channels as the first dimension.
Default is True.</p></dd>
<dt><code>images: bool</code></dt><dd><p>Whether the input represents image data. Default is True.</p></dd>
<dt><code>bias: bool</code></dt><dd><p>Whether to include a learnable bias term. Default is False.</p></dd>
</dl>

<h3 id="fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15RMS_norm.forward"><code>fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15RMS_norm.forward</code></h3>
<pre class="doc-signature"><code>forward(x)</code></pre>

<h2 id="fastvideo.models.upsamplers.hunyuan15.get_act_fn"><code>fastvideo.models.upsamplers.hunyuan15.get_act_fn</code></h2>
<pre class="doc-signature"><code>get_act_fn(act_fn_name: str) -&gt; nn.Module</code></pre>
<p>Get an activation function by name.</p>
<h2 id="fastvideo.models.upsamplers.hunyuan15.SRTo720pUpsamplerConfig"><code>fastvideo.models.upsamplers.hunyuan15.SRTo720pUpsamplerConfig</code></h2>
<pre class="doc-signature"><code>SRTo720pUpsamplerConfig(arch_config: ArchConfig = ArchConfig(), in_channels: int = 0, out_channels: int = 0, hidden_channels: int = 64, num_blocks: int = 6, global_residual: bool = False, *, _resolved_attention_backend: AttentionBackendEnum | None = None)</code></pre>


<h2 id="fastvideo.models.upsamplers.hunyuan15.SRTo1080pUpsamplerConfig"><code>fastvideo.models.upsamplers.hunyuan15.SRTo1080pUpsamplerConfig</code></h2>
<pre class="doc-signature"><code>SRTo1080pUpsamplerConfig(arch_config: ArchConfig = ArchConfig(), z_channels: int = 0, out_channels: int = 0, block_out_channels: tuple&#91;int, ...&#93; = (0, 0), num_res_blocks: int = 2, is_residual: bool = False, *, _resolved_attention_backend: AttentionBackendEnum | None = None)</code></pre>


<h2 id="fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15ResnetBlock"><code>fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15ResnetBlock</code></h2>
<pre class="doc-signature"><code>HunyuanVideo15ResnetBlock(in_channels: int, out_channels: int | None = None, non_linearity: str = &#x27;swish&#x27;)</code></pre>


<details><summary>Source</summary><pre><code>class HunyuanVideo15ResnetBlock(nn.Module):

    def __init__(
        self,
        in_channels: int,
        out_channels: int | None = None,
        non_linearity: str = &quot;swish&quot;,
    ) -&gt; None:
        super().__init__()
        out_channels = out_channels or in_channels

        self.nonlinearity = get_act_fn(non_linearity)

        self.norm1 = HunyuanVideo15RMS_norm(in_channels, images=False)
        self.conv1 = HunyuanVideo15CausalConv3d(in_channels, out_channels, kernel_size=3)

        self.norm2 = HunyuanVideo15RMS_norm(out_channels, images=False)
        self.conv2 = HunyuanVideo15CausalConv3d(out_channels, out_channels, kernel_size=3)

        self.nin_shortcut = None
        if in_channels != out_channels:
            self.nin_shortcut = nn.Conv3d(in_channels, out_channels, kernel_size=1, stride=1, padding=0)

    def forward(self, hidden_states: torch.Tensor) -&gt; torch.Tensor:
        residual = hidden_states

        hidden_states = self.norm1(hidden_states)
        hidden_states = self.nonlinearity(hidden_states)
        hidden_states = self.conv1(hidden_states)

        hidden_states = self.norm2(hidden_states)
        hidden_states = self.nonlinearity(hidden_states)
        hidden_states = self.conv2(hidden_states)

        if self.nin_shortcut is not None:
            residual = self.nin_shortcut(residual)

        return hidden_states + residual</code></pre></details>
<h3 id="fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15ResnetBlock.forward"><code>fastvideo.models.upsamplers.hunyuan15.HunyuanVideo15ResnetBlock.forward</code></h3>
<pre class="doc-signature"><code>forward(hidden_states: torch.Tensor) -&gt; torch.Tensor</code></pre>

<details><summary>Source</summary><pre><code>def forward(self, hidden_states: torch.Tensor) -&gt; torch.Tensor:
    residual = hidden_states

    hidden_states = self.norm1(hidden_states)
    hidden_states = self.nonlinearity(hidden_states)
    hidden_states = self.conv1(hidden_states)

    hidden_states = self.norm2(hidden_states)
    hidden_states = self.nonlinearity(hidden_states)
    hidden_states = self.conv2(hidden_states)

    if self.nin_shortcut is not None:
        residual = self.nin_shortcut(residual)

    return hidden_states + residual</code></pre></details>
<h2 id="fastvideo.models.upsamplers.hunyuan15.SRResidualCausalBlock3D"><code>fastvideo.models.upsamplers.hunyuan15.SRResidualCausalBlock3D</code></h2>
<pre class="doc-signature"><code>SRResidualCausalBlock3D(channels: int)</code></pre>


<details><summary>Source</summary><pre><code>class SRResidualCausalBlock3D(nn.Module):

    def __init__(self, channels: int):
        super().__init__()
        self.block = nn.Sequential(
            HunyuanVideo15CausalConv3d(channels, channels, kernel_size=3),
            nn.SiLU(inplace=True),
            HunyuanVideo15CausalConv3d(channels, channels, kernel_size=3),
            nn.SiLU(inplace=True),
            HunyuanVideo15CausalConv3d(channels, channels, kernel_size=3),
        )

    def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
        return x + self.block(x)</code></pre></details>
<h3 id="fastvideo.models.upsamplers.hunyuan15.SRResidualCausalBlock3D.forward"><code>fastvideo.models.upsamplers.hunyuan15.SRResidualCausalBlock3D.forward</code></h3>
<pre class="doc-signature"><code>forward(x: torch.Tensor) -&gt; torch.Tensor</code></pre>

<details><summary>Source</summary><pre><code>def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
    return x + self.block(x)</code></pre></details>
<h2 id="fastvideo.models.upsamplers.hunyuan15.SRTo720pUpsampler"><code>fastvideo.models.upsamplers.hunyuan15.SRTo720pUpsampler</code></h2>
<pre class="doc-signature"><code>SRTo720pUpsampler(config: SRTo720pUpsamplerConfig)</code></pre>


<details><summary>Source</summary><pre><code>class SRTo720pUpsampler(nn.Module):

    def __init__(
        self,
        config: SRTo720pUpsamplerConfig,
    ):
        super().__init__()
        self.in_conv = HunyuanVideo15CausalConv3d(config.in_channels, config.hidden_channels, kernel_size=3)
        self.blocks = nn.ModuleList(&#91;SRResidualCausalBlock3D(config.hidden_channels) for _ in range(config.num_blocks)&#93;)
        self.out_conv = HunyuanVideo15CausalConv3d(config.hidden_channels, config.out_channels, kernel_size=3)
        self.global_residual = bool(config.global_residual)

    def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
        residual = x
        y = self.in_conv(x)
        for blk in self.blocks:
            y = blk(y)
        y = self.out_conv(y)
        if self.global_residual and (y.shape == residual.shape):
            y = y + residual
        return y</code></pre></details>
<h3 id="fastvideo.models.upsamplers.hunyuan15.SRTo720pUpsampler.forward"><code>fastvideo.models.upsamplers.hunyuan15.SRTo720pUpsampler.forward</code></h3>
<pre class="doc-signature"><code>forward(x: torch.Tensor) -&gt; torch.Tensor</code></pre>

<details><summary>Source</summary><pre><code>def forward(self, x: torch.Tensor) -&gt; torch.Tensor:
    residual = x
    y = self.in_conv(x)
    for blk in self.blocks:
        y = blk(y)
    y = self.out_conv(y)
    if self.global_residual and (y.shape == residual.shape):
        y = y + residual
    return y</code></pre></details>
<h2 id="fastvideo.models.upsamplers.hunyuan15.SRTo1080pUpsampler"><code>fastvideo.models.upsamplers.hunyuan15.SRTo1080pUpsampler</code></h2>
<pre class="doc-signature"><code>SRTo1080pUpsampler(config: SRTo1080pUpsamplerConfig)</code></pre>


<details><summary>Source</summary><pre><code>class SRTo1080pUpsampler(nn.Module):

    def __init__(
        self,
        config: SRTo1080pUpsamplerConfig,
    ):
        super().__init__()
        self.num_res_blocks = config.num_res_blocks
        self.block_out_channels = config.block_out_channels
        self.z_channels = config.z_channels

        block_in = config.block_out_channels&#91;0&#93;
        self.conv_in = HunyuanVideo15CausalConv3d(config.z_channels, block_in, kernel_size=3)

        self.up = nn.ModuleList()
        for i_level, ch in enumerate(config.block_out_channels):
            block = nn.ModuleList()
            block_out = ch
            for _ in range(self.num_res_blocks + 1):
                block.append(HunyuanVideo15ResnetBlock(in_channels=block_in, out_channels=block_out))
                block_in = block_out
            up = nn.Module()
            up.block = block

            self.up.append(up)

        self.norm_out = HunyuanVideo15RMS_norm(block_in, images=False)
        self.conv_out = HunyuanVideo15CausalConv3d(block_in, config.out_channels, kernel_size=3)

        self.gradient_checkpointing = False
        self.is_residual = config.is_residual

    def forward(self, z: Tensor, target_shape: Sequence&#91;int&#93; = None) -&gt; Tensor:
        &quot;&quot;&quot;
        Args:
            z: (B, C, T, H, W)
            target_shape: (H, W)
        &quot;&quot;&quot;
        if target_shape is not None and z.shape&#91;-2:&#93; != target_shape:
            bsz = z.shape&#91;0&#93;
            z = rearrange(z, &quot;b c f h w -&gt; (b f) c h w&quot;)
            z = F.interpolate(z, size=target_shape, mode=&quot;bilinear&quot;, align_corners=False)
            z = rearrange(z, &quot;(b f) c h w -&gt; b c f h w&quot;, b=bsz)

        # z to block_in
        repeats = self.block_out_channels&#91;0&#93; // (self.z_channels)
        h = self.conv_in(z) + z.repeat_interleave(repeats=repeats, dim=1)

        # upsampling
        for i_level in range(len(self.block_out_channels)):
            for i_block in range(self.num_res_blocks + 1):
                h = self.up&#91;i_level&#93;.block&#91;i_block&#93;(h)
            if hasattr(self.up&#91;i_level&#93;, &quot;upsample&quot;):
                h = self.up&#91;i_level&#93;.upsample(h)

        # end
        h = self.norm_out(h)
        h = get_act_fn(&quot;swish&quot;)(h)
        h = self.conv_out(h)
        return h</code></pre></details>
<h3 id="fastvideo.models.upsamplers.hunyuan15.SRTo1080pUpsampler.forward"><code>fastvideo.models.upsamplers.hunyuan15.SRTo1080pUpsampler.forward</code></h3>
<pre class="doc-signature"><code>forward(z: Tensor, target_shape: Sequence&#91;int&#93; = None) -&gt; Tensor</code></pre>
<h4>Parameters</h4>
<dl>
<dt><code>z: Tensor</code></dt><dd><p>(B, C, T, H, W)</p></dd>
<dt><code>target_shape: Sequence[int]</code></dt><dd><p>(H, W)</p></dd>
</dl>
<details><summary>Source</summary><pre><code>def forward(self, z: Tensor, target_shape: Sequence&#91;int&#93; = None) -&gt; Tensor:
    &quot;&quot;&quot;
    Args:
        z: (B, C, T, H, W)
        target_shape: (H, W)
    &quot;&quot;&quot;
    if target_shape is not None and z.shape&#91;-2:&#93; != target_shape:
        bsz = z.shape&#91;0&#93;
        z = rearrange(z, &quot;b c f h w -&gt; (b f) c h w&quot;)
        z = F.interpolate(z, size=target_shape, mode=&quot;bilinear&quot;, align_corners=False)
        z = rearrange(z, &quot;(b f) c h w -&gt; b c f h w&quot;, b=bsz)

    # z to block_in
    repeats = self.block_out_channels&#91;0&#93; // (self.z_channels)
    h = self.conv_in(z) + z.repeat_interleave(repeats=repeats, dim=1)

    # upsampling
    for i_level in range(len(self.block_out_channels)):
        for i_block in range(self.num_res_blocks + 1):
            h = self.up&#91;i_level&#93;.block&#91;i_block&#93;(h)
        if hasattr(self.up&#91;i_level&#93;, &quot;upsample&quot;):
            h = self.up&#91;i_level&#93;.upsample(h)

    # end
    h = self.norm_out(h)
    h = get_act_fn(&quot;swish&quot;)(h)
    h = self.conv_out(h)
    return h</code></pre></details>
</div>
