
"""simple docstring"""




import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
    import torch


A__      :	Tuple          =    random.Random()



def 							a__ (				lowerCAmelCase	:       Tuple       ,    lowerCAmelCase	:       Dict=1.0       ,    lowerCAmelCase	:       int=None       ,    lowerCAmelCase	:       List[str]=None		):






     '''simple docstring'''
     if rng is None:
          UpperCAmelCase__							: Union[str, Any] 							=						global_rng

     UpperCAmelCase__							: Any 							=						[]
     for batch_idx in range(shape[0]		):
          values.append([]		)
          for _ in range(shape[1]		):
               values[-1].append(rng.random() * scale		)

     return values







@require_torch
class   _lowercase						(       unittest.TestCase				):


     '''simple docstring'''





     def __init__(      self ,			__UpperCamelCase ,			__UpperCamelCase=7 ,			__UpperCamelCase=4_00 ,			__UpperCamelCase=20_00 ,			__UpperCamelCase=1 ,			__UpperCamelCase=0.0 ,			__UpperCamelCase=1_60_00 ,			__UpperCamelCase=True ,			__UpperCamelCase=80 ,			__UpperCamelCase=16 ,			__UpperCamelCase=64 ,			__UpperCamelCase="hann_window" ,			__UpperCamelCase=80 ,			__UpperCamelCase=76_00 ,			__UpperCamelCase=1E-10 ,			__UpperCamelCase=True ,			)->					Tuple:
          UpperCAmelCase__							: List[str] 							=						parent
          UpperCAmelCase__							: Union[str, Any] 							=						batch_size
          UpperCAmelCase__							: Any 							=						min_seq_length
          UpperCAmelCase__							: Optional[Any] 							=						max_seq_length
          UpperCAmelCase__							: Optional[int] 							=						(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
          UpperCAmelCase__							: List[str] 							=						feature_size
          UpperCAmelCase__							: int 							=						padding_value
          UpperCAmelCase__							: Optional[Any] 							=						sampling_rate
          UpperCAmelCase__							: Optional[int] 							=						do_normalize
          UpperCAmelCase__							: Union[str, Any] 							=						num_mel_bins
          UpperCAmelCase__							: Any 							=						hop_length
          UpperCAmelCase__							: Optional[int] 							=						win_length
          UpperCAmelCase__							: Tuple 							=						win_function
          UpperCAmelCase__							: Dict 							=						fmin
          UpperCAmelCase__							: Dict 							=						fmax
          UpperCAmelCase__							: str 							=						mel_floor
          UpperCAmelCase__							: Any 							=						return_attention_mask



     def  lowerCAmelCase__       (      self  )->					int:
          return {
              "feature_size": self.feature_size,
              "padding_value": self.padding_value,
              "sampling_rate": self.sampling_rate,
              "do_normalize": self.do_normalize,
              "num_mel_bins": self.num_mel_bins,
              "hop_length": self.hop_length,
              "win_length": self.win_length,
              "win_function": self.win_function,
              "fmin": self.fmin,
              "fmax": self.fmax,
              "mel_floor": self.mel_floor,
              "return_attention_mask": self.return_attention_mask,
          }



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=False ,			__UpperCamelCase=False  )->					Optional[int]:
          def _flatten(__UpperCamelCase  ):
               return list(itertools.chain(*__UpperCamelCase  )  )

          if equal_length:
               UpperCAmelCase__							: Tuple 							=						floats_list((self.batch_size, self.max_seq_length)  )
          else:
               # make sure that inputs increase in size
               UpperCAmelCase__							: List[str] 							=						[
                   _flatten(floats_list((x, self.feature_size)  )  )
                   for x in range(self.min_seq_length ,			self.max_seq_length ,			self.seq_length_diff  )
               ]

          if numpify:
               UpperCAmelCase__							: Optional[Any] 							=						[np.asarray(__UpperCamelCase  ) for x in speech_inputs]

          return speech_inputs



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase=False ,			__UpperCamelCase=False  )->					List[str]:
          if equal_length:
               UpperCAmelCase__							: List[str] 							=						[floats_list((self.max_seq_length, self.num_mel_bins)  ) for _ in range(self.batch_size  )]
          else:
               # make sure that inputs increase in size
               UpperCAmelCase__							: Any 							=						[
                   floats_list((x, self.num_mel_bins)  )
                   for x in range(self.min_seq_length ,			self.max_seq_length ,			self.seq_length_diff  )
               ]

          if numpify:
               UpperCAmelCase__							: Dict 							=						[np.asarray(__UpperCamelCase  ) for x in speech_inputs]

          return speech_inputs







@require_torch
class   _lowercase						(       lowerCAmelCase_	,   unittest.TestCase				):


     '''simple docstring'''





     _A								=							SpeechTaFeatureExtractor



     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          UpperCAmelCase__							: str 							=						SpeechTaFeatureExtractionTester(self  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase  )->					int:
          self.assertTrue(np.all(np.mean(__UpperCamelCase ,			axis=0  ) < 1E-3  )  )
          self.assertTrue(np.all(np.abs(np.var(__UpperCamelCase ,			axis=0  ) - 1  ) < 1E-3  )  )



     def  lowerCAmelCase__       (      self  )->					int:
          # Tests that all call wrap to encode_plus and batch_encode_plus
          UpperCAmelCase__							: Optional[int] 							=						self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
          # create three inputs of length 800, 1000, and 1200
          UpperCAmelCase__							: str 							=						[floats_list((1, x)  )[0] for x in range(8_00 ,			14_00 ,			2_00  )]
          UpperCAmelCase__							: Any 							=						[np.asarray(__UpperCamelCase  ) for speech_input in speech_inputs]

          # Test not batched input
          UpperCAmelCase__							: str 							=						feat_extract(speech_inputs[0] ,			return_tensors="np"  ).input_values
          UpperCAmelCase__							: Optional[int] 							=						feat_extract(np_speech_inputs[0] ,			return_tensors="np"  ).input_values
          self.assertTrue(np.allclose(__UpperCamelCase ,			__UpperCamelCase ,			atol=1E-3  )  )

          # Test batched
          UpperCAmelCase__							: Tuple 							=						feat_extract(__UpperCamelCase ,			return_tensors="np"  ).input_values
          UpperCAmelCase__							: Union[str, Any] 							=						feat_extract(__UpperCamelCase ,			return_tensors="np"  ).input_values
          for enc_seq_a, enc_seq_a in zip(__UpperCamelCase ,			__UpperCamelCase  ):
               self.assertTrue(np.allclose(__UpperCamelCase ,			__UpperCamelCase ,			atol=1E-3  )  )



     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          UpperCAmelCase__							: Optional[int] 							=						self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
          UpperCAmelCase__							: Any 							=						[floats_list((1, x)  )[0] for x in range(8_00 ,			14_00 ,			2_00  )]

          UpperCAmelCase__							: Dict 							=						["longest", "max_length", "do_not_pad"]
          UpperCAmelCase__							: Dict 							=						[None, 16_00, None]
          for max_length, padding in zip(__UpperCamelCase ,			__UpperCamelCase  ):
               UpperCAmelCase__							: Optional[int] 							=						feat_extract(__UpperCamelCase ,			padding=__UpperCamelCase ,			max_length=__UpperCamelCase ,			return_tensors="np"  )
               UpperCAmelCase__							: int 							=						processed.input_values

               self._check_zero_mean_unit_variance(input_values[0][:8_00]  )
               self.assertTrue(input_values[0][8_00:].sum() < 1E-6  )
               self._check_zero_mean_unit_variance(input_values[1][:10_00]  )
               self.assertTrue(input_values[0][10_00:].sum() < 1E-6  )
               self._check_zero_mean_unit_variance(input_values[2][:12_00]  )



     def  lowerCAmelCase__       (      self  )->					List[str]:
          UpperCAmelCase__							: int 							=						self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
          UpperCAmelCase__							: Dict 							=						range(8_00 ,			14_00 ,			2_00  )
          UpperCAmelCase__							: str 							=						[floats_list((1, x)  )[0] for x in lengths]

          UpperCAmelCase__							: List[Any] 							=						["longest", "max_length", "do_not_pad"]
          UpperCAmelCase__							: Dict 							=						[None, 16_00, None]

          for max_length, padding in zip(__UpperCamelCase ,			__UpperCamelCase  ):
               UpperCAmelCase__							: Any 							=						feat_extract(__UpperCamelCase ,			max_length=__UpperCamelCase ,			padding=__UpperCamelCase  )
               UpperCAmelCase__							: Any 							=						processed.input_values

               self._check_zero_mean_unit_variance(input_values[0][:8_00]  )
               self._check_zero_mean_unit_variance(input_values[1][:10_00]  )
               self._check_zero_mean_unit_variance(input_values[2][:12_00]  )



     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          UpperCAmelCase__							: str 							=						self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
          UpperCAmelCase__							: List[str] 							=						[floats_list((1, x)  )[0] for x in range(8_00 ,			14_00 ,			2_00  )]
          UpperCAmelCase__							: Union[str, Any] 							=						feat_extract(
              __UpperCamelCase ,			truncation=__UpperCamelCase ,			max_length=10_00 ,			padding="max_length" ,			return_tensors="np"  )
          UpperCAmelCase__							: Dict 							=						processed.input_values

          self._check_zero_mean_unit_variance(input_values[0, :8_00]  )
          self._check_zero_mean_unit_variance(input_values[1]  )
          self._check_zero_mean_unit_variance(input_values[2]  )



     def  lowerCAmelCase__       (      self  )->					str:
          UpperCAmelCase__							: Optional[Any] 							=						self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
          UpperCAmelCase__							: Tuple 							=						[floats_list((1, x)  )[0] for x in range(8_00 ,			14_00 ,			2_00  )]
          UpperCAmelCase__							: Any 							=						feat_extract(
              __UpperCamelCase ,			truncation=__UpperCamelCase ,			max_length=10_00 ,			padding="longest" ,			return_tensors="np"  )
          UpperCAmelCase__							: Union[str, Any] 							=						processed.input_values

          self._check_zero_mean_unit_variance(input_values[0, :8_00]  )
          self._check_zero_mean_unit_variance(input_values[1, :10_00]  )
          self._check_zero_mean_unit_variance(input_values[2]  )

          # make sure that if max_length < longest -> then pad to max_length
          self.assertTrue(input_values.shape == (3, 10_00)  )

          UpperCAmelCase__							: str 							=						[floats_list((1, x)  )[0] for x in range(8_00 ,			14_00 ,			2_00  )]
          UpperCAmelCase__							: Optional[Any] 							=						feat_extract(
              __UpperCamelCase ,			truncation=__UpperCamelCase ,			max_length=20_00 ,			padding="longest" ,			return_tensors="np"  )
          UpperCAmelCase__							: Union[str, Any] 							=						processed.input_values

          self._check_zero_mean_unit_variance(input_values[0, :8_00]  )
          self._check_zero_mean_unit_variance(input_values[1, :10_00]  )
          self._check_zero_mean_unit_variance(input_values[2]  )

          # make sure that if max_length > longest -> then pad to longest
          self.assertTrue(input_values.shape == (3, 12_00)  )



     def  lowerCAmelCase__       (      self  )->					List[str]:
          UpperCAmelCase__							: Any 							=						self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
          UpperCAmelCase__							: Union[str, Any] 							=						np.random.rand(1_00  ).astype(np.floataa  )
          UpperCAmelCase__							: Any 							=						np_speech_inputs.tolist()

          for inputs in [py_speech_inputs, np_speech_inputs]:
               UpperCAmelCase__							: Any 							=						feature_extractor.pad([{"input_values": inputs}] ,			return_tensors="np"  )
               self.assertTrue(np_processed.input_values.dtype == np.floataa  )
               UpperCAmelCase__							: Optional[Any] 							=						feature_extractor.pad([{"input_values": inputs}] ,			return_tensors="pt"  )
               self.assertTrue(pt_processed.input_values.dtype == torch.floataa  )



     def  lowerCAmelCase__       (      self  )->					List[str]:
          # Tests that all call wrap to encode_plus and batch_encode_plus
          UpperCAmelCase__							: Any 							=						self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
          # create three inputs of length 800, 1000, and 1200
          UpperCAmelCase__							: str 							=						[floats_list((1, x)  )[0] for x in range(8_00 ,			14_00 ,			2_00  )]
          UpperCAmelCase__							: str 							=						[np.asarray(__UpperCamelCase  ) for speech_input in speech_inputs]

          # Test feature size
          UpperCAmelCase__							: Optional[int] 							=						feature_extractor(audio_target=__UpperCamelCase ,			padding=__UpperCamelCase ,			return_tensors="np"  ).input_values
          self.assertTrue(input_values.ndim == 3  )
          self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins  )

          # Test not batched input
          UpperCAmelCase__							: Dict 							=						feature_extractor(speech_inputs[0] ,			return_tensors="np"  ).input_values
          UpperCAmelCase__							: Union[str, Any] 							=						feature_extractor(np_speech_inputs[0] ,			return_tensors="np"  ).input_values
          self.assertTrue(np.allclose(__UpperCamelCase ,			__UpperCamelCase ,			atol=1E-3  )  )

          # Test batched
          UpperCAmelCase__							: str 							=						feature_extractor(__UpperCamelCase ,			return_tensors="np"  ).input_values
          UpperCAmelCase__							: Union[str, Any] 							=						feature_extractor(__UpperCamelCase ,			return_tensors="np"  ).input_values
          for enc_seq_a, enc_seq_a in zip(__UpperCamelCase ,			__UpperCamelCase  ):
               self.assertTrue(np.allclose(__UpperCamelCase ,			__UpperCamelCase ,			atol=1E-3  )  )

          # Test 2-D numpy arrays are batched.
          UpperCAmelCase__							: int 							=						[floats_list((1, x)  )[0] for x in (8_00, 8_00, 8_00)]
          UpperCAmelCase__							: Union[str, Any] 							=						np.asarray(__UpperCamelCase  )
          UpperCAmelCase__							: List[Any] 							=						feature_extractor(__UpperCamelCase ,			return_tensors="np"  ).input_values
          UpperCAmelCase__							: List[str] 							=						feature_extractor(__UpperCamelCase ,			return_tensors="np"  ).input_values
          for enc_seq_a, enc_seq_a in zip(__UpperCamelCase ,			__UpperCamelCase  ):
               self.assertTrue(np.allclose(__UpperCamelCase ,			__UpperCamelCase ,			atol=1E-3  )  )



     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          UpperCAmelCase__							: str 							=						self.feat_extract_tester.prepare_inputs_for_target()
          UpperCAmelCase__							: Union[str, Any] 							=						self.feature_extraction_class(**self.feat_extract_dict  )
          UpperCAmelCase__							: Optional[int] 							=						feat_extract.model_input_names[0]

          UpperCAmelCase__							: List[Any] 							=						BatchFeature({input_name: speech_inputs}  )

          self.assertTrue(all(len(__UpperCamelCase  ) == len(__UpperCamelCase  ) for x, y in zip(__UpperCamelCase ,			processed_features[input_name]  )  )  )

          UpperCAmelCase__							: Dict 							=						self.feat_extract_tester.prepare_inputs_for_target(equal_length=__UpperCamelCase  )
          UpperCAmelCase__							: Optional[Any] 							=						BatchFeature({input_name: speech_inputs} ,			tensor_type="np"  )

          UpperCAmelCase__							: Optional[int] 							=						processed_features[input_name]

          if len(batch_features_input.shape  ) < 3:
               UpperCAmelCase__							: Optional[int] 							=						batch_features_input[:, :, None]

          self.assertTrue(
              batch_features_input.shape
              == (self.feat_extract_tester.batch_size, len(speech_inputs[0]  ), self.feat_extract_tester.num_mel_bins)  )



     @require_torch
     def  lowerCAmelCase__       (      self  )->					List[str]:
          UpperCAmelCase__							: str 							=						self.feat_extract_tester.prepare_inputs_for_target(equal_length=__UpperCamelCase  )
          UpperCAmelCase__							: Union[str, Any] 							=						self.feature_extraction_class(**self.feat_extract_dict  )
          UpperCAmelCase__							: List[str] 							=						feat_extract.model_input_names[0]

          UpperCAmelCase__							: str 							=						BatchFeature({input_name: speech_inputs} ,			tensor_type="pt"  )

          UpperCAmelCase__							: Any 							=						processed_features[input_name]

          if len(batch_features_input.shape  ) < 3:
               UpperCAmelCase__							: str 							=						batch_features_input[:, :, None]

          self.assertTrue(
              batch_features_input.shape
              == (self.feat_extract_tester.batch_size, len(speech_inputs[0]  ), self.feat_extract_tester.num_mel_bins)  )



     @require_torch
     def  lowerCAmelCase__       (      self  )->					Optional[int]:
          UpperCAmelCase__							: Dict 							=						self.feature_extraction_class(**self.feat_extract_dict  )
          UpperCAmelCase__							: Dict 							=						self.feat_extract_tester.prepare_inputs_for_target()
          UpperCAmelCase__							: Dict 							=						feat_extract.model_input_names[0]

          UpperCAmelCase__							: Tuple 							=						BatchFeature({input_name: speech_inputs}  )

          UpperCAmelCase__							: Optional[int] 							=						feat_extract.num_mel_bins  # hack!

          UpperCAmelCase__							: List[Any] 							=						feat_extract.pad(__UpperCamelCase ,			padding="longest" ,			return_tensors="np"  )[input_name]
          UpperCAmelCase__							: Optional[int] 							=						feat_extract.pad(__UpperCamelCase ,			padding="longest" ,			return_tensors="pt"  )[input_name]

          self.assertTrue(abs(input_np.astype(np.floataa  ).sum() - input_pt.numpy().astype(np.floataa  ).sum()  ) < 1E-2  )



     def  lowerCAmelCase__       (      self  )->					Optional[int]:
          UpperCAmelCase__							: List[str] 							=						self.feat_extract_dict
          UpperCAmelCase__							: int 							=						True
          UpperCAmelCase__							: Optional[Any] 							=						self.feature_extraction_class(**__UpperCamelCase  )
          UpperCAmelCase__							: Optional[Any] 							=						self.feat_extract_tester.prepare_inputs_for_target()
          UpperCAmelCase__							: Any 							=						[len(__UpperCamelCase  ) for x in speech_inputs]
          UpperCAmelCase__							: List[Any] 							=						feat_extract.model_input_names[0]

          UpperCAmelCase__							: int 							=						BatchFeature({input_name: speech_inputs}  )

          UpperCAmelCase__							: Union[str, Any] 							=						feat_extract.num_mel_bins  # hack!

          UpperCAmelCase__							: Dict 							=						feat_extract.pad(__UpperCamelCase ,			padding="longest" ,			return_tensors="np"  )
          self.assertIn("attention_mask" ,			__UpperCamelCase  )
          self.assertListEqual(list(processed.attention_mask.shape  ) ,			list(processed[input_name].shape[:2]  )  )
          self.assertListEqual(processed.attention_mask.sum(-1  ).tolist() ,			__UpperCamelCase  )



     def  lowerCAmelCase__       (      self  )->					Tuple:
          UpperCAmelCase__							: int 							=						self.feat_extract_dict
          UpperCAmelCase__							: List[str] 							=						True
          UpperCAmelCase__							: List[Any] 							=						self.feature_extraction_class(**__UpperCamelCase  )
          UpperCAmelCase__							: List[str] 							=						self.feat_extract_tester.prepare_inputs_for_target()
          UpperCAmelCase__							: int 							=						[len(__UpperCamelCase  ) for x in speech_inputs]
          UpperCAmelCase__							: Optional[Any] 							=						feat_extract.model_input_names[0]

          UpperCAmelCase__							: Any 							=						BatchFeature({input_name: speech_inputs}  )
          UpperCAmelCase__							: int 							=						min(__UpperCamelCase  )

          UpperCAmelCase__							: Optional[Any] 							=						feat_extract.num_mel_bins  # hack!

          UpperCAmelCase__							: int 							=						feat_extract.pad(
              __UpperCamelCase ,			padding="max_length" ,			max_length=__UpperCamelCase ,			truncation=__UpperCamelCase ,			return_tensors="np"  )
          self.assertIn("attention_mask" ,			__UpperCamelCase  )
          self.assertListEqual(
              list(processed_pad.attention_mask.shape  ) ,			[processed_pad[input_name].shape[0], max_length]  )
          self.assertListEqual(
              processed_pad.attention_mask[:, :max_length].sum(-1  ).tolist() ,			[max_length for x in speech_inputs]  )



     def  lowerCAmelCase__       (      self ,			__UpperCamelCase  )->					str:
          from datasets import load_dataset

          UpperCAmelCase__							: List[Any] 							=						load_dataset("hf-internal-testing/librispeech_asr_dummy" ,			"clean" ,			split="validation"  )
          # automatic decoding with librispeech
          UpperCAmelCase__							: Optional[Any] 							=						ds.sort("id"  ).select(range(__UpperCamelCase  )  )[:num_samples]["audio"]

          return [x["array"] for x in speech_samples]



     def  lowerCAmelCase__       (      self  )->					List[Any]:
          # fmt: off
          UpperCAmelCase__							: List[Any] 							=						torch.tensor(
              [2.38_04E-03, 2.07_52E-03, 1.98_36E-03, 2.10_57E-03, 1.61_74E-03,
               3.05_18E-04, 9.15_53E-05, 3.35_69E-04, 9.76_56E-04, 1.83_11E-03,
               2.01_42E-03, 2.10_57E-03, 1.73_95E-03, 4.57_76E-04, -3.96_73E-04,
               4.57_76E-04, 1.00_71E-03, 9.15_53E-05, 4.88_28E-04, 1.15_97E-03,
               7.32_42E-04, 9.46_04E-04, 1.80_05E-03, 1.83_11E-03, 8.85_01E-04,
               4.27_25E-04, 4.88_28E-04, 7.32_42E-04, 1.09_86E-03, 2.10_57E-03]  )
          # fmt: on

          UpperCAmelCase__							: Dict 							=						self._load_datasamples(1  )
          UpperCAmelCase__							: str 							=						SpeechTaFeatureExtractor()
          UpperCAmelCase__							: Union[str, Any] 							=						feature_extractor(__UpperCamelCase ,			return_tensors="pt"  ).input_values
          self.assertEquals(input_values.shape ,			(1, 9_36_80)  )
          self.assertTrue(torch.allclose(input_values[0, :30] ,			__UpperCamelCase ,			atol=1E-6  )  )



     def  lowerCAmelCase__       (      self  )->					List[str]:
          # fmt: off
          UpperCAmelCase__							: int 							=						torch.tensor(
              [-2.6870, -3.0104, -3.1356, -3.5352, -3.0044, -3.0353, -3.4719, -3.6777,
               -3.1520, -2.9435, -2.6553, -2.8795, -2.9944, -2.5921, -3.0279, -3.0386,
               -3.0864, -3.1291, -3.2353, -2.7444, -2.6831, -2.7287, -3.1761, -3.1571,
               -3.2726, -3.0582, -3.1007, -3.4533, -3.4695, -3.0998]  )
          # fmt: on

          UpperCAmelCase__							: Tuple 							=						self._load_datasamples(1  )
          UpperCAmelCase__							: Union[str, Any] 							=						SpeechTaFeatureExtractor()
          UpperCAmelCase__							: List[Any] 							=						feature_extractor(audio_target=__UpperCamelCase ,			return_tensors="pt"  ).input_values
          self.assertEquals(input_values.shape ,			(1, 3_66, 80)  )
          self.assertTrue(torch.allclose(input_values[0, 0, :30] ,			__UpperCamelCase ,			atol=1E-4  )  )





"""simple docstring"""




import argparse
import os

import torch

from transformers.utils import WEIGHTS_NAME


A__      :	Optional[int]          =    ["""small""", """medium""", """large"""]

A__      :	Optional[int]          =    """lm_head.decoder.weight"""
A__      :	Dict          =    """lm_head.weight"""



def 							a__ (				lowerCAmelCase	:       str       ,    lowerCAmelCase	:       str		):






     '''simple docstring'''
     UpperCAmelCase__							: Dict 							=						torch.load(lowerCAmelCase		)
     UpperCAmelCase__							: Optional[int] 							=						d.pop(lowerCAmelCase		)
     os.makedirs(lowerCAmelCase       ,    exist_ok=lowerCAmelCase		)
     torch.save(lowerCAmelCase       ,    os.path.join(lowerCAmelCase       ,    lowerCAmelCase		)		)


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



