
    PiZ                         d dl Z d dlZd dlmZ d dlmZmZ d dlZd dlm	Z	 d dl
mZmZ  ee          j        j        j        Z G d de	          ZdS )    N)Path)ListOptional)
Subcommand)Configget_all_recipesc                        e Zd ZdZdej        f fdZdee         fdZ	dede
e         fdZded	edd
fdZdej        dd
fdZ xZS )Catz2Holds all the logic for the `tune cat` subcommand.
subparsersc           	      ~   t                                                       |                    ddddt          j        d          t
          j                  | _        | j                            dt          d           | j        
                    | j        	           | j                            d
dd           d S )Ncatztune catz`Pretty print a config, making it easy to know which parameters you can override with `tune run`.an                  examples:
                    $ tune cat llama2/7B_full
                    output_dir: /tmp/torchtune/llama2_7B/full
                    tokenizer:
                        _component_: torchtune.models.llama2.llama2_tokenizer
                        path: /tmp/Llama-2-7b-hf/tokenizer.model
                        max_seq_len: null
                    ...

                    # Pretty print the config in sorted order
                    $ tune cat llama2/7B_full --sort

                    # Pretty print the contents of LOCALFILE.yaml
                    $ tune cat LOCALFILE.yaml

                You can now easily override a key based on your findings from `tune cat`:
                    $ tune run full_finetune_distributed --config llama2/7B_full output_dir=./

                Need to find all the "cat"-able configs? Try `tune ls`!
                )proghelpdescriptionepilogformatter_classconfig_namezName of the config to print)typer   )funcz--sort
store_truez Print the config in sorted order)actionr   )super__init__
add_parsertextwrapdedentargparseRawTextHelpFormatter_parseradd_argumentstrset_defaults_cat_cmd)selfr   	__class__s     f/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchtune/_cli/cat.pyr   zCat.__init__   s    !,,sz? . %99 - 
 
< 	!!*G 	" 	
 	
 	
 	!!t}!555!!\0R 	" 	
 	
 	
 	
 	
    returnc                 2    d t                      D             S )Nc                     g | ]	}|j         
S  )name).0recipes     r&   
<listcomp>z(Cat._get_all_recipes.<locals>.<listcomp>@   s    <<<<<<r'   )r   )r$   s    r&   _get_all_recipeszCat._get_all_recipes?   s    <</*;*;<<<<r'   
config_strc                 ^    t                      D ]}|j        D ]}|j        |k    r|c c S d S )N)r   configsr,   )r$   r1   r.   configs       r&   _get_configzCat._get_configB   sV    %'' 	" 	"F . " ";*,,!MMMMM -"	" 	"r'   file	sort_keysNc                 L   	 t          |d          5 }t          j        |          }|r)t          t          j        |d|ddd          d           d d d            d S # 1 swxY w Y   d S # t          j        $ r(}| j                            d	|            Y d }~d S d }~ww xY w)
NrF   P   T)default_flow_styler7   indentwidthallow_unicode )endzError parsing YAML file: )openyaml	safe_loadprintdump	YAMLErrorr   error)r$   r6   r7   fdataes         r&   _print_yaml_filezCat._print_yaml_fileI   s(   	@dC A~a(( 	 /4&/#$"$*.   
 
 
 
                  ~ 	@ 	@ 	@L>1>>?????????	@s;   A, A AA, A##A, &A#'A, ,B#;BB#argsc                    |j         }||                                 v rt          d| d           dS |                     |          }|rt          dz  dz  |j        z  }nJt          |          }|j                                        dvr | j	        
                    d| d           dS |                                s | j	        
                    d	| d
           dS |                     t          |          |j                   dS )aP  Display the contents of a configuration file.

        Handles both predefined configurations and direct file paths, ensuring:
        - Input is not a recipe name
        - File exists
        - File is YAML format

        Args:
            args (argparse.Namespace): Command-line arguments containing 'config_name' attribute
        'z6' is a recipe, not a config. Please use a config name.Nrecipesr3   >   .yml.yamlzInvalid config format: 'z'. Must be YAML (.yaml/.yml)zConfig 'z' not found.)r   r0   rE   r5   ROOT	file_pathr   suffixlowerr   rH   existsrL   r!   sort)r$   rM   r1   r4   config_paths        r&   r#   zCat._cat_cmd\   s:    %
 ..0000VJVVV   F !!*-- 	*Y69IIKKz**K!''))1BBB""X{XXX   !!## 	LB*BBBCCCFc+..	:::::r'   )__name__
__module____qualname____doc__r   _SubParsersActionr   r   r!   r0   r   r   r5   boolrL   	Namespacer#   __classcell__)r%   s   @r&   r
   r
      s        <<&
8#= &
 &
 &
 &
 &
 &
P=$s) = = = ="c "hv.> " " " "@S @T @d @ @ @ @&$;X/ $;D $; $; $; $; $; $; $; $;r'   r
   )r   r   pathlibr   typingr   r   rC   torchtune._cli.subcommandr   torchtune._recipe_registryr   r   __file__parentrS   r
   r+   r'   r&   <module>rh      s            ! ! ! ! ! ! ! !  0 0 0 0 0 0 > > > > > > > >tH~~#*l; l; l; l; l;* l; l; l; l; l;r'   