





import itertools
import json
import os
import unittest

from transformers import AddedToken, RobertaTokenizer, RobertaTokenizerFast
from transformers.models.roberta.tokenization_roberta import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class   __lowerCAmelCase			(					A_		,unittest.TestCase  ):
   _UpperCamelCase :						Any     		=				RobertaTokenizer
   _UpperCamelCase :						Optional[int]     		=				RobertaTokenizerFast
   _UpperCamelCase :						Union[str, Any]     		=				True
   _UpperCamelCase :						List[str]     		=				{'''cls_token''': '''<s>'''}





   def 	_snake_case ( self      )				->  int:
      """simple docstring"""





      super().setUp()

      # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
      a__	:						Dict      		=  [
          """l""",
          """o""",
          """w""",
          """e""",
          """r""",
          """s""",
          """t""",
          """i""",
          """d""",
          """n""",
          """\u0120""",
          """\u0120l""",
          """\u0120n""",
          """\u0120lo""",
          """\u0120low""",
          """er""",
          """\u0120lowest""",
          """\u0120newer""",
          """\u0120wider""",
          """<unk>""",
      ]
      a__	:						Any      		=  dict(zip(snake_case					,			range(len(snake_case      )      )      )      )
      a__	:						Optional[int]      		=  ["""#version: 0.2""", """\u0120 l""", """\u0120l o""", """\u0120lo w""", """e r""", """"""]
      a__	:						int      		=  {"""unk_token""": """<unk>"""}

      a__	:						str      		=  os.path.join(self.tmpdirname					,			VOCAB_FILES_NAMES["vocab_file"]      )
      a__	:						Optional[int]      		=  os.path.join(self.tmpdirname					,			VOCAB_FILES_NAMES["merges_file"]      )
      with open(self.vocab_file					,			"w"					,			encoding="utf-8"      ) as fp:
         fp.write(json.dumps(snake_case      ) + "\n"      )
      with open(self.merges_file					,			"w"					,			encoding="utf-8"      ) as fp:
         fp.write("\n".join(snake_case      )      )





   def 	_snake_case ( self					,			**snake_case      )				->  Any:
      """simple docstring"""





      kwargs.update(self.special_tokens_map      )
      return self.tokenizer_class.from_pretrained(self.tmpdirname					,			**snake_case      )





   def 	_snake_case ( self					,			**snake_case      )				->  Optional[int]:
      """simple docstring"""





      kwargs.update(self.special_tokens_map      )
      return RobertaTokenizerFast.from_pretrained(self.tmpdirname					,			**snake_case      )





   def 	_snake_case ( self					,			snake_case      )				->  Dict:
      """simple docstring"""





      a__	:						Union[str, Any]      		=  """lower newer"""
      a__	:						Optional[int]      		=  """lower newer"""
      return input_text, output_text





   def 	_snake_case ( self      )				->  Optional[Any]:
      """simple docstring"""





      a__	:						Any      		=  self.tokenizer_class(self.vocab_file					,			self.merges_file					,			**self.special_tokens_map      )
      a__	:						int      		=  """lower newer"""
      a__	:						Union[str, Any]      		=  ["""l""", """o""", """w""", """er""", """\u0120""", """n""", """e""", """w""", """er"""]
      a__	:						List[Any]      		=  tokenizer.tokenize(snake_case      )  # , add_prefix_space=True)
      self.assertListEqual(snake_case					,			snake_case      )

      a__	:						Dict      		=  tokens + [tokenizer.unk_token]
      a__	:						List[str]      		=  [0, 1, 2, 15, 10, 9, 3, 2, 15, 19]
      self.assertListEqual(tokenizer.convert_tokens_to_ids(snake_case      )					,			snake_case      )





   def 	_snake_case ( self      )				->  Any:
      """simple docstring"""





      a__	:						int      		=  self.get_tokenizer()

      self.assertListEqual(tokenizer.encode("Hello world!"					,			add_special_tokens=snake_case      )					,			[0, 31_414, 232, 328, 2]      )
      self.assertListEqual(
          tokenizer.encode("Hello world! cécé herlolip 418"					,			add_special_tokens=snake_case      )					,			[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]					,			)





   @slow
   def 	_snake_case ( self      )				->  Union[str, Any]:
      """simple docstring"""





      a__	:						Optional[int]      		=  self.tokenizer_class.from_pretrained("roberta-base"      )

      a__	:						Optional[Any]      		=  tokenizer.encode("sequence builders"					,			add_special_tokens=snake_case      )
      a__	:						Any      		=  tokenizer.encode("multi-sequence build"					,			add_special_tokens=snake_case      )

      a__	:						int      		=  tokenizer.encode(
          "sequence builders"					,			add_special_tokens=snake_case					,			add_prefix_space=snake_case      )
      a__	:						Union[str, Any]      		=  tokenizer.encode(
          "sequence builders"					,			"multi-sequence build"					,			add_special_tokens=snake_case					,			add_prefix_space=snake_case      )

      a__	:						int      		=  tokenizer.build_inputs_with_special_tokens(snake_case      )
      a__	:						List[Any]      		=  tokenizer.build_inputs_with_special_tokens(snake_case					,			snake_case      )

      assert encoded_sentence == encoded_text_from_decode
      assert encoded_pair == encoded_pair_from_decode





   def 	_snake_case ( self      )				->  Optional[int]:
      """simple docstring"""





      a__	:						Any      		=  self.get_tokenizer()

      a__	:						Optional[int]      		=  """Encode this sequence."""
      a__	:						int      		=  tokenizer.byte_encoder[""" """.encode("utf-8"      )[0]]

      # Testing encoder arguments
      a__	:						Dict      		=  tokenizer.encode(snake_case					,			add_special_tokens=snake_case					,			add_prefix_space=snake_case      )
      a__	:						Dict      		=  tokenizer.convert_ids_to_tokens(encoded[0]      )[0]
      self.assertNotEqual(snake_case					,			snake_case      )

      a__	:						str      		=  tokenizer.encode(snake_case					,			add_special_tokens=snake_case					,			add_prefix_space=snake_case      )
      a__	:						List[str]      		=  tokenizer.convert_ids_to_tokens(encoded[0]      )[0]
      self.assertEqual(snake_case					,			snake_case      )

      tokenizer.add_special_tokens({"bos_token": "<s>"}      )
      a__	:						Any      		=  tokenizer.encode(snake_case					,			add_special_tokens=snake_case      )
      a__	:						Optional[Any]      		=  tokenizer.convert_ids_to_tokens(encoded[1]      )[0]
      self.assertNotEqual(snake_case					,			snake_case      )

      # Testing spaces after special tokens
      a__	:						Union[str, Any]      		=  """<mask>"""
      tokenizer.add_special_tokens(
          {"mask_token": AddedToken(snake_case					,			lstrip=snake_case					,			rstrip=snake_case      )}      )  # mask token has a left space
      a__	:						List[str]      		=  tokenizer.convert_tokens_to_ids(snake_case      )

      a__	:						Tuple      		=  """Encode <mask> sequence"""
      a__	:						str      		=  """Encode <mask>sequence"""

      a__	:						int      		=  tokenizer.encode(snake_case      )
      a__	:						Union[str, Any]      		=  encoded.index(snake_case      )
      a__	:						Tuple      		=  tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]      )[0]
      self.assertEqual(snake_case					,			snake_case      )

      a__	:						List[Any]      		=  tokenizer.encode(snake_case      )
      a__	:						Optional[Any]      		=  encoded.index(snake_case      )
      a__	:						Dict      		=  tokenizer.convert_ids_to_tokens(encoded[mask_loc + 1]      )[0]
      self.assertNotEqual(snake_case					,			snake_case      )





   def 	_snake_case ( self      )				->  Dict:
      """simple docstring"""





      pass





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
         with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""      ):
            a__	:						Union[str, Any]      		=  self.rust_tokenizer_class.from_pretrained(snake_case					,			**snake_case      )
            a__	:						int      		=  self.tokenizer_class.from_pretrained(snake_case					,			**snake_case      )
            a__	:						Optional[int]      		=  """A, <mask> AllenNLP sentence."""
            a__	:						Optional[int]      		=  tokenizer_r.encode_plus(snake_case					,			add_special_tokens=snake_case					,			return_token_type_ids=snake_case      )
            a__	:						Any      		=  tokenizer_p.encode_plus(snake_case					,			add_special_tokens=snake_case					,			return_token_type_ids=snake_case      )

            # token_type_ids should put 0 everywhere
            self.assertEqual(sum(tokens_r["token_type_ids"]      )					,			sum(tokens_p["token_type_ids"]      )      )

            # attention_mask should put 1 everywhere, so sum over length should be 1
            self.assertEqual(
                sum(tokens_r["attention_mask"]      ) / len(tokens_r["attention_mask"]      )					,			sum(tokens_p["attention_mask"]      ) / len(tokens_p["attention_mask"]      )					,			)

            a__	:						Any      		=  tokenizer_r.convert_ids_to_tokens(tokens_r["input_ids"]      )
            a__	:						Optional[int]      		=  tokenizer_p.convert_ids_to_tokens(tokens_p["input_ids"]      )

            # Rust correctly handles the space before the mask while python doesnt
            self.assertSequenceEqual(tokens_p["input_ids"]					,			[0, 250, 6, 50_264, 3_823, 487, 21_992, 3_645, 4, 2]      )
            self.assertSequenceEqual(tokens_r["input_ids"]					,			[0, 250, 6, 50_264, 3_823, 487, 21_992, 3_645, 4, 2]      )

            self.assertSequenceEqual(
                snake_case					,			["<s>", "A", ",", "<mask>", "ĠAllen", "N", "LP", "Ġsentence", ".", "</s>"]      )
            self.assertSequenceEqual(
                snake_case					,			["<s>", "A", ",", "<mask>", "ĠAllen", "N", "LP", "Ġsentence", ".", "</s>"]      )





   def 	_snake_case ( self      )				->  Optional[int]:
      """simple docstring"""





      for trim_offsets, add_prefix_space in itertools.product([True, False]					,			repeat=2      ):
         a__	:						Union[str, Any]      		=  self.rust_tokenizer_class.from_pretrained(
             self.tmpdirname					,			use_fast=snake_case					,			add_prefix_space=snake_case					,			trim_offsets=snake_case      )

         a__	:						int      		=  json.loads(tokenizer_r.backend_tokenizer.pre_tokenizer.__getstate__()      )
         a__	:						Optional[Any]      		=  json.loads(tokenizer_r.backend_tokenizer.post_processor.__getstate__()      )

         self.assertEqual(pre_tokenizer_state["add_prefix_space"]					,			snake_case      )

         self.assertEqual(post_processor_state["add_prefix_space"]					,			snake_case      )
         self.assertEqual(post_processor_state["trim_offsets"]					,			snake_case      )





   def 	_snake_case ( self      )				->  Tuple:
      """simple docstring"""





      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
         with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""      ):
            a__	:						Union[str, Any]      		=  """hello"""  # `hello` is a token in the vocabulary of `pretrained_name`
            a__	:						List[Any]      		=  F"""{text_of_1_token} {text_of_1_token}"""

            a__	:						List[str]      		=  self.rust_tokenizer_class.from_pretrained(
                snake_case					,			use_fast=snake_case					,			add_prefix_space=snake_case					,			trim_offsets=snake_case      )
            a__	:						Optional[int]      		=  tokenizer_r(snake_case					,			return_offsets_mapping=snake_case					,			add_special_tokens=snake_case      )
            self.assertEqual(encoding.offset_mapping[0]					,			(0, len(snake_case      ))      )
            self.assertEqual(
                encoding.offset_mapping[1]					,			(len(snake_case      ) + 1, len(snake_case      ) + 1 + len(snake_case      ))					,			)

            a__	:						List[Any]      		=  self.rust_tokenizer_class.from_pretrained(
                snake_case					,			use_fast=snake_case					,			add_prefix_space=snake_case					,			trim_offsets=snake_case      )
            a__	:						Optional[Any]      		=  tokenizer_r(snake_case					,			return_offsets_mapping=snake_case					,			add_special_tokens=snake_case      )
            self.assertEqual(encoding.offset_mapping[0]					,			(0, len(snake_case      ))      )
            self.assertEqual(
                encoding.offset_mapping[1]					,			(len(snake_case      ) + 1, len(snake_case      ) + 1 + len(snake_case      ))					,			)

            a__	:						List[str]      		=  self.rust_tokenizer_class.from_pretrained(
                snake_case					,			use_fast=snake_case					,			add_prefix_space=snake_case					,			trim_offsets=snake_case      )
            a__	:						Optional[Any]      		=  tokenizer_r(snake_case					,			return_offsets_mapping=snake_case					,			add_special_tokens=snake_case      )
            self.assertEqual(encoding.offset_mapping[0]					,			(0, len(snake_case      ))      )
            self.assertEqual(
                encoding.offset_mapping[1]					,			(len(snake_case      ), len(snake_case      ) + 1 + len(snake_case      ))					,			)

            a__	:						Optional[Any]      		=  self.rust_tokenizer_class.from_pretrained(
                snake_case					,			use_fast=snake_case					,			add_prefix_space=snake_case					,			trim_offsets=snake_case      )
            a__	:						Optional[Any]      		=  tokenizer_r(snake_case					,			return_offsets_mapping=snake_case					,			add_special_tokens=snake_case      )
            self.assertEqual(encoding.offset_mapping[0]					,			(0, len(snake_case      ))      )
            self.assertEqual(
                encoding.offset_mapping[1]					,			(len(snake_case      ), len(snake_case      ) + 1 + len(snake_case      ))					,			)

            a__	:						Tuple      		=  F""" {text}"""

            # tokenizer_r = self.rust_tokenizer_class.from_pretrained(
            #     pretrained_name, use_fast=True, add_prefix_space=True, trim_offsets=True
            # )
            # encoding = tokenizer_r(text, return_offsets_mapping=True, add_special_tokens=False)
            # self.assertEqual(encoding.offset_mapping[0], (1, 1 + len(text_of_1_token)))
            # self.assertEqual(
            #     encoding.offset_mapping[1],
            #     (1 + len(text_of_1_token) + 1, 1 + len(text_of_1_token) + 1 + len(text_of_1_token)),
            # )

            a__	:						Optional[int]      		=  self.rust_tokenizer_class.from_pretrained(
                snake_case					,			use_fast=snake_case					,			add_prefix_space=snake_case					,			trim_offsets=snake_case      )
            a__	:						Optional[Any]      		=  tokenizer_r(snake_case					,			return_offsets_mapping=snake_case					,			add_special_tokens=snake_case      )
            self.assertEqual(encoding.offset_mapping[0]					,			(1, 1 + len(snake_case      ))      )
            self.assertEqual(
                encoding.offset_mapping[1]					,			(1 + len(snake_case      ) + 1, 1 + len(snake_case      ) + 1 + len(snake_case      ))					,			)

            a__	:						Dict      		=  self.rust_tokenizer_class.from_pretrained(
                snake_case					,			use_fast=snake_case					,			add_prefix_space=snake_case					,			trim_offsets=snake_case      )
            a__	:						Union[str, Any]      		=  tokenizer_r(snake_case					,			return_offsets_mapping=snake_case					,			add_special_tokens=snake_case      )
            self.assertEqual(encoding.offset_mapping[0]					,			(0, 1 + len(snake_case      ))      )
            self.assertEqual(
                encoding.offset_mapping[1]					,			(1 + len(snake_case      ), 1 + len(snake_case      ) + 1 + len(snake_case      ))					,			)

            a__	:						List[str]      		=  self.rust_tokenizer_class.from_pretrained(
                snake_case					,			use_fast=snake_case					,			add_prefix_space=snake_case					,			trim_offsets=snake_case      )
            a__	:						List[Any]      		=  tokenizer_r(snake_case					,			return_offsets_mapping=snake_case					,			add_special_tokens=snake_case      )
            self.assertEqual(encoding.offset_mapping[0]					,			(0, 1 + len(snake_case      ))      )
            self.assertEqual(
                encoding.offset_mapping[1]					,			(1 + len(snake_case      ), 1 + len(snake_case      ) + 1 + len(snake_case      ))					,			)












import argparse
import hashlib
import os
import urllib
import warnings

import torch
from torch import nn
from tqdm import tqdm

from transformers import WhisperConfig, WhisperForConditionalGeneration


SCREAMING_SNAKE_CASE__       :			List[str]			      =						{
    """tiny.en""": """https://openaipublic.azureedge.net/main/whisper/models/d3dd57d32accea0b295c96e26691aa14d8822fac7d9d27d5dc00b4ca2826dd03/tiny.en.pt""",
    """tiny""": """https://openaipublic.azureedge.net/main/whisper/models/65147644a518d12f04e32d6f3b26facc3f8dd46e5390956a9424a650c0ce22b9/tiny.pt""",
    """base.en""": """https://openaipublic.azureedge.net/main/whisper/models/25a8566e1d0c1e2231d1c762132cd20e0f96a85d16145c3a00adf5d1ac670ead/base.en.pt""",
    """base""": """https://openaipublic.azureedge.net/main/whisper/models/ed3a0b6b1c0edf879ad9b11b1af5a0e6ab5db9205f891f668f8b0e6c6326e34e/base.pt""",
    """small.en""": """https://openaipublic.azureedge.net/main/whisper/models/f953ad0fd29cacd07d5a9eda5624af0f6bcf2258be67c92b79389873d91e0872/small.en.pt""",
    """small""": """https://openaipublic.azureedge.net/main/whisper/models/9ecf779972d90ba49c06d968637d720dd632c55bbf19d441fb42bf17a411e794/small.pt""",
    """medium.en""": """https://openaipublic.azureedge.net/main/whisper/models/d7440d1dc186f76616474e0ff0b3b6b879abc9d1a4926b7adfa41db2d497ab4f/medium.en.pt""",
    """medium""": """https://openaipublic.azureedge.net/main/whisper/models/345ae4da62f9b3d59415adc60127b97c714f32e89e936602e85993674d08dcb1/medium.pt""",
    """large""": """https://openaipublic.azureedge.net/main/whisper/models/e4b87e7e0bf463eb8e6956e646f1e277e901512310def2c24bf0e11bd3c28e9a/large.pt""",
    """large-v2""": """https://openaipublic.azureedge.net/main/whisper/models/81f7c96c852ee8fc832187b0132e569d6c3065a3252ed18e56effd0b6a73e524/large-v2.pt""",
}






def       _A  (      lowerCamelCase   ):
   a__	:						Optional[int]      		=  ["layers", "blocks"]
   for k in ignore_keys:
      state_dict.pop(lowerCamelCase							, lowerCamelCase   )


SCREAMING_SNAKE_CASE__       :			List[str]			      =						{
    """blocks""": """layers""",
    """mlp.0""": """fc1""",
    """mlp.2""": """fc2""",
    """mlp_ln""": """final_layer_norm""",
    """.attn.query""": """.self_attn.q_proj""",
    """.attn.key""": """.self_attn.k_proj""",
    """.attn.value""": """.self_attn.v_proj""",
    """.attn_ln""": """.self_attn_layer_norm""",
    """.attn.out""": """.self_attn.out_proj""",
    """.cross_attn.query""": """.encoder_attn.q_proj""",
    """.cross_attn.key""": """.encoder_attn.k_proj""",
    """.cross_attn.value""": """.encoder_attn.v_proj""",
    """.cross_attn_ln""": """.encoder_attn_layer_norm""",
    """.cross_attn.out""": """.encoder_attn.out_proj""",
    """decoder.ln.""": """decoder.layer_norm.""",
    """encoder.ln.""": """encoder.layer_norm.""",
    """token_embedding""": """embed_tokens""",
    """encoder.positional_embedding""": """encoder.embed_positions.weight""",
    """decoder.positional_embedding""": """decoder.embed_positions.weight""",
    """ln_post""": """layer_norm""",
}






def       _A  (      lowerCamelCase   ):
   a__	:						Tuple      		=  list(s_dict.keys()   )
   for key in keys:
      a__	:						Optional[Any]      		=  key
      for k, v in WHISPER_MAPPING.items():
         if k in key:
            a__	:						Optional[int]      		=  new_key.replace(lowerCamelCase							, lowerCamelCase   )

      print(F"""{key} -> {new_key}"""   )

      a__	:						Dict      		=  s_dict.pop(lowerCamelCase   )
   return s_dict






def       _A  (      lowerCamelCase   ):
   a__		,     a__	:						Any      		=  emb.weight.shape
   a__	:						Optional[Any]      		=  nn.Linear(lowerCamelCase							, lowerCamelCase							, bias=lowerCamelCase   )
   a__	:						Optional[Any]      		=  emb.weight.data
   return lin_layer






def       _A  (      lowerCamelCase							, lowerCamelCase   ):
   os.makedirs(lowerCamelCase							, exist_ok=lowerCamelCase   )
   a__	:						Optional[Any]      		=  os.path.basename(lowerCamelCase   )

   a__	:						List[Any]      		=  url.split("/"   )[-2]
   a__	:						Tuple      		=  os.path.join(lowerCamelCase							, lowerCamelCase   )

   if os.path.exists(lowerCamelCase   ) and not os.path.isfile(lowerCamelCase   ):
      raise RuntimeError(F"""{download_target} exists and is not a regular file"""   )

   if os.path.isfile(lowerCamelCase   ):
      a__	:						Any      		=  open(lowerCamelCase							, "rb"   ).read()
      if hashlib.shaaaa(lowerCamelCase   ).hexdigest() == expected_shaaaa:
         return model_bytes
      else:
         warnings.warn(F"""{download_target} exists, but the SHA256 checksum does not match; re-downloading the file"""   )

   with urllib.request.urlopen(lowerCamelCase   ) as source, open(lowerCamelCase							, "wb"   ) as output:
      with tqdm(
          total=int(source.info().get("Content-Length"   )   )							, ncols=80							, unit="iB"							, unit_scale=lowerCamelCase							, unit_divisor=1024   ) as loop:
         while True:
            a__	:						Optional[Any]      		=  source.read(8192   )
            if not buffer:
               break

            output.write(lowerCamelCase   )
            loop.update(len(lowerCamelCase   )   )

   a__	:						Optional[int]      		=  open(lowerCamelCase							, "rb"   ).read()
   if hashlib.shaaaa(lowerCamelCase   ).hexdigest() != expected_shaaaa:
      raise RuntimeError(
          "Model has been downloaded but the SHA256 checksum does not not match. Please retry loading the model."   )

   return model_bytes






def       _A  (      lowerCamelCase							, lowerCamelCase   ):
   if ".pt" not in checkpoint_path:
      a__	:						str      		=  _download(_MODELS[checkpoint_path]   )
   else:
      a__	:						str      		=  torch.load(lowerCamelCase							, map_location="cpu"   )
   a__	:						Dict      		=  original_checkpoint["dims"]
   a__	:						Optional[int]      		=  original_checkpoint["model_state_dict"]
   a__	:						Any      		=  state_dict["decoder.token_embedding.weight"]
   remove_ignore_keys_(lowerCamelCase   )
   rename_keys(lowerCamelCase   )
   a__	:						Optional[Any]      		=  True
   a__	:						Optional[Any]      		=  state_dict["decoder.layers.0.fc1.weight"].shape[0]

   a__	:						Tuple      		=  WhisperConfig(
       vocab_size=dimensions["n_vocab"]							, encoder_ffn_dim=lowerCamelCase							, decoder_ffn_dim=lowerCamelCase							, num_mel_bins=dimensions["n_mels"]							, d_model=dimensions["n_audio_state"]							, max_target_positions=dimensions["n_text_ctx"]							, encoder_layers=dimensions["n_audio_layer"]							, encoder_attention_heads=dimensions["n_audio_head"]							, decoder_layers=dimensions["n_text_layer"]							, decoder_attention_heads=dimensions["n_text_state"]							, max_source_positions=dimensions["n_audio_ctx"]							, )

   a__	:						Optional[Any]      		=  WhisperForConditionalGeneration(lowerCamelCase   )
   a__		,     a__	:						Tuple      		=  model.model.load_state_dict(lowerCamelCase							, strict=lowerCamelCase   )
   if len(lowerCamelCase   ) > 0 and not set(lowerCamelCase   ) <= {
       "encoder.embed_positions.weights",
       "decoder.embed_positions.weights",
   }:
      raise ValueError(
          "Only `encoder.embed_positions.weights` and `decoder.embed_positions.weights`  are allowed to be missing,"
          F""" but all the following weights are missing {missing}"""   )

   if tie_embeds:
      a__	:						Any      		=  make_linear_from_emb(model.model.decoder.embed_tokens   )
   else:
      a__	:						str      		=  proj_out_weights

   model.save_pretrained(lowerCamelCase   )


if __name__ == "__main__":
  SCREAMING_SNAKE_CASE__       :			Tuple			      =						argparse.ArgumentParser()
  # # Required parameters
  parser.add_argument("""--checkpoint_path""", type=str, help="""Patht to the downloaded checkpoints""")
  parser.add_argument("""--pytorch_dump_folder_path""", default=None, type=str, help="""Path to the output PyTorch model.""")
  SCREAMING_SNAKE_CASE__       :			List[str]			      =						parser.parse_args()

  convert_openai_whisper_to_tfms(args.checkpoint_path, args.pytorch_dump_folder_path)

