MCPcopy Create free account
hub / github.com/CompVis/zigma / initialize_weights

Method initialize_weights

model_zigma.py:840–872  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

838 print("m_init", m_init)
839
840 def initialize_weights(self):
841
842 if self.use_pe == 1:
843 # Initialize (and freeze) pos_embed by sin-cos embedding:
844 pos_embed = get_2d_sincos_pos_embed(
845 self.pos_embed.shape[-1], int(self.x_embedder.num_patches**0.5)
846 )
847 self.pos_embed.data.copy_(torch.from_numpy(pos_embed).float().unsqueeze(0))
848
849 # Initialize patch_embed like nn.Linear (instead of nn.Conv2d):
850 w = self.x_embedder.proj.weight.data
851 nn.init.xavier_uniform_(w.view([w.shape[0], -1]))
852 nn.init.constant_(self.x_embedder.proj.bias, 0)
853
854 # if self.has_text:
855 # Initialize label embedding table:
856 # nn.init.normal_(self.y_embedder.y_embedding, std=0.02)
857
858 # Initialize timestep embedding MLP:
859 nn.init.normal_(self.t_embedder.mlp[0].weight, std=0.02)
860 nn.init.normal_(self.t_embedder.mlp[2].weight, std=0.02)
861
862 # Zero-out adaLN modulation layers in DiT blocks:
863 for block in self.blocks:
864 nn.init.constant_(block.adaLN_modulation[-1].weight, 0)
865 nn.init.constant_(block.adaLN_modulation[-1].bias, 0)
866
867 # Zero-out output layers:
868 try:
869 nn.init.constant_(self.final_layer.adaLN_modulation[-1].weight, 0)
870 nn.init.constant_(self.final_layer.adaLN_modulation[-1].bias, 0)
871 except:
872 pass
873
874 def unpatchify(self, x):
875 """

Callers 1

__init__Method · 0.95

Calls 1

get_2d_sincos_pos_embedFunction · 0.85

Tested by

no test coverage detected