Team Ai
Apppublic

hugging-apps/echo-memory

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
svd_vae_decoder.py579 linesDownload Raw Back to models
1import torch2from .attention import Attention3from .sd_unet import ResnetBlock, UpSampler4from .tiler import TileWorker5from einops import rearrange, repeat6 7 8class VAEAttentionBlock(torch.nn.Module):9 10    def __init__(self, num_attention_heads, attention_head_dim, in_channels, num_layers=1, norm_num_groups=32, eps=1e-5):11        super().__init__()12        inner_dim = num_attention_heads * attention_head_dim13 14        self.norm = torch.nn.GroupNorm(num_groups=norm_num_groups, num_channels=in_channels, eps=eps, affine=True)15 16        self.transformer_blocks = torch.nn.ModuleList([17            Attention(18                inner_dim,19                num_attention_heads,20                attention_head_dim,21                bias_q=True,22                bias_kv=True,23                bias_out=True24            )25            for d in range(num_layers)26        ])27 28    def forward(self, hidden_states, time_emb, text_emb, res_stack):29        batch, _, height, width = hidden_states.shape30        residual = hidden_states31 32        hidden_states = self.norm(hidden_states)33        inner_dim = hidden_states.shape[1]34        hidden_states = hidden_states.permute(0, 2, 3, 1).reshape(batch, height * width, inner_dim)35 36        for block in self.transformer_blocks:37            hidden_states = block(hidden_states)38 39        hidden_states = hidden_states.reshape(batch, height, width, inner_dim).permute(0, 3, 1, 2).contiguous()40        hidden_states = hidden_states + residual41 42        return hidden_states, time_emb, text_emb, res_stack43    44 45class TemporalResnetBlock(torch.nn.Module):46 47    def __init__(self, in_channels, out_channels, groups=32, eps=1e-5):48        super().__init__()49        self.norm1 = torch.nn.GroupNorm(num_groups=groups, num_channels=in_channels, eps=eps, affine=True)50        self.conv1 = torch.nn.Conv3d(in_channels, out_channels, kernel_size=(3, 1, 1), stride=1, padding=(1, 0, 0))51        self.norm2 = torch.nn.GroupNorm(num_groups=groups, num_channels=out_channels, eps=eps, affine=True)52        self.conv2 = torch.nn.Conv3d(out_channels, out_channels, kernel_size=(3, 1, 1), stride=1, padding=(1, 0, 0))53        self.nonlinearity = torch.nn.SiLU()54        self.mix_factor = torch.nn.Parameter(torch.Tensor([0.5]))55 56    def forward(self, hidden_states, time_emb, text_emb, res_stack, **kwargs):57        x_spatial = hidden_states58        x = rearrange(hidden_states, "T C H W -> 1 C T H W")59        x = self.norm1(x)60        x = self.nonlinearity(x)61        x = self.conv1(x)62        x = self.norm2(x)63        x = self.nonlinearity(x)64        x = self.conv2(x)65        x_temporal = hidden_states + x[0].permute(1, 0, 2, 3)66        alpha = torch.sigmoid(self.mix_factor)67        hidden_states = alpha * x_temporal + (1 - alpha) * x_spatial68        return hidden_states, time_emb, text_emb, res_stack69    70 71class SVDVAEDecoder(torch.nn.Module):72    def __init__(self):73        super().__init__()74        self.scaling_factor = 0.1821575        self.conv_in = torch.nn.Conv2d(4, 512, kernel_size=3, padding=1)76 77        self.blocks = torch.nn.ModuleList([78            # UNetMidBlock79            ResnetBlock(512, 512, eps=1e-6),80            TemporalResnetBlock(512, 512, eps=1e-6),81            VAEAttentionBlock(1, 512, 512, 1, eps=1e-6),82            ResnetBlock(512, 512, eps=1e-6),83            TemporalResnetBlock(512, 512, eps=1e-6),84            # UpDecoderBlock85            ResnetBlock(512, 512, eps=1e-6),86            TemporalResnetBlock(512, 512, eps=1e-6),87            ResnetBlock(512, 512, eps=1e-6),88            TemporalResnetBlock(512, 512, eps=1e-6),89            ResnetBlock(512, 512, eps=1e-6),90            TemporalResnetBlock(512, 512, eps=1e-6),91            UpSampler(512),92            # UpDecoderBlock93            ResnetBlock(512, 512, eps=1e-6),94            TemporalResnetBlock(512, 512, eps=1e-6),95            ResnetBlock(512, 512, eps=1e-6),96            TemporalResnetBlock(512, 512, eps=1e-6),97            ResnetBlock(512, 512, eps=1e-6),98            TemporalResnetBlock(512, 512, eps=1e-6),99            UpSampler(512),100            # UpDecoderBlock101            ResnetBlock(512, 256, eps=1e-6),102            TemporalResnetBlock(256, 256, eps=1e-6),103            ResnetBlock(256, 256, eps=1e-6),104            TemporalResnetBlock(256, 256, eps=1e-6),105            ResnetBlock(256, 256, eps=1e-6),106            TemporalResnetBlock(256, 256, eps=1e-6),107            UpSampler(256),108            # UpDecoderBlock109            ResnetBlock(256, 128, eps=1e-6),110            TemporalResnetBlock(128, 128, eps=1e-6),111            ResnetBlock(128, 128, eps=1e-6),112            TemporalResnetBlock(128, 128, eps=1e-6),113            ResnetBlock(128, 128, eps=1e-6),114            TemporalResnetBlock(128, 128, eps=1e-6),115        ])116 117        self.conv_norm_out = torch.nn.GroupNorm(num_channels=128, num_groups=32, eps=1e-5)118        self.conv_act = torch.nn.SiLU()119        self.conv_out = torch.nn.Conv2d(128, 3, kernel_size=3, padding=1)120        self.time_conv_out = torch.nn.Conv3d(3, 3, kernel_size=(3, 1, 1), padding=(1, 0, 0))121 122 123    def forward(self, sample):124        # 1. pre-process125        hidden_states = rearrange(sample, "C T H W -> T C H W")126        hidden_states = hidden_states / self.scaling_factor127        hidden_states = self.conv_in(hidden_states)128        time_emb, text_emb, res_stack = None, None, None129 130        # 2. blocks131        for i, block in enumerate(self.blocks):132            hidden_states, time_emb, text_emb, res_stack = block(hidden_states, time_emb, text_emb, res_stack)133 134        # 3. output135        hidden_states = self.conv_norm_out(hidden_states)136        hidden_states = self.conv_act(hidden_states)137        hidden_states = self.conv_out(hidden_states)138        hidden_states = rearrange(hidden_states, "T C H W -> C T H W")139        hidden_states = self.time_conv_out(hidden_states)140 141        return hidden_states142    143    144    def build_mask(self, data, is_bound):145        _, T, H, W = data.shape146        t = repeat(torch.arange(T), "T -> T H W", T=T, H=H, W=W)147        h = repeat(torch.arange(H), "H -> T H W", T=T, H=H, W=W)148        w = repeat(torch.arange(W), "W -> T H W", T=T, H=H, W=W)149        border_width = (T + H + W) // 6150        pad = torch.ones_like(t) * border_width151        mask = torch.stack([152            pad if is_bound[0] else t + 1,153            pad if is_bound[1] else T - t,154            pad if is_bound[2] else h + 1,155            pad if is_bound[3] else H - h,156            pad if is_bound[4] else w + 1,157            pad if is_bound[5] else W - w158        ]).min(dim=0).values159        mask = mask.clip(1, border_width)160        mask = (mask / border_width).to(dtype=data.dtype, device=data.device)161        mask = rearrange(mask, "T H W -> 1 T H W")162        return mask163    164 165    def decode_video(166        self, sample,167        batch_time=8, batch_height=128, batch_width=128,168        stride_time=4, stride_height=32, stride_width=32,169        progress_bar=lambda x:x170    ):171        sample = sample.permute(1, 0, 2, 3)172        data_device = sample.device173        computation_device = self.conv_in.weight.device174        torch_dtype = sample.dtype175        _, T, H, W = sample.shape176 177        weight = torch.zeros((1, T, H*8, W*8), dtype=torch_dtype, device=data_device)178        values = torch.zeros((3, T, H*8, W*8), dtype=torch_dtype, device=data_device)179 180        # Split tasks181        tasks = []182        for t in range(0, T, stride_time):183            for h in range(0, H, stride_height):184                for w in range(0, W, stride_width):185                    if (t-stride_time >= 0 and t-stride_time+batch_time >= T)\186                        or (h-stride_height >= 0 and h-stride_height+batch_height >= H)\187                        or (w-stride_width >= 0 and w-stride_width+batch_width >= W):188                        continue189                    tasks.append((t, t+batch_time, h, h+batch_height, w, w+batch_width))190        191        # Run192        for tl, tr, hl, hr, wl, wr in progress_bar(tasks):193            sample_batch = sample[:, tl:tr, hl:hr, wl:wr].to(computation_device)194            sample_batch = self.forward(sample_batch).to(data_device)195            mask = self.build_mask(sample_batch, is_bound=(tl==0, tr>=T, hl==0, hr>=H, wl==0, wr>=W))196            values[:, tl:tr, hl*8:hr*8, wl*8:wr*8] += sample_batch * mask197            weight[:, tl:tr, hl*8:hr*8, wl*8:wr*8] += mask198        values /= weight199        return values200    201    202    @staticmethod203    def state_dict_converter():204        return SVDVAEDecoderStateDictConverter()205    206 207class SVDVAEDecoderStateDictConverter:208    def __init__(self):209        pass210 211    def from_diffusers(self, state_dict):212        static_rename_dict = {213            "decoder.conv_in":  "conv_in",214            "decoder.mid_block.attentions.0.group_norm": "blocks.2.norm",215            "decoder.mid_block.attentions.0.to_q": "blocks.2.transformer_blocks.0.to_q",216            "decoder.mid_block.attentions.0.to_k": "blocks.2.transformer_blocks.0.to_k",217            "decoder.mid_block.attentions.0.to_v": "blocks.2.transformer_blocks.0.to_v",218            "decoder.mid_block.attentions.0.to_out.0": "blocks.2.transformer_blocks.0.to_out",219            "decoder.up_blocks.0.upsamplers.0.conv": "blocks.11.conv",220            "decoder.up_blocks.1.upsamplers.0.conv": "blocks.18.conv",221            "decoder.up_blocks.2.upsamplers.0.conv": "blocks.25.conv",222            "decoder.conv_norm_out": "conv_norm_out",223            "decoder.conv_out": "conv_out",224            "decoder.time_conv_out": "time_conv_out"225        }226        prefix_rename_dict = {227            "decoder.mid_block.resnets.0.spatial_res_block": "blocks.0",228            "decoder.mid_block.resnets.0.temporal_res_block": "blocks.1",229            "decoder.mid_block.resnets.0.time_mixer": "blocks.1",230            "decoder.mid_block.resnets.1.spatial_res_block": "blocks.3",231            "decoder.mid_block.resnets.1.temporal_res_block": "blocks.4",232            "decoder.mid_block.resnets.1.time_mixer": "blocks.4",233 234            "decoder.up_blocks.0.resnets.0.spatial_res_block": "blocks.5",235            "decoder.up_blocks.0.resnets.0.temporal_res_block": "blocks.6",236            "decoder.up_blocks.0.resnets.0.time_mixer": "blocks.6",237            "decoder.up_blocks.0.resnets.1.spatial_res_block": "blocks.7",238            "decoder.up_blocks.0.resnets.1.temporal_res_block": "blocks.8",239            "decoder.up_blocks.0.resnets.1.time_mixer": "blocks.8",240            "decoder.up_blocks.0.resnets.2.spatial_res_block": "blocks.9",241            "decoder.up_blocks.0.resnets.2.temporal_res_block": "blocks.10",242            "decoder.up_blocks.0.resnets.2.time_mixer": "blocks.10",243 244            "decoder.up_blocks.1.resnets.0.spatial_res_block": "blocks.12",245            "decoder.up_blocks.1.resnets.0.temporal_res_block": "blocks.13",246            "decoder.up_blocks.1.resnets.0.time_mixer": "blocks.13",247            "decoder.up_blocks.1.resnets.1.spatial_res_block": "blocks.14",248            "decoder.up_blocks.1.resnets.1.temporal_res_block": "blocks.15",249            "decoder.up_blocks.1.resnets.1.time_mixer": "blocks.15",250            "decoder.up_blocks.1.resnets.2.spatial_res_block": "blocks.16",251            "decoder.up_blocks.1.resnets.2.temporal_res_block": "blocks.17",252            "decoder.up_blocks.1.resnets.2.time_mixer": "blocks.17",253 254            "decoder.up_blocks.2.resnets.0.spatial_res_block": "blocks.19",255            "decoder.up_blocks.2.resnets.0.temporal_res_block": "blocks.20",256            "decoder.up_blocks.2.resnets.0.time_mixer": "blocks.20",257            "decoder.up_blocks.2.resnets.1.spatial_res_block": "blocks.21",258            "decoder.up_blocks.2.resnets.1.temporal_res_block": "blocks.22",259            "decoder.up_blocks.2.resnets.1.time_mixer": "blocks.22",260            "decoder.up_blocks.2.resnets.2.spatial_res_block": "blocks.23",261            "decoder.up_blocks.2.resnets.2.temporal_res_block": "blocks.24",262            "decoder.up_blocks.2.resnets.2.time_mixer": "blocks.24",263 264            "decoder.up_blocks.3.resnets.0.spatial_res_block": "blocks.26",265            "decoder.up_blocks.3.resnets.0.temporal_res_block": "blocks.27",266            "decoder.up_blocks.3.resnets.0.time_mixer": "blocks.27",267            "decoder.up_blocks.3.resnets.1.spatial_res_block": "blocks.28",268            "decoder.up_blocks.3.resnets.1.temporal_res_block": "blocks.29",269            "decoder.up_blocks.3.resnets.1.time_mixer": "blocks.29",270            "decoder.up_blocks.3.resnets.2.spatial_res_block": "blocks.30",271            "decoder.up_blocks.3.resnets.2.temporal_res_block": "blocks.31",272            "decoder.up_blocks.3.resnets.2.time_mixer": "blocks.31",273        }274        suffix_rename_dict = {275            "norm1.weight": "norm1.weight",276            "conv1.weight": "conv1.weight",277            "norm2.weight": "norm2.weight",278            "conv2.weight": "conv2.weight",279            "conv_shortcut.weight": "conv_shortcut.weight",280            "norm1.bias": "norm1.bias",281            "conv1.bias": "conv1.bias",282            "norm2.bias": "norm2.bias",283            "conv2.bias": "conv2.bias",284            "conv_shortcut.bias": "conv_shortcut.bias",285            "mix_factor": "mix_factor",286        }287 288        state_dict_ = {}289        for name in static_rename_dict:290            state_dict_[static_rename_dict[name] + ".weight"] = state_dict[name + ".weight"]291            state_dict_[static_rename_dict[name] + ".bias"] = state_dict[name + ".bias"]292        for prefix_name in prefix_rename_dict:293            for suffix_name in suffix_rename_dict:294                name = prefix_name + "." + suffix_name295                name_ = prefix_rename_dict[prefix_name] + "." + suffix_rename_dict[suffix_name]296                if name in state_dict:297                    state_dict_[name_] = state_dict[name]298        299        return state_dict_300    301 302    def from_civitai(self, state_dict):303        rename_dict = {304            "first_stage_model.decoder.conv_in.bias": "conv_in.bias",305            "first_stage_model.decoder.conv_in.weight": "conv_in.weight",306            "first_stage_model.decoder.conv_out.bias": "conv_out.bias",307            "first_stage_model.decoder.conv_out.time_mix_conv.bias": "time_conv_out.bias",308            "first_stage_model.decoder.conv_out.time_mix_conv.weight": "time_conv_out.weight",309            "first_stage_model.decoder.conv_out.weight": "conv_out.weight",310            "first_stage_model.decoder.mid.attn_1.k.bias": "blocks.2.transformer_blocks.0.to_k.bias",311            "first_stage_model.decoder.mid.attn_1.k.weight": "blocks.2.transformer_blocks.0.to_k.weight",312            "first_stage_model.decoder.mid.attn_1.norm.bias": "blocks.2.norm.bias",313            "first_stage_model.decoder.mid.attn_1.norm.weight": "blocks.2.norm.weight",314            "first_stage_model.decoder.mid.attn_1.proj_out.bias": "blocks.2.transformer_blocks.0.to_out.bias",315            "first_stage_model.decoder.mid.attn_1.proj_out.weight": "blocks.2.transformer_blocks.0.to_out.weight",316            "first_stage_model.decoder.mid.attn_1.q.bias": "blocks.2.transformer_blocks.0.to_q.bias",317            "first_stage_model.decoder.mid.attn_1.q.weight": "blocks.2.transformer_blocks.0.to_q.weight",318            "first_stage_model.decoder.mid.attn_1.v.bias": "blocks.2.transformer_blocks.0.to_v.bias",319            "first_stage_model.decoder.mid.attn_1.v.weight": "blocks.2.transformer_blocks.0.to_v.weight",320            "first_stage_model.decoder.mid.block_1.conv1.bias": "blocks.0.conv1.bias",321            "first_stage_model.decoder.mid.block_1.conv1.weight": "blocks.0.conv1.weight",322            "first_stage_model.decoder.mid.block_1.conv2.bias": "blocks.0.conv2.bias",323            "first_stage_model.decoder.mid.block_1.conv2.weight": "blocks.0.conv2.weight",324            "first_stage_model.decoder.mid.block_1.mix_factor": "blocks.1.mix_factor",325            "first_stage_model.decoder.mid.block_1.norm1.bias": "blocks.0.norm1.bias",326            "first_stage_model.decoder.mid.block_1.norm1.weight": "blocks.0.norm1.weight",327            "first_stage_model.decoder.mid.block_1.norm2.bias": "blocks.0.norm2.bias",328            "first_stage_model.decoder.mid.block_1.norm2.weight": "blocks.0.norm2.weight",329            "first_stage_model.decoder.mid.block_1.time_stack.in_layers.0.bias": "blocks.1.norm1.bias",330            "first_stage_model.decoder.mid.block_1.time_stack.in_layers.0.weight": "blocks.1.norm1.weight",331            "first_stage_model.decoder.mid.block_1.time_stack.in_layers.2.bias": "blocks.1.conv1.bias",332            "first_stage_model.decoder.mid.block_1.time_stack.in_layers.2.weight": "blocks.1.conv1.weight",333            "first_stage_model.decoder.mid.block_1.time_stack.out_layers.0.bias": "blocks.1.norm2.bias",334            "first_stage_model.decoder.mid.block_1.time_stack.out_layers.0.weight": "blocks.1.norm2.weight",335            "first_stage_model.decoder.mid.block_1.time_stack.out_layers.3.bias": "blocks.1.conv2.bias",336            "first_stage_model.decoder.mid.block_1.time_stack.out_layers.3.weight": "blocks.1.conv2.weight",337            "first_stage_model.decoder.mid.block_2.conv1.bias": "blocks.3.conv1.bias",338            "first_stage_model.decoder.mid.block_2.conv1.weight": "blocks.3.conv1.weight",339            "first_stage_model.decoder.mid.block_2.conv2.bias": "blocks.3.conv2.bias",340            "first_stage_model.decoder.mid.block_2.conv2.weight": "blocks.3.conv2.weight",341            "first_stage_model.decoder.mid.block_2.mix_factor": "blocks.4.mix_factor",342            "first_stage_model.decoder.mid.block_2.norm1.bias": "blocks.3.norm1.bias",343            "first_stage_model.decoder.mid.block_2.norm1.weight": "blocks.3.norm1.weight",344            "first_stage_model.decoder.mid.block_2.norm2.bias": "blocks.3.norm2.bias",345            "first_stage_model.decoder.mid.block_2.norm2.weight": "blocks.3.norm2.weight",346            "first_stage_model.decoder.mid.block_2.time_stack.in_layers.0.bias": "blocks.4.norm1.bias",347            "first_stage_model.decoder.mid.block_2.time_stack.in_layers.0.weight": "blocks.4.norm1.weight",348            "first_stage_model.decoder.mid.block_2.time_stack.in_layers.2.bias": "blocks.4.conv1.bias",349            "first_stage_model.decoder.mid.block_2.time_stack.in_layers.2.weight": "blocks.4.conv1.weight",350            "first_stage_model.decoder.mid.block_2.time_stack.out_layers.0.bias": "blocks.4.norm2.bias",351            "first_stage_model.decoder.mid.block_2.time_stack.out_layers.0.weight": "blocks.4.norm2.weight",352            "first_stage_model.decoder.mid.block_2.time_stack.out_layers.3.bias": "blocks.4.conv2.bias",353            "first_stage_model.decoder.mid.block_2.time_stack.out_layers.3.weight": "blocks.4.conv2.weight",354            "first_stage_model.decoder.norm_out.bias": "conv_norm_out.bias",355            "first_stage_model.decoder.norm_out.weight": "conv_norm_out.weight",356            "first_stage_model.decoder.up.0.block.0.conv1.bias": "blocks.26.conv1.bias",357            "first_stage_model.decoder.up.0.block.0.conv1.weight": "blocks.26.conv1.weight",358            "first_stage_model.decoder.up.0.block.0.conv2.bias": "blocks.26.conv2.bias",359            "first_stage_model.decoder.up.0.block.0.conv2.weight": "blocks.26.conv2.weight",360            "first_stage_model.decoder.up.0.block.0.mix_factor": "blocks.27.mix_factor",361            "first_stage_model.decoder.up.0.block.0.nin_shortcut.bias": "blocks.26.conv_shortcut.bias",362            "first_stage_model.decoder.up.0.block.0.nin_shortcut.weight": "blocks.26.conv_shortcut.weight",363            "first_stage_model.decoder.up.0.block.0.norm1.bias": "blocks.26.norm1.bias",364            "first_stage_model.decoder.up.0.block.0.norm1.weight": "blocks.26.norm1.weight",365            "first_stage_model.decoder.up.0.block.0.norm2.bias": "blocks.26.norm2.bias",366            "first_stage_model.decoder.up.0.block.0.norm2.weight": "blocks.26.norm2.weight",367            "first_stage_model.decoder.up.0.block.0.time_stack.in_layers.0.bias": "blocks.27.norm1.bias",368            "first_stage_model.decoder.up.0.block.0.time_stack.in_layers.0.weight": "blocks.27.norm1.weight",369            "first_stage_model.decoder.up.0.block.0.time_stack.in_layers.2.bias": "blocks.27.conv1.bias",370            "first_stage_model.decoder.up.0.block.0.time_stack.in_layers.2.weight": "blocks.27.conv1.weight",371            "first_stage_model.decoder.up.0.block.0.time_stack.out_layers.0.bias": "blocks.27.norm2.bias",372            "first_stage_model.decoder.up.0.block.0.time_stack.out_layers.0.weight": "blocks.27.norm2.weight",373            "first_stage_model.decoder.up.0.block.0.time_stack.out_layers.3.bias": "blocks.27.conv2.bias",374            "first_stage_model.decoder.up.0.block.0.time_stack.out_layers.3.weight": "blocks.27.conv2.weight",375            "first_stage_model.decoder.up.0.block.1.conv1.bias": "blocks.28.conv1.bias",376            "first_stage_model.decoder.up.0.block.1.conv1.weight": "blocks.28.conv1.weight",377            "first_stage_model.decoder.up.0.block.1.conv2.bias": "blocks.28.conv2.bias",378            "first_stage_model.decoder.up.0.block.1.conv2.weight": "blocks.28.conv2.weight",379            "first_stage_model.decoder.up.0.block.1.mix_factor": "blocks.29.mix_factor",380            "first_stage_model.decoder.up.0.block.1.norm1.bias": "blocks.28.norm1.bias",381            "first_stage_model.decoder.up.0.block.1.norm1.weight": "blocks.28.norm1.weight",382            "first_stage_model.decoder.up.0.block.1.norm2.bias": "blocks.28.norm2.bias",383            "first_stage_model.decoder.up.0.block.1.norm2.weight": "blocks.28.norm2.weight",384            "first_stage_model.decoder.up.0.block.1.time_stack.in_layers.0.bias": "blocks.29.norm1.bias",385            "first_stage_model.decoder.up.0.block.1.time_stack.in_layers.0.weight": "blocks.29.norm1.weight",386            "first_stage_model.decoder.up.0.block.1.time_stack.in_layers.2.bias": "blocks.29.conv1.bias",387            "first_stage_model.decoder.up.0.block.1.time_stack.in_layers.2.weight": "blocks.29.conv1.weight",388            "first_stage_model.decoder.up.0.block.1.time_stack.out_layers.0.bias": "blocks.29.norm2.bias",389            "first_stage_model.decoder.up.0.block.1.time_stack.out_layers.0.weight": "blocks.29.norm2.weight",390            "first_stage_model.decoder.up.0.block.1.time_stack.out_layers.3.bias": "blocks.29.conv2.bias",391            "first_stage_model.decoder.up.0.block.1.time_stack.out_layers.3.weight": "blocks.29.conv2.weight",392            "first_stage_model.decoder.up.0.block.2.conv1.bias": "blocks.30.conv1.bias",393            "first_stage_model.decoder.up.0.block.2.conv1.weight": "blocks.30.conv1.weight",394            "first_stage_model.decoder.up.0.block.2.conv2.bias": "blocks.30.conv2.bias",395            "first_stage_model.decoder.up.0.block.2.conv2.weight": "blocks.30.conv2.weight",396            "first_stage_model.decoder.up.0.block.2.mix_factor": "blocks.31.mix_factor",397            "first_stage_model.decoder.up.0.block.2.norm1.bias": "blocks.30.norm1.bias",398            "first_stage_model.decoder.up.0.block.2.norm1.weight": "blocks.30.norm1.weight",399            "first_stage_model.decoder.up.0.block.2.norm2.bias": "blocks.30.norm2.bias",400            "first_stage_model.decoder.up.0.block.2.norm2.weight": "blocks.30.norm2.weight",401            "first_stage_model.decoder.up.0.block.2.time_stack.in_layers.0.bias": "blocks.31.norm1.bias",402            "first_stage_model.decoder.up.0.block.2.time_stack.in_layers.0.weight": "blocks.31.norm1.weight",403            "first_stage_model.decoder.up.0.block.2.time_stack.in_layers.2.bias": "blocks.31.conv1.bias",404            "first_stage_model.decoder.up.0.block.2.time_stack.in_layers.2.weight": "blocks.31.conv1.weight",405            "first_stage_model.decoder.up.0.block.2.time_stack.out_layers.0.bias": "blocks.31.norm2.bias",406            "first_stage_model.decoder.up.0.block.2.time_stack.out_layers.0.weight": "blocks.31.norm2.weight",407            "first_stage_model.decoder.up.0.block.2.time_stack.out_layers.3.bias": "blocks.31.conv2.bias",408            "first_stage_model.decoder.up.0.block.2.time_stack.out_layers.3.weight": "blocks.31.conv2.weight",409            "first_stage_model.decoder.up.1.block.0.conv1.bias": "blocks.19.conv1.bias",410            "first_stage_model.decoder.up.1.block.0.conv1.weight": "blocks.19.conv1.weight",411            "first_stage_model.decoder.up.1.block.0.conv2.bias": "blocks.19.conv2.bias",412            "first_stage_model.decoder.up.1.block.0.conv2.weight": "blocks.19.conv2.weight",413            "first_stage_model.decoder.up.1.block.0.mix_factor": "blocks.20.mix_factor",414            "first_stage_model.decoder.up.1.block.0.nin_shortcut.bias": "blocks.19.conv_shortcut.bias",415            "first_stage_model.decoder.up.1.block.0.nin_shortcut.weight": "blocks.19.conv_shortcut.weight",416            "first_stage_model.decoder.up.1.block.0.norm1.bias": "blocks.19.norm1.bias",417            "first_stage_model.decoder.up.1.block.0.norm1.weight": "blocks.19.norm1.weight",418            "first_stage_model.decoder.up.1.block.0.norm2.bias": "blocks.19.norm2.bias",419            "first_stage_model.decoder.up.1.block.0.norm2.weight": "blocks.19.norm2.weight",420            "first_stage_model.decoder.up.1.block.0.time_stack.in_layers.0.bias": "blocks.20.norm1.bias",421            "first_stage_model.decoder.up.1.block.0.time_stack.in_layers.0.weight": "blocks.20.norm1.weight",422            "first_stage_model.decoder.up.1.block.0.time_stack.in_layers.2.bias": "blocks.20.conv1.bias",423            "first_stage_model.decoder.up.1.block.0.time_stack.in_layers.2.weight": "blocks.20.conv1.weight",424            "first_stage_model.decoder.up.1.block.0.time_stack.out_layers.0.bias": "blocks.20.norm2.bias",425            "first_stage_model.decoder.up.1.block.0.time_stack.out_layers.0.weight": "blocks.20.norm2.weight",426            "first_stage_model.decoder.up.1.block.0.time_stack.out_layers.3.bias": "blocks.20.conv2.bias",427            "first_stage_model.decoder.up.1.block.0.time_stack.out_layers.3.weight": "blocks.20.conv2.weight",428            "first_stage_model.decoder.up.1.block.1.conv1.bias": "blocks.21.conv1.bias",429            "first_stage_model.decoder.up.1.block.1.conv1.weight": "blocks.21.conv1.weight",430            "first_stage_model.decoder.up.1.block.1.conv2.bias": "blocks.21.conv2.bias",431            "first_stage_model.decoder.up.1.block.1.conv2.weight": "blocks.21.conv2.weight",432            "first_stage_model.decoder.up.1.block.1.mix_factor": "blocks.22.mix_factor",433            "first_stage_model.decoder.up.1.block.1.norm1.bias": "blocks.21.norm1.bias",434            "first_stage_model.decoder.up.1.block.1.norm1.weight": "blocks.21.norm1.weight",435            "first_stage_model.decoder.up.1.block.1.norm2.bias": "blocks.21.norm2.bias",436            "first_stage_model.decoder.up.1.block.1.norm2.weight": "blocks.21.norm2.weight",437            "first_stage_model.decoder.up.1.block.1.time_stack.in_layers.0.bias": "blocks.22.norm1.bias",438            "first_stage_model.decoder.up.1.block.1.time_stack.in_layers.0.weight": "blocks.22.norm1.weight",439            "first_stage_model.decoder.up.1.block.1.time_stack.in_layers.2.bias": "blocks.22.conv1.bias",440            "first_stage_model.decoder.up.1.block.1.time_stack.in_layers.2.weight": "blocks.22.conv1.weight",441            "first_stage_model.decoder.up.1.block.1.time_stack.out_layers.0.bias": "blocks.22.norm2.bias",442            "first_stage_model.decoder.up.1.block.1.time_stack.out_layers.0.weight": "blocks.22.norm2.weight",443            "first_stage_model.decoder.up.1.block.1.time_stack.out_layers.3.bias": "blocks.22.conv2.bias",444            "first_stage_model.decoder.up.1.block.1.time_stack.out_layers.3.weight": "blocks.22.conv2.weight",445            "first_stage_model.decoder.up.1.block.2.conv1.bias": "blocks.23.conv1.bias",446            "first_stage_model.decoder.up.1.block.2.conv1.weight": "blocks.23.conv1.weight",447            "first_stage_model.decoder.up.1.block.2.conv2.bias": "blocks.23.conv2.bias",448            "first_stage_model.decoder.up.1.block.2.conv2.weight": "blocks.23.conv2.weight",449            "first_stage_model.decoder.up.1.block.2.mix_factor": "blocks.24.mix_factor",450            "first_stage_model.decoder.up.1.block.2.norm1.bias": "blocks.23.norm1.bias",451            "first_stage_model.decoder.up.1.block.2.norm1.weight": "blocks.23.norm1.weight",452            "first_stage_model.decoder.up.1.block.2.norm2.bias": "blocks.23.norm2.bias",453            "first_stage_model.decoder.up.1.block.2.norm2.weight": "blocks.23.norm2.weight",454            "first_stage_model.decoder.up.1.block.2.time_stack.in_layers.0.bias": "blocks.24.norm1.bias",455            "first_stage_model.decoder.up.1.block.2.time_stack.in_layers.0.weight": "blocks.24.norm1.weight",456            "first_stage_model.decoder.up.1.block.2.time_stack.in_layers.2.bias": "blocks.24.conv1.bias",457            "first_stage_model.decoder.up.1.block.2.time_stack.in_layers.2.weight": "blocks.24.conv1.weight",458            "first_stage_model.decoder.up.1.block.2.time_stack.out_layers.0.bias": "blocks.24.norm2.bias",459            "first_stage_model.decoder.up.1.block.2.time_stack.out_layers.0.weight": "blocks.24.norm2.weight",460            "first_stage_model.decoder.up.1.block.2.time_stack.out_layers.3.bias": "blocks.24.conv2.bias",461            "first_stage_model.decoder.up.1.block.2.time_stack.out_layers.3.weight": "blocks.24.conv2.weight",462            "first_stage_model.decoder.up.1.upsample.conv.bias": "blocks.25.conv.bias",463            "first_stage_model.decoder.up.1.upsample.conv.weight": "blocks.25.conv.weight",464            "first_stage_model.decoder.up.2.block.0.conv1.bias": "blocks.12.conv1.bias",465            "first_stage_model.decoder.up.2.block.0.conv1.weight": "blocks.12.conv1.weight",466            "first_stage_model.decoder.up.2.block.0.conv2.bias": "blocks.12.conv2.bias",467            "first_stage_model.decoder.up.2.block.0.conv2.weight": "blocks.12.conv2.weight",468            "first_stage_model.decoder.up.2.block.0.mix_factor": "blocks.13.mix_factor",469            "first_stage_model.decoder.up.2.block.0.norm1.bias": "blocks.12.norm1.bias",470            "first_stage_model.decoder.up.2.block.0.norm1.weight": "blocks.12.norm1.weight",471            "first_stage_model.decoder.up.2.block.0.norm2.bias": "blocks.12.norm2.bias",472            "first_stage_model.decoder.up.2.block.0.norm2.weight": "blocks.12.norm2.weight",473            "first_stage_model.decoder.up.2.block.0.time_stack.in_layers.0.bias": "blocks.13.norm1.bias",474            "first_stage_model.decoder.up.2.block.0.time_stack.in_layers.0.weight": "blocks.13.norm1.weight",475            "first_stage_model.decoder.up.2.block.0.time_stack.in_layers.2.bias": "blocks.13.conv1.bias",476            "first_stage_model.decoder.up.2.block.0.time_stack.in_layers.2.weight": "blocks.13.conv1.weight",477            "first_stage_model.decoder.up.2.block.0.time_stack.out_layers.0.bias": "blocks.13.norm2.bias",478            "first_stage_model.decoder.up.2.block.0.time_stack.out_layers.0.weight": "blocks.13.norm2.weight",479            "first_stage_model.decoder.up.2.block.0.time_stack.out_layers.3.bias": "blocks.13.conv2.bias",480            "first_stage_model.decoder.up.2.block.0.time_stack.out_layers.3.weight": "blocks.13.conv2.weight",481            "first_stage_model.decoder.up.2.block.1.conv1.bias": "blocks.14.conv1.bias",482            "first_stage_model.decoder.up.2.block.1.conv1.weight": "blocks.14.conv1.weight",483            "first_stage_model.decoder.up.2.block.1.conv2.bias": "blocks.14.conv2.bias",484            "first_stage_model.decoder.up.2.block.1.conv2.weight": "blocks.14.conv2.weight",485            "first_stage_model.decoder.up.2.block.1.mix_factor": "blocks.15.mix_factor",486            "first_stage_model.decoder.up.2.block.1.norm1.bias": "blocks.14.norm1.bias",487            "first_stage_model.decoder.up.2.block.1.norm1.weight": "blocks.14.norm1.weight",488            "first_stage_model.decoder.up.2.block.1.norm2.bias": "blocks.14.norm2.bias",489            "first_stage_model.decoder.up.2.block.1.norm2.weight": "blocks.14.norm2.weight",490            "first_stage_model.decoder.up.2.block.1.time_stack.in_layers.0.bias": "blocks.15.norm1.bias",491            "first_stage_model.decoder.up.2.block.1.time_stack.in_layers.0.weight": "blocks.15.norm1.weight",492            "first_stage_model.decoder.up.2.block.1.time_stack.in_layers.2.bias": "blocks.15.conv1.bias",493            "first_stage_model.decoder.up.2.block.1.time_stack.in_layers.2.weight": "blocks.15.conv1.weight",494            "first_stage_model.decoder.up.2.block.1.time_stack.out_layers.0.bias": "blocks.15.norm2.bias",495            "first_stage_model.decoder.up.2.block.1.time_stack.out_layers.0.weight": "blocks.15.norm2.weight",496            "first_stage_model.decoder.up.2.block.1.time_stack.out_layers.3.bias": "blocks.15.conv2.bias",497            "first_stage_model.decoder.up.2.block.1.time_stack.out_layers.3.weight": "blocks.15.conv2.weight",498            "first_stage_model.decoder.up.2.block.2.conv1.bias": "blocks.16.conv1.bias",499            "first_stage_model.decoder.up.2.block.2.conv1.weight": "blocks.16.conv1.weight",500            "first_stage_model.decoder.up.2.block.2.conv2.bias": "blocks.16.conv2.bias",501            "first_stage_model.decoder.up.2.block.2.conv2.weight": "blocks.16.conv2.weight",502            "first_stage_model.decoder.up.2.block.2.mix_factor": "blocks.17.mix_factor",503            "first_stage_model.decoder.up.2.block.2.norm1.bias": "blocks.16.norm1.bias",504            "first_stage_model.decoder.up.2.block.2.norm1.weight": "blocks.16.norm1.weight",505            "first_stage_model.decoder.up.2.block.2.norm2.bias": "blocks.16.norm2.bias",506            "first_stage_model.decoder.up.2.block.2.norm2.weight": "blocks.16.norm2.weight",507            "first_stage_model.decoder.up.2.block.2.time_stack.in_layers.0.bias": "blocks.17.norm1.bias",508            "first_stage_model.decoder.up.2.block.2.time_stack.in_layers.0.weight": "blocks.17.norm1.weight",509            "first_stage_model.decoder.up.2.block.2.time_stack.in_layers.2.bias": "blocks.17.conv1.bias",510            "first_stage_model.decoder.up.2.block.2.time_stack.in_layers.2.weight": "blocks.17.conv1.weight",511            "first_stage_model.decoder.up.2.block.2.time_stack.out_layers.0.bias": "blocks.17.norm2.bias",512            "first_stage_model.decoder.up.2.block.2.time_stack.out_layers.0.weight": "blocks.17.norm2.weight",513            "first_stage_model.decoder.up.2.block.2.time_stack.out_layers.3.bias": "blocks.17.conv2.bias",514            "first_stage_model.decoder.up.2.block.2.time_stack.out_layers.3.weight": "blocks.17.conv2.weight",515            "first_stage_model.decoder.up.2.upsample.conv.bias": "blocks.18.conv.bias",516            "first_stage_model.decoder.up.2.upsample.conv.weight": "blocks.18.conv.weight",517            "first_stage_model.decoder.up.3.block.0.conv1.bias": "blocks.5.conv1.bias",518            "first_stage_model.decoder.up.3.block.0.conv1.weight": "blocks.5.conv1.weight",519            "first_stage_model.decoder.up.3.block.0.conv2.bias": "blocks.5.conv2.bias",520            "first_stage_model.decoder.up.3.block.0.conv2.weight": "blocks.5.conv2.weight",521            "first_stage_model.decoder.up.3.block.0.mix_factor": "blocks.6.mix_factor",522            "first_stage_model.decoder.up.3.block.0.norm1.bias": "blocks.5.norm1.bias",523            "first_stage_model.decoder.up.3.block.0.norm1.weight": "blocks.5.norm1.weight",524            "first_stage_model.decoder.up.3.block.0.norm2.bias": "blocks.5.norm2.bias",525            "first_stage_model.decoder.up.3.block.0.norm2.weight": "blocks.5.norm2.weight",526            "first_stage_model.decoder.up.3.block.0.time_stack.in_layers.0.bias": "blocks.6.norm1.bias",527            "first_stage_model.decoder.up.3.block.0.time_stack.in_layers.0.weight": "blocks.6.norm1.weight",528            "first_stage_model.decoder.up.3.block.0.time_stack.in_layers.2.bias": "blocks.6.conv1.bias",529            "first_stage_model.decoder.up.3.block.0.time_stack.in_layers.2.weight": "blocks.6.conv1.weight",530            "first_stage_model.decoder.up.3.block.0.time_stack.out_layers.0.bias": "blocks.6.norm2.bias",531            "first_stage_model.decoder.up.3.block.0.time_stack.out_layers.0.weight": "blocks.6.norm2.weight",532            "first_stage_model.decoder.up.3.block.0.time_stack.out_layers.3.bias": "blocks.6.conv2.bias",533            "first_stage_model.decoder.up.3.block.0.time_stack.out_layers.3.weight": "blocks.6.conv2.weight",534            "first_stage_model.decoder.up.3.block.1.conv1.bias": "blocks.7.conv1.bias",535            "first_stage_model.decoder.up.3.block.1.conv1.weight": "blocks.7.conv1.weight",536            "first_stage_model.decoder.up.3.block.1.conv2.bias": "blocks.7.conv2.bias",537            "first_stage_model.decoder.up.3.block.1.conv2.weight": "blocks.7.conv2.weight",538            "first_stage_model.decoder.up.3.block.1.mix_factor": "blocks.8.mix_factor",539            "first_stage_model.decoder.up.3.block.1.norm1.bias": "blocks.7.norm1.bias",540            "first_stage_model.decoder.up.3.block.1.norm1.weight": "blocks.7.norm1.weight",541            "first_stage_model.decoder.up.3.block.1.norm2.bias": "blocks.7.norm2.bias",542            "first_stage_model.decoder.up.3.block.1.norm2.weight": "blocks.7.norm2.weight",543            "first_stage_model.decoder.up.3.block.1.time_stack.in_layers.0.bias": "blocks.8.norm1.bias",544            "first_stage_model.decoder.up.3.block.1.time_stack.in_layers.0.weight": "blocks.8.norm1.weight",545            "first_stage_model.decoder.up.3.block.1.time_stack.in_layers.2.bias": "blocks.8.conv1.bias",546            "first_stage_model.decoder.up.3.block.1.time_stack.in_layers.2.weight": "blocks.8.conv1.weight",547            "first_stage_model.decoder.up.3.block.1.time_stack.out_layers.0.bias": "blocks.8.norm2.bias",548            "first_stage_model.decoder.up.3.block.1.time_stack.out_layers.0.weight": "blocks.8.norm2.weight",549            "first_stage_model.decoder.up.3.block.1.time_stack.out_layers.3.bias": "blocks.8.conv2.bias",550            "first_stage_model.decoder.up.3.block.1.time_stack.out_layers.3.weight": "blocks.8.conv2.weight",551            "first_stage_model.decoder.up.3.block.2.conv1.bias": "blocks.9.conv1.bias",552            "first_stage_model.decoder.up.3.block.2.conv1.weight": "blocks.9.conv1.weight",553            "first_stage_model.decoder.up.3.block.2.conv2.bias": "blocks.9.conv2.bias",554            "first_stage_model.decoder.up.3.block.2.conv2.weight": "blocks.9.conv2.weight",555            "first_stage_model.decoder.up.3.block.2.mix_factor": "blocks.10.mix_factor",556            "first_stage_model.decoder.up.3.block.2.norm1.bias": "blocks.9.norm1.bias",557            "first_stage_model.decoder.up.3.block.2.norm1.weight": "blocks.9.norm1.weight",558            "first_stage_model.decoder.up.3.block.2.norm2.bias": "blocks.9.norm2.bias",559            "first_stage_model.decoder.up.3.block.2.norm2.weight": "blocks.9.norm2.weight",560            "first_stage_model.decoder.up.3.block.2.time_stack.in_layers.0.bias": "blocks.10.norm1.bias",561            "first_stage_model.decoder.up.3.block.2.time_stack.in_layers.0.weight": "blocks.10.norm1.weight",562            "first_stage_model.decoder.up.3.block.2.time_stack.in_layers.2.bias": "blocks.10.conv1.bias",563            "first_stage_model.decoder.up.3.block.2.time_stack.in_layers.2.weight": "blocks.10.conv1.weight",564            "first_stage_model.decoder.up.3.block.2.time_stack.out_layers.0.bias": "blocks.10.norm2.bias",565            "first_stage_model.decoder.up.3.block.2.time_stack.out_layers.0.weight": "blocks.10.norm2.weight",566            "first_stage_model.decoder.up.3.block.2.time_stack.out_layers.3.bias": "blocks.10.conv2.bias",567            "first_stage_model.decoder.up.3.block.2.time_stack.out_layers.3.weight": "blocks.10.conv2.weight",568            "first_stage_model.decoder.up.3.upsample.conv.bias": "blocks.11.conv.bias",569            "first_stage_model.decoder.up.3.upsample.conv.weight": "blocks.11.conv.weight",570        }571        state_dict_ = {}572        for name in state_dict:573            if name in rename_dict:574                param = state_dict[name]575                if "blocks.2.transformer_blocks.0" in rename_dict[name]:576                    param = param.squeeze()577                state_dict_[rename_dict[name]] = param578        return state_dict_579