





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_		(	_lowerCamelCase       ):
					lowerCAmelCase_				=						'''graphormer'''
					lowerCAmelCase_				=						['''past_key_values''']




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

										# These parameters are here for future extensions
										# atm, the model only supports self attention
										_snake_case						=					kdim
										_snake_case						=					vdim
										_snake_case						=					self_attention
										_snake_case						=					bias

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










# 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__  (  UpperCamelCase__      :							List[str]    )      ->			str:



					'''simple docstring'''




					if config_file is not None:
										if not os.path.isfile(UpperCamelCase__    ):
															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:
										_snake_case						=					default_config_file
					with open(UpperCamelCase__							,     'r'							,     encoding='utf-8'    ) as f:
										if config_file.endswith('.json'    ):
															if (
															    json.load(UpperCamelCase__    ).get('compute_environment'							,     ComputeEnvironment.LOCAL_MACHINE    )
															    == ComputeEnvironment.LOCAL_MACHINE
															):
																				_snake_case						=					ClusterConfig
															else:
																				_snake_case						=					SageMakerConfig
															return config_class.from_json_file(json_file=UpperCamelCase__    )
										else:
															if (
															    yaml.safe_load(UpperCamelCase__    ).get('compute_environment'							,     ComputeEnvironment.LOCAL_MACHINE    )
															    == ComputeEnvironment.LOCAL_MACHINE
															):
																				_snake_case						=					ClusterConfig
															else:
																				_snake_case						=					SageMakerConfig
															return config_class.from_yaml_file(yaml_file=UpperCamelCase__    )
@dataclass
class       UpperCamelCase_		:
					lowerCAmelCase_				=						42
					lowerCAmelCase_				=						42
					lowerCAmelCase_				=						42
					lowerCAmelCase_				=						42




					def 						lowerCAmelCase      (		self	)		->				Optional[Any]:
										_snake_case						=					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(lowerCAmelCase_					,    lowerCAmelCase_	):
																				_snake_case						=					value.value
															if isinstance(lowerCAmelCase_					,    lowerCAmelCase_	) and not bool(lowerCAmelCase_	):
																				_snake_case						=					None
										_snake_case						=					{k: v for k, v in result.items() if v is not None}
										return result




					@classmethod
					def 						lowerCAmelCase      (		cls					,    lowerCAmelCase_=None	)		->				List[Any]:
										_snake_case						=					default_json_config_file if json_file is None else json_file
										with open(lowerCAmelCase_					,    'r'					,    encoding='utf-8'	) as f:
															_snake_case						=					json.load(lowerCAmelCase_	)
										if "compute_environment" not in config_dict:
															_snake_case						=					ComputeEnvironment.LOCAL_MACHINE
										if "mixed_precision" not in config_dict:
															_snake_case						=					'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.
															_snake_case						=					config_dict.pop('dynamo_backend'	)
															_snake_case						=					{} if dynamo_backend == 'NO' else {'dynamo_backend': dynamo_backend}
										if "use_cpu" not in config_dict:
															_snake_case						=					False
										return cls(**lowerCAmelCase_	)




					def 						lowerCAmelCase      (		self					,    lowerCAmelCase_	)		->				List[str]:
										with open(lowerCAmelCase_					,    'w'					,    encoding='utf-8'	) as f:
															_snake_case						=					json.dumps(self.to_dict()					,    indent=2					,    sort_keys=lowerCAmelCase_	) + '\n'
															f.write(lowerCAmelCase_	)




					@classmethod
					def 						lowerCAmelCase      (		cls					,    lowerCAmelCase_=None	)		->				int:
										_snake_case						=					default_yaml_config_file if yaml_file is None else yaml_file
										with open(lowerCAmelCase_					,    'r'					,    encoding='utf-8'	) as f:
															_snake_case						=					yaml.safe_load(lowerCAmelCase_	)
										if "compute_environment" not in config_dict:
															_snake_case						=					ComputeEnvironment.LOCAL_MACHINE

										if "mixed_precision" not in config_dict:
															_snake_case						=					'fp16' if ('fp16' in config_dict and config_dict['fp16']) else None
										if isinstance(config_dict['mixed_precision']					,    lowerCAmelCase_	) and not config_dict["mixed_precision"]:
															_snake_case						=					'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.
															_snake_case						=					config_dict.pop('dynamo_backend'	)
															_snake_case						=					{} if dynamo_backend == 'NO' else {'dynamo_backend': dynamo_backend}
										if "use_cpu" not in config_dict:
															_snake_case						=					False
										return cls(**lowerCAmelCase_	)




					def 						lowerCAmelCase      (		self					,    lowerCAmelCase_	)		->				List[str]:
										with open(lowerCAmelCase_					,    'w'					,    encoding='utf-8'	) as f:
															yaml.safe_dump(self.to_dict()					,    lowerCAmelCase_	)






					def 						lowerCAmelCase      (		self	)		->				Tuple:
										if isinstance(self.compute_environment					,    lowerCAmelCase_	):
															_snake_case						=					ComputeEnvironment(self.compute_environment	)
										if isinstance(self.distributed_type					,    lowerCAmelCase_	):
															if self.compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
																				_snake_case						=					SageMakerDistributedType(self.distributed_type	)
															else:
																				_snake_case						=					DistributedType(self.distributed_type	)
										if self.dynamo_config is None:
															_snake_case						=					{}





@dataclass
class       UpperCamelCase_		(	_lowerCamelCase       ):
					lowerCAmelCase_				=						42
					lowerCAmelCase_				=						0
					lowerCAmelCase_				=						1
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						"static"
					lowerCAmelCase_				=						False
					lowerCAmelCase_				=						"main"

					# args for deepspeed_plugin
					lowerCAmelCase_				=						None
					# args for fsdp
					lowerCAmelCase_				=						None
					# args for megatron_lm
					lowerCAmelCase_				=						None
					# args for ipex
					lowerCAmelCase_				=						None
					# args for TPU
					lowerCAmelCase_				=						False

					# args for TPU pods
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						False
					lowerCAmelCase_				=						False
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None

					# args for dynamo
					lowerCAmelCase_				=						None




					def 						lowerCAmelCase      (		self	)		->				Optional[Any]:
										if self.deepspeed_config is None:
															_snake_case						=					{}
										if self.fsdp_config is None:
															_snake_case						=					{}
										if self.megatron_lm_config is None:
															_snake_case						=					{}
										if self.ipex_config is None:
															_snake_case						=					{}
										return super().__post_init__()





@dataclass
class       UpperCamelCase_		(	_lowerCamelCase       ):
					lowerCAmelCase_				=						42
					lowerCAmelCase_				=						42
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						"us-east-1"
					lowerCAmelCase_				=						1
					lowerCAmelCase_				=						"all"
					lowerCAmelCase_				=						f"accelerate-sagemaker-{num_machines}"
					lowerCAmelCase_				=						SAGEMAKER_PYTORCH_VERSION
					lowerCAmelCase_				=						SAGEMAKER_TRANSFORMERS_VERSION
					lowerCAmelCase_				=						SAGEMAKER_PYTHON_VERSION
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None
					lowerCAmelCase_				=						None



