






import sys
import turtle






def      _snake_case     (__lowercase     ,   __lowercase):
   return (pa[0] + pa[0]) / 2, (pa[1] + pa[1]) / 2






def      _snake_case     (__lowercase     ,   __lowercase     ,   __lowercase     ,   __lowercase     ,   ):
   my_pen.up()
   my_pen.goto(vertexa[0]     ,   vertexa[1])
   my_pen.down()
   my_pen.goto(vertexa[0]     ,   vertexa[1])
   my_pen.goto(vertexa[0]     ,   vertexa[1])
   my_pen.goto(vertexa[0]     ,   vertexa[1])

   if depth == 0:
      return

   triangle(__lowercase     ,   get_mid(__lowercase     ,   __lowercase)     ,   get_mid(__lowercase     ,   __lowercase)     ,   depth - 1)
   triangle(__lowercase     ,   get_mid(__lowercase     ,   __lowercase)     ,   get_mid(__lowercase     ,   __lowercase)     ,   depth - 1)
   triangle(__lowercase     ,   get_mid(__lowercase     ,   __lowercase)     ,   get_mid(__lowercase     ,   __lowercase)     ,   depth - 1)


if __name__ == "__main__":
 if len(sys.argv) != 2:
  raise ValueError(
      """Correct format for using this script: """
      """python fractals.py <int:depth_for_fractal>"""
  )
 snake_case__   :						Tuple													=   turtle.Turtle()
 my_pen.ht()
 my_pen.speed(5)
 my_pen.pencolor("""red""")

 snake_case__   :						Optional[Any]													=   [(-1_7_5, -1_2_5), (0, 1_7_5), (1_7_5, -1_2_5)]  # vertices of triangle
 triangle(vertices[0], vertices[1], vertices[2], int(sys.argv[1]))










'''simple docstring'''






import baseaa
import io
import json
import os
from copy import deepcopy

from ..optimizer import AcceleratedOptimizer
from ..scheduler import AcceleratedScheduler

class 				a__:







    def __init__( self					:    List[Any]		,     __snake_case					:    str      ):
      if isinstance(__snake_case		,     __snake_case      ):
        # Don't modify user's data should they want to reuse it (e.g. in tests), because once we
        # modified it, it will not be accepted here again, since `auto` values would have been overridden
        a		:   Union[str, Any]	  =	deepcopy(__snake_case      )
      elif os.path.exists(__snake_case      ):
        with io.open(__snake_case		,     'r'		,     encoding='utf-8'      ) as f:
          a		:   List[str]	  =	json.load(__snake_case      )
      else:
        try:
          a		:   str	  =	baseaa.urlsafe_baadecode(__snake_case      ).decode('utf-8'      )
          a		:   Union[str, Any]	  =	json.loads(__snake_case      )
        except (UnicodeDecodeError, AttributeError, ValueError):
          raise ValueError(
              F"""Expected a string path to an existing deepspeed config, or a dictionary, or a base64 encoded string. Received: {config_file_or_dict}"""      )

      a		:   Optional[int]	  =	config

      self.set_stage_and_offload()







    def      lowercase_			( self					:    Any      ):
      # zero stage - this is done as early as possible, before model is created, to allow
      # ``is_deepspeed_zero3_enabled`` query and getting to the early deepspeed config object
      # during ``zero.Init()`` which needs to know the dtype, and some other hparams.
      a		:   List[str]	  =	self.get_value('zero_optimization.stage'		,     -1      )

      # offload
      a		:   Union[str, Any]	  =	False
      if self.is_zeroa() or self.is_zeroa():
        a		:   Any	  =	set(['cpu', 'nvme']      )
        a		:   Tuple	  =	set(
            [
                self.get_value('zero_optimization.offload_optimizer.device'      ),
                self.get_value('zero_optimization.offload_param.device'      ),
            ]      )
        if len(offload_devices & offload_devices_valid      ) > 0:
          a		:   Optional[int]	  =	True







    def      lowercase_			( self					:    str		,     __snake_case					:    Optional[Any]      ):
      a		:   Any	  =	self.config

      # find the config node of interest if it exists
      a		:   Dict	  =	ds_key_long.split('.'      )
      a		:   str	  =	nodes.pop()
      for node in nodes:
        a		:   Tuple	  =	config.get(__snake_case      )
        if config is None:
          return None, ds_key

      return config, ds_key







    def      lowercase_			( self					:    int		,     __snake_case					:    Optional[int]		,     __snake_case					:    List[str]=None      ):
      a  ,      a		:   int	  =	self.find_config_node(__snake_case      )
      if config is None:
        return default
      return config.get(__snake_case		,     __snake_case      )







    def      lowercase_			( self					:    Dict		,     __snake_case					:    List[str]		,     __snake_case					:    List[Any]=False      ):
      a		:   Union[str, Any]	  =	self.config

      # find the config node of interest if it exists
      a		:   Tuple	  =	ds_key_long.split('.'      )
      for node in nodes:
        a		:   Optional[int]	  =	config
        a		:   List[str]	  =	config.get(__snake_case      )
        if config is None:
          if must_exist:
            raise ValueError(F"""Can't find {ds_key_long} entry in the config: {self.config}"""      )
          else:
            return

        # if found remove it
      if parent_config is not None:
        parent_config.pop(__snake_case      )







    def      lowercase_			( self					:    List[str]		,     __snake_case					:    Dict      ):
      a		:   Optional[Any]	  =	self.get_value(__snake_case      )
      return False if value is None else bool(__snake_case      )







    def      lowercase_			( self					:    str		,     __snake_case					:    Optional[Any]      ):
      a		:   Optional[Any]	  =	self.get_value(__snake_case      )
      return False if value is None else not bool(__snake_case      )







    def      lowercase_			( self					:    Tuple      ):
      return self._stage == 2







    def      lowercase_			( self					:    str      ):
      return self._stage == 3







    def      lowercase_			( self					:    int      ):
      return self._offload

class 				a__:







    def __init__( self					:    str		,     __snake_case					:    Any      ):
      a		:   Any	  =	engine







    def      lowercase_			( self					:    Optional[Any]		,     __snake_case					:    int		,     **__snake_case					:    List[Any]      ):
      # runs backpropagation and handles mixed precision
      self.engine.backward(__snake_case		,     **__snake_case      )

      # Deepspeed's `engine.step` performs the following operations:
      # - gradient accumulation check
      # - gradient clipping
      # - optimizer step
      # - zero grad
      # - checking overflow
      # - lr_scheduler step (only if engine.lr_scheduler is not None)
      self.engine.step()
      # and this plugin overrides the above calls with no-ops when Accelerate runs under
      # Deepspeed, but allows normal functionality for non-Deepspeed cases thus enabling a simple
      # training loop that works transparently under many training regimes.

class 				a__(   lowerCamelCase__      ):







    def __init__( self					:    Dict		,     __snake_case					:    Any      ):
      super().__init__(__snake_case		,     device_placement=__snake_case		,     scaler=__snake_case      )
      a		:   List[Any]	  =	hasattr(self.optimizer		,     'overflow'      )







    def      lowercase_			( self					:    Optional[Any]		,     __snake_case					:    str=None      ):
      pass  # `accelerator.backward(loss)` is doing that automatically. Therefore, its implementation is not needed







    def      lowercase_			( self					:    int      ):
      pass  # `accelerator.backward(loss)` is doing that automatically. Therefore, its implementation is not needed







    @property
    def      lowercase_			( self					:    Any      ):
      if self.__has_overflow__:
        return self.optimizer.overflow
      return False

class 				a__(   lowerCamelCase__      ):







    def __init__( self					:    str		,     __snake_case					:    List[Any]		,     __snake_case					:    str      ):
      super().__init__(__snake_case		,     __snake_case      )







    def      lowercase_			( self					:    Union[str, Any]      ):
      pass  # `accelerator.backward(loss)` is doing that automatically. Therefore, its implementation is not needed

class 				a__:







    def __init__( self					:    Optional[Any]		,     __snake_case					:    Union[str, Any]		,     __snake_case					:    int=0.001		,     __snake_case					:    Any=0		,     **__snake_case					:    List[Any]      ):
      a		:   Optional[Any]	  =	params
      a		:   Union[str, Any]	  =	lr
      a		:   Any	  =	weight_decay
      a		:   Any	  =	kwargs

class 				a__:







    def __init__( self					:    Any		,     __snake_case					:    int		,     __snake_case					:    int=None		,     __snake_case					:    Dict=0		,     **__snake_case					:    Optional[int]      ):
      a		:   Optional[int]	  =	optimizer
      a		:   List[str]	  =	total_num_steps
      a		:   Tuple	  =	warmup_num_steps
      a		:   Optional[Any]	  =	kwargs