






"""simple docstring"""
import functools
import operator

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


snake_case : Dict     		=		logging.get_logger(__name__)

snake_case : str     		=		{
    """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        UpperCamelCase__ (				a_):







    """simple docstring"""
    __UpperCAmelCase           = """unispeech"""







    def __init__(		self :	Union[str, Any]				,    UpperCamelCase_ :	Optional[Any]=3_2				,    UpperCamelCase_ :	List[str]=7_6_8				,    UpperCamelCase_ :	Optional[int]=1_2				,    UpperCamelCase_ :	Optional[Any]=1_2				,    UpperCamelCase_ :	List[Any]=3_0_7_2				,    UpperCamelCase_ :	Union[str, Any]="gelu"				,    UpperCamelCase_ :	List[Any]=0.1				,    UpperCamelCase_ :	Union[str, Any]=0.1				,    UpperCamelCase_ :	List[str]=0.1				,    UpperCamelCase_ :	List[Any]=0.0				,    UpperCamelCase_ :	Dict=0.0				,    UpperCamelCase_ :	Optional[Any]=0.1				,    UpperCamelCase_ :	int=0.1				,    UpperCamelCase_ :	str=0.02				,    UpperCamelCase_ :	Tuple=1e-5				,    UpperCamelCase_ :	Any="group"				,    UpperCamelCase_ :	Union[str, Any]="gelu"				,    UpperCamelCase_ :	int=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)				,    UpperCamelCase_ :	Dict=(5, 2, 2, 2, 2, 2, 2)				,    UpperCamelCase_ :	Dict=(1_0, 3, 3, 3, 3, 2, 2)				,    UpperCamelCase_ :	Union[str, Any]=False				,    UpperCamelCase_ :	Optional[Any]=1_2_8				,    UpperCamelCase_ :	List[Any]=1_6				,    UpperCamelCase_ :	str=False				,    UpperCamelCase_ :	Optional[int]=True				,    UpperCamelCase_ :	str=0.05				,    UpperCamelCase_ :	str=1_0				,    UpperCamelCase_ :	Optional[Any]=2				,    UpperCamelCase_ :	Tuple=0.0				,    UpperCamelCase_ :	Optional[Any]=1_0				,    UpperCamelCase_ :	List[Any]=0				,    UpperCamelCase_ :	Optional[int]=3_2_0				,    UpperCamelCase_ :	List[Any]=2				,    UpperCamelCase_ :	Optional[int]=0.1				,    UpperCamelCase_ :	Tuple=1_0_0				,    UpperCamelCase_ :	Union[str, Any]=2_5_6				,    UpperCamelCase_ :	Any=2_5_6				,    UpperCamelCase_ :	Optional[Any]=0.1				,    UpperCamelCase_ :	Optional[Any]="mean"				,    UpperCamelCase_ :	int=False				,    UpperCamelCase_ :	int=False				,    UpperCamelCase_ :	Dict=2_5_6				,    UpperCamelCase_ :	Dict=8_0				,    UpperCamelCase_ :	List[str]=0				,    UpperCamelCase_ :	List[str]=1				,    UpperCamelCase_ :	List[str]=2				,    UpperCamelCase_ :	Optional[int]=0.5				,    **UpperCamelCase_ :	Optional[Any]				,    ):





           '''simple docstring'''

           super().__init__(**UpperCamelCase_				,    pad_token_id=UpperCamelCase_				,    bos_token_id=UpperCamelCase_				,    eos_token_id=UpperCamelCase_ )
           __magic_name__      				=    hidden_size
           __magic_name__      				=    feat_extract_norm
           __magic_name__      				=    feat_extract_activation
           __magic_name__      				=    list(UpperCamelCase_ )
           __magic_name__      				=    list(UpperCamelCase_ )
           __magic_name__      				=    list(UpperCamelCase_ )
           __magic_name__      				=    conv_bias
           __magic_name__      				=    num_conv_pos_embeddings
           __magic_name__      				=    num_conv_pos_embedding_groups
           __magic_name__      				=    len(self.conv_dim )
           __magic_name__      				=    num_hidden_layers
           __magic_name__      				=    intermediate_size
           __magic_name__      				=    hidden_act
           __magic_name__      				=    num_attention_heads
           __magic_name__      				=    hidden_dropout
           __magic_name__      				=    attention_dropout
           __magic_name__      				=    activation_dropout
           __magic_name__      				=    feat_proj_dropout
           __magic_name__      				=    final_dropout
           __magic_name__      				=    layerdrop
           __magic_name__      				=    layer_norm_eps
           __magic_name__      				=    initializer_range
           __magic_name__      				=    num_ctc_classes
           __magic_name__      				=    vocab_size
           __magic_name__      				=    do_stable_layer_norm
           __magic_name__      				=    use_weighted_layer_sum
           __magic_name__      				=    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
           __magic_name__      				=    apply_spec_augment
           __magic_name__      				=    mask_time_prob
           __magic_name__      				=    mask_time_length
           __magic_name__      				=    mask_time_min_masks
           __magic_name__      				=    mask_feature_prob
           __magic_name__      				=    mask_feature_length
           __magic_name__      				=    mask_feature_min_masks

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

           # ctc loss
           __magic_name__      				=    ctc_loss_reduction
           __magic_name__      				=    ctc_zero_infinity

           # pretraining loss
           __magic_name__      				=    replace_prob







    @property
    def 				a__			(		self :	Any ):





           '''simple docstring'''

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







"""simple docstring"""
import argparse
import json
import os

from tensorflow.core.protobuf.saved_model_pba import SavedModel


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_copies.py
snake_case : Optional[Any]     		=		"""."""

# Internal TensorFlow ops that can be safely ignored (mostly specific to a saved model)
snake_case : List[str]     		=		[
    """Assert""",
    """AssignVariableOp""",
    """EmptyTensorList""",
    """MergeV2Checkpoints""",
    """ReadVariableOp""",
    """ResourceGather""",
    """RestoreV2""",
    """SaveV2""",
    """ShardedFilename""",
    """StatefulPartitionedCall""",
    """StaticRegexFullMatch""",
    """VarHandleOp""",
]


def 							A						(				__snake_case: Optional[Any] ,     __snake_case: Tuple ,     __snake_case: Any  )    ->		int:

       """simple docstring"""





       __magic_name__      				=    SavedModel()
       __magic_name__      				=    []

       with open(os.path.join(__snake_case ,     'utils' ,     'tf_ops' ,     'onnx.json'  )  ) as f:
              __magic_name__      				=    json.load(__snake_case  )['opsets']

       for i in range(1 ,     opset + 1  ):
              onnx_ops.extend(onnx_opsets[str(__snake_case  )]  )

       with open(__snake_case ,     'rb'  ) as f:
              saved_model.ParseFromString(f.read()  )

       __magic_name__      				=    set()

       # Iterate over every metagraph in case there is more than one (a saved model can contain multiple graphs)
       for meta_graph in saved_model.meta_graphs:
              # Add operations in the graph definition
              model_op_names.update(node.op for node in meta_graph.graph_def.node  )

              # Go through the functions in the graph definition
              for func in meta_graph.graph_def.library.function:
                     # Add operations in each function
                     model_op_names.update(node.op for node in func.node_def  )

    # Convert to list, sorted if you want
       __magic_name__      				=    sorted(__snake_case  )
       __magic_name__      				=    []

       for op in model_op_names:
              if op not in onnx_ops and op not in INTERNAL_OPS:
                     incompatible_ops.append(__snake_case  )

       if strict and len(__snake_case  ) > 0:
              raise Exception(F"""Found the following incompatible ops for the opset {opset}:\n""" + incompatible_ops  )
       elif len(__snake_case  ) > 0:
              print(F"""Found the following incompatible ops for the opset {opset}:"""  )
              print(*__snake_case ,     sep='\n'  )
       else:
              print(F"""The saved model {saved_model_path} can properly be converted with ONNX."""  )


if __name__ == "__main__":
 snake_case : Optional[Any]     		=		argparse.ArgumentParser()
 parser.add_argument("""--saved_model_path""", help="""Path of the saved model to check (the .pb file).""")
 parser.add_argument(
     """--opset""", default=1_2, type=int, help="""The ONNX opset against which the model has to be tested."""
 )
 parser.add_argument(
     """--framework""", choices=["""onnx"""], default="""onnx""", help="""Frameworks against which to test the saved model."""
 )
 parser.add_argument(
     """--strict""", action="""store_true""", help="""Whether make the checking strict (raise errors) or not (raise warnings)"""
 )
 snake_case : Any     		=		parser.parse_args()

 if args.framework == "onnx":
  onnx_compliancy(args.saved_model_path, args.strict, args.opset)