code: def init_shared_parameters(config, in_features, device):
      """
      Create and initialize the parameters shared by all compacter modules
      """
      parameters = nn.ParameterDict()
      if config["shared_W_phm"]:
          if config["factorized_phm_W"]:
              out_features = in_features // config["reduction_factor"]
              _in_feats_per_axis = in_features // config["phm_dim"]
              _out_feats_per_axis = out_features // config["phm_dim"]
              W_down_left = torch.Tensor(
                  size=(
                      config["phm_dim"],
                      _in_feats_per_axis,
                      config["phm_rank"],
                  )
              )
              W_down_right = torch.Tensor(
                  size=(
                      config["phm_dim"],
                      config["phm_rank"],
                      _out_feats_per_axis,
                  )
              )
              W_up_left = torch.Tensor(
                  size=(
                      config["phm_dim"],
                      _out_feats_per_axis,
                      config["phm_rank"],
                  )
              )
              W_up_right = torch.Tensor(
                  size=(
                      config["phm_dim"],
                      config["phm_rank"],
                      _in_feats_per_axis,
                  )
              )
              init_W(config, W_left=W_down_left, W_right=W_down_right)
              init_W(config, W_left=W_up_left, W_right=W_up_right)
              parameters["W_down_left"] = nn.Parameter(
                  W_down_left, requires_grad=True
              )
              parameters["W_down_right"] = nn.Parameter(
                  W_down_right, requires_grad=True
              )
              parameters["W_up_left"] = nn.Parameter(
                  W_up_left, requires_grad=True
              )
              parameters["W_up_right"] = nn.Parameter(
                  W_up_right, requires_grad=True
              )
          else:
              W_down = torch.Tensor(
                  size=(
                      config["phm_dim"],
                      _in_feats_per_axis,
                      _out_feats_per_axis,
                  )
              )
              W_up = torch.Tensor(
                  size=(
                      config["phm_dim"],
                      _out_feats_per_axis,
                      _in_feats_per_axis,
                  )
              )
              init_W(config, W=W_down)
              init_W(config, W=W_up)
              parameters["W_down"] = nn.Parameter(
                  W_down, requires_grad=True
              )
              parameters["W_up"] = nn.Parameter(
                  W_up, requires_grad=True
              )
      if config["shared_phm_rule"]:
          if config["factorized_phm_rule"]:
              phm_rule_left = nn.Parameter(
                  torch.FloatTensor(
                      config["phm_dim"], config["phm_dim"], 1
                  ).to(device),
                  requires_grad=config["learn_phm"],
              )
              phm_rule_right = nn.Parameter(
                  torch.FloatTensor(
                      config["phm_dim"], 1, config["phm_dim"]
                  ).to(device),
                  requires_grad=config["learn_phm"],
              )
              if config["phm_c_init"] == "normal":
                  phm_rule_left.data.normal_(
                      mean=0, std=config["phm_init_range"]
                  )
                  phm_rule_right.data.normal_(
                      mean=0, std=config["phm_init_range"]
                  )
              elif config["phm_c_init"] == "uniform":
                  phm_rule_left.data.uniform_(-1, 1)
                  phm_rule_right.data.uniform_(-1, 1)
              else:
                  raise NotImplementedError
              parameters["phm_rule_left"] = phm_rule_left
              parameters["phm_rule_right"] = phm_rule_right
          else:
              phm_rule = nn.Parameter(
                  torch.FloatTensor(
                      config["phm_dim"],
                      config["phm_dim"],
                      config["phm_dim"],
                  ),
                  requires_grad=config["learn_phm"],
              )
              if config["phm_c_init"] == "normal":
                  phm_rule.data.normal_(
                      mean=0, std=config["phm_init_range"]
                  )
              elif config["phm_c_init"] == "uniform":
                  phm_rule.data.uniform_(-1, 1)
              else:
                  raise NotImplementedError
              parameters["phm_rule"] = phm_rule
      return parameters
  
imports: import math
  import torch
  from torch import nn
  from transformers.activations import get_activation
  from ..configuration import AdapterFusionConfig, BnConfig
  from ..context import ForwardContext
label_desc: Use image node_id 3 for calling a global function with example usage: init_shared_parameters(config, in_features, device) and returns: parameters