


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

from pathlib import Path

import torch

from ...utils import is_npu_available, is_xpu_available
from .config_args import ClusterConfig, default_json_config_file
from .config_utils import SubcommandHelpFormatter


__A   :    int											= "Create a default config file for Accelerate with only a few flags set."







def 							UpperCamelCase_     (       A__   :  Any="no"				,       A__   :  str = default_json_config_file				,       A__   :  bool = False   ):
  '''simple docstring'''





  lowerCAmelCase_     : Union[str, Any]     =  Path(A__   )
  path.parent.mkdir(parents=A__				,       exist_ok=A__   )
  if path.exists():
    print(
        f'Configuration already exists at {save_location}, will not override. Run `accelerate config` manually or pass a different `save_location`.'   )
    return False
  lowerCAmelCase_     : List[str]     =  mixed_precision.lower()
  if mixed_precision not in ["no", "fp16", "bf16", "fp8"]:
    raise ValueError(
        f'`mixed_precision` should be one of \'no\', \'fp16\', \'bf16\', or \'fp8\'. Received {mixed_precision}'   )
  lowerCAmelCase_     : Any     =  {
      """compute_environment""": """LOCAL_MACHINE""",
      """mixed_precision""": mixed_precision,
  }
  if torch.cuda.is_available():
    lowerCAmelCase_     : List[str]     =  torch.cuda.device_count()
    lowerCAmelCase_     : Optional[int]     =  num_gpus
    lowerCAmelCase_     : Union[str, Any]     =  False
    if num_gpus > 1:
      lowerCAmelCase_     : Any     =  """MULTI_GPU"""
    else:
      lowerCAmelCase_     : Dict     =  """NO"""
  elif is_xpu_available() and use_xpu:
    lowerCAmelCase_     : Any     =  torch.xpu.device_count()
    lowerCAmelCase_     : Optional[int]     =  num_xpus
    lowerCAmelCase_     : List[str]     =  False
    if num_xpus > 1:
      lowerCAmelCase_     : Any     =  """MULTI_XPU"""
    else:
      lowerCAmelCase_     : str     =  """NO"""
  elif is_npu_available():
    lowerCAmelCase_     : Tuple     =  torch.npu.device_count()
    lowerCAmelCase_     : List[Any]     =  num_npus
    lowerCAmelCase_     : str     =  False
    if num_npus > 1:
      lowerCAmelCase_     : Dict     =  """MULTI_NPU"""
    else:
      lowerCAmelCase_     : Optional[int]     =  """NO"""
  else:
    lowerCAmelCase_     : Dict     =  0
    lowerCAmelCase_     : List[Any]     =  True
    lowerCAmelCase_     : str     =  1
    lowerCAmelCase_     : Optional[Any]     =  """NO"""
  lowerCAmelCase_     : Optional[int]     =  ClusterConfig(**A__   )
  config.to_json_file(A__   )
  return path







def 							UpperCamelCase_     (       A__   :  Dict				,       A__   :  Union[str, Any]   ):
  '''simple docstring'''





  lowerCAmelCase_     : Optional[int]     =  parser.add_parser("""default"""				,       parents=A__				,       help=A__				,       formatter_class=A__   )
  parser.add_argument(
      """--config_file"""				,       default=A__				,       help=(
          """The path to use to store the config file. Will default to a file named default_config.yaml in the cache """
          """location, which is the content of the environment `HF_HOME` suffixed with 'accelerate', or if you don't have """
          """such an environment variable, your cache directory ('~/.cache' or the content of `XDG_CACHE_HOME`) suffixed """
          """with 'huggingface'."""
      )				,       dest="""save_location"""				,       )

  parser.add_argument(
      """--mixed_precision"""				,       choices=["""no""", """fp16""", """bf16"""]				,       type=A__				,       help="""Whether or not to use mixed precision training. """
      """Choose between FP16 and BF16 (bfloat16) training. """
      """BF16 training is only supported on Nvidia Ampere GPUs and PyTorch 1.10 or later."""				,       default="""no"""				,       )
  parser.set_defaults(func=A__   )
  return parser







def 							UpperCamelCase_     (       A__   :  List[str]   ):
  '''simple docstring'''





  lowerCAmelCase_     : Tuple     =  write_basic_config(args.mixed_precision				,       args.save_location   )
  if config_file:
    print(f'accelerate configuration saved at {config_file}'   )







'''simple docstring'''






from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__A   :    List[Any]											= logging.get_logger(__name__)

__A   :    List[Any]											= {
    "andreasmadsen/efficient_mlm_m0.40": (
        "https://huggingface.co/andreasmadsen/efficient_mlm_m0.40/resolve/main/config.json"
    ),
}






class   __snake_case			(  _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    lowercase  					=   'roberta-prelayernorm'

    def __init__(  self       :    Tuple       ,		lowerCamelCase       :    Tuple=5_02_65       ,		lowerCamelCase       :    Optional[int]=7_68       ,		lowerCamelCase       :    Optional[int]=12       ,		lowerCamelCase       :    Optional[int]=12       ,		lowerCamelCase       :    int=30_72       ,		lowerCamelCase       :    Optional[int]="gelu"       ,		lowerCamelCase       :    List[str]=0.1       ,		lowerCamelCase       :    Tuple=0.1       ,		lowerCamelCase       :    Optional[int]=5_12       ,		lowerCamelCase       :    Union[str, Any]=2       ,		lowerCamelCase       :    int=0.02       ,		lowerCamelCase       :    Any=1E-12       ,		lowerCamelCase       :    int=1       ,		lowerCamelCase       :    List[Any]=0       ,		lowerCamelCase       :    List[Any]=2       ,		lowerCamelCase       :    Optional[Any]="absolute"       ,		lowerCamelCase       :    List[Any]=True       ,		lowerCamelCase       :    Tuple=None       ,		**lowerCamelCase       :    int       ,		)  ->    Optional[Any]:
      super().__init__(pad_token_id=lowerCamelCase       ,		bos_token_id=lowerCamelCase       ,		eos_token_id=lowerCamelCase       ,		**lowerCamelCase						)

      lowerCAmelCase_     : Dict     =  vocab_size
      lowerCAmelCase_     : str     =  hidden_size
      lowerCAmelCase_     : Dict     =  num_hidden_layers
      lowerCAmelCase_     : List[Any]     =  num_attention_heads
      lowerCAmelCase_     : List[str]     =  hidden_act
      lowerCAmelCase_     : Optional[Any]     =  intermediate_size
      lowerCAmelCase_     : List[str]     =  hidden_dropout_prob
      lowerCAmelCase_     : Tuple     =  attention_probs_dropout_prob
      lowerCAmelCase_     : Optional[int]     =  max_position_embeddings
      lowerCAmelCase_     : List[Any]     =  type_vocab_size
      lowerCAmelCase_     : List[Any]     =  initializer_range
      lowerCAmelCase_     : Union[str, Any]     =  layer_norm_eps
      lowerCAmelCase_     : List[str]     =  position_embedding_type
      lowerCAmelCase_     : Tuple     =  use_cache
      lowerCAmelCase_     : Union[str, Any]     =  classifier_dropout







class   __snake_case			(  _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    @property
    def __lowercase  (  self       :    List[Any]						)  ->    Mapping[str, Mapping[int, str]]:
      if self.task == "multiple-choice":
        lowerCAmelCase_     : Dict     =  {0: """batch""", 1: """choice""", 2: """sequence"""}
      else:
        lowerCAmelCase_     : Optional[int]     =  {0: """batch""", 1: """sequence"""}
      return OrderedDict(
          [
              ("""input_ids""", dynamic_axis),
              ("""attention_mask""", dynamic_axis),
          ]						)



