





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A__:  List[Any]       					={'''configuration_dinat''': ['''DINAT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DinatConfig''']}


try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   A__:  Union[str, Any]       					=[
       '''DINAT_PRETRAINED_MODEL_ARCHIVE_LIST''',
       '''DinatForImageClassification''',
       '''DinatModel''',
       '''DinatPreTrainedModel''',
       '''DinatBackbone''',
   ]

if TYPE_CHECKING:
   from .configuration_dinat import DINAT_PRETRAINED_CONFIG_ARCHIVE_MAP, DinatConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_dinat import (
          DINAT_PRETRAINED_MODEL_ARCHIVE_LIST,
          DinatBackbone,
          DinatForImageClassification,
          DinatModel,
          DinatPreTrainedModel,
      )

else:
   import sys

   A__:  Tuple       					=_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)








# 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


A__:  Union[str, Any]       					=					os.path.expanduser(
    os.getenv('''HF_HOME''', os.path.join(os.getenv('''XDG_CACHE_HOME''', '''~/.cache'''), '''huggingface'''))
)
A__:  int       					=					os.path.join(hf_cache_home, '''accelerate''')
A__:  Dict       					=					os.path.join(cache_dir, '''default_config.yaml''')
A__:  Union[str, Any]       					=					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):
   A__:  Tuple       					=					default_yaml_config_file
else:
   A__:  int       					=					default_json_config_file



def 							lowerCAmelCase_				(    A_):
    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__:					Optional[int]												=      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__:					Union[str, Any]												=      ClusterConfig
            else:
                UpperCamelCase__:					int												=      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__:					Union[str, Any]												=      ClusterConfig
            else:
                UpperCamelCase__:					int												=      SageMakerConfig
            return config_class.from_yaml_file(yaml_file=A_)




@dataclass
class    _a  :

      """simple docstring"""


      UpperCamelCase__       						=   42
      UpperCamelCase__       						=   42
      UpperCamelCase__       						=   42
      UpperCamelCase__       						=   42






      def 	UpperCAmelCase_   (						self:	Union[str, Any]			):
          '''simple docstring'''


          UpperCamelCase__:					Tuple												=      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			):
                  UpperCamelCase__:					str												=      value.value
              if isinstance(__lowerCamelCase					,  __lowerCamelCase			) and not bool(__lowerCamelCase			):
                  UpperCamelCase__:					Tuple												=      None
          UpperCamelCase__:					List[Any]												=      {k: v for k, v in result.items() if v is not None}
          return result






      @classmethod
      def 	UpperCAmelCase_   (						cls:	str					,  __lowerCamelCase:	Any=None			):
          '''simple docstring'''


          UpperCamelCase__:					List[str]												=      default_json_config_file if json_file is None else json_file
          with open(__lowerCamelCase					,  "r"					,  encoding="utf-8"			) as f:
              UpperCamelCase__:					str												=      json.load(__lowerCamelCase			)
          if "compute_environment" not in config_dict:
              UpperCamelCase__:					List[str]												=      ComputeEnvironment.LOCAL_MACHINE
          if "mixed_precision" not in config_dict:
              UpperCamelCase__:					Optional[Any]												=      "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__:					Dict												=      {} if dynamo_backend == "NO" else {"dynamo_backend": dynamo_backend}
          if "use_cpu" not in config_dict:
              UpperCamelCase__:					str												=      False
          return cls(**__lowerCamelCase			)






      def 	UpperCAmelCase_   (						self:	Tuple					,  __lowerCamelCase:	List[Any]			):
          '''simple docstring'''


          with open(__lowerCamelCase					,  "w"					,  encoding="utf-8"			) as f:
              UpperCamelCase__:					Any												=      json.dumps(self.to_dict()					,  indent=2					,  sort_keys=__lowerCamelCase			) + "\n"
              f.write(__lowerCamelCase			)






      @classmethod
      def 	UpperCAmelCase_   (						cls:	Tuple					,  __lowerCamelCase:	Tuple=None			):
          '''simple docstring'''


          UpperCamelCase__:					Optional[Any]												=      default_yaml_config_file if yaml_file is None else yaml_file
          with open(__lowerCamelCase					,  "r"					,  encoding="utf-8"			) as f:
              UpperCamelCase__:					Union[str, Any]												=      yaml.safe_load(__lowerCamelCase			)
          if "compute_environment" not in config_dict:
              UpperCamelCase__:					List[Any]												=      ComputeEnvironment.LOCAL_MACHINE

          if "mixed_precision" not in config_dict:
              UpperCamelCase__:					Optional[int]												=      "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"]:
              UpperCamelCase__:					List[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__:					List[str]												=      config_dict.pop("dynamo_backend"			)
              UpperCamelCase__:					Optional[Any]												=      {} if dynamo_backend == "NO" else {"dynamo_backend": dynamo_backend}
          if "use_cpu" not in config_dict:
              UpperCamelCase__:					int												=      False
          return cls(**__lowerCamelCase			)






      def 	UpperCAmelCase_   (						self:	Optional[int]					,  __lowerCamelCase:	Tuple			):
          '''simple docstring'''


          with open(__lowerCamelCase					,  "w"					,  encoding="utf-8"			) as f:
              yaml.safe_dump(self.to_dict()					,  __lowerCamelCase			)






      def 	UpperCAmelCase_   (						self:	Dict			):
          '''simple docstring'''


          if isinstance(self.compute_environment					,  __lowerCamelCase			):
              UpperCamelCase__:					Optional[int]												=      ComputeEnvironment(self.compute_environment			)
          if isinstance(self.distributed_type					,  __lowerCamelCase			):
              if self.compute_environment == ComputeEnvironment.AMAZON_SAGEMAKER:
                  UpperCamelCase__:					str												=      SageMakerDistributedType(self.distributed_type			)
              else:
                  UpperCamelCase__:					Optional[int]												=      DistributedType(self.distributed_type			)
          if self.dynamo_config is None:
              UpperCamelCase__:					List[Any]												=      {}




@dataclass
class    _a  (  UpperCamelCase__):

      """simple docstring"""


      UpperCamelCase__       						=   42
      UpperCamelCase__       						=   0
      UpperCamelCase__       						=   1
      UpperCamelCase__       						=   None
      UpperCamelCase__       						=   None
      UpperCamelCase__       						=   None
      UpperCamelCase__       						=   "static"
      UpperCamelCase__       						=   False
      UpperCamelCase__       						=   "main"

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

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

      # args for dynamo
      UpperCamelCase__       						=   None






      def 	UpperCAmelCase_   (						self:	Optional[Any]			):
          '''simple docstring'''


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




@dataclass
class    _a  (  UpperCamelCase__):

      """simple docstring"""


      UpperCamelCase__       						=   42
      UpperCamelCase__       						=   42
      UpperCamelCase__       						=   None
      UpperCamelCase__       						=   None
      UpperCamelCase__       						=   "us-east-1"
      UpperCamelCase__       						=   1
      UpperCamelCase__       						=   "all"
      UpperCamelCase__       						=   F'''accelerate-sagemaker-{num_machines}'''
      UpperCamelCase__       						=   SAGEMAKER_PYTORCH_VERSION
      UpperCamelCase__       						=   SAGEMAKER_TRANSFORMERS_VERSION
      UpperCamelCase__       						=   SAGEMAKER_PYTHON_VERSION
      UpperCamelCase__       						=   None
      UpperCamelCase__       						=   None
      UpperCamelCase__       						=   None
      UpperCamelCase__       						=   None

