File size: 1,938 Bytes
c0bba28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from typing import Optional

import torch
import torch.nn as nn
import torch.nn.functional as F
from diffusers.utils import deprecate
from diffusers.models.upsampling import Upsample2D

from distvae.models.layers.normalization import RMSNorm
from distvae.modules.adapters.layers.conv_adapters import Conv2dAdapter


class PatchUpsample2D(Upsample2D):
    """A 2D upsampling layer with an optional convolution.

    Parameters:
        channels (`int`):
            number of channels in the inputs and outputs.
        use_conv (`bool`, default `False`):
            option to use a convolution.
        use_conv_transpose (`bool`, default `False`):
            option to use a convolution transpose.
        out_channels (`int`, optional):
            number of output channels. Defaults to `channels`.
        name (`str`, default `conv`):
            name of the upsampling 2D layer.
    """

    def __init__(
        self,
        channels: int,
        use_conv: bool = False,
        use_conv_transpose: bool = False,
        out_channels: Optional[int] = None,
        name: str = "conv",
        kernel_size: Optional[int] = None,
        padding=1,
        norm_type=None,
        eps=None,
        elementwise_affine=None,
        bias=True,
        interpolate=True,
        conv_block_size = 0,
    ):
        assert norm_type is None, "norm_type has not been supported for PatchUpsample2D yat."
        assert use_conv_transpose is False, "use_conv_transpose has not been supported for PatchUpsample2D yet."
        super().__init__(channels, use_conv, use_conv_transpose, out_channels, name, 
                         kernel_size, padding, norm_type, eps, elementwise_affine, 
                         bias, interpolate)
        if name == "conv":
            self.conv = Conv2dAdapter(self.conv, block_size=conv_block_size)
        else:
            self.Conv2d_0 = Conv2dAdapter(self.Conv2d_0, block_size=conv_block_size)