

import gc
import importlib.metadata
import tempfile
import unittest

from packaging import version

from transformers import (
    AutoModel,
    AutoModelForCausalLM,
    AutoModelForSeqaSeqLM,
    AutoModelForSequenceClassification,
    AutoTokenizer,
    BitsAndBytesConfig,
    pipeline,
)
from transformers.testing_utils import (
    is_torch_available,
    require_accelerate,
    require_bitsandbytes,
    require_torch,
    require_torch_gpu,
    require_torch_multi_gpu,
    slow,
)

def 		UpperCamelCase      (lowercase_:				Tuple      )  ->   Optional[Any]:
 if model.config.model_type == "gpt2":
  return model.transformer.h[0].mlp.c_fc
 return model.transformer.h[0].mlp.dense_ah_to_h


if is_torch_available():
 import torch
 import torch.nn as nn



 class 					_a		(nn.Module       ):


      '''simple docstring'''






      def __init__(				self					, A__					, A__    ):
       super().__init__()
       A__							:					Dict       =	module
       A__							:					Optional[Any]       =	nn.Sequential(
           nn.Linear(module.in_features					, UpperCamelCase_					, bias=UpperCamelCase_    )					, nn.Linear(UpperCamelCase_					, module.out_features					, bias=UpperCamelCase_    )					, )
       A__							:					Union[str, Any]       =	(2.0 / (5 * min(module.in_features					, module.out_features    ))) ** 0.5
       nn.init.normal_(self.adapter[0].weight					, std=UpperCamelCase_    )
       nn.init.zeros_(self.adapter[1].weight    )
       self.adapter.to(module.weight.device    )






      def 						__A    (				self					, A__					, *A__					, **A__    ):
       return self.module(UpperCamelCase_					, *UpperCamelCase_					, **UpperCamelCase_    ) + self.adapter(UpperCamelCase_    )



@require_bitsandbytes
@require_accelerate
@require_torch
@require_torch_gpu
@slow
class 					_a		(unittest.TestCase       ):


     '''simple docstring'''






     UpperCAmelCase__:     Any													= '''bigscience/bloom-1b7'''

     # Constant values
     UpperCAmelCase__:     int													= 2.1_09_65_95_52_69_25_74

     UpperCAmelCase__:     int													= '''Hello my name is'''
     UpperCAmelCase__:     str													= set()
     EXPECTED_OUTPUTS.add('''Hello my name is John and I am a professional photographer. I'''       )
     EXPECTED_OUTPUTS.add('''Hello my name is John.\nI am a friend of your father.\n'''       )
     EXPECTED_OUTPUTS.add('''Hello my name is John Doe, I am a student at the University'''       )
     UpperCAmelCase__:     Optional[int]													= 10






     def 						__A    (				self    ):
      A__							:					List[Any]       =	AutoTokenizer.from_pretrained(self.model_name    )



class 					_a		(__magic_name__       ):


     '''simple docstring'''






     def 						__A    (				self    ):
      super().setUp()

      # Models and tokenizer
      A__							:					Union[str, Any]       =	AutoModelForCausalLM.from_pretrained(
          self.model_name					, torch_dtype=torch.floataa					, device_map="""auto"""    )
      A__							:					int       =	AutoModelForCausalLM.from_pretrained(self.model_name					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )






     def 						__A    (				self    ):
      del self.model_fpaa
      del self.model_abit

      gc.collect()
      torch.cuda.empty_cache()






     def 						__A    (				self    ):
      A__							:					Any       =	self.model_abit.config

      self.assertTrue(hasattr(UpperCamelCase_					, """quantization_config"""    )    )

      A__							:					int       =	config.to_dict()
      A__							:					Union[str, Any]       =	config.to_diff_dict()

      A__							:					Optional[Any]       =	config.to_json_string()






     def 						__A    (				self    ):
      from bitsandbytes.nn import Paramsabit

      A__							:					Any       =	self.model_fpaa.get_memory_footprint()
      A__							:					str       =	self.model_abit.get_memory_footprint()

      self.assertAlmostEqual(mem_fpaa / mem_abit					, self.EXPECTED_RELATIVE_DIFFERENCE    )
      A__							:					Optional[Any]       =	get_some_linear_layer(self.model_abit    )
      self.assertTrue(linear.weight.__class__ == Paramsabit    )






     def 						__A    (				self    ):
      from transformers import TaPreTrainedModel

      self.model_fpaa.get_memory_footprint()
      self.model_abit.get_memory_footprint()

      for name, module in self.model_abit.named_modules():
       if isinstance(UpperCamelCase_					, torch.nn.Linear    ):
        if name not in ["lm_head"] + TaPreTrainedModel._keep_in_fpaa_modules:
         # 4-bit parameters are packed in uint8 variables
         self.assertTrue(module.weight.dtype == torch.uinta    )






     def 						__A    (				self    ):
      A__							:					Union[str, Any]       =	self.tokenizer(self.input_text					, return_tensors="""pt"""    )
      A__							:					List[Any]       =	self.model_abit.generate(input_ids=encoded_input["""input_ids"""].to(0    )					, max_new_tokens=10    )

      self.assertIn(self.tokenizer.decode(output_sequences[0]					, skip_special_tokens=UpperCamelCase_    )					, self.EXPECTED_OUTPUTS    )






     def 						__A    (				self    ):
      A__							:					Tuple       =	BitsAndBytesConfig()
      A__							:					Optional[int]       =	True

      A__							:					Union[str, Any]       =	AutoModelForCausalLM.from_pretrained(
          self.model_name					, quantization_config=UpperCamelCase_					, device_map="""auto"""    )

      A__							:					str       =	self.tokenizer(self.input_text					, return_tensors="""pt"""    )
      A__							:					Tuple       =	model_abit_from_config.generate(
          input_ids=encoded_input["""input_ids"""].to(0    )					, max_new_tokens=10    )

      self.assertIn(self.tokenizer.decode(output_sequences[0]					, skip_special_tokens=UpperCamelCase_    )					, self.EXPECTED_OUTPUTS    )






     def 						__A    (				self    ):





      with self.assertRaises(UpperCamelCase_    ), tempfile.TemporaryDirectory() as tmpdirname:
       self.model_abit.save_pretrained(UpperCamelCase_    )






     def 						__A    (				self    ):
      A__							:					int       =	BitsAndBytesConfig()

      with self.assertRaises(UpperCamelCase_    ):
       A__							:					int       =	AutoModelForCausalLM.from_pretrained(
           self.model_name					, quantization_config=UpperCamelCase_					, load_in_abit=UpperCamelCase_					, device_map="""auto"""					, bnb_abit_quant_type="""nf4"""					, )






     def 						__A    (				self    ):





      with self.assertRaises(UpperCamelCase_    ):
       # Tries with `str`
       self.model_abit.to("""cpu"""    )

      with self.assertRaises(UpperCamelCase_    ):
       # Tries with a `dtype``
       self.model_abit.to(torch.floataa    )

      with self.assertRaises(UpperCamelCase_    ):
       # Tries with a `device`
       self.model_abit.to(torch.device("""cuda:0"""    )    )

      with self.assertRaises(UpperCamelCase_    ):
       # Tries with a `device`
       self.model_abit.float()

      with self.assertRaises(UpperCamelCase_    ):
       # Tries with a `device`
       self.model_abit.half()

      # Test if we did not break anything
      A__							:					int       =	self.tokenizer(self.input_text					, return_tensors="""pt"""    )

      A__							:					Union[str, Any]       =	self.model_fpaa.to(torch.floataa    )
      A__							:					Tuple       =	self.model_fpaa.generate(input_ids=encoded_input["""input_ids"""].to(0    )					, max_new_tokens=10    )

      # Check this does not throw an error
      A__							:					Tuple       =	self.model_fpaa.to("""cpu"""    )

      # Check this does not throw an error
      A__							:					Dict       =	self.model_fpaa.half()

      # Check this does not throw an error
      A__							:					Tuple       =	self.model_fpaa.float()






     def 						__A    (				self    ):
      A__							:					Tuple       =	AutoModelForSeqaSeqLM.from_pretrained("""t5-small"""					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )
      self.assertTrue(model.decoder.block[0].layer[2].DenseReluDense.wo.weight.dtype == torch.floataa    )



@require_bitsandbytes
@require_accelerate
@require_torch
@require_torch_gpu
@slow
class 					_a		(unittest.TestCase       ):


     '''simple docstring'''






     @classmethod
     def 						__A    (				cls    ):
      A__							:					Optional[int]       =	't5-small'
      A__							:					Tuple       =	'google/flan-t5-small'  # flan-t5 uses dense-act instead of dense-relu-dense
      A__							:					Optional[int]       =	AutoTokenizer.from_pretrained(cls.model_name    )
      A__							:					Union[str, Any]       =	'Translate in German: Hello, my dog is cute'






     def 						__A    (				self    ):
      gc.collect()
      torch.cuda.empty_cache()






     def 						__A    (				self    ):
      from transformers import TaForConditionalGeneration

      A__							:					Union[str, Any]       =	TaForConditionalGeneration._keep_in_fpaa_modules
      A__							:					Optional[Any]       =	None

      # test with `t5-small`
      A__							:					List[Any]       =	TaForConditionalGeneration.from_pretrained(self.model_name					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )
      A__							:					Any       =	self.tokenizer(self.input_text					, return_tensors="""pt"""    ).to(0    )
      A__							:					Optional[Any]       =	model.generate(**UpperCamelCase_    )

      # test with `flan-t5-small`
      A__							:					Dict       =	TaForConditionalGeneration.from_pretrained(
          self.dense_act_model_name					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )
      A__							:					str       =	self.tokenizer(self.input_text					, return_tensors="""pt"""    ).to(0    )
      A__							:					int       =	model.generate(**UpperCamelCase_    )
      A__							:					Optional[Any]       =	modules






     def 						__A    (				self    ):
      import bitsandbytes as bnb

      from transformers import TaForConditionalGeneration

      # test with `t5-small`
      A__							:					List[Any]       =	TaForConditionalGeneration.from_pretrained(self.model_name					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )

      # there was a bug with decoders - this test checks that it is fixed
      self.assertTrue(isinstance(model.decoder.block[0].layer[0].SelfAttention.q					, bnb.nn.Linearabit    )    )

      A__							:					Optional[Any]       =	self.tokenizer(self.input_text					, return_tensors="""pt"""    ).to(0    )
      A__							:					List[Any]       =	model.generate(**UpperCamelCase_    )

      # test with `flan-t5-small`
      A__							:					List[str]       =	TaForConditionalGeneration.from_pretrained(
          self.dense_act_model_name					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )
      A__							:					Any       =	self.tokenizer(self.input_text					, return_tensors="""pt"""    ).to(0    )
      A__							:					List[Any]       =	model.generate(**UpperCamelCase_    )



class 					_a		(__magic_name__       ):


     '''simple docstring'''






     def 						__A    (				self    ):
      super().setUp()
      # model_name
      A__							:					str       =	'bigscience/bloom-560m'
      A__							:					str       =	't5-small'

      # Different types of model

      A__							:					Tuple       =	AutoModel.from_pretrained(self.model_name					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )
      # Sequence classification model
      A__							:					Optional[int]       =	AutoModelForSequenceClassification.from_pretrained(
          self.model_name					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )
      # CausalLM model
      A__							:					Tuple       =	AutoModelForCausalLM.from_pretrained(self.model_name					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )
      # Seq2seq model
      A__							:					List[Any]       =	AutoModelForSeqaSeqLM.from_pretrained(
          self.seq_to_seq_name					, load_in_abit=UpperCamelCase_					, device_map="""auto"""    )






     def 						__A    (				self    ):
      del self.base_model
      del self.sequence_model
      del self.model_abit
      del self.seq_to_seq_model

      gc.collect()
      torch.cuda.empty_cache()






     def 						__A    (				self    ):
      from bitsandbytes.nn import Paramsabit

      self.assertTrue(self.base_model.h[-1].mlp.dense_ah_to_h.weight.__class__ == Paramsabit    )

      # Other heads should be nn.Parameter
      self.assertTrue(self.model_abit.lm_head.weight.__class__ == torch.nn.Parameter    )
      self.assertTrue(self.sequence_model.score.weight.__class__ == torch.nn.Parameter    )
      self.assertTrue(self.seq_to_seq_model.lm_head.weight.__class__ == torch.nn.Parameter    )



class 					_a		(__magic_name__       ):


     '''simple docstring'''






     def 						__A    (				self    ):
      super().setUp()






     def 						__A    (				self    ):
      del self.pipe

      gc.collect()
      torch.cuda.empty_cache()






     def 						__A    (				self    ):
      A__							:					str       =	pipeline(
          """text-generation"""					, model=self.model_name					, model_kwargs={"""device_map""": """auto""", """load_in_4bit""": True, """torch_dtype""": torch.floataa}					, max_new_tokens=self.MAX_NEW_TOKENS					, )

      # Real second forward pass
      A__							:					int       =	self.pipe(self.input_text    )
      self.assertIn(pipeline_output[0]["""generated_text"""]					, self.EXPECTED_OUTPUTS    )



@require_torch_multi_gpu
class 					_a		(__magic_name__       ):


     '''simple docstring'''






     def 						__A    (				self    ):
      super().setUp()






     def 						__A    (				self    ):
      A__							:					List[str]       =	AutoModelForCausalLM.from_pretrained(
          self.model_name					, load_in_abit=UpperCamelCase_					, device_map="""balanced"""    )

      # Check correct device map
      self.assertEqual(set(model_parallel.hf_device_map.values()    )					, {0, 1}    )

      # Check that inference pass works on the model
      A__							:					int       =	self.tokenizer(self.input_text					, return_tensors="""pt"""    )

      # Second real batch
      A__							:					str       =	model_parallel.generate(input_ids=encoded_input["""input_ids"""].to(0    )					, max_new_tokens=10    )
      self.assertIn(self.tokenizer.decode(output_parallel[0]					, skip_special_tokens=UpperCamelCase_    )					, self.EXPECTED_OUTPUTS    )



class 					_a		(__magic_name__       ):


     '''simple docstring'''






     def 						__A    (				self    ):
      A__							:					Union[str, Any]       =	'facebook/opt-350m'
      super().setUp()






     def 						__A    (				self    ):





      if version.parse(importlib.metadata.version("""bitsandbytes"""    )    ) < version.parse("""0.37.0"""    ):
       return

      # Step 1: freeze all parameters
      A__							:					Optional[int]       =	AutoModelForCausalLM.from_pretrained(self.model_name					, load_in_abit=UpperCamelCase_    )

      self.assertEqual(set(model.hf_device_map.values()    )					, {torch.cuda.current_device()}    )

      for param in model.parameters():
       A__							:					List[Any]       =	False  # freeze the model - train adapters later
       if param.ndim == 1:
        # cast the small parameters (e.g. layernorm) to fp32 for stability
        A__							:					int       =	param.data.to(torch.floataa    )

        # Step 2: add adapters
      for _, module in model.named_modules():
       if "OPTAttention" in repr(type(UpperCamelCase_    )    ):
        A__							:					Optional[Any]       =	LoRALayer(module.q_proj					, rank=16    )
        A__							:					Optional[int]       =	LoRALayer(module.k_proj					, rank=16    )
        A__							:					Tuple       =	LoRALayer(module.v_proj					, rank=16    )

        # Step 3: dummy batch
      A__							:					Dict       =	self.tokenizer("""Test batch """					, return_tensors="""pt"""    ).to(0    )

      # Step 4: Check if the gradient is not None
      with torch.cuda.amp.autocast():
       A__							:					List[str]       =	model.forward(**UpperCamelCase_    )
       out.logits.norm().backward()

      for module in model.modules():
       if isinstance(UpperCamelCase_					, UpperCamelCase_    ):
        self.assertTrue(module.adapter[1].weight.grad is not None    )
        self.assertTrue(module.adapter[1].weight.grad.norm().item() > 0    )
       elif isinstance(UpperCamelCase_					, nn.Embedding    ):
        self.assertTrue(module.weight.grad is None    )



class 					_a		(__magic_name__       ):


     '''simple docstring'''






     UpperCAmelCase__:     Tuple													= '''gpt2-xl'''
     UpperCAmelCase__:     int													= 3.31_91_85_48_54_15_21_87






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


A_ :				Dict						 =    {
    '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 		UpperCamelCase      (lowercase_:				Optional[Any]      )  ->   Optional[int]:
	A__							:					List[Any]       =	["""layers""", """blocks"""]
	for k in ignore_keys:
		state_dict.pop(lowercase_					,   lowercase_      )


A_ :				Any						 =    {
    '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 		UpperCamelCase      (lowercase_:				str      )  ->   Any:
	A__							:					Dict       =	list(s_dict.keys()      )
	for key in keys:
		A__							:					List[str]       =	key
		for k, v in WHISPER_MAPPING.items():
			if k in key:
				A__							:					List[Any]       =	new_key.replace(lowercase_					,   lowercase_      )

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

		A__							:					Tuple       =	s_dict.pop(lowercase_      )
	return s_dict

def 		UpperCamelCase      (lowercase_:				Tuple      )  ->   Optional[int]:
	A__     ,     A__							:					Any       =	emb.weight.shape
	A__							:					str       =	nn.Linear(lowercase_					,   lowercase_					,   bias=lowercase_      )
	A__							:					Union[str, Any]       =	emb.weight.data
	return lin_layer

def 		UpperCamelCase      (lowercase_:				str					,   lowercase_:				str      )  ->   bytes:
	os.makedirs(lowercase_					,   exist_ok=lowercase_      )
	A__							:					Tuple       =	os.path.basename(lowercase_      )

	A__							:					int       =	url.split("""/"""      )[-2]
	A__							:					Dict       =	os.path.join(lowercase_					,   lowercase_      )

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

	if os.path.isfile(lowercase_      ):
		A__							:					Optional[Any]       =	open(lowercase_					,   """rb"""      ).read()
		if hashlib.shaaaa(lowercase_      ).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(lowercase_      ) as source, open(lowercase_					,   """wb"""      ) as output:
		with tqdm(
		    total=int(source.info().get("""Content-Length"""      )      )					,   ncols=80					,   unit="""iB"""					,   unit_scale=lowercase_					,   unit_divisor=1024      ) as loop:
			while True:
				A__							:					Any       =	source.read(8192      )
				if not buffer:
					break

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

	A__							:					Dict       =	open(lowercase_					,   """rb"""      ).read()
	if hashlib.shaaaa(lowercase_      ).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 		UpperCamelCase      (lowercase_:				List[Any]					,   lowercase_:				Tuple      )  ->   Optional[Any]:
	if ".pt" not in checkpoint_path:
		A__							:					Tuple       =	_download(_MODELS[checkpoint_path]      )
	else:
		A__							:					Optional[int]       =	torch.load(lowercase_					,   map_location="""cpu"""      )
	A__							:					str       =	original_checkpoint["""dims"""]
	A__							:					List[Any]       =	original_checkpoint["""model_state_dict"""]
	A__							:					Optional[Any]       =	state_dict["""decoder.token_embedding.weight"""]
	remove_ignore_keys_(lowercase_      )
	rename_keys(lowercase_      )
	A__							:					List[str]       =	True
	A__							:					Optional[Any]       =	state_dict["""decoder.layers.0.fc1.weight"""].shape[0]

	A__							:					List[Any]       =	WhisperConfig(
	    vocab_size=dimensions["""n_vocab"""]					,   encoder_ffn_dim=lowercase_					,   decoder_ffn_dim=lowercase_					,   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(lowercase_      )
	A__     ,     A__							:					List[Any]       =	model.model.load_state_dict(lowercase_					,   strict=lowercase_      )
	if len(lowercase_      ) > 0 and not set(lowercase_      ) <= {
	    "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(lowercase_      )


if __name__ == "__main__":
	A_ :				Any						 =    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.')
	A_ :				Tuple						 =    parser.parse_args()

	convert_openai_whisper_to_tfms(args.checkpoint_path, args.pytorch_dump_folder_path)



