docstr: Creates a new hook based on the old hook. Use it only if you know what you are doing !
code: def _create_new_hook(self, old_hook):
      r"""
      Creates a new hook based on the old hook. Use it only if you know what you are doing !
      """
      old_hook_cls = getattr(
          accelerate.hooks, old_hook.__class__.__name__
      )
      old_hook_attr = old_hook.__dict__
      filtered_old_hook_attr = {}
      old_hook_init_signature = inspect.signature(old_hook_cls.__init__)
      for k in old_hook_attr.keys():
          if k in old_hook_init_signature.parameters:
              filtered_old_hook_attr[k] = old_hook_attr[k]
      new_hook = old_hook_cls(**filtered_old_hook_attr)
      return new_hook
  
imports: import copy
  import inspect
  import warnings
  from typing import Optional, Tuple
  import accelerate
  import torch
  from accelerate.hooks import add_hook_to_module, remove_hook_from_module
  from accelerate.utils import is_npu_available, is_xpu_available
  from safetensors.torch import storage_ptr, storage_size
  from ..import_utils import is_auto_gptq_available, is_torch_tpu_available
  from .constants import CONFIG_NAME, EMBEDDING_LAYER_NAMES, INCLUDE_LINEAR_LAYERS_SHORTHAND, SAFETENSORS_WEIGHTS_NAME, TRANSFORMERS_MODELS_TO_ADALORA_TARGET_MODULES_MAPPING, TRANSFORMERS_MODELS_TO_IA3_FEEDFORWARD_MODULES_MAPPING, TRANSFORMERS_MODELS_TO_IA3_TARGET_MODULES_MAPPING, TRANSFORMERS_MODELS_TO_LORA_TARGET_MODULES_MAPPING, TRANSFORMERS_MODELS_TO_PREFIX_TUNING_POSTPROCESS_MAPPING, WEIGHTS_NAME, bloom_model_postprocess_past_key_value, starcoder_model_postprocess_past_key_value
label_desc: Use image node_id 6 for calling the ModulesToSaveWrapper obj's underlying member method code with example usage: obj._create_new_hook(old_hook) and returns: new_hook