


# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os

from accelerate.utils import ComputeEnvironment

from .cluster import get_cluster_input
from .config_args import cache_dir, default_config_file, default_yaml_config_file, load_config_from_file  # noqa: F401
from .config_utils import _ask_field, _ask_options, _convert_compute_environment  # noqa: F401
from .sagemaker import get_sagemaker_input


__UpperCamelCase				:  Union[str, Any]      					=							'Launches a series of prompts to create and save a `default_config.yaml` configuration file for your training system. Should always be ran first on your machine'
def      snake_case_						( ):
   UpperCAmelCase_							:      int						=   _ask_options(
       '''In which compute environment are you running?'''			,       ['''This machine''', '''AWS (Amazon SageMaker)''']			,       _convert_compute_environment			,       )
   if compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
      UpperCAmelCase_							:      List[str]						=   get_sagemaker_input()
   else:
      UpperCAmelCase_							:      int						=   get_cluster_input()
   return config
def      snake_case_						( __lowercase=None       ):

   if subparsers is not None:
      UpperCAmelCase_							:      Any						=   subparsers.add_parser('''config'''			,       description=lowerCamelCase_       )
   else:
      UpperCAmelCase_							:      Optional[Any]						=   argparse.ArgumentParser('''Accelerate config command'''			,       description=lowerCamelCase_       )

   parser.add_argument(
       '''--config_file'''			,       default=lowerCamelCase_			,       help=(
           '''The path to use to store the config file. Will default to a file named default_config.yaml in the cache '''
           '''location, which is the content of the environment `HF_HOME` suffixed with \'accelerate\', or if you don\'t have '''
           '''such an environment variable, your cache directory (\'~/.cache\' or the content of `XDG_CACHE_HOME`) suffixed '''
           '''with \'huggingface\'.'''
       )			,       )

   if subparsers is not None:
      parser.set_defaults(func=lowerCamelCase_       )
   return parser
def      snake_case_						( __lowercase       ):
   UpperCAmelCase_							:      Tuple						=   get_user_input()
   if args.config_file is not None:
      UpperCAmelCase_							:      Any						=   args.config_file
   else:
      if not os.path.isdir(lowerCamelCase_       ):
         os.makedirs(lowerCamelCase_       )
      UpperCAmelCase_							:      int						=   default_yaml_config_file

   if config_file.endswith('''.json'''       ):
      config.to_json_file(lowerCamelCase_       )
   else:
      config.to_yaml_file(lowerCamelCase_       )
   print(F'''accelerate configuration saved at {config_file}'''       )
def      snake_case_						( ):
   UpperCAmelCase_							:      List[Any]						=   config_command_parser()
   UpperCAmelCase_							:      int						=   parser.parse_args()
   config_command(lowerCamelCase_       )


if __name__ == "__main__":
     main()



import functools
import operator

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


__UpperCamelCase				:  Union[str, Any]      					=							logging.get_logger(__name__)

__UpperCamelCase				:  str      					=							{
    '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  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    A_  :     List[Any]			= 'unispeech-sat'





    def __init__(	self				:   int       ,   __snake_case				:   Optional[int]=32       ,   __snake_case				:   Dict=768       ,   __snake_case				:   Optional[Any]=12       ,   __snake_case				:   Optional[int]=12       ,   __snake_case				:   Dict=3_072       ,   __snake_case				:   List[str]="gelu"       ,   __snake_case				:   Any=0.1       ,   __snake_case				:   Tuple=0.1       ,   __snake_case				:   Optional[int]=0.1       ,   __snake_case				:   Tuple=0.0       ,   __snake_case				:   List[Any]=0.0       ,   __snake_case				:   Tuple=0.1       ,   __snake_case				:   Union[str, Any]=0.1       ,   __snake_case				:   Dict=0.02       ,   __snake_case				:   Optional[Any]=1E-5       ,   __snake_case				:   Optional[int]="group"       ,   __snake_case				:   str="gelu"       ,   __snake_case				:   Union[str, Any]=(512, 512, 512, 512, 512, 512, 512)       ,   __snake_case				:   str=(5, 2, 2, 2, 2, 2, 2)       ,   __snake_case				:   Tuple=(10, 3, 3, 3, 3, 2, 2)       ,   __snake_case				:   int=False       ,   __snake_case				:   Optional[int]=128       ,   __snake_case				:   Any=16       ,   __snake_case				:   Union[str, Any]=False       ,   __snake_case				:   Union[str, Any]=True       ,   __snake_case				:   List[Any]=0.05       ,   __snake_case				:   Dict=10       ,   __snake_case				:   int=2       ,   __snake_case				:   Optional[Any]=0.0       ,   __snake_case				:   Optional[int]=10       ,   __snake_case				:   List[Any]=0       ,   __snake_case				:   Optional[int]=320       ,   __snake_case				:   int=2       ,   __snake_case				:   Any=0.1       ,   __snake_case				:   Optional[int]=100       ,   __snake_case				:   Tuple=256       ,   __snake_case				:   List[str]=256       ,   __snake_case				:   List[Any]=0.1       ,   __snake_case				:   Tuple="mean"       ,   __snake_case				:   List[Any]=False       ,   __snake_case				:   List[str]=False       ,   __snake_case				:   Optional[Any]=256       ,   __snake_case				:   Tuple=(512, 512, 512, 512, 1_500)       ,   __snake_case				:   Optional[int]=(5, 3, 3, 1, 1)       ,   __snake_case				:   Any=(1, 2, 3, 1, 1)       ,   __snake_case				:   int=512       ,   __snake_case				:   Optional[int]=0       ,   __snake_case				:   Dict=1       ,   __snake_case				:   Tuple=2       ,   __snake_case				:   Union[str, Any]=504       ,   **__snake_case				:   List[str]       ,   ):





       '''simple docstring'''
       super().__init__(**__snake_case       ,   pad_token_id=__snake_case       ,   bos_token_id=__snake_case       ,   eos_token_id=__snake_case	)
       UpperCAmelCase_							:      Union[str, Any]						=   hidden_size
       UpperCAmelCase_							:      int						=   feat_extract_norm
       UpperCAmelCase_							:      Dict						=   feat_extract_activation
       UpperCAmelCase_							:      Union[str, Any]						=   list(__snake_case	)
       UpperCAmelCase_							:      List[str]						=   list(__snake_case	)
       UpperCAmelCase_							:      Any						=   list(__snake_case	)
       UpperCAmelCase_							:      Any						=   conv_bias
       UpperCAmelCase_							:      List[str]						=   num_conv_pos_embeddings
       UpperCAmelCase_							:      Dict						=   num_conv_pos_embedding_groups
       UpperCAmelCase_							:      Optional[int]						=   len(self.conv_dim	)
       UpperCAmelCase_							:      List[str]						=   num_hidden_layers
       UpperCAmelCase_							:      Dict						=   intermediate_size
       UpperCAmelCase_							:      Union[str, Any]						=   hidden_act
       UpperCAmelCase_							:      str						=   num_attention_heads
       UpperCAmelCase_							:      Union[str, Any]						=   hidden_dropout
       UpperCAmelCase_							:      List[str]						=   attention_dropout
       UpperCAmelCase_							:      Optional[Any]						=   activation_dropout
       UpperCAmelCase_							:      Dict						=   feat_proj_dropout
       UpperCAmelCase_							:      Optional[Any]						=   final_dropout
       UpperCAmelCase_							:      List[Any]						=   layerdrop
       UpperCAmelCase_							:      int						=   layer_norm_eps
       UpperCAmelCase_							:      int						=   initializer_range
       UpperCAmelCase_							:      List[Any]						=   vocab_size
       UpperCAmelCase_							:      int						=   num_clusters
       UpperCAmelCase_							:      int						=   do_stable_layer_norm
       UpperCAmelCase_							:      Any						=   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
       UpperCAmelCase_							:      int						=   apply_spec_augment
       UpperCAmelCase_							:      Optional[Any]						=   mask_time_prob
       UpperCAmelCase_							:      str						=   mask_time_length
       UpperCAmelCase_							:      Any						=   mask_time_min_masks
       UpperCAmelCase_							:      str						=   mask_feature_prob
       UpperCAmelCase_							:      str						=   mask_feature_length
       UpperCAmelCase_							:      Tuple						=   mask_feature_min_masks

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

       # ctc loss
       UpperCAmelCase_							:      Any						=   ctc_loss_reduction
       UpperCAmelCase_							:      Optional[Any]						=   ctc_zero_infinity

       # SequenceClassification-specific parameter. Feel free to ignore for other classes.
       UpperCAmelCase_							:      Optional[int]						=   classifier_proj_size

       # XVector-specific parameters. Feel free to ignore for other classes.
       UpperCAmelCase_							:      Dict						=   list(__snake_case	)
       UpperCAmelCase_							:      Dict						=   list(__snake_case	)
       UpperCAmelCase_							:      Dict						=   list(__snake_case	)
       UpperCAmelCase_							:      Union[str, Any]						=   xvector_output_dim





    @property
    def 					_lowerCamelCase (	self				:   List[str]	):





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