


"""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  :     Optional[int]    					=    "Create a default config file for Accelerate with only a few flags set."


def _lowerCamelCase			(	_UpperCamelCase="no"					,				_UpperCamelCase = default_json_config_file					,				_UpperCamelCase = False   ):

			'''simple docstring'''




			__lowerCAmelCase       					=    Path(_UpperCamelCase   )
			path.parent.mkdir(parents=_UpperCamelCase					,				exist_ok=_UpperCamelCase   )
			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       					=    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       					=    {
			    "compute_environment": "LOCAL_MACHINE",
			    "mixed_precision": mixed_precision,
			}
			if torch.cuda.is_available():
						__lowerCAmelCase       					=    torch.cuda.device_count()
						__lowerCAmelCase       					=    num_gpus
						__lowerCAmelCase       					=    False
						if num_gpus > 1:
									__lowerCAmelCase       					=    "MULTI_GPU"
						else:
									__lowerCAmelCase       					=    "NO"
			elif is_xpu_available() and use_xpu:
						__lowerCAmelCase       					=    torch.xpu.device_count()
						__lowerCAmelCase       					=    num_xpus
						__lowerCAmelCase       					=    False
						if num_xpus > 1:
									__lowerCAmelCase       					=    "MULTI_XPU"
						else:
									__lowerCAmelCase       					=    "NO"
			elif is_npu_available():
						__lowerCAmelCase       					=    torch.npu.device_count()
						__lowerCAmelCase       					=    num_npus
						__lowerCAmelCase       					=    False
						if num_npus > 1:
									__lowerCAmelCase       					=    "MULTI_NPU"
						else:
									__lowerCAmelCase       					=    "NO"
			else:
						__lowerCAmelCase       					=    0
						__lowerCAmelCase       					=    True
						__lowerCAmelCase       					=    1
						__lowerCAmelCase       					=    "NO"
			__lowerCAmelCase       					=    ClusterConfig(**_UpperCamelCase   )
			config.to_json_file(_UpperCamelCase   )
			return path


def _lowerCamelCase			(	_UpperCamelCase					,				_UpperCamelCase   ):

			'''simple docstring'''




			__lowerCAmelCase       					=    parser.add_parser("default"					,				parents=_UpperCamelCase					,				help=_UpperCamelCase					,				formatter_class=_UpperCamelCase   )
			parser.add_argument(
			    "--config_file"					,				default=_UpperCamelCase					,				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=_UpperCamelCase					,				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=_UpperCamelCase   )
			return parser


def _lowerCamelCase			(	_UpperCamelCase   ):

			'''simple docstring'''




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








"""simple docstring"""


A  :     List[Any]    					=    [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
A  :     Optional[int]    					=    [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
A  :     Optional[int]    					=    {
    0: "Sunday",
    1: "Monday",
    2: "Tuesday",
    3: "Wednesday",
    4: "Thursday",
    5: "Friday",
    6: "Saturday",
}


def _lowerCamelCase			(	_UpperCamelCase					,				_UpperCamelCase					,				_UpperCamelCase   ):

			'''simple docstring'''




			assert len(str(_UpperCamelCase   )   ) > 2, "year should be in YYYY format"
			assert 1 <= month <= 12, "month should be between 1 to 12"
			assert 1 <= day <= 31, "day should be between 1 to 31"

			# Doomsday algorithm:
			__lowerCAmelCase       					=    year // 100
			__lowerCAmelCase       					=    (5 * (century % 4) + 2) % 7
			__lowerCAmelCase       					=    year % 100
			__lowerCAmelCase       					=    centurian % 12
			__lowerCAmelCase       					=    (
			    (centurian // 12) + centurian_m + (centurian_m // 4) + century_anchor
			) % 7
			__lowerCAmelCase       					=    (
			    DOOMSDAY_NOT_LEAP[month - 1]
			    if (year % 4 != 0) or (centurian == 0 and (year % 400) == 0)
			    else DOOMSDAY_LEAP[month - 1]
			)
			__lowerCAmelCase       					=    (dooms_day + day - day_anchor) % 7
			return WEEK_DAY_NAMES[week_day]


if __name__ == "__main__":
	import doctest

	doctest.testmod()




