'''simple docstring'''






import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


SCREAMING_SNAKE_CASE_	   =			logging.getLogger()




@unittest.skip("""Temporarily disable the doc tests."""				)
@require_torch
@require_tf
@slow
class    a (       unittest.TestCase				):



  """simple docstring"""







  def    lowercase_  (							self   ,    snake_case_   ,    snake_case_ = None   ,    snake_case_ = None   ,    snake_case_ = None   ,    snake_case_ = True   ,    ):

    '''simple docstring'''







    __UpperCAmelCase:					Any		= [file for file in os.listdir(snake_case_					) if os.path.isfile(os.path.join(snake_case_   ,    snake_case_					)					)]

    if identifier is not None:
      __UpperCAmelCase:					Union[str, Any]		= [file for file in files if identifier in file]

    if n_identifier is not None:
      if isinstance(snake_case_   ,    snake_case_					):
        for n_ in n_identifier:
          __UpperCAmelCase:					List[Any]		= [file for file in files if n_ not in file]
      else:
        __UpperCAmelCase:					List[str]		= [file for file in files if n_identifier not in file]

    __UpperCAmelCase:					List[str]		= ignore_files or []
    ignore_files.append("""__init__.py"""					)
    __UpperCAmelCase:					int		= [file for file in files if file not in ignore_files]

    for file in files:
      # Open all files
      print("""Testing"""   ,    snake_case_					)

      if only_modules:
        __UpperCAmelCase:					List[Any]		= file.split("""."""					)[0]
        try:
          __UpperCAmelCase:					Tuple		= getattr(snake_case_   ,    snake_case_					)
          __UpperCAmelCase:					Union[str, Any]		= doctest.DocTestSuite(snake_case_					)
          __UpperCAmelCase:					Dict		= unittest.TextTestRunner().run(snake_case_					)
          self.assertIs(len(result.failures					)   ,    0					)
        except AttributeError:
          logger.info(F'''{module_identifier} is not a module.'''					)
      else:
        __UpperCAmelCase:					int		= doctest.testfile(str("""..""" / directory / file					)   ,    optionflags=doctest.ELLIPSIS					)
        self.assertIs(result.failed   ,    0					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					str		= Path("""src/transformers"""					)
    __UpperCAmelCase:					Dict		= """modeling"""
    __UpperCAmelCase:					Dict		= [
        """modeling_ctrl.py""",
        """modeling_tf_ctrl.py""",
    ]
    self.analyze_directory(snake_case_   ,    identifier=snake_case_   ,    ignore_files=snake_case_					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[int]		= Path("""src/transformers"""					)
    __UpperCAmelCase:					List[str]		= """tokenization"""
    self.analyze_directory(snake_case_   ,    identifier=snake_case_					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					List[Any]		= Path("""src/transformers"""					)
    __UpperCAmelCase:					str		= """configuration"""
    self.analyze_directory(snake_case_   ,    identifier=snake_case_					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Union[str, Any]		= Path("""src/transformers"""					)
    __UpperCAmelCase:					Union[str, Any]		= ["""configuration""", """modeling""", """tokenization"""]
    self.analyze_directory(snake_case_   ,    n_identifier=snake_case_					)







  def    lowercase_  (							self					):

    '''simple docstring'''







    __UpperCAmelCase:					Optional[int]		= Path("""docs/source"""					)
    __UpperCAmelCase:					int		= ["""favicon.ico"""]
    self.analyze_directory(snake_case_   ,    ignore_files=snake_case_   ,    only_modules=snake_case_					)
'''simple docstring'''






import argparse
import os

import torch

from transformers.utils import WEIGHTS_NAME


SCREAMING_SNAKE_CASE_	   =			['small', 'medium', 'large']

SCREAMING_SNAKE_CASE_	   =			'lm_head.decoder.weight'
SCREAMING_SNAKE_CASE_	   =			'lm_head.weight'






def  UpperCamelCase__					(					_lowercase    :				str   ,    _lowercase    :				str     )							->	List[str]:
  __UpperCAmelCase:					Tuple		= torch.load(_lowercase     )
  __UpperCAmelCase:					Tuple		= d.pop(_lowercase     )
  os.makedirs(_lowercase   ,    exist_ok=_lowercase     )
  torch.save(_lowercase   ,    os.path.join(_lowercase   ,    _lowercase     )     )


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