MCPcopy Create free account
hub / github.com/SooLab/CGFormer / _init_weights

Method _init_weights

bert/modeling_bert.py:551–561  ·  view source on GitHub ↗

Initialize the weights

(self, module)

Source from the content-addressed store, hash-verified

549 base_model_prefix = "bert"
550
551 def _init_weights(self, module):
552 """ Initialize the weights """
553 if isinstance(module, (nn.Linear, nn.Embedding)):
554 # Slightly different from the TF version which uses truncated_normal for initialization
555 # cf https://github.com/pytorch/pytorch/pull/5617
556 module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
557 elif isinstance(module, BertLayerNorm):
558 module.bias.data.zero_()
559 module.weight.data.fill_(1.0)
560 if isinstance(module, nn.Linear) and module.bias is not None:
561 module.bias.data.zero_()
562
563
564BERT_START_DOCSTRING = r"""

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected