class_docstr: Implementation of the Switch Transformers Sparse MLP module.
class_docstr_tok: ["Implementation","of","the","Switch","Transformers","Sparse","MLP","module","."]
code: def __init__(
      self,
      config: GPTSanJapaneseConfig,
      expert_class: nn.Module = GPTSanJapaneseDenseActDense,
  ):
      super().__init__()
      # Step 1: Get the correct router according to its class
      self.router = GPTSanJapaneseTop1Router(config)
  
      # Step 2: Get the experts
      self.experts = nn.ModuleDict()
      for idx in range(config.num_experts):
          self.experts[f"expert_{idx}"] = expert_class(config)
  
imports: import copy
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn
  from ...activations import ACT2FN
  from ...modeling_outputs import MoECausalLMOutputWithPast, MoEModelOutputWithPastAndCrossAttentions
  from ...modeling_utils import PreTrainedModel
  from ...utils import DUMMY_INPUTS, DUMMY_MASK, add_start_docstrings, add_start_docstrings_to_model_forward, is_torch_fx_proxy, logging
  from .configuration_gptsan_japanese import GPTSanJapaneseConfig
label_desc: Use image node_id 1 to create a new GPTSanJapaneseSparseMLP object from inherited base classes: nn with example: obj = GPTSanJapaneseSparseMLP(config, expert_class)