
    Pi[                        d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlZd dlmZ d dlmZmZ d dlmZmZ d dlmZ eej        eeef         Z ed          Zd	ed
efdZddddeeef         dedefdZ G d de          Z G d de          Z  G d de          Z! G d de          Z" G d de          Z# G d de          Z$ G d d e          Z%dS )!    N)Path)AnyDictListMappingOptionalUnion)ndarray)
DictConfig	OmegaConf)
get_loggerget_world_size_and_rank)ProtocolDEBUGconfigreturnc                     	 t          | j                  }|                    dd           |dz  }t          j        | |           |S # t
          $ r)}t                              d| d           Y d}~dS d}~ww xY w)a  
    Save the OmegaConf configuration to a YAML file at `{config.output_dir}/torchtune_config.yaml`.

    Args:
        config (DictConfig): The OmegaConf config object to be saved. It must contain an `output_dir` attribute
            specifying where the configuration file should be saved.

    Returns:
        Path: The path to the saved configuration file.

    Note:
        If the specified `output_dir` does not exist, it will be created.
    Tparentsexist_okztorchtune_config.yamlzError saving config.
Error: 
.N)r   
output_dirmkdirr   save	Exceptionlogwarning)r   r   output_config_fnamees       u/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchtune/training/metric_logging.pysave_configr!      s    <&+,,
555(+BBv2333"" < < <:a:::;;;;;;;;;<s   AA	 	
A<A77A<r    sep
parent_keydr$   r%   c                8   g }|                                  D ]u\  }}|r| | | n|}t          |t                    r8|                    t	          |||                                                      ^|                    ||f           vt          |          S )a  Recursively flattens a nested dictionary into one level of key-value pairs.

    Args:
        d (Dict[str, Any]): Any dictionary to flatten.
        sep (str, optional): Desired separator for flattening nested keys. Defaults to ".".
        parent_key (str, optional): Key prefix for children (nested keys), containing parent key names. Defaults to "".

    Example:
        >>> flatten_dict({"foo": {"bar": "baz"}, "qux": "quux"}, sep="--")
        {"foo--bar": "baz", "qux": "quux"}

    Returns:
        Dict[str, Any]: Flattened dictionary.

    Note:
        Does not unnest dictionaries within list values (i.e., {"foo": [{"bar": "baz"}]}).
    r#   )items
isinstancedictextendflatten_dictappend)r&   r$   r%   r(   kvnew_keys          r    r,   r,   3   s    $ E		 ' '1-7>Z))a)))Qa 	'LLaSWEEEKKMMNNNNLL'1&&&&;;    c                   f    e Zd ZdZdedededdfdZdeddfd	Z	d
e
eef         deddfdZddZdS )MetricLoggerInterfacezAbstract metric logger.namedatastepr   Nc                     dS )zLog scalar data.

        Args:
            name (str): tag name used to group scalars
            data (Scalar): scalar data to log
            step (int): step value to record
        N selfr4   r5   r6   s       r    r   zMetricLoggerInterface.logR   s	     	r1   r   c                     dS )z^Logs the config as file

        Args:
            config (DictConfig): config to log
        Nr8   )r:   r   s     r    
log_configz MetricLoggerInterface.log_configa   s	     	r1   payloadc                     dS )zLog multiple scalar values.

        Args:
            payload (Mapping[str, Scalar]): dictionary of tag name and scalar value
            step (int): step value to record
        Nr8   r:   r=   r6   s      r    log_dictzMetricLoggerInterface.log_dicti   s	     	r1   c                     dS )zx
        Close log resource, flushing if necessary.
        Logs should not be written after `close` is called.
        Nr8   r:   s    r    closezMetricLoggerInterface.closer   s	    
 	r1   r   N)__name__
__module____qualname____doc__strScalarintr   r   r<   r   r@   rC   r8   r1   r    r3   r3   O   s        !!  	
 
        V 4 C D         r1   r3   c                       e Zd ZdZddedee         fdZdefdZded	e	d
e
ddfdZdeddfdZdeee	f         d
e
ddfdZddZddZdS )
DiskLoggera  Logger to disk.

    Args:
        log_dir (str): directory to store logs
        filename (Optional[str]): optional filename to write logs to.
            Default: None, in which case log_{unixtimestamp}.txt will be used.
        **kwargs: additional arguments

    Warning:
        This logger is not thread-safe.

    Note:
        This logger creates a new file based on the current time.
    Nlog_dirfilenamec                 6   t          |          | _        | j                            dd           |s&t          t	          j                              }d| d}| j        |z  | _        t          | j        d          | _        t          d| j                    d S )NTr   log_z.txtazWriting logs to )	r   rN   r   rK   time
_file_nameopen_fileprint)r:   rN   rO   kwargsunix_timestamps        r    __init__zDiskLogger.__init__   s    G}}4$777 	3 --N2n222H,1$/3//
22233333r1   r   c                     | j         S N)rT   rB   s    r    path_to_log_filezDiskLogger.path_to_log_file   s
    r1   r4   r5   r6   c           	          | j                             d| d| d| d           | j                                          d S )NStep  | :
)rV   writeflushr9   s       r    r   zDiskLogger.log   sN    
999$99999:::
r1   r   c                 $    t          |          }d S r\   r!   r:   r   _s      r    r<   zDiskLogger.log_config       r1   r=   c                    | j                             d| d           |                                D ]%\  }}| j                             | d| d           &| j                             d           | j                                          d S )Nr_   r`   ra    rb   )rV   rc   r(   rd   r:   r=   r6   r4   r5   s        r    r@   zDiskLogger.log_dict   s    
****+++!--// 	0 	0JD$J..t...////

r1   c                 8    | j                                          d S r\   rV   rC   rB   s    r    __del__zDiskLogger.__del__       
r1   c                 8    | j                                          d S r\   rn   rB   s    r    rC   zDiskLogger.close   rp   r1   r\   rD   )rE   rF   rG   rH   rI   r   rZ   r   r]   rJ   rK   r   r   r<   r   r@   ro   rC   r8   r1   r    rM   rM   z   s        4 4 4x} 4 4 4 4$     6                 V 4 C D            r1   rM   c                   n    e Zd ZdZdedededdfdZdeddfd	Z	d
e
eef         deddfdZddZddZdS )StdoutLoggerzLogger to standard output.r4   r5   r6   r   Nc                 6    t          d| d| d|            d S )Nr_   r`   ra   )rW   r9   s       r    r   zStdoutLogger.log   s/    ,d,,t,,d,,-----r1   r   c                 $    t          |          }d S r\   rf   rg   s      r    r<   zStdoutLogger.log_config   ri   r1   r=   c                     t          d| dd           |                                D ]\  }}t          | d| dd           t          dd           d S )Nr_   r`   r"   )endra   rk   rb   )rW   r(   rl   s        r    r@   zStdoutLogger.log_dict   s|    dR((((!--// 	- 	-JD$T##D###,,,,,dr1   c                 B    t           j                                         d S r\   sysstdoutrd   rB   s    r    ro   zStdoutLogger.__del__       
r1   c                 B    t           j                                         d S r\   ry   rB   s    r    rC   zStdoutLogger.close   r|   r1   rD   )rE   rF   rG   rH   rI   rJ   rK   r   r   r<   r   r@   ro   rC   r8   r1   r    rs   rs      s        $$. .6 . . . . . .           V 4 C D            r1   rs   c            
           e Zd ZdZ	 	 	 	 ddedee         dee         dee         fdZd	ed
dfdZdede	de
d
dfdZdeee	f         de
d
dfdZddZddZdS )WandBLoggera  Logger for use w/ Weights and Biases application (https://wandb.ai/).
    For more information about arguments expected by WandB, see https://docs.wandb.ai/ref/python/init.

    Args:
        project (str): WandB project name. Default is `torchtune`.
        entity (Optional[str]): WandB entity name. If you don't specify an entity,
            the run will be sent to your default entity, which is usually your username.
        group (Optional[str]): WandB group name for grouping runs together. If you don't
            specify a group, the run will be logged as an individual experiment.
        log_dir (Optional[str]): WandB log directory. If not specified, use the `dir`
            argument provided in kwargs. Else, use root directory.
        **kwargs: additional arguments to pass to wandb.init

    Example:
        >>> from torchtune.training.metric_logging import WandBLogger
        >>> logger = WandBLogger(project="my_project", entity="my_entity", group="my_group")
        >>> logger.log("my_metric", 1.0, 1)
        >>> logger.log_dict({"my_metric": 1.0}, 1)
        >>> logger.close()

    Raises:
        ImportError: If ``wandb`` package is not installed.

    Note:
        This logger requires the wandb package to be installed.
        You can install it with `pip install wandb`.
        In order to use the logger, you need to login to your WandB account.
        You can do this by running `wandb login` in your terminal.
    	torchtuneNprojectentitygrouprN   c                    	 dd l }n"# t          $ r}t          d          |d }~ww xY w|| _        |                    d|          | _        | j        =t
          j                            | j                  st          j        | j                   t                      \  }| _
        | j        j        '| j
        dk    r | j        j        d|||| j        d|}	| j        j        r | j        j                            d           t          | j        dd           r7| j                            d           | j                            d	dd
           |                    dd          | _        d S )Nr   z``wandb`` package not found. Please install wandb using `pip install wandb` to use WandBLogger.Alternatively, use the ``StdoutLogger``, which can be specified by setting metric_logger_type='stdout'.dir)r   r   r   r   r   )repodefine_metricglobal_step*T)step_metric	step_syncallow_val_changeFr8   )wandbImportError_wandbpoprN   ospathexistsmakedirsr   rankruninit_labelgetattrr   getconfig_allow_val_change)
r:   r   r   r   rN   rX   r   r   rh   r   s
             r    rZ   zWandBLogger.__init__   s   	LLLL 	 	 	z  	
  zz%11 <#BGNN4<,H,H#K%%%.0049;?"tyA~~"$+" L	 
  C ;? 	5KO"""444 4;66 	VK%%m444K%%c}PT%UUU'-zz2De'L'L$$$    
&!&r   r   c                 n   | j         j        rt          j        |d          }| j         j                            || j                   t          |          }	 | j                             ||j	                   dS # t          $ r,}t                              d| d| d           Y d}~dS d}~ww xY wdS )	aw  Saves the config locally and also logs the config to W&B. The config is
        stored in the same directory as the checkpoint. You can
        see an example of the logged config to W&B in the following link:
        https://wandb.ai/capecape/torchtune/runs/6053ofw0/files/torchtune_config_j67sb73v.yaml

        Args:
            config (DictConfig): config to log
        Tresolve)r   )	base_pathzError uploading z to W&B.
Error: 
z8.Don't worry the config will be logged the W&B workspaceN)r   r   r   to_containerr   updater   r!   r   parentr   r   r   r:   r   resolvedr   r   s        r    r<   zWandBLogger.log_config  s    ;? 	 -fdCCCHK%%4+G &   
 #.f"5"5  '3F3M !         N': N Nq N N N        	 	s   !A< <
B2!B--B2r4   r5   r6   c                 ^    | j         j        r | j                             ||d|i           d S d S Nr   r   r   r   r9   s       r    r   zWandBLogger.log*  s;    ;? 	?KOOT4=>>>>>	? 	?r1   r=   c                 b    | j         j        r"| j                             i |d|i           d S d S r   r   r?   s      r    r@   zWandBLogger.log_dict.  sB    ;? 	>KOO<w<t<<=====	> 	>r1   c                 x    t          | d          r'| j        j        r| j                                         d S d S d S )Nr   )hasattrr   r   finishrB   s    r    ro   zWandBLogger.__del__2  sM    4"" 	!t{ 	!K     	! 	! 	! 	!r1   c                 T    | j         j        r| j                                          d S d S r\   )r   r   r   rB   s    r    rC   zWandBLogger.close7  s2    ;? 	!K     	! 	!r1   )r   NNNrD   )rE   rF   rG   rH   rI   r   rZ   r   r<   rJ   rK   r   r   r@   ro   rC   r8   r1   r    r   r      s.        @ # $#!%,M ,M,M ,M }	,M
 #,M ,M ,M ,M\     6? ?6 ? ? ? ? ? ?>V 4 >C >D > > > >! ! ! !
! ! ! ! ! !r1   r   c                       e Zd ZdZddedefdZdededed	d
fdZ	de
d	d
fdZdeeef         ded	d
fdZddZddZd
S )TensorBoardLoggeraJ  Logger for use w/ PyTorch's implementation of TensorBoard (https://pytorch.org/docs/stable/tensorboard.html).

    Args:
        log_dir (str): torch.TensorBoard log directory
        organize_logs (bool): If `True`, this class will create a subdirectory within `log_dir` for the current
            run. Having sub-directories allows you to compare logs across runs. When TensorBoard is
            passed a logdir at startup, it recursively walks the directory tree rooted at logdir looking for
            subdirectories that contain tfevents data. Every time it encounters such a subdirectory,
            it loads it as a new run, and the frontend will organize the data accordingly.
            Recommended value is `True`. Run `tensorboard --logdir my_log_dir` to view the logs.
        **kwargs: additional arguments

    Example:
        >>> from torchtune.training.metric_logging import TensorBoardLogger
        >>> logger = TensorBoardLogger(log_dir="my_log_dir")
        >>> logger.log("my_metric", 1.0, 1)
        >>> logger.log_dict({"my_metric": 1.0}, 1)
        >>> logger.close()

    Note:
        This utility requires the tensorboard package to be installed.
        You can install it with `pip install tensorboard`.
        In order to view TensorBoard logs, you need to run `tensorboard --logdir my_log_dir` in your terminal.
    TrN   organize_logsc                    ddl m} d | _        t                      \  }| _        |r<t
          j                            |d| j         dt          j                               n|| _	        | j        dk    r || j	                  | _        d S d S )Nr   )SummaryWriterrun_rh   )rN   )
torch.utils.tensorboardr   _writerr   _rankr   r   joinrS   rN   )r:   rN   r   rX   r   rh   s         r    rZ   zTensorBoardLogger.__init__V  s    99999904/114: BGLL"C"C"Cdikk"C"CDDD 	 :??(=>>>DLLL ?r1   r4   r5   r6   r   Nc                 T    | j         r | j                             |||d           d S d S )NT)r   	new_style)r   
add_scalarr9   s       r    r   zTensorBoardLogger.logh  s>    < 	RL##D$DD#QQQQQ	R 	Rr1   r   c                 $    t          |          }d S r\   rf   rg   s      r    r<   zTensorBoardLogger.log_configl  ri   r1   r=   c                 h    |                                 D ]\  }}|                     |||           d S r\   )r(   r   rl   s        r    r@   zTensorBoardLogger.log_dicto  s@    !--// 	' 	'JD$HHT4&&&&	' 	'r1   c                 X    | j         r"| j                                          d | _         d S d S r\   r   rC   rB   s    r    ro   zTensorBoardLogger.__del__s  5    < 	 L   DLLL	  	 r1   c                 X    | j         r"| j                                          d | _         d S d S r\   r   rB   s    r    rC   zTensorBoardLogger.closex  r   r1   )TrD   )rE   rF   rG   rH   rI   boolrZ   rJ   rK   r   r   r<   r   r@   ro   rC   r8   r1   r    r   r   <  s         2? ? ?D ? ? ? ?$R R6 R R R R R R           'V 4 'C 'D ' ' ' '       
           r1   r   c                   .   e Zd ZdZ	 	 	 	 	 	 	 	 	 ddee         dee         dee         dee         dee         d	ee         d
ee         deee                  dedeee	f         fdZ
dedededdfdZdeeef         deddfdZdeddfdZddZddZdS )CometLoggera
  Logger for use w/ Comet (https://www.comet.com/site/).
    Comet is an experiment tracking tool that helps ML teams track, debug,
    compare, and reproduce their model training runs.

    For more information about arguments expected by Comet, see
    https://www.comet.com/docs/v2/guides/experiment-management/configure-sdk/#for-the-experiment.

    Args:
        api_key (Optional[str]): Comet API key. It's recommended to configure the API Key with `comet login`.
        workspace (Optional[str]): Comet workspace name. If not provided, uses the default workspace.
        project (Optional[str]): Comet project name. Defaults to Uncategorized.
        experiment_key (Optional[str]): The key for comet experiment to be used for logging. This is used either to
            append data to an Existing Experiment or to control the ID of new experiments (for example to match another
            ID). Must be an alphanumeric string whose length is between 32 and 50 characters.
        mode (Optional[str]): Control how the Comet experiment is started.

            * ``"get_or_create"``: Starts a fresh experiment if required, or persists logging to an existing one.
            * ``"get"``: Continue logging to an existing experiment identified by the ``experiment_key`` value.
            * ``"create"``: Always creates of a new experiment, useful for HPO sweeps.
        online (Optional[bool]): If True, the data will be logged to Comet server, otherwise it will be stored locally
            in an offline experiment. Default is ``True``.
        experiment_name (Optional[str]): Name of the experiment. If not provided, Comet will auto-generate a name.
        tags (Optional[List[str]]): Tags to associate with the experiment.
        log_code (bool): Whether to log the source code. Defaults to True.
        **kwargs (Dict[str, Any]): additional arguments to pass to ``comet_ml.start``. See
            https://www.comet.com/docs/v2/api-and-sdk/python-sdk/reference/Experiment-Creation/#comet_ml.ExperimentConfig

    Example:
        >>> from torchtune.training.metric_logging import CometLogger
        >>> logger = CometLogger(project_name="my_project", workspace="my_workspace")
        >>> logger.log("my_metric", 1.0, 1)
        >>> logger.log_dict({"my_metric": 1.0}, 1)
        >>> logger.close()

    Raises:
        ImportError: If ``comet_ml`` package is not installed.

    Note:
        This logger requires the comet_ml package to be installed.
        You can install it with ``pip install comet_ml``.
        You need to set up your Comet.ml API key before using this logger.
        You can do this by calling ``comet login`` in your terminal.
        You can also set it as the `COMET_API_KEY` environment variable.
    NTapi_key	workspacer   experiment_keymodeonlineexperiment_nametagslog_coderX   c
                    	 dd l }n"# t          $ r}t          d          |d }~ww xY wd|
v r|
d= t                      \  }| _        d | _        | j        dk    r2|                    |||||| |j        d|	||d|
          | _        d S d S )Nr   z``comet_ml`` package not found. Please install comet_ml using `pip install comet_ml` to use CometLogger.Alternatively, use the ``StdoutLogger``, which can be specified by setting metric_logger_type='stdout'.rN   )r   r   r4   )r   r   r   r   r   r   experiment_configr8   )comet_mlr   r   r   
experimentstartExperimentConfig)r:   r   r   r   r   r   r   r   r   r   rX   r   r   rh   s                 r    rZ   zCometLogger.__init__  s    	OOOO 	 	 	z  	 y!.0049
 9>>&nn#-";("; #%D# #JP# # - 
 
DOOO >r   r4   r5   r6   r   c                 R    | j         | j                             |||           d S d S N)r6   )r   
log_metricr9   s       r    r   zCometLogger.log  s5    ?&O&&tT&===== '&r1   r=   c                 P    | j         | j                             ||           d S d S r   )r   log_metricsr?   s      r    r@   zCometLogger.log_dict  s3    ?&O''d';;;;; '&r1   r   c                 D   | j         t          j        |d          }| j                             |           t	          |          }	 | j                             ||j                   d S # t          $ r(}t          	                    d|            Y d }~d S d }~ww xY wd S )NTr   )	file_namez0Failed to upload config to Comet assets. Error: )
r   r   r   log_parametersr!   	log_assetr4   r   r   r   r   s        r    r<   zCometLogger.log_config  s    ?& -fdCCCHO**8444 #.f"5"5T))'3F3K *       T T TRqRRSSSSSSSSST '&s   !A+ +
B5BBc                 J    | j         | j                                          d S d S r\   )r   rw   rB   s    r    rC   zCometLogger.close  s,    ?&O!!!!! '&r1   c                 .    |                                   d S r\   )rC   rB   s    r    ro   zCometLogger.__del__  s    

r1   )	NNNNNNNNTrD   )rE   rF   rG   rH   r   rI   r   r   r   r   rZ   rJ   rK   r   r   r@   r   r<   rC   ro   r8   r1   r    r   r   ~  s       + +^ "&#'!%(,"!%)-$(* *#* C=* #	*
 !* sm* * "#* tCy!* * sCx.* * * *X> >6 > > > > > ><V 4 <C <D < < < <T T T T T T" " " "     r1   r   c            
           e Zd ZdZ	 	 	 	 ddee         dee         dee         dee         fdZded	dfd
Zdede	de
d	dfdZdeee	f         de
d	dfdZddZddZdS )MLFlowLoggera  Logger for use w/ MLFlow (https://mlflow.org/).

    Args:
        experiment_name (Optional[str]): MLFlow experiment name. If not specified, will
            default to MLFLOW_EXPERIMENT_NAME environment variable if set, or default.
        tracking_uri (Optional[str]): MLFlow tracking uri. If not specified, will default
            to MLFLOW_TRACKING_URI environment variable if set, or default.
        run_id (Optional[str]): MLFlow run name. If not specified, will default
            to mlflow-generated HRID. Unused if run_id is specified or MLFLOW_RUN_ID
            environment variable is found.
        run_name (Optional[str]): MLFlow run ID. If not specified, will default
            to MLFLOW_RUN_ID environment variable if set, or a new run will be created.

    Example:
        >>> logger = MLFlowLogger(experiment_name="my_experiment", run_name="run1")
        >>> logger.log("accuracy", 0.95, step=1)
        >>> logger.log_dict({"loss": 0.1, "accuracy": 0.95}, step=1)
        >>> logger.log_config(config)
        >>> logger.close()

    Raises:
        ImportError: If ``mlflow`` package is not installed.

    Note:
        This logger requires the mlflow package to be installed.
        You can install it with `pip install mlflow`.
    Nr   tracking_urirun_idrun_namec                    	 dd l }n"# t          $ r}t          d          |d }~ww xY wt                      \  }| _        || _        |pt          j        d          | _        |pt          j        d          | _        |pt          j        d          | _	        | j        dk    r| j        
                                s&| j        | j                            | j                   | j                                        | j        s| j	        rV| j        | j                            | j                   | j                            |          }|j        j        | _	        d S d S d S )Nr   z``mlflow`` package not found. Please install mlflow using `pip install mlflow` to use MLFlowLogger.Alternatively, use the ``StdoutLogger``, which can be specified by setting metric_logger_type='stdout'.MLFLOW_TRACKING_URIMLFLOW_EXPERIMENT_NAMEMLFLOW_RUN_ID)r   )mlflowr   r   r   _mlflowr   getenv_tracking_uri_experiment_name_run_idis_tracking_uri_setset_tracking_uri
active_run_nested_runset_experiment	start_runinfor   )	r:   r   r   r   r   r   r   rh   r   s	            r    rZ   zMLFlowLogger.__init__  sm   	MMMM 	 	 	z  	 /0049)MRY7L-M-M / V29=U3V3V;?!;!;9>><3355 F%1L11$2DEEE|&&((0D4D00(4L//0EFFFl,,h,??"x >
 10r   r   r   c                 x   | j                                         rt          j        |d          }t	          |          }| j                             || j                   t          |          }t          |j	                  
                    d          }| j                             ||| j                   dS dS )zSaves the config locally and also logs the config to mlflow. The config is
        stored in the same directory as the checkpoint.

        Args:
            config (DictConfig): config to log
        Tr   )r   /)artifact_pathr   N)r   r   r   r   r,   
log_paramsr   r!   rI   r   lstriplog_artifact)r:   r   r   config_as_paramsr   r   s         r    r<   zMLFlowLogger.log_config6  s     <""$$ 	 -fdCCCH  ,H55L##$4T\#JJJ"-f"5"5   3 :;;BB3GGML%%#+| &     	 	r1   r4   r5   r6   c                     | j                                         r%| j                             |||| j                   d S d S N)r6   r   )r   r   r   r   r9   s       r    r   zMLFlowLogger.logO  sL    <""$$ 	PL##D$T$,#OOOOO	P 	Pr1   r=   c                     | j                                         r$| j                             ||| j                   d S d S r   )r   r   r   r   r?   s      r    r@   zMLFlowLogger.log_dictS  sJ    <""$$ 	NL$$W4$MMMMM	N 	Nr1   c                     | j         dk    r4| j                                        r| j                                         dS dS dS )zk
        Ends the MLflow run.
        After calling close, no further logging should be performed.
        r   N)r   r   r   end_runrB   s    r    rC   zMLFlowLogger.closeW  sF    
 9>>dl5577>L  """"" >>>r1   c                     t          | d          r4| j                                        r| j                                         d S d S d S )Nr   )r   r   r   r   rB   s    r    ro   zMLFlowLogger.__del___  sW    4## 	#(?(?(A(A 	#L  """""	# 	# 	# 	#r1   )NNNNrD   )rE   rF   rG   rH   r   rI   rZ   r   r<   rJ   rK   r   r   r@   rC   ro   r8   r1   r    r   r     s7        < *.&* $"&!/ !/!#!/ sm!/ 	!/
 3-!/ !/ !/ !/F     2P P6 P P P P P PNV 4 NC ND N N N N# # # ## # # # # #r1   r   )&r   rz   rS   pathlibr   typingr   r   r   r   r   r	   torchnumpyr
   	omegaconfr   r   torchtune.utilsr   r   typing_extensionsr   TensorrK   floatrJ   r   r!   rI   r,   r3   rM   rs   r   r   r   r   r8   r1   r    <module>r	     s   
			 



        < < < < < < < < < < < < < < < <        + + + + + + + + ? ? ? ? ? ? ? ? & & & & & &	u|Wc50	1j<
 <t < < < <2 36   DcN C 3    8( ( ( ( (H ( ( (V/ / / / /& / / /d    (   ,w! w! w! w! w!' w! w! w!t?  ?  ?  ?  ? - ?  ?  ? Du u u u u' u u upl# l# l# l# l#( l# l# l# l# l#r1   