




import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase__	   = logging.get_logger(__name__)

lowerCAmelCase__	   = {
    """microsoft/unispeech-large-1500h-cv""": (
        """https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json"""
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}

class 					a__						(					snake_case			):
			"""simple docstring"""







			__lowerCamelCase        =       'unispeech'


			def __init__(    self      ,      lowercase=32      ,      lowercase=768      ,      lowercase=12      ,      lowercase=12      ,      lowercase=3072      ,      lowercase="gelu"      ,      lowercase=0.1      ,      lowercase=0.1      ,      lowercase=0.1      ,      lowercase=0.0      ,      lowercase=0.0      ,      lowercase=0.1      ,      lowercase=0.1      ,      lowercase=0.02      ,      lowercase=1e-5      ,      lowercase="group"      ,      lowercase="gelu"      ,      lowercase=(512, 512, 512, 512, 512, 512, 512)      ,      lowercase=(5, 2, 2, 2, 2, 2, 2)      ,      lowercase=(10, 3, 3, 3, 3, 2, 2)      ,      lowercase=False      ,      lowercase=128      ,      lowercase=16      ,      lowercase=False      ,      lowercase=True      ,      lowercase=0.05      ,      lowercase=10      ,      lowercase=2      ,      lowercase=0.0      ,      lowercase=10      ,      lowercase=0      ,      lowercase=320      ,      lowercase=2      ,      lowercase=0.1      ,      lowercase=100      ,      lowercase=256      ,      lowercase=256      ,      lowercase=0.1      ,      lowercase="mean"      ,      lowercase=False      ,      lowercase=False      ,      lowercase=256      ,      lowercase=80      ,      lowercase=0      ,      lowercase=1      ,      lowercase=2      ,      lowercase=0.5      ,      **lowercase      ,      )  ->						Tuple:
							'''simple docstring'''






							super().__init__(**lowercase      ,      pad_token_id=lowercase      ,      bos_token_id=lowercase      ,      eos_token_id=lowercase       )
							A__        =			hidden_size
							A__        =			feat_extract_norm
							A__        =			feat_extract_activation
							A__        =			list(lowercase       )
							A__        =			list(lowercase       )
							A__        =			list(lowercase       )
							A__        =			conv_bias
							A__        =			num_conv_pos_embeddings
							A__        =			num_conv_pos_embedding_groups
							A__        =			len(self.conv_dim       )
							A__        =			num_hidden_layers
							A__        =			intermediate_size
							A__        =			hidden_act
							A__        =			num_attention_heads
							A__        =			hidden_dropout
							A__        =			attention_dropout
							A__        =			activation_dropout
							A__        =			feat_proj_dropout
							A__        =			final_dropout
							A__        =			layerdrop
							A__        =			layer_norm_eps
							A__        =			initializer_range
							A__        =			num_ctc_classes
							A__        =			vocab_size
							A__        =			do_stable_layer_norm
							A__        =			use_weighted_layer_sum
							A__        =			classifier_proj_size

							if (
							    (len(self.conv_stride       ) != self.num_feat_extract_layers)
							    or (len(self.conv_kernel       ) != self.num_feat_extract_layers)
							    or (len(self.conv_dim       ) != self.num_feat_extract_layers)
							):
											raise ValueError(
											    "Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="
											    " `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="
											    F' {len(self.conv_dim       )}`, `len(config.conv_stride) = {len(self.conv_stride       )}`,'
											    F' `len(config.conv_kernel) = {len(self.conv_kernel       )}`.'       )

							# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
							A__        =			apply_spec_augment
							A__        =			mask_time_prob
							A__        =			mask_time_length
							A__        =			mask_time_min_masks
							A__        =			mask_feature_prob
							A__        =			mask_feature_length
							A__        =			mask_feature_min_masks

							# parameters for pretraining with codevector quantized representations
							A__        =			num_codevectors_per_group
							A__        =			num_codevector_groups
							A__        =			contrastive_logits_temperature
							A__        =			feat_quantizer_dropout
							A__        =			num_negatives
							A__        =			codevector_dim
							A__        =			proj_codevector_dim
							A__        =			diversity_loss_weight

							# ctc loss
							A__        =			ctc_loss_reduction
							A__        =			ctc_zero_infinity

							# pretraining loss
							A__        =			replace_prob


			@property
			def      UpperCamelCase		(    self       )  ->						str:
							'''simple docstring'''






							return functools.reduce(operator.mul      ,      self.conv_stride      ,      1       )




from dataclasses import dataclass, field
from typing import Optional

from transformers import AutoConfig, AutoImageProcessor, AutoTokenizer, FlaxVisionEncoderDecoderModel, HfArgumentParser

@dataclass
class 					a__						:
			"""simple docstring"""







			__lowerCamelCase        =       field(
			    metadata={'help': 'The output directory where the model will be written.'}							,	)
			__lowerCamelCase        =       field(
			    metadata={
			        'help': (
			            'The encoder model checkpoint for weights initialization.'
			            'Don\'t set if you want to train an encoder model from scratch.'
			        )
			    }							,	)
			__lowerCamelCase        =       field(
			    metadata={
			        'help': (
			            'The decoder model checkpoint for weights initialization.'
			            'Don\'t set if you want to train a decoder model from scratch.'
			        )
			    }							,	)
			__lowerCamelCase        =       field(
			    default=snake_case							,	metadata={'help': 'Pretrained encoder config name or path if not the same as encoder_model_name'}			)
			__lowerCamelCase        =       field(
			    default=snake_case							,	metadata={'help': 'Pretrained decoder config name or path if not the same as decoder_model_name'}			)



def 					lowerCAmelCase__							(	)			->      List[Any]:




				'''simple docstring'''





				A__        =			HfArgumentParser((ModelArguments,)      )
				((A__)    ,				)        =			parser.parse_args_into_dataclasses()

				# Load pretrained model and tokenizer

				# Use explicit specified encoder config
				if model_args.encoder_config_name:
								A__        =			AutoConfig.from_pretrained(model_args.encoder_config_name      )
				# Use pretrained encoder model's config
				else:
								A__        =			AutoConfig.from_pretrained(model_args.encoder_model_name_or_path      )

				# Use explicit specified decoder config
				if model_args.decoder_config_name:
								A__        =			AutoConfig.from_pretrained(model_args.decoder_config_name      )
				# Use pretrained decoder model's config
				else:
								A__        =			AutoConfig.from_pretrained(model_args.decoder_model_name_or_path      )

				# necessary for `from_encoder_decoder_pretrained` when `decoder_config` is passed
				A__        =			True
				A__        =			True

				A__        =			FlaxVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
				    encoder_pretrained_model_name_or_path=model_args.encoder_model_name_or_path	,       decoder_pretrained_model_name_or_path=model_args.decoder_model_name_or_path	,       encoder_config=SCREAMING_SNAKE_CASE_	,       decoder_config=SCREAMING_SNAKE_CASE_	,       )

				# GPT2 only has bos/eos tokens but not decoder_start/pad tokens
				A__        =			decoder_config.decoder_start_token_id
				A__        =			decoder_config.pad_token_id
				if decoder_start_token_id is None:
								A__        =			decoder_config.bos_token_id
				if pad_token_id is None:
								A__        =			decoder_config.eos_token_id

				# This is necessary to make Flax's generate() work
				A__        =			decoder_config.eos_token_id
				A__        =			decoder_start_token_id
				A__        =			pad_token_id

				A__        =			AutoImageProcessor.from_pretrained(model_args.encoder_model_name_or_path      )

				A__        =			AutoTokenizer.from_pretrained(model_args.decoder_model_name_or_path      )
				A__        =			tokenizer.convert_ids_to_tokens(model.config.pad_token_id      )

				model.save_pretrained(model_args.output_dir      )
				image_processor.save_pretrained(model_args.output_dir      )
				tokenizer.save_pretrained(model_args.output_dir      )


if __name__ == "__main__":
	main()

