




'''simple docstring'''







import os
import re
import shutil
import sys
import tempfile
import unittest

import black


lowercase      :   str      =       os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, """utils"""))

import check_copies  # noqa: E402


# This is the reference code that will be used in the tests.
# If BertLMPredictionHead is changed in modeling_bert.py, this code needs to be manually updated.
lowercase      :   Dict      =       """    def __init__(self, config):
        super().__init__()
        self.transform = BertPredictionHeadTransform(config)

        # The output weights are the same as the input embeddings, but there is
        # an output-only bias for each token.
        self.decoder = nn.Linear(config.hidden_size, config.vocab_size, bias=False)

        self.bias = nn.Parameter(torch.zeros(config.vocab_size))

        # Need a link between the two variables so that the bias is correctly resized with `resize_token_embeddings`
        self.decoder.bias = self.bias

    def forward(self, hidden_states):
        hidden_states = self.transform(hidden_states)
        hidden_states = self.decoder(hidden_states)
        return hidden_states
"""







class 					_a (unittest.TestCase	):





     '''simple docstring'''



     def 			snake_case_      (				self							)      ->				Union[str, Any]:
          snake_case			:      Dict        =			tempfile.mkdtemp()
          os.makedirs(os.path.join(self.transformer_dir							,"""models/bert/"""							)							)
          snake_case			:      List[str]        =			self.transformer_dir
          shutil.copy(
              os.path.join(__a							,"""src/transformers/models/bert/modeling_bert.py"""							)							,os.path.join(self.transformer_dir							,"""models/bert/modeling_bert.py"""							)							,)







     def 			snake_case_      (				self							)      ->				Dict:
          snake_case			:      Tuple        =			"""src/transformers"""
          shutil.rmtree(self.transformer_dir							)







     def 			snake_case_      (				self							,__a							,__a							,__a							,__a=None							)      ->				List[str]:
          snake_case			:      Dict        =			comment + F'''\nclass {class_name}(nn.Module):\n''' + class_code
          if overwrite_result is not None:
               snake_case			:      Optional[int]        =			comment + F'''\nclass {class_name}(nn.Module):\n''' + overwrite_result
          snake_case			:      Tuple        =			black.Mode(target_versions={black.TargetVersion.PYaa}							,line_length=119							)
          snake_case			:      str        =			black.format_str(__a							,mode=__a							)
          snake_case			:      List[Any]        =			os.path.join(self.transformer_dir							,"""new_code.py"""							)
          with open(__a							,"""w"""							,newline="""\n"""							) as f:
               f.write(__a							)
          if overwrite_result is None:
               self.assertTrue(len(check_copies.is_copy_consistent(__a							)							) == 0							)
          else:
               check_copies.is_copy_consistent(f.name							,overwrite=__a							)
               with open(__a							,"""r"""							) as f:
                    self.assertTrue(f.read()							,__a							)







     def 			snake_case_      (				self							)      ->				Tuple:
          snake_case			:      int        =			check_copies.find_code_in_transformers("""models.bert.modeling_bert.BertLMPredictionHead"""							)
          self.assertEqual(__a							,__a							)







     def 			snake_case_      (				self							)      ->				Union[str, Any]:
          # Base copy consistency
          self.check_copy_consistency(
              """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead"""							,"""BertLMPredictionHead"""							,REFERENCE_CODE + """\n"""							,)

          # With no empty line at the end
          self.check_copy_consistency(
              """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead"""							,"""BertLMPredictionHead"""							,__a							,)

          # Copy consistency with rename
          self.check_copy_consistency(
              """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel"""							,"""TestModelLMPredictionHead"""							,re.sub("""Bert"""							,"""TestModel"""							,__a							)							,)

          # Copy consistency with a really long name
          snake_case			:      List[str]        =			"""TestModelWithAReallyLongNameBecauseSomePeopleLikeThatForSomeReason"""
          self.check_copy_consistency(
              F'''# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->{long_class_name}'''							,F'''{long_class_name}LMPredictionHead'''							,re.sub("""Bert"""							,__a							,__a							)							,)

          # Copy consistency with overwrite
          self.check_copy_consistency(
              """# Copied from transformers.models.bert.modeling_bert.BertLMPredictionHead with Bert->TestModel"""							,"""TestModelLMPredictionHead"""							,__a							,overwrite_result=re.sub("""Bert"""							,"""TestModel"""							,__a							)							,)







     def 			snake_case_      (				self							)      ->				int:
          snake_case			:      Optional[int]        =			check_copies.LOCALIZED_READMES["""README_zh-hans.md"""]

          snake_case			:      List[Any]        =			(
              """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the"""
              """ Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for"""
              """ Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong"""
              """ Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut.\n1."""
              """ **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (from HuggingFace),"""
              """ released together with the paper [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and"""
              """ lighter](https://arxiv.org/abs/1910.01108) by Victor Sanh, Lysandre Debut and Thomas Wolf. The same"""
              """ method has been applied to compress GPT2 into"""
              """ [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into"""
              """ [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),"""
              """ Multilingual BERT into"""
              """ [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German"""
              """ version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)**"""
              """ (from Google Research/Stanford University) released with the paper [ELECTRA: Pre-training text encoders"""
              """ as discriminators rather than generators](https://arxiv.org/abs/2003.10555) by Kevin Clark, Minh-Thang"""
              """ Luong, Quoc V. Le, Christopher D. Manning."""
          )
          snake_case			:      Any        =			(
              """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"""
              """ Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
              """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
              """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"""
          )
          snake_case			:      Optional[Any]        =			(
              """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"""
              """ Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
              """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
              """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n1."""
              """ **[DistilBERT](https://huggingface.co/transformers/model_doc/distilbert.html)** (来自 HuggingFace) 伴随论文"""
              """ [DistilBERT, a distilled version of BERT: smaller, faster, cheaper and"""
              """ lighter](https://arxiv.org/abs/1910.01108) 由 Victor Sanh, Lysandre Debut and Thomas Wolf 发布。 The same"""
              """ method has been applied to compress GPT2 into"""
              """ [DistilGPT2](https://github.com/huggingface/transformers/tree/main/examples/distillation), RoBERTa into"""
              """ [DistilRoBERTa](https://github.com/huggingface/transformers/tree/main/examples/distillation),"""
              """ Multilingual BERT into"""
              """ [DistilmBERT](https://github.com/huggingface/transformers/tree/main/examples/distillation) and a German"""
              """ version of DistilBERT.\n1. **[ELECTRA](https://huggingface.co/transformers/model_doc/electra.html)** (来自"""
              """ Google Research/Stanford University) 伴随论文 [ELECTRA: Pre-training text encoders as discriminators rather"""
              """ than generators](https://arxiv.org/abs/2003.10555) 由 Kevin Clark, Minh-Thang Luong, Quoc V. Le,"""
              """ Christopher D. Manning 发布。\n"""
          )

          snake_case ,		snake_case			:      Tuple        =			check_copies.convert_to_localized_md(
              __a							,__a							,localized_readme["""format_model_list"""]							)

          self.assertFalse(__a							)
          self.assertEqual(__a							,__a							)

          snake_case ,		snake_case			:      Tuple        =			check_copies.convert_to_localized_md(
              __a							,__a							,localized_readme["""format_model_list"""]							)

          # Check whether the number of models is equal to README.md after conversion.
          self.assertTrue(__a							)

          snake_case			:      Optional[int]        =			(
              """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (from Google Research and the"""
              """ Toyota Technological Institute at Chicago) released with the paper [ALBERT: A Lite BERT for"""
              """ Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942), by Zhenzhong"""
              """ Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut."""
          )
          snake_case			:      Tuple        =			(
              """1. **[ALBERT](https://huggingface.co/transformers/main/model_doc/albert.html)** (来自 Google Research and"""
              """ the Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
              """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
              """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"""
          )
          snake_case			:      str        =			(
              """1. **[ALBERT](https://huggingface.co/transformers/model_doc/albert.html)** (来自 Google Research and the"""
              """ Toyota Technological Institute at Chicago) 伴随论文 [ALBERT: A Lite BERT for Self-supervised Learning of"""
              """ Language Representations](https://arxiv.org/abs/1909.11942), 由 Zhenzhong Lan, Mingda Chen, Sebastian"""
              """ Goodman, Kevin Gimpel, Piyush Sharma, Radu Soricut 发布。\n"""
          )

          snake_case ,		snake_case			:      List[str]        =			check_copies.convert_to_localized_md(
              __a							,__a							,localized_readme["""format_model_list"""]							)

          # Check if the model link is synchronized.
          self.assertEqual(__a							,__a							)









'''simple docstring'''







import functools
import operator

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


lowercase      :   Optional[int]      =       logging.get_logger(__name__)

lowercase      :   Union[str, Any]      =       {
    """microsoft/unispeech-sat-base-100h-libri-ft""": (
        """https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json"""
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}







class 					_a (a__	):





     '''simple docstring'''



     lowerCAmelCase_  :     List[Any]          =					"""unispeech-sat"""







     def __init__(				self							,__a=32							,__a=768							,__a=12							,__a=12							,__a=3_072							,__a="gelu"							,__a=0.1							,__a=0.1							,__a=0.1							,__a=0.0							,__a=0.0							,__a=0.1							,__a=0.1							,__a=0.02							,__a=1E-5							,__a="group"							,__a="gelu"							,__a=(512, 512, 512, 512, 512, 512, 512)							,__a=(5, 2, 2, 2, 2, 2, 2)							,__a=(10, 3, 3, 3, 3, 2, 2)							,__a=False							,__a=128							,__a=16							,__a=False							,__a=True							,__a=0.05							,__a=10							,__a=2							,__a=0.0							,__a=10							,__a=0							,__a=320							,__a=2							,__a=0.1							,__a=100							,__a=256							,__a=256							,__a=0.1							,__a="mean"							,__a=False							,__a=False							,__a=256							,__a=(512, 512, 512, 512, 1_500)							,__a=(5, 3, 3, 1, 1)							,__a=(1, 2, 3, 1, 1)							,__a=512							,__a=0							,__a=1							,__a=2							,__a=504							,**__a							,)      ->				str:
          super().__init__(**__a							,pad_token_id=__a							,bos_token_id=__a							,eos_token_id=__a							)
          snake_case			:      List[Any]        =			hidden_size
          snake_case			:      Any        =			feat_extract_norm
          snake_case			:      Dict        =			feat_extract_activation
          snake_case			:      List[Any]        =			list(__a							)
          snake_case			:      int        =			list(__a							)
          snake_case			:      Dict        =			list(__a							)
          snake_case			:      int        =			conv_bias
          snake_case			:      Optional[Any]        =			num_conv_pos_embeddings
          snake_case			:      Any        =			num_conv_pos_embedding_groups
          snake_case			:      Dict        =			len(self.conv_dim							)
          snake_case			:      str        =			num_hidden_layers
          snake_case			:      Optional[Any]        =			intermediate_size
          snake_case			:      Optional[Any]        =			hidden_act
          snake_case			:      Union[str, Any]        =			num_attention_heads
          snake_case			:      str        =			hidden_dropout
          snake_case			:      Tuple        =			attention_dropout
          snake_case			:      Tuple        =			activation_dropout
          snake_case			:      List[Any]        =			feat_proj_dropout
          snake_case			:      List[str]        =			final_dropout
          snake_case			:      Union[str, Any]        =			layerdrop
          snake_case			:      Optional[int]        =			layer_norm_eps
          snake_case			:      int        =			initializer_range
          snake_case			:      List[Any]        =			vocab_size
          snake_case			:      Any        =			num_clusters
          snake_case			:      Dict        =			do_stable_layer_norm
          snake_case			:      int        =			use_weighted_layer_sum

          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
          snake_case			:      Dict        =			apply_spec_augment
          snake_case			:      Optional[int]        =			mask_time_prob
          snake_case			:      int        =			mask_time_length
          snake_case			:      int        =			mask_time_min_masks
          snake_case			:      int        =			mask_feature_prob
          snake_case			:      Optional[Any]        =			mask_feature_length
          snake_case			:      List[Any]        =			mask_feature_min_masks

          # parameters for pretraining with codevector quantized representations
          snake_case			:      Optional[Any]        =			num_codevectors_per_group
          snake_case			:      Optional[int]        =			num_codevector_groups
          snake_case			:      Any        =			contrastive_logits_temperature
          snake_case			:      List[str]        =			feat_quantizer_dropout
          snake_case			:      Dict        =			num_negatives
          snake_case			:      int        =			codevector_dim
          snake_case			:      Optional[int]        =			proj_codevector_dim
          snake_case			:      Union[str, Any]        =			diversity_loss_weight

          # ctc loss
          snake_case			:      Union[str, Any]        =			ctc_loss_reduction
          snake_case			:      Optional[int]        =			ctc_zero_infinity

          # SequenceClassification-specific parameter. Feel free to ignore for other classes.
          snake_case			:      Dict        =			classifier_proj_size

          # XVector-specific parameters. Feel free to ignore for other classes.
          snake_case			:      int        =			list(__a							)
          snake_case			:      Tuple        =			list(__a							)
          snake_case			:      List[Any]        =			list(__a							)
          snake_case			:      Dict        =			xvector_output_dim







     @property
     def 			snake_case_      (				self							)      ->				List[str]:
          return functools.reduce(operator.mul							,self.conv_stride							,1							)



