
      iI                     :    d dl mZmZmZ d dlmZ  G d de      Zy)    )AnyCallableOptional)overridec                       e Zd ZdZ	 	 	 ddedee   dee   dededefd	Z	e
dded
ee   defd       ZdeddfdZdefdZdefdZy)_StrategyRegistrya>  This class is a Registry that stores information about the Training Strategies.

    The Strategies are mapped to strings. These strings are names that identify
    a strategy, e.g., "deepspeed". It also returns Optional description and
    parameters to initialize the Strategy, which were defined durng the
    registration.

    The motivation for having a StrategyRegistry is to make it convenient
    for the Users to try different Strategies by passing just strings
    to the strategy flag to the Trainer.

    Example::

        @StrategyRegistry.register("lightning", description="Super fast", a=1, b=True)
        class LightningStrategy:
            def __init__(self, a, b):
                ...

        or

        StrategyRegistry.register("lightning", LightningStrategy, description="Super fast", a=1, b=True)

    Nnamestrategydescriptionr   init_paramsreturnc                      t        t              st        d        v r|st        d d      i ||ndd<   |d<   dt        dt        f fd	}| ||      S |S )
a  Registers a strategy mapped to a name and with required metadata.

        Args:
            name : the name that identifies a strategy, e.g. "deepspeed_stage_3"
            strategy : strategy class
            description : strategy description
            override : overrides the registered strategy, if True
            init_params: parameters to initialize the strategy

        z`name` must be a str, found 'z@' is already present in the registry. HINT: Use `override=True`. r   r   r
   r   c                 &    | d<   d<   <   | S )Nr
   strategy_name )r
   datar	   selfs    y/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/lightning/fabric/strategies/registry.pydo_registerz/_StrategyRegistry.register.<locals>.do_registerI   s%    'D$(D!DJO    )
isinstancestr	TypeError
ValueErrorr   )r   r	   r
   r   r   r   r   r   s   ``     @r   registerz_StrategyRegistry.register,   s    $ 
4 5:4&ABB4<q&fghh!-8-Dk"])]	( 	x 	 x((r   defaultc                     || v r| |   } |d   di |d   S ||S d}dj                  t        | j                                     xs d}t        |j	                  ||            )zCalls the registered strategy with the required parameters and returns the strategy object.

        Args:
            name (str): the name that identifies a strategy, e.g. "deepspeed_stage_3"

        r
   r   z/'{}' not found in registry. Available names: {}, noner   )joinsortedkeysKeyErrorformat)r   r	   r   r   err_msgavailable_namess         r   getz_StrategyRegistry.getT   sr     4<:D#4
#:d=&9::NC))F499;$78BFw~~dO<==r   c                 &    | j                  |       y)z(Removes the registered strategy by name.N)pop)r   r	   s     r   removez_StrategyRegistry.removeg   s    r   c                 4    t        | j                               S )z(Returns a list of registered strategies.)listr$   r   s    r   available_strategiesz&_StrategyRegistry.available_strategiesk   s    DIIK  r   c                 ^    dj                  dj                  | j                                     S )NzRegistered Strategies: {}r    )r&   r"   r$   r/   s    r   __str__z_StrategyRegistry.__str__o   s"    *11$))DIIK2HIIr   )NNF)N)__name__
__module____qualname____doc__r   r   r   boolr   r   r   r)   r,   r.   r0   r2   r   r   r   r   r      s    6 (,%)&& 8$& c]	&
 & & 
&P > >hsm >s > >$3 4 !d !J Jr   r   N)typingr   r   r   typing_extensionsr   dictr   r   r   r   <module>r;      s     + * &]J ]Jr   