



# 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 argparse

from ...utils.dataclasses import (
    ComputeEnvironment,
    DistributedType,
    DynamoBackend,
    PrecisionType,
    SageMakerDistributedType,
)
from ..menu import BulletMenu


SCREAMING_SNAKE_CASE_:List[str]					=						[
    """EAGER""",
    """AOT_EAGER""",
    """INDUCTOR""",
    """NVFUSER""",
    """AOT_NVFUSER""",
    """AOT_CUDAGRAPHS""",
    """OFI""",
    """FX2TRT""",
    """ONNXRT""",
    """IPEX""",
]




def      __UpperCamelCase     (  _lowerCAmelCase				,					_lowerCAmelCase=None				,					_lowerCAmelCase=None				,					_lowerCAmelCase=None		)	->  Union[str, Any]:



    """simple docstring"""






    A			:	int										=       True
    while ask_again:
        A			:	List[str]										=       input(_lowerCAmelCase		)
        try:
            if default is not None and len(_lowerCAmelCase		) == 0:
                return default
            return convert_value(_lowerCAmelCase		) if convert_value is not None else result
        except Exception:
            if error_message is not None:
                print(_lowerCAmelCase		)




def      __UpperCamelCase     (  _lowerCAmelCase				,					_lowerCAmelCase=[]				,					_lowerCAmelCase=None				,					_lowerCAmelCase=0		)	->  str:



    """simple docstring"""






    A			:	Dict										=       BulletMenu(_lowerCAmelCase				,					_lowerCAmelCase		)
    A			:	List[str]										=       menu.run(default_choice=_lowerCAmelCase		)
    return convert_value(_lowerCAmelCase		) if convert_value is not None else result




def      __UpperCamelCase     (  _lowerCAmelCase		)	->  Tuple:



    """simple docstring"""






    A			:	List[Any]										=       int(_lowerCAmelCase		)
    return ComputeEnvironment(["""LOCAL_MACHINE""", """AMAZON_SAGEMAKER"""][value]		)




def      __UpperCamelCase     (  _lowerCAmelCase		)	->  str:



    """simple docstring"""






    A			:	List[Any]										=       int(_lowerCAmelCase		)
    return DistributedType(["""NO""", """MULTI_CPU""", """MULTI_XPU""", """MULTI_GPU""", """MULTI_NPU""", """TPU"""][value]		)




def      __UpperCamelCase     (  _lowerCAmelCase		)	->  Optional[Any]:



    """simple docstring"""






    A			:	Union[str, Any]										=       int(_lowerCAmelCase		)
    return DynamoBackend(DYNAMO_BACKENDS[value]		).value




def      __UpperCamelCase     (  _lowerCAmelCase		)	->  str:



    """simple docstring"""






    A			:	Any										=       int(_lowerCAmelCase		)
    return PrecisionType(["""no""", """fp16""", """bf16""", """fp8"""][value]		)




def      __UpperCamelCase     (  _lowerCAmelCase		)	->  Dict:



    """simple docstring"""






    A			:	str										=       int(_lowerCAmelCase		)
    return SageMakerDistributedType(["""NO""", """DATA_PARALLEL""", """MODEL_PARALLEL"""][value]		)




def      __UpperCamelCase     (  _lowerCAmelCase		)	->  Optional[int]:



    """simple docstring"""






    return {"yes": True, "no": False}[value.lower()]






class SCREAMING_SNAKE_CASE__					(		argparse.RawDescriptionHelpFormatter   ):




    '''simple docstring'''






    def       _lowerCAmelCase (	self,		lowerCamelCase__,		lowerCamelCase__,		lowerCamelCase__,		lowerCamelCase__		):
        A			:	Tuple										=       super()._format_usage(lowerCamelCase__,		lowerCamelCase__,		lowerCamelCase__,		lowerCamelCase__		)
        A			:	int										=       usage.replace("""<command> [<args>] """,		""""""		)
        return usage







from random import randint, random




def      __UpperCamelCase     (  _lowerCAmelCase				,					_lowerCAmelCase				,					_lowerCAmelCase				,					_lowerCAmelCase = False				,					_lowerCAmelCase = False				,					_lowerCAmelCase = 5				,					)	->  list:



    """simple docstring"""






    A			:	Any										=       [[-1] * number_of_cells]  # Create a highway without any car
    A			:	Tuple										=       0
    A			:	Dict										=       max(_lowerCAmelCase				,					0		)
    while i < number_of_cells:
        A			:	Any										=       (
            randint(0				,					_lowerCAmelCase		) if random_speed else initial_speed
        )  # Place the cars
        i += (
            randint(1				,					max_speed * 2		) if random_frequency else frequency
        )  # Arbitrary number, may need tuning
    return highway




def      __UpperCamelCase     (  _lowerCAmelCase				,					_lowerCAmelCase		)	->  int:



    """simple docstring"""






    A			:	List[str]										=       0
    A			:	Dict										=       highway_now[car_index + 1 :]
    for cell in range(len(_lowerCAmelCase		)		):  # May need a better name for this
        if cells[cell] != -1:  # If the cell is not empty then
            return distance  # we have the distance we wanted
        distance += 1
    # Here if the car is near the end of the highway
    return distance + get_distance(_lowerCAmelCase				,					-1		)




def      __UpperCamelCase     (  _lowerCAmelCase				,					_lowerCAmelCase				,					_lowerCAmelCase		)	->  list:



    """simple docstring"""






    A			:	str										=       len(_lowerCAmelCase		)
    # Beforce calculations, the highway is empty
    A			:	Any										=       [-1] * number_of_cells

    for car_index in range(_lowerCAmelCase		):
        if highway_now[car_index] != -1:
            # Add 1 to the current speed of the car and cap the speed
            A			:	str										=       min(highway_now[car_index] + 1				,					_lowerCAmelCase		)
            # Number of empty cell before the next car
            A			:	Optional[int]										=       get_distance(_lowerCAmelCase				,					_lowerCAmelCase		) - 1
            # We can't have the car causing an accident
            A			:	Any										=       min(next_highway[car_index]				,					_lowerCAmelCase		)
            if random() < probability:
                # Randomly, a driver will slow down
                A			:	Optional[Any]										=       max(next_highway[car_index] - 1				,					0		)
    return next_highway




def      __UpperCamelCase     (  _lowerCAmelCase				,					_lowerCAmelCase				,					_lowerCAmelCase				,					_lowerCAmelCase		)	->  list:



    """simple docstring"""






    A			:	Any										=       len(highway[0]		)

    for i in range(_lowerCAmelCase		):
        A			:	Optional[int]										=       update(highway[i]				,					_lowerCAmelCase				,					_lowerCAmelCase		)
        A			:	Tuple										=       [-1] * number_of_cells

        for car_index in range(_lowerCAmelCase		):
            A			:	Dict										=       next_speeds_calculated[car_index]
            if speed != -1:
                # Change the position based on the speed (with % to create the loop)
                A			:	Optional[int]										=       (car_index + speed) % number_of_cells
                # Commit the change of position
                A			:	Dict										=       speed
        highway.append(_lowerCAmelCase		)

    return highway


if __name__ == "__main__":
     import doctest

     doctest.testmod()


