class_docstr: Replace original Huggingface's layer into Megatron tensor sliced layer.
  
  Args:
      model (nn.Module): Huggingface pre-trained transformer model
      mp_group (Any): process group for model parallelism
      fp16: (bool): Whether use FP16 or not.
      num_gpus (int): number of GPUs
      custom_policies (Union[Policy, List[Policy]]): custom policy object (default=None)
class_docstr_tok: ["Replace","original","Huggingface","'s","layer","into","Megatron","tensor","sliced","layer",".","Args",":","model","(","nn.Module",")",":","Huggingface","pre-trained","transformer","model","mp_group","(","Any",")",":","process","group","for","model","parallelism","fp16",":","(","bool",")",":","Whether","use","FP16","or","not",".","num_gpus","(","int",")",":","number","of","GPUs","custom_policies","(","Union","[","Policy",",","List","[","Policy","]","]",")",":","custom","policy","object","(","default=None",")"]
docstr: Preprocess user's policy object to replace tensors
  
  Args:
      function_output (List[Layer]): list of layers in the policy object
      policy (Policy): policy object
  
  Returns:
      Tuple[Dict, Dict, Dict, Dict]:
          Tuple of dictionaries of parameters and attributes required for tensor slicing
docstr_tok: ["Preprocess","user","'s","policy","object","to","replace","tensors","Args",":","function_output","(","List","[","Layer","]",")",":","list","of","layers","in","the","policy","object","policy","(","Policy",")",":","policy","object","Returns",":","Tuple","[","Dict",",","Dict",",","Dict",",","Dict","]",":","Tuple","of","dictionaries","of","parameters","and","attributes","required","for","tensor","slicing"]
code: def preprocess(
      self,
      function_output: List[Layer],
      policy: Policy,
  ) -> Tuple[Dict, Dict, Dict, Dict]:
      """
      Preprocess user's policy object to replace tensors
  
      Args:
          function_output (List[Layer]): list of layers in the policy object
          policy (Policy): policy object
  
      Returns:
          Tuple[Dict, Dict, Dict, Dict]:
              Tuple of dictionaries of parameters and attributes required for tensor slicing
      """
      weight_dict, bias_dict, weight_attr_dict, bias_attr_dict = (
          {},
          {},
          {},
          {},
      )
  
      for layer_params in function_output:
          w = layer_params.weight
          b = layer_params.bias
          replace = layer_params.replace
          n_fused = layer_params.n_fused
          reversed = layer_params.reversed
          ignore = layer_params.ignore_checker
  
          if w is not None:
              if rhasattr(policy, f"{self.varname}.{w}"):
                  w_layer = rgetattr(policy, f"{self.varname}.{w}")
                  weight_dict[f"{self.varname}.{w}"] = w_layer
                  weight_attr_dict[f"{self.varname}.{w}"] = (
                      n_fused,
                      reversed,
                  )
  
                  orig_layer_name = ".".join(w.split(".")[:-1])
                  orig_layer = rgetattr(
                      policy,
                      f"{self.varname}.{orig_layer_name}",
                  )
              elif not ignore:
                  raise Exception(
                      f"'{policy.original_layer_class().__qualname__}' object has no attribute '{w}'"
                  )
  
          if b is not None:
              if rhasattr(policy, f"{self.varname}.{b}"):
                  b_layer = rgetattr(policy, f"{self.varname}.{b}")
                  bias_dict[f"{self.varname}.{b}"] = b_layer
                  bias_attr_dict[f"{self.varname}.{b}"] = (
                      n_fused,
                      reversed,
                  )
  
                  orig_layer_name = ".".join(b.split(".")[:-1])
                  orig_layer = rgetattr(
                      policy,
                      f"{self.varname}.{orig_layer_name}",
                  )
              elif not ignore:
                  raise Exception(
                      f"'{policy.original_layer_class().__qualname__}' object has no attribute '{b}'"
                  )
  
          if not w and not b:
              raise Exception("both weight and bias are empty !")
  
          if replace is not None:
              orig_layer.__class__ = replace
              orig_layer.mp_group = self.mp_group
  
      return weight_dict, bias_dict, weight_attr_dict, bias_attr_dict
  
file_path: parallelformers/parallelformers/parallel/replacing.py
imports: from contextlib import suppress
  from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union
  import torch.nn
  from torch import Size, Tensor
  from parallelformers.parallel.slicing import TensorSlicer
  from parallelformers.policies.base import Layer, Policy
  from parallelformers.policies.base.auto import AutoPolicy
  from parallelformers.utils import rgetattr, rhasattr, rsetattr
label_desc: Use image node_id 6 for calling the TensorReplacer obj's underlying member method code with example usage: obj.preprocess(function_output, policy) and returns: weight_dict,  bias_dict,  weight_attr_dict,  bias_attr_dict