






'''simple docstring'''







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


UpperCamelCase_					=				logging.get_logger(__name__)

UpperCamelCase_					=				{
    # pcqm4mv1 now deprecated
    "graphormer-base": "https://huggingface.co/clefourrier/graphormer-base-pcqm4mv2/resolve/main/config.json",
    # See all Graphormer models at https://huggingface.co/models?filter=graphormer
}




class 					__UpperCAmelCase (		UpperCamelCase__	):

      '''simple docstring'''





      SCREAMING_SNAKE_CASE				:    str				       =					"graphormer"
      SCREAMING_SNAKE_CASE				:    str				       =					["past_key_values"]




      def __init__(					self  ,		_UpperCAmelCase = 1  ,		_UpperCAmelCase = 512 * 9  ,		_UpperCAmelCase = 512 * 3  ,		_UpperCAmelCase = 512  ,		_UpperCAmelCase = 512  ,		_UpperCAmelCase = 512  ,		_UpperCAmelCase = 128  ,		_UpperCAmelCase = 5  ,		_UpperCAmelCase = 1024  ,		_UpperCAmelCase = "multi_hop"  ,		_UpperCAmelCase = 512  ,		_UpperCAmelCase = False  ,		_UpperCAmelCase = 12  ,		_UpperCAmelCase = 768  ,		_UpperCAmelCase = 768  ,		_UpperCAmelCase = 32  ,		_UpperCAmelCase = 0.1  ,		_UpperCAmelCase = 0.1  ,		_UpperCAmelCase = 0.0  ,		_UpperCAmelCase = False  ,		_UpperCAmelCase = False  ,		_UpperCAmelCase = False  ,		_UpperCAmelCase = "gelu"  ,		_UpperCAmelCase = None  ,		_UpperCAmelCase = False  ,		_UpperCAmelCase = 0  ,		_UpperCAmelCase = False  ,		_UpperCAmelCase = 0.0  ,		_UpperCAmelCase = 8  ,		_UpperCAmelCase = None  ,		_UpperCAmelCase = None  ,		_UpperCAmelCase = True  ,		_UpperCAmelCase = True  ,		_UpperCAmelCase=0  ,		_UpperCAmelCase=1  ,		_UpperCAmelCase=2  ,		**_UpperCAmelCase  ,		):
             UpperCAmelCase__	:   List[Any]												=	num_classes
             UpperCAmelCase__	:   Dict												=	num_atoms
             UpperCAmelCase__	:   Optional[int]												=	num_in_degree
             UpperCAmelCase__	:   str												=	num_out_degree
             UpperCAmelCase__	:   List[str]												=	num_edges
             UpperCAmelCase__	:   Dict												=	num_spatial
             UpperCAmelCase__	:   Optional[int]												=	num_edge_dis
             UpperCAmelCase__	:   Optional[int]												=	edge_type
             UpperCAmelCase__	:   List[str]												=	multi_hop_max_dist
             UpperCAmelCase__	:   int												=	spatial_pos_max
             UpperCAmelCase__	:   Any												=	max_nodes
             UpperCAmelCase__	:   Union[str, Any]												=	num_hidden_layers
             UpperCAmelCase__	:   Optional[int]												=	embedding_dim
             UpperCAmelCase__	:   Optional[int]												=	embedding_dim
             UpperCAmelCase__	:   Any												=	ffn_embedding_dim
             UpperCAmelCase__	:   Optional[int]												=	num_attention_heads
             UpperCAmelCase__	:   Union[str, Any]												=	dropout
             UpperCAmelCase__	:   Dict												=	attention_dropout
             UpperCAmelCase__	:   Dict												=	layerdrop
             UpperCAmelCase__	:   Union[str, Any]												=	encoder_normalize_before
             UpperCAmelCase__	:   Tuple												=	pre_layernorm
             UpperCAmelCase__	:   Tuple												=	apply_graphormer_init
             UpperCAmelCase__	:   Dict												=	activation_fn
             UpperCAmelCase__	:   str												=	embed_scale
             UpperCAmelCase__	:   Dict												=	freeze_embeddings
             UpperCAmelCase__	:   Optional[int]												=	num_trans_layers_to_freeze
             UpperCAmelCase__	:   Optional[int]												=	share_input_output_embed
             UpperCAmelCase__	:   Any												=	traceable
             UpperCAmelCase__	:   List[Any]												=	q_noise
             UpperCAmelCase__	:   List[Any]												=	qn_block_size

             # These parameters are here for future extensions
             # atm, the model only supports self attention
             UpperCAmelCase__	:   Optional[int]												=	kdim
             UpperCAmelCase__	:   int												=	vdim
             UpperCAmelCase__	:   Union[str, Any]												=	self_attention
             UpperCAmelCase__	:   Union[str, Any]												=	bias

             super().__init__(
                 pad_token_id=_UpperCAmelCase  ,		bos_token_id=_UpperCAmelCase  ,		eos_token_id=_UpperCAmelCase  ,		**_UpperCAmelCase  ,		)







'''simple docstring'''







# 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 json
import os
from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import yaml

from ...utils import ComputeEnvironment, DistributedType, SageMakerDistributedType
from ...utils.constants import SAGEMAKER_PYTHON_VERSION, SAGEMAKER_PYTORCH_VERSION, SAGEMAKER_TRANSFORMERS_VERSION


UpperCamelCase_					=				os.path.expanduser(
    os.getenv("HF_HOME", os.path.join(os.getenv("XDG_CACHE_HOME", "~/.cache"), "huggingface"))
)
UpperCamelCase_					=				os.path.join(hf_cache_home, "accelerate")
UpperCamelCase_					=				os.path.join(cache_dir, "default_config.yaml")
UpperCamelCase_					=				os.path.join(cache_dir, "default_config.yaml")

# For backward compatibility: the default config is the json one if it's the only existing file.
if os.path.isfile(default_yaml_config_file) or not os.path.isfile(default_json_config_file):
  UpperCamelCase_					=				default_yaml_config_file
else:
  UpperCamelCase_					=				default_json_config_file






def  lowerCAmelCase__		(					a_  :     List[Any]			)   -> Optional[Any]:
       if config_file is not None:
              if not os.path.isfile(a_			):
                     raise FileNotFoundError(
                         f"""The passed configuration file `{config_file}` does not exist. """
                         '''Please pass an existing file to `accelerate launch`, or use the the default one '''
                         '''created through `accelerate config` and run `accelerate launch` '''
                         '''without the `--config_file` argument.'''			)
       else:
              UpperCAmelCase__	:   Dict												=	default_config_file
       with open(a_			,						'''r'''			,						encoding='''utf-8'''			) as f:
              if config_file.endswith('''.json'''			):
                     if (
                         json.load(a_			).get('''compute_environment'''			,						ComputeEnvironment.LOCAL_MACHINE			)
                         == ComputeEnvironment.LOCAL_MACHINE
                     ):
                            UpperCAmelCase__	:   Optional[Any]												=	ClusterConfig
                     else:
                            UpperCAmelCase__	:   Dict												=	SageMakerConfig
                     return config_class.from_json_file(json_file=a_			)
              else:
                     if (
                         yaml.safe_load(a_			).get('''compute_environment'''			,						ComputeEnvironment.LOCAL_MACHINE			)
                         == ComputeEnvironment.LOCAL_MACHINE
                     ):
                            UpperCAmelCase__	:   Dict												=	ClusterConfig
                     else:
                            UpperCAmelCase__	:   int												=	SageMakerConfig
                     return config_class.from_yaml_file(yaml_file=a_			)




@dataclass
class 					__UpperCAmelCase :

      '''simple docstring'''





      SCREAMING_SNAKE_CASE				:    ComputeEnvironment
      SCREAMING_SNAKE_CASE				:    Union[DistributedType, SageMakerDistributedType]
      SCREAMING_SNAKE_CASE				:    str
      SCREAMING_SNAKE_CASE				:    bool




      def 							lowerCamelCase     (					self						):
             UpperCAmelCase__	:   List[Any]												=	self.__dict__
             # For serialization, it's best to convert Enums to strings (or their underlying value type).
             for key, value in result.items():
                    if isinstance(_UpperCAmelCase  ,		_UpperCAmelCase						):
                           UpperCAmelCase__	:   Union[str, Any]												=	value.value
                    if isinstance(_UpperCAmelCase  ,		_UpperCAmelCase						) and not bool(_UpperCAmelCase						):
                           UpperCAmelCase__	:   Optional[int]												=	None
             UpperCAmelCase__	:   Optional[Any]												=	{k: v for k, v in result.items() if v is not None}
             return result




      @classmethod
      def 							lowerCamelCase     (					cls  ,		_UpperCAmelCase=None						):
             UpperCAmelCase__	:   str												=	default_json_config_file if json_file is None else json_file
             with open(_UpperCAmelCase  ,		'''r'''  ,		encoding='''utf-8'''						) as f:
                    UpperCAmelCase__	:   Optional[int]												=	json.load(_UpperCAmelCase						)
             if "compute_environment" not in config_dict:
                    UpperCAmelCase__	:   List[str]												=	ComputeEnvironment.LOCAL_MACHINE
             if "mixed_precision" not in config_dict:
                    UpperCAmelCase__	:   Dict												=	'''fp16''' if ('''fp16''' in config_dict and config_dict['''fp16''']) else None
             if "fp16" in config_dict:  # Convert the config to the new format.
                    del config_dict["fp16"]
             if "dynamo_backend" in config_dict:  # Convert the config to the new format.
                    UpperCAmelCase__	:   int												=	config_dict.pop('''dynamo_backend'''						)
                    UpperCAmelCase__	:   int												=	{} if dynamo_backend == '''NO''' else {'''dynamo_backend''': dynamo_backend}
             if "use_cpu" not in config_dict:
                    UpperCAmelCase__	:   Optional[Any]												=	False
             return cls(**_UpperCAmelCase						)




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase						):
             with open(_UpperCAmelCase  ,		'''w'''  ,		encoding='''utf-8'''						) as f:
                    UpperCAmelCase__	:   Any												=	json.dumps(self.to_dict()  ,		indent=2  ,		sort_keys=_UpperCAmelCase						) + '''\n'''
                    f.write(_UpperCAmelCase						)




      @classmethod
      def 							lowerCamelCase     (					cls  ,		_UpperCAmelCase=None						):
             UpperCAmelCase__	:   List[Any]												=	default_yaml_config_file if yaml_file is None else yaml_file
             with open(_UpperCAmelCase  ,		'''r'''  ,		encoding='''utf-8'''						) as f:
                    UpperCAmelCase__	:   str												=	yaml.safe_load(_UpperCAmelCase						)
             if "compute_environment" not in config_dict:
                    UpperCAmelCase__	:   List[Any]												=	ComputeEnvironment.LOCAL_MACHINE

             if "mixed_precision" not in config_dict:
                    UpperCAmelCase__	:   Tuple												=	'''fp16''' if ('''fp16''' in config_dict and config_dict['''fp16''']) else None
             if isinstance(config_dict['''mixed_precision''']  ,		_UpperCAmelCase						) and not config_dict["mixed_precision"]:
                    UpperCAmelCase__	:   Any												=	'''no'''
             if "fp16" in config_dict:  # Convert the config to the new format.
                    del config_dict["fp16"]
             if "dynamo_backend" in config_dict:  # Convert the config to the new format.
                    UpperCAmelCase__	:   Optional[int]												=	config_dict.pop('''dynamo_backend'''						)
                    UpperCAmelCase__	:   Dict												=	{} if dynamo_backend == '''NO''' else {'''dynamo_backend''': dynamo_backend}
             if "use_cpu" not in config_dict:
                    UpperCAmelCase__	:   List[str]												=	False
             return cls(**_UpperCAmelCase						)




      def 							lowerCamelCase     (					self  ,		_UpperCAmelCase						):
             with open(_UpperCAmelCase  ,		'''w'''  ,		encoding='''utf-8'''						) as f:
                    yaml.safe_dump(self.to_dict()  ,		_UpperCAmelCase						)




      def 							lowerCamelCase     (					self						):
             if isinstance(self.compute_environment  ,		_UpperCAmelCase						):
                    UpperCAmelCase__	:   Tuple												=	ComputeEnvironment(self.compute_environment						)
             if isinstance(self.distributed_type  ,		_UpperCAmelCase						):
                    if self.compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
                           UpperCAmelCase__	:   Optional[Any]												=	SageMakerDistributedType(self.distributed_type						)
                    else:
                           UpperCAmelCase__	:   Dict												=	DistributedType(self.distributed_type						)
             if self.dynamo_config is None:
                    UpperCAmelCase__	:   Optional[Any]												=	{}




@dataclass
class 					__UpperCAmelCase (		UpperCamelCase__	):

      '''simple docstring'''





      SCREAMING_SNAKE_CASE				:    int
      SCREAMING_SNAKE_CASE				:    int				       =					0
      SCREAMING_SNAKE_CASE				:    int				       =					1
      SCREAMING_SNAKE_CASE				:    Optional[str]				       =					None
      SCREAMING_SNAKE_CASE				:    Optional[str]				       =					None
      SCREAMING_SNAKE_CASE				:    Optional[int]				       =					None
      SCREAMING_SNAKE_CASE				:    Optional[str]				       =					"static"
      SCREAMING_SNAKE_CASE				:    Optional[bool]				       =					False
      SCREAMING_SNAKE_CASE				:    str				       =					"main"

      # args for deepspeed_plugin
      SCREAMING_SNAKE_CASE				:    dict				       =					None
      # args for fsdp
      SCREAMING_SNAKE_CASE				:    dict				       =					None
      # args for megatron_lm
      SCREAMING_SNAKE_CASE				:    dict				       =					None
      # args for ipex
      SCREAMING_SNAKE_CASE				:    dict				       =					None
      # args for TPU
      SCREAMING_SNAKE_CASE				:    bool				       =					False

      # args for TPU pods
      SCREAMING_SNAKE_CASE				:    str				       =					None
      SCREAMING_SNAKE_CASE				:    str				       =					None
      SCREAMING_SNAKE_CASE				:    bool				       =					False
      SCREAMING_SNAKE_CASE				:    bool				       =					False
      SCREAMING_SNAKE_CASE				:    str				       =					None
      SCREAMING_SNAKE_CASE				:    List[str]				       =					None
      SCREAMING_SNAKE_CASE				:    List[str]				       =					None
      SCREAMING_SNAKE_CASE				:    List[str]				       =					None

      # args for dynamo
      SCREAMING_SNAKE_CASE				:    dict				       =					None




      def 							lowerCamelCase     (					self						):
             if self.deepspeed_config is None:
                    UpperCAmelCase__	:   Union[str, Any]												=	{}
             if self.fsdp_config is None:
                    UpperCAmelCase__	:   Any												=	{}
             if self.megatron_lm_config is None:
                    UpperCAmelCase__	:   Tuple												=	{}
             if self.ipex_config is None:
                    UpperCAmelCase__	:   List[str]												=	{}
             return super().__post_init__()




@dataclass
class 					__UpperCAmelCase (		UpperCamelCase__	):

      '''simple docstring'''





      SCREAMING_SNAKE_CASE				:    str
      SCREAMING_SNAKE_CASE				:    str
      SCREAMING_SNAKE_CASE				:    Optional[str]				       =					None
      SCREAMING_SNAKE_CASE				:    Optional[str]				       =					None
      SCREAMING_SNAKE_CASE				:    str				       =					"us-east-1"
      SCREAMING_SNAKE_CASE				:    int				       =					1
      SCREAMING_SNAKE_CASE				:    str				       =					"all"
      SCREAMING_SNAKE_CASE				:    str				       =					F"accelerate-sagemaker-{num_machines}"
      SCREAMING_SNAKE_CASE				:    str				       =					SAGEMAKER_PYTORCH_VERSION
      SCREAMING_SNAKE_CASE				:    str				       =					SAGEMAKER_TRANSFORMERS_VERSION
      SCREAMING_SNAKE_CASE				:    str				       =					SAGEMAKER_PYTHON_VERSION
      SCREAMING_SNAKE_CASE				:    str				       =					None
      SCREAMING_SNAKE_CASE				:    str				       =					None
      SCREAMING_SNAKE_CASE				:    dict				       =					None
      SCREAMING_SNAKE_CASE				:    dict				       =					None