class_docstr: The base class for all the policies. For each different model, it should have a different policy class,
  like BertPolicy for Bert Model or OPTPolicy for OPT model.
  
  Shardformer has provided many built-in sharding policies for the mainstream models. You can use the
  built-in policies by setting `policy = None`, which is already the default argument for `Shardformer.optimize`.
  If you want to define your own policy, you can inherit from this class and overwrite the methods you want to modify.
docstr: Append or create a new method replacement description to the policy for the given key.
  
  Args:
      description (Union[SubModuleReplacementDescription, List[SubModuleReplacementDescription]]): the submodule replacement description to be appended
      policy (Dict[Union[str, nn.Module], ModulePolicyDescription]): the policy to be updated
      target_key (Union[str, nn.Module]): the key of the policy to be updated
docstr_tok: ["Append","or","create","a","new","method","replacement","description","to","the","policy","for","the","given","key",".","Args",":","description","(","Union","[","SubModuleReplacementDescription",",","List","[","SubModuleReplacementDescription","]","]",")",":","the","submodule","replacement","description","to","be","appended","policy","(","Dict","[","Union","[","str",",","nn.Module","]",",","ModulePolicyDescription","]",")",":","the","policy","to","be","updated","target_key","(","Union","[","str",",","nn.Module","]",")",":","the","key","of","the","policy","to","be","updated"]
code: def append_or_create_method_replacement(
      self,
      description: Dict[str, Callable],
      policy: Dict[Union[str, nn.Module], ModulePolicyDescription],
      target_key: Union[str, nn.Module],
  ) -> Dict[Union[str, nn.Module], ModulePolicyDescription]:
      r"""
      Append or create a new method replacement description to the policy for the given key.
  
      Args:
          description (Union[SubModuleReplacementDescription, List[SubModuleReplacementDescription]]): the submodule replacement description to be appended
          policy (Dict[Union[str, nn.Module], ModulePolicyDescription]): the policy to be updated
          target_key (Union[str, nn.Module]): the key of the policy to be updated
      """
      if target_key in policy:
          if policy[target_key].method_replacement is None:
              policy[target_key].method_replacement = description
          else:
              policy[target_key].method_replacement.update(description)
      else:
          policy[target_key] = ModulePolicyDescription(
              method_replacement=description
          )
  
      return policy
  
imports: from abc import ABC, abstractmethod
  from dataclasses import dataclass
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import numpy
  import torch.nn
  from torch import Tensor
  from torch.nn import Module
  from colossalai.pipeline.stage_manager import PipelineStageManager
  from ..layer.normalization import BaseLayerNorm
  from ..layer.parallel_module import ParallelModule
  from ..shard.shard_config import ShardConfig
label_desc: Use image node_id 10 for calling the Policy obj's underlying member method code with example usage: obj.append_or_create_method_replacement(description, policy, target_key) and returns: policy