






'''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
UpperCamelCase__ =			'.'

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




def 		__SCREAMING_SNAKE_CASE					(  _UpperCamelCase						,		_UpperCamelCase						,		_UpperCamelCase							):


   """simple docstring"""




   lowercase_	:    List[str]           =     SavedModel()
   lowercase_	:    Union[str, Any]           =     []

   with open(os.path.join(_UpperCamelCase						,		"utils"						,		"tf_ops"						,		"onnx.json"							)							) as f:
      lowercase_	:    int           =     json.load(_UpperCamelCase							)["opsets"]

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

   with open(_UpperCamelCase						,		"rb"							) as f:
      saved_model.ParseFromString(f.read()							)

   lowercase_	:    Optional[int]           =     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
   lowercase_	:    Optional[int]           =     sorted(_UpperCamelCase							)
   lowercase_	:    str           =     []

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

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


if __name__ == "__main__":
 UpperCamelCase__ =			argparse.ArgumentParser()
 parser.add_argument('--saved_model_path', help='Path of the saved model to check (the .pb file).')
 parser.add_argument(
     '--opset', default=12, 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)'
 )
 UpperCamelCase__ =			parser.parse_args()

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












'''simple docstring'''
from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__ =			logging.get_logger(__name__)

UpperCamelCase__ =			{
    'abeja/gpt-neox-japanese-2.7b': 'https://huggingface.co/abeja/gpt-neox-japanese-2.7b/resolve/main/config.json',
}


class        _UpperCAmelCase						(		snake_case			):
    __lowerCamelCase:   List[Any]		       =    'gpt_neox_japanese'




    def __init__(			self  :       List[str]  ,     a  :       List[Any]=3_2_0_0_0  ,     a  :       Union[str, Any]=2_5_6_0  ,     a  :       Optional[Any]=3_2  ,     a  :       Any=3_2  ,     a  :       str=4  ,     a  :       Optional[int]="gelu"  ,     a  :       Optional[Any]=1.00  ,     a  :       Dict=1_0_0_0_0  ,     a  :       List[Any]=2_0_4_8  ,     a  :       Dict=0.02  ,     a  :       int=1e-5  ,     a  :       Optional[int]=True  ,     a  :       Union[str, Any]=3_1_9_9_6  ,     a  :       List[Any]=3_1_9_9_9  ,     a  :       List[str]=0.1  ,     a  :       Dict=0.0  ,     **a  :       Union[str, Any]  ,     ):






       '''simple docstring'''






       super().__init__(bos_token_id=a  ,     eos_token_id=a  ,     **a			)
       lowercase_	:    int           =     vocab_size
       lowercase_	:    int           =     max_position_embeddings
       lowercase_	:    List[str]           =     hidden_size
       lowercase_	:    Any           =     num_hidden_layers
       lowercase_	:    Any           =     num_attention_heads
       lowercase_	:    List[Any]           =     intermediate_multiple_size
       lowercase_	:    List[str]           =     hidden_act
       lowercase_	:    Optional[int]           =     rotary_pct
       lowercase_	:    Tuple           =     rotary_emb_base
       lowercase_	:    Optional[Any]           =     initializer_range
       lowercase_	:    List[str]           =     layer_norm_eps
       lowercase_	:    List[str]           =     use_cache
       lowercase_	:    Any           =     attention_dropout
       lowercase_	:    List[Any]           =     hidden_dropout




