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: Replace original Huggingface layers to Megatron tensor sliced layers
  
  Args:
      model (nn.Module): model weight
      policy_cls (Type[Policy]): class of policy
  
  Returns:
      nn.Module: parallelized paramerters
docstr_tok: ["Replace","original","Huggingface","layers","to","Megatron","tensor","sliced","layers","Args",":","model","(","nn.Module",")",":","model","weight","policy_cls","(","Type","[","Policy","]",")",":","class","of","policy","Returns",":","nn.Module",":","parallelized","paramerters"]
code: def replace_orig_to_megatron_modules(
      self,
      model: nn.Module,
      policy_cls: Type[Policy],
  ) -> nn.Module:
      """
      Replace original Huggingface layers to Megatron tensor sliced layers
  
      Args:
          model (nn.Module): model weight
          policy_cls (Type[Policy]): class of policy
  
      Returns:
          nn.Module: parallelized paramerters
      """
      for name, child in model.named_children():
          if child.__class__ == policy_cls.original_layer_class():
              policy = policy_cls(layer=child)
              arguments = policy.replace_arguments(
                  self.config, self.num_gpus
              )
  
              for k, v in arguments.items():
                  with suppress(Exception):
                      rsetattr(policy, f"{self.varname}.{k}", v)
  
              rsetattr(model, name, self.make_megatron_layer(policy))
  
          self.replace_orig_to_megatron_modules(child, policy_cls)
  
      return model
  
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 5 for calling the TensorReplacer obj's underlying member method code with example usage: obj.replace_orig_to_megatron_modules(model, policy_cls) and returns: model