X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=mygpt.py;h=ebc9a83e7162de6f520c35dd1f3dd688a977abda;hb=3b62d298013c7b940aec7cab0f74fb5118493f99;hp=3bce361424ec4a8b37150c300dc0df05b01de7ef;hpb=f3a734b6c522b2be0004a1b8bc2fe2eab2a90263;p=mygpt.git diff --git a/mygpt.py b/mygpt.py index 3bce361..ebc9a83 100755 --- a/mygpt.py +++ b/mygpt.py @@ -97,10 +97,6 @@ class MyGPT(nn.Module): AddPositionalEncoding(len_max), ) - # Small embedding initialization - with torch.no_grad(): - self.embedding[0].weight.normal_(0, 2e-2) - trunk_blocks = [ ] for _ in range(nb_blocks): @@ -128,6 +124,14 @@ class MyGPT(nn.Module): self.readout = nn.Linear(in_features = dim_model, out_features = vocabulary_size) + with torch.no_grad(): + for m in self.modules(): + if isinstance(m, nn.Embedding): + m.weight.normal_(mean = 0, std = 2e-2) + elif isinstance(m, nn.LayerNorm): + m.bias.zero_() + m.weight.fill_(1.0) + def forward(self, x): x = F.pad(x, (1, -1)) x = self.embedding(x)