


import logging
import os
import random
import sys
from dataclasses import dataclass, field
from typing import Optional

import datasets
import evaluate
import numpy as np
from datasets import load_dataset

import transformers
from transformers import (
    AutoConfig,
    AutoModelForSequenceClassification,
    AutoTokenizer,
    DataCollatorWithPadding,
    EvalPrediction,
    HfArgumentParser,
    Trainer,
    TrainingArguments,
    default_data_collator,
    set_seed,
)
from transformers.trainer_utils import get_last_checkpoint
from transformers.utils import check_min_version, send_example_telemetry
from transformers.utils.versions import require_version


# Will error if the minimal version of Transformers is not installed. Remove at your own risks.
check_min_version('4.31.0')

require_version('datasets>=1.8.0', 'To fix: pip install -r examples/pytorch/text-classification/requirements.txt')

__UpperCamelCase    :						int     =							logging.getLogger(__name__)



@dataclass
class 							_UpperCamelCase :

   '''simple docstring'''







   a_				:							Optional[int]    = field(
       default=128,metadata={
           "help": (
               "The maximum total input sequence length after tokenization. Sequences longer "
               "than this will be truncated, sequences shorter will be padded."
           )
       },)
   a_				:							bool    = field(
       default=A,metadata={"help": "Overwrite the cached preprocessed datasets or not."}						)
   a_				:							bool    = field(
       default=A,metadata={
           "help": (
               "Whether to pad all samples to `max_seq_length`. "
               "If False, will pad the samples dynamically when batching to the maximum length in the batch."
           )
       },)
   a_				:							Optional[int]    = field(
       default=A,metadata={
           "help": (
               "For debugging purposes or quicker training, truncate the number of training examples to this "
               "value if set."
           )
       },)
   a_				:							Optional[int]    = field(
       default=A,metadata={
           "help": (
               "For debugging purposes or quicker training, truncate the number of evaluation examples to this "
               "value if set."
           )
       },)
   a_				:							Optional[int]    = field(
       default=A,metadata={
           "help": (
               "For debugging purposes or quicker training, truncate the number of prediction examples to this "
               "value if set."
           )
       },)



@dataclass
class 							_UpperCamelCase :

   '''simple docstring'''







   a_				:							str    = field(
       default=A,metadata={"help": "Path to pretrained model or model identifier from huggingface.co/models"}						)
   a_				:							str    = field(
       default=A,metadata={"help": "Evaluation language. Also train language if `train_language` is set to None."}						)
   a_				:							Optional[str]    = field(
       default=A,metadata={"help": "Train language if it is different from the evaluation language."}						)
   a_				:							Optional[str]    = field(
       default=A,metadata={"help": "Pretrained config name or path if not the same as model_name"}						)
   a_				:							Optional[str]    = field(
       default=A,metadata={"help": "Pretrained tokenizer name or path if not the same as model_name"}						)
   a_				:							Optional[str]    = field(
       default=A,metadata={"help": "Where do you want to store the pretrained models downloaded from huggingface.co"},)
   a_				:							Optional[bool]    = field(
       default=A,metadata={"help": "arg to indicate if tokenizer should do lower case in AutoTokenizer.from_pretrained()"},)
   a_				:							bool    = field(
       default=A,metadata={"help": "Whether to use one of the fast tokenizer (backed by the tokenizers library) or not."},)
   a_				:							str    = field(
       default="main",metadata={"help": "The specific model version to use (can be a branch name, tag name or commit id)."},)
   a_				:							bool    = field(
       default=A,metadata={
           "help": (
               "Will use the token generated when running `huggingface-cli login` (necessary to use this script "
               "with private models)."
           )
       },)
   a_				:							bool    = field(
       default=A,metadata={"help": "Will enable to load a pretrained model whose head dimensions are different."},)





def   _UpperCAmelCase       (     ):
      """simple docstring"""




      __lowerCamelCase     :      int       						=						HfArgumentParser((ModelArguments, DataTrainingArguments, TrainingArguments)      )
      __lowerCamelCase						, __lowerCamelCase						, __lowerCamelCase     :      Tuple       						=						parser.parse_args_into_dataclasses()

      # Sending telemetry. Tracking the example usage helps us better allocate resources to maintain them. The
      # information sent is the one passed as arguments along with your Python/PyTorch versions.
      send_example_telemetry("""run_xnli"""						,	UpperCAmelCase      )

      # Setup logging
      logging.basicConfig(
          format="""%(asctime)s - %(levelname)s - %(name)s - %(message)s"""						,	datefmt="""%m/%d/%Y %H:%M:%S"""						,	handlers=[logging.StreamHandler(sys.stdout      )]						,	)

      if training_args.should_log:
            # The default of training_args.log_level is passive, so we set log level at info here to have that default.
            transformers.utils.logging.set_verbosity_info()

      __lowerCamelCase     :      Dict       						=						training_args.get_process_log_level()
      logger.setLevel(UpperCAmelCase      )
      datasets.utils.logging.set_verbosity(UpperCAmelCase      )
      transformers.utils.logging.set_verbosity(UpperCAmelCase      )
      transformers.utils.logging.enable_default_handler()
      transformers.utils.logging.enable_explicit_format()

      # Log on each process the small summary:
      logger.warning(
          f"""Process rank: {training_args.local_rank}, device: {training_args.device}, n_gpu: {training_args.n_gpu}"""
          + f"""distributed training: {bool(training_args.local_rank != -1      )}, 16-bits training: {training_args.fpaa}"""      )
      logger.info(f"""Training/evaluation parameters {training_args}"""      )

      # Detecting last checkpoint.
      __lowerCamelCase     :      Tuple       						=						None
      if os.path.isdir(training_args.output_dir      ) and training_args.do_train and not training_args.overwrite_output_dir:
            __lowerCamelCase     :      List[Any]       						=						get_last_checkpoint(training_args.output_dir      )
            if last_checkpoint is None and len(os.listdir(training_args.output_dir      )      ) > 0:
                  raise ValueError(
                      f"""Output directory ({training_args.output_dir}) already exists and is not empty. """
                      """Use --overwrite_output_dir to overcome."""      )
            elif last_checkpoint is not None:
                  logger.info(
                      f"""Checkpoint detected, resuming training at {last_checkpoint}. To avoid this behavior, change """
                      """the `--output_dir` or add `--overwrite_output_dir` to train from scratch."""      )

    # Set seed before initializing model.
      set_seed(training_args.seed      )

      # In distributed training, the load_dataset function guarantees that only one local process can concurrently
      # download the dataset.
      # Downloading and loading xnli dataset from the hub.
      if training_args.do_train:
            if model_args.train_language is None:
                  __lowerCamelCase     :      Union[str, Any]       						=						load_dataset(
                      """xnli"""						,	model_args.language						,	split="""train"""						,	cache_dir=model_args.cache_dir						,	use_auth_token=True if model_args.use_auth_token else None						,	)
            else:
                  __lowerCamelCase     :      str       						=						load_dataset(
                      """xnli"""						,	model_args.train_language						,	split="""train"""						,	cache_dir=model_args.cache_dir						,	use_auth_token=True if model_args.use_auth_token else None						,	)
            __lowerCamelCase     :      List[Any]       						=						train_dataset.features["""label"""].names

      if training_args.do_eval:
            __lowerCamelCase     :      List[Any]       						=						load_dataset(
                """xnli"""						,	model_args.language						,	split="""validation"""						,	cache_dir=model_args.cache_dir						,	use_auth_token=True if model_args.use_auth_token else None						,	)
            __lowerCamelCase     :      List[Any]       						=						eval_dataset.features["""label"""].names

      if training_args.do_predict:
            __lowerCamelCase     :      Any       						=						load_dataset(
                """xnli"""						,	model_args.language						,	split="""test"""						,	cache_dir=model_args.cache_dir						,	use_auth_token=True if model_args.use_auth_token else None						,	)
            __lowerCamelCase     :      Tuple       						=						predict_dataset.features["""label"""].names

      # Labels
      __lowerCamelCase     :      Dict       						=						len(UpperCAmelCase      )

      # Load pretrained model and tokenizer
      # In distributed training, the .from_pretrained methods guarantee that only one local process can concurrently
      # download model & vocab.
      __lowerCamelCase     :      Dict       						=						AutoConfig.from_pretrained(
          model_args.config_name if model_args.config_name else model_args.model_name_or_path						,	num_labels=UpperCAmelCase						,	idalabel={str(UpperCAmelCase      ): label for i, label in enumerate(UpperCAmelCase      )}						,	labelaid={label: i for i, label in enumerate(UpperCAmelCase      )}						,	finetuning_task="""xnli"""						,	cache_dir=model_args.cache_dir						,	revision=model_args.model_revision						,	use_auth_token=True if model_args.use_auth_token else None						,	)
      __lowerCamelCase     :      Union[str, Any]       						=						AutoTokenizer.from_pretrained(
          model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path						,	do_lower_case=model_args.do_lower_case						,	cache_dir=model_args.cache_dir						,	use_fast=model_args.use_fast_tokenizer						,	revision=model_args.model_revision						,	use_auth_token=True if model_args.use_auth_token else None						,	)
      __lowerCamelCase     :      Any       						=						AutoModelForSequenceClassification.from_pretrained(
          model_args.model_name_or_path						,	from_tf=bool(""".ckpt""" in model_args.model_name_or_path      )						,	config=UpperCAmelCase						,	cache_dir=model_args.cache_dir						,	revision=model_args.model_revision						,	use_auth_token=True if model_args.use_auth_token else None						,	ignore_mismatched_sizes=model_args.ignore_mismatched_sizes						,	)

      # Preprocessing the datasets
      # Padding strategy
      if data_args.pad_to_max_length:
            __lowerCamelCase     :      Dict       						=						"""max_length"""
      else:
            # We will pad later, dynamically at batch creation, to the max sequence length in each batch
            __lowerCamelCase     :      Optional[Any]       						=						False

      def preprocess_function(UpperCAmelCase      :			Optional[int]      ):
            # Tokenize the texts
            return tokenizer(
                examples["""premise"""]						,	examples["""hypothesis"""]						,	padding=UpperCAmelCase						,	max_length=data_args.max_seq_length						,	truncation=UpperCAmelCase						,	)

      if training_args.do_train:
            if data_args.max_train_samples is not None:
                  __lowerCamelCase     :      List[Any]       						=						min(len(UpperCAmelCase      )						,	data_args.max_train_samples      )
                  __lowerCamelCase     :      Optional[Any]       						=						train_dataset.select(range(UpperCAmelCase      )      )
            with training_args.main_process_first(desc="""train dataset map pre-processing"""      ):
                  __lowerCamelCase     :      Any       						=						train_dataset.map(
                      UpperCAmelCase						,	batched=UpperCAmelCase						,	load_from_cache_file=not data_args.overwrite_cache						,	desc="""Running tokenizer on train dataset"""						,	)
            # Log a few random samples from the training set:
            for index in random.sample(range(len(UpperCAmelCase      )      )						,	3      ):
                  logger.info(f"""Sample {index} of the training set: {train_dataset[index]}."""      )

      if training_args.do_eval:
            if data_args.max_eval_samples is not None:
                  __lowerCamelCase     :      List[str]       						=						min(len(UpperCAmelCase      )						,	data_args.max_eval_samples      )
                  __lowerCamelCase     :      Tuple       						=						eval_dataset.select(range(UpperCAmelCase      )      )
            with training_args.main_process_first(desc="""validation dataset map pre-processing"""      ):
                  __lowerCamelCase     :      Tuple       						=						eval_dataset.map(
                      UpperCAmelCase						,	batched=UpperCAmelCase						,	load_from_cache_file=not data_args.overwrite_cache						,	desc="""Running tokenizer on validation dataset"""						,	)

      if training_args.do_predict:
            if data_args.max_predict_samples is not None:
                  __lowerCamelCase     :      int       						=						min(len(UpperCAmelCase      )						,	data_args.max_predict_samples      )
                  __lowerCamelCase     :      str       						=						predict_dataset.select(range(UpperCAmelCase      )      )
            with training_args.main_process_first(desc="""prediction dataset map pre-processing"""      ):
                  __lowerCamelCase     :      Optional[Any]       						=						predict_dataset.map(
                      UpperCAmelCase						,	batched=UpperCAmelCase						,	load_from_cache_file=not data_args.overwrite_cache						,	desc="""Running tokenizer on prediction dataset"""						,	)

    # Get the metric function
      __lowerCamelCase     :      Optional[int]       						=						evaluate.load("""xnli"""      )

      # You can define your custom compute_metrics function. It takes an `EvalPrediction` object (a namedtuple with a
      # predictions and label_ids field) and has to return a dictionary string to float.
      def compute_metrics(UpperCAmelCase      :			EvalPrediction      ):
            __lowerCamelCase     :      Union[str, Any]       						=						p.predictions[0] if isinstance(p.predictions						,	UpperCAmelCase      ) else p.predictions
            __lowerCamelCase     :      Dict       						=						np.argmax(UpperCAmelCase						,	axis=1      )
            return metric.compute(predictions=UpperCAmelCase						,	references=p.label_ids      )

      # Data collator will default to DataCollatorWithPadding, so we change it if we already did the padding.
      if data_args.pad_to_max_length:
            __lowerCamelCase     :      List[Any]       						=						default_data_collator
      elif training_args.fpaa:
            __lowerCamelCase     :      List[str]       						=						DataCollatorWithPadding(UpperCAmelCase						,	pad_to_multiple_of=8      )
      else:
            __lowerCamelCase     :      List[Any]       						=						None

      # Initialize our Trainer
      __lowerCamelCase     :      Dict       						=						Trainer(
          model=UpperCAmelCase						,	args=UpperCAmelCase						,	train_dataset=train_dataset if training_args.do_train else None						,	eval_dataset=eval_dataset if training_args.do_eval else None						,	compute_metrics=UpperCAmelCase						,	tokenizer=UpperCAmelCase						,	data_collator=UpperCAmelCase						,	)

      # Training
      if training_args.do_train:
            __lowerCamelCase     :      Optional[int]       						=						None
            if training_args.resume_from_checkpoint is not None:
                  __lowerCamelCase     :      Union[str, Any]       						=						training_args.resume_from_checkpoint
            elif last_checkpoint is not None:
                  __lowerCamelCase     :      Dict       						=						last_checkpoint
            __lowerCamelCase     :      List[str]       						=						trainer.train(resume_from_checkpoint=UpperCAmelCase      )
            __lowerCamelCase     :      Tuple       						=						train_result.metrics
            __lowerCamelCase     :      Optional[Any]       						=						(
                data_args.max_train_samples if data_args.max_train_samples is not None else len(UpperCAmelCase      )
            )
            __lowerCamelCase     :      str       						=						min(UpperCAmelCase						,	len(UpperCAmelCase      )      )

            trainer.save_model()  # Saves the tokenizer too for easy upload

            trainer.log_metrics("""train"""						,	UpperCAmelCase      )
            trainer.save_metrics("""train"""						,	UpperCAmelCase      )
            trainer.save_state()

      # Evaluation
      if training_args.do_eval:
            logger.info("""*** Evaluate ***"""      )
            __lowerCamelCase     :      Optional[Any]       						=						trainer.evaluate(eval_dataset=UpperCAmelCase      )

            __lowerCamelCase     :      List[Any]       						=						data_args.max_eval_samples if data_args.max_eval_samples is not None else len(UpperCAmelCase      )
            __lowerCamelCase     :      Optional[Any]       						=						min(UpperCAmelCase						,	len(UpperCAmelCase      )      )

            trainer.log_metrics("""eval"""						,	UpperCAmelCase      )
            trainer.save_metrics("""eval"""						,	UpperCAmelCase      )

      # Prediction
      if training_args.do_predict:
            logger.info("""*** Predict ***"""      )
            __lowerCamelCase						, __lowerCamelCase						, __lowerCamelCase     :      Dict       						=						trainer.predict(UpperCAmelCase						,	metric_key_prefix="""predict"""      )

            __lowerCamelCase     :      Optional[Any]       						=						(
                data_args.max_predict_samples if data_args.max_predict_samples is not None else len(UpperCAmelCase      )
            )
            __lowerCamelCase     :      Any       						=						min(UpperCAmelCase						,	len(UpperCAmelCase      )      )

            trainer.log_metrics("""predict"""						,	UpperCAmelCase      )
            trainer.save_metrics("""predict"""						,	UpperCAmelCase      )

            __lowerCamelCase     :      Union[str, Any]       						=						np.argmax(UpperCAmelCase						,	axis=1      )
            __lowerCamelCase     :      Dict       						=						os.path.join(training_args.output_dir						,	"""predictions.txt"""      )
            if trainer.is_world_process_zero():
                  with open(UpperCAmelCase						,	"""w"""      ) as writer:
                        writer.write("""index\tprediction\n"""      )
                        for index, item in enumerate(UpperCAmelCase      ):
                              __lowerCamelCase     :      List[str]       						=						label_list[item]
                              writer.write(f"""{index}\t{item}\n"""      )


if __name__ == "__main__":
    main()







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


__UpperCamelCase    :						Tuple     =							{
    '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       (     UpperCAmelCase      :			Dict      ):
      """simple docstring"""




      __lowerCamelCase     :      int       						=						["""layers""", """blocks"""]
      for k in ignore_keys:
            state_dict.pop(UpperCAmelCase						,	UpperCAmelCase      )


__UpperCamelCase    :						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   _UpperCAmelCase       (     UpperCAmelCase      :			Dict      ):
      """simple docstring"""




      __lowerCamelCase     :      List[str]       						=						list(s_dict.keys()      )
      for key in keys:
            __lowerCamelCase     :      Union[str, Any]       						=						key
            for k, v in WHISPER_MAPPING.items():
                  if k in key:
                        __lowerCamelCase     :      Optional[int]       						=						new_key.replace(UpperCAmelCase						,	UpperCAmelCase      )

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

            __lowerCamelCase     :      Dict       						=						s_dict.pop(UpperCAmelCase      )
      return s_dict





def   _UpperCAmelCase       (     UpperCAmelCase      :			Optional[int]      ):
      """simple docstring"""




      __lowerCamelCase						, __lowerCamelCase     :      Dict       						=						emb.weight.shape
      __lowerCamelCase     :      Tuple       						=						nn.Linear(UpperCAmelCase						,	UpperCAmelCase						,	bias=UpperCAmelCase      )
      __lowerCamelCase     :      Union[str, Any]       						=						emb.weight.data
      return lin_layer





def   _UpperCAmelCase       (     UpperCAmelCase      :			str						,	UpperCAmelCase      :			str      ):
      """simple docstring"""




      os.makedirs(UpperCAmelCase						,	exist_ok=UpperCAmelCase      )
      __lowerCamelCase     :      Any       						=						os.path.basename(UpperCAmelCase      )

      __lowerCamelCase     :      int       						=						url.split("""/"""      )[-2]
      __lowerCamelCase     :      str       						=						os.path.join(UpperCAmelCase						,	UpperCAmelCase      )

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

      if os.path.isfile(UpperCAmelCase      ):
            __lowerCamelCase     :      Any       						=						open(UpperCAmelCase						,	"""rb"""      ).read()
            if hashlib.shaaaa(UpperCAmelCase      ).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(UpperCAmelCase      ) as source, open(UpperCAmelCase						,	"""wb"""      ) as output:
            with tqdm(
                total=int(source.info().get("""Content-Length"""      )      )						,	ncols=80						,	unit="""iB"""						,	unit_scale=UpperCAmelCase						,	unit_divisor=1_024      ) as loop:
                  while True:
                        __lowerCamelCase     :      Union[str, Any]       						=						source.read(8_192      )
                        if not buffer:
                              break

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

      __lowerCamelCase     :      List[str]       						=						open(UpperCAmelCase						,	"""rb"""      ).read()
      if hashlib.shaaaa(UpperCAmelCase      ).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       (     UpperCAmelCase      :			List[Any]						,	UpperCAmelCase      :			Optional[int]      ):
      """simple docstring"""




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

      __lowerCamelCase     :      Any       						=						WhisperConfig(
          vocab_size=dimensions["""n_vocab"""]						,	encoder_ffn_dim=UpperCAmelCase						,	decoder_ffn_dim=UpperCAmelCase						,	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"""]						,	)

      __lowerCamelCase     :      List[str]       						=						WhisperForConditionalGeneration(UpperCAmelCase      )
      __lowerCamelCase						, __lowerCamelCase     :      str       						=						model.model.load_state_dict(UpperCAmelCase						,	strict=UpperCAmelCase      )
      if len(UpperCAmelCase      ) > 0 and not set(UpperCAmelCase      ) <= {
          "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:
            __lowerCamelCase     :      Tuple       						=						make_linear_from_emb(model.model.decoder.embed_tokens      )
      else:
            __lowerCamelCase     :      Tuple       						=						proj_out_weights

      model.save_pretrained(UpperCAmelCase      )


if __name__ == "__main__":
    __UpperCamelCase    :						Union[str, 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.')
    __UpperCamelCase    :						Tuple     =							parser.parse_args()

    convert_openai_whisper_to_tfms(args.checkpoint_path, args.pytorch_dump_folder_path)



