





import argparse
import os

import torch

from transformers.utils import WEIGHTS_NAME


SCREAMING_SNAKE_CASE__							:      Any         =    ["""small""", """medium""", """large"""]

SCREAMING_SNAKE_CASE__							:      str         =    """lm_head.decoder.weight"""
SCREAMING_SNAKE_CASE__							:      str         =    """lm_head.weight"""






def    _A	(   lowerCamelCase				,			lowerCamelCase ):
   a__						:    Union[str, Any]   		=	torch.load(lowerCamelCase )
   a__						:    List[Any]   		=	d.pop(lowerCamelCase )
   os.makedirs(lowerCamelCase				,			exist_ok=lowerCamelCase )
   torch.save(lowerCamelCase				,			os.path.join(lowerCamelCase				,			lowerCamelCase ) )


if __name__ == "__main__":
  SCREAMING_SNAKE_CASE__							:      List[str]         =    argparse.ArgumentParser()
  parser.add_argument("""--dialogpt_path""", default=""".""", type=str)
  SCREAMING_SNAKE_CASE__							:      int         =    parser.parse_args()
  for MODEL in DIALOGPT_MODELS:
    SCREAMING_SNAKE_CASE__							:      str         =    os.path.join(args.dialogpt_path, f'{MODEL}_ft.pkl')
    SCREAMING_SNAKE_CASE__							:      str         =    f'./DialoGPT-{MODEL}'
    convert_dialogpt_checkpoint(
        checkpoint_path,
        pytorch_dump_folder_path,
    )








from packaging import version

from .import_utils import is_accelerate_available


if is_accelerate_available():
  import accelerate






def    _A	(   lowerCamelCase ):
   if not is_accelerate_available():
      return method
   a__						:    List[Any]   		=	version.parse(accelerate.__version__ ).base_version
   if version.parse(lowerCamelCase ) < version.parse("0.17.0" ):
      return method

   def wrapper(self				,			*lowerCamelCase				,			**lowerCamelCase ):
      if hasattr(self				,			"_hf_hook" ) and hasattr(self._hf_hook				,			"pre_forward" ):
         self._hf_hook.pre_forward(self )
      return method(self				,			*lowerCamelCase				,			**lowerCamelCase )

   return wrapper

