class_docstr: An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
  models.
class_docstr_tok: ["An","abstract","class","to","handle","weights","initialization","and","a","simple","interface","for","downloading","and","loading","pretrained","models","."]
docstr: Initialize the weights
docstr_tok: ["Initialize","the","weights"]
code: def _init_weights(
      self,
      module: Union[
          nn.Linear,
          nn.Conv2d,
          nn.Embedding,
          nn.LayerNorm,
          GraphormerMultiheadAttention,
          GraphormerGraphEncoder,
      ],
  ):
      """
      Initialize the weights
      """
      if isinstance(module, (nn.Linear, nn.Conv2d)):
          # We might be missing part of the Linear init, dependant on the layer num
          module.weight.data.normal_(mean=0.0, std=0.02)
          if module.bias is not None:
              module.bias.data.zero_()
      elif isinstance(module, nn.Embedding):
          module.weight.data.normal_(mean=0.0, std=0.02)
          if module.padding_idx is not None:
              module.weight.data[module.padding_idx].zero_()
      elif isinstance(module, GraphormerMultiheadAttention):
          module.q_proj.weight.data.normal_(mean=0.0, std=0.02)
          module.k_proj.weight.data.normal_(mean=0.0, std=0.02)
          module.v_proj.weight.data.normal_(mean=0.0, std=0.02)
          module.reset_parameters()
      elif isinstance(module, nn.LayerNorm):
          module.bias.data.zero_()
          module.weight.data.fill_(1.0)
      elif isinstance(module, GraphormerGraphEncoder):
          if module.apply_graphormer_init:
              module.apply(self.init_graphormer_params)
  
      elif isinstance(module, nn.LayerNorm):
          module.bias.data.zero_()
          module.weight.data.fill_(1.0)
  
imports: import math
  from typing import Iterable, Iterator, List, Optional, Tuple, Union
  import torch
  import torch.nn
  from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
  from ...activations import ACT2FN
  from ...modeling_outputs import BaseModelOutputWithNoAttention, SequenceClassifierOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import logging
  from .configuration_graphormer import GraphormerConfig
label_desc: Use image node_id 3 for calling the GraphormerPreTrainedModel obj's underlying member method code with example usage: obj._init_weights(module) without return types