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
code: def _init_weights(
      self, module: Union[nn.Linear, nn.Conv2d, nn.LayerNorm]
  ) -> None:
      """Initialize the weights"""
      if isinstance(module, MgpstrEmbeddings):
          nn.init.trunc_normal_(
              module.pos_embed,
              mean=0.0,
              std=self.config.initializer_range,
          )
          nn.init.trunc_normal_(
              module.cls_token,
              mean=0.0,
              std=self.config.initializer_range,
          )
      elif isinstance(module, (nn.Linear, nn.Conv2d)):
          module.weight.data = nn.init.trunc_normal_(
              module.weight.data,
              mean=0.0,
              std=self.config.initializer_range,
          )
          if module.bias is not None:
              module.bias.data.zero_()
      elif isinstance(module, nn.LayerNorm):
          module.bias.data.zero_()
          module.weight.data.fill_(1.0)
  
imports: import collections.abc
  from dataclasses import dataclass
  from typing import Optional, Tuple, Union
  import torch
  import torch.nn.functional
  import torch.utils.checkpoint
  from torch import nn
  from ...modeling_outputs import BaseModelOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import ModelOutput, add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_mgp_str import MgpstrConfig
label_desc: Use image node_id 1 for calling the MgpstrPreTrainedModel obj's underlying member method code with example usage: obj._init_weights(module) without return types