
    9i                     T    d dl Z d dlZd dlZd dlmZmZ d dlmZmZ dZ	ddZ
d Zd Zy)	    N)Versionparse)default_config_fileload_config_from_filezQRun commands across TPU VMs for initial setup before running `accelerate launch`.c                 \   | | j                  dt              }nt        j                  dt              }|j	                  dd      }|j                  dt        d d       |j                  d	d d
       |j                  dd d       |j	                  dd      }|j                  ddd       |j                  dd d       |j                  dddd       |j                  ddd       |j                  ddd       |j                  d dd!       | |j                  t        "       |S )#Nz
tpu-config)descriptionzAccelerate tpu-config commandzConfig Argumentsz=Arguments that can be configured through `accelerate config`.z--config_filez.Path to the config file to use for accelerate.)typedefaulthelpz
--tpu_namez\The name of the TPU to use. If not specified, will use the TPU specified in the config file.)r
   r   z
--tpu_zonez]The zone of the TPU to use. If not specified, will use the zone specified in the config file.zTPU Argumentsz)Arguments for options ran inside the TPU.z--use_alpha
store_truezWWhether to use `gcloud alpha` when running the TPU training script instead of `gcloud`.)actionr   z--command_filezJThe path to the file containing the commands to run on the pod on startup.	--commandappend+z:A command to run on the pod. Can be passed multiple times.)r   nargsr   z--install_acceleratez<Whether to install accelerate on the pod. Defaults to False.z--accelerate_versionlatestzThe version of accelerate to install on the pod. If not specified, will use the latest pypi version. Specify 'dev' to install from GitHub.z--debugzGIf set, will print the command that would be run instead of running it.)func)	
add_parser_descriptionargparseArgumentParseradd_argument_groupadd_argumentstrset_defaultstpu_command_launcher)
subparsersparserconfig_argspod_argss       a/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/accelerate/commands/tpu.pytpu_command_parserr"      s   &&|&N(()HVbc++[K =	   k  
 l  
 ((:efHf  
 Y  
 I	   K  
  Z  
 ,-v   !56M    c                    d }| j                   #t        j                  j                  t              rt        | j                         }| j                  s)|j                  | j                  s|j                  | _        | j                  s|j                  |j                  | _        | j                  s|j                  | _	        | j                  s|j                  | _
        | j                  dk(  rd| _        nN| j                  dk(  rd| _        n7t        t        | j                        t              rd| j                   | _        | j                  s| j                  st        d      | j                  rCt!        | j                  d      5 }|j#                         j%                         g| _        d d d        t        | j                  d   t&              r(| j                  D cg c]  }|D ]  }|  c}}| _        d	g}| j(                  r|d
| j                   gz  }|| j                  z  }dj+                  |      | _        dg}| j,                  r|dgz  }|dddd| j                  d| j                  d| j                  ddgz  }| j.                  rt1        ddj+                  |              y t3        j4                  |       t1        d       y # 1 sw Y   $xY wc c}}w )Ndevz1git+https://github.com/huggingface/accelerate.gitr   zaccelerate -Uzaccelerate==zFYou must specify either a command file or a command to run on the pod.rr   zcd /usr/sharezpip install z; gcloudalphacomputetpusztpu-vmsshz--zoner   z--workerallzRunning  zSuccessfully setup pod.)config_fileospathisfiler   r   command_filecommandcommandstpu_nametpu_zoneaccelerate_version
isinstancer   r   
ValueErroropenread
splitlineslistinstall_acceleratejoin	use_alphadebugprint
subprocessrun)argsdefaultsfcmdlinenew_cmds         r!   r   r   Z   su   H #rww~~6I'J()9)9:  X%:%:%Ft|| ( 5 5D|| 1 1 =#,,DL}}$--DM}}$--DM%'"U		 	 H	,"1	E$112G	<$01H1H0I"JT\\abb$##S) 	3QFFH//12DL	3 $,,q/4((,EEEEGl4#:#:";<==t||G99W%DL *C~~y C zz#()NN3	
#$G	3 	3
 Fs   	%K"KKc                  N    t               } | j                         }t        |       y N)r"   
parse_argsr   )r   rE   s     r!   mainrN      s     !FDr#   rL   )r   r/   rC   packaging.versionr   r   &accelerate.commands.config.config_argsr   r   r   r"   r   rN    r#   r!   <module>rR      s/   "  	  , ] c:z<%~r#   