
    g                     V    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dS )	    N)Versionparse)default_config_fileload_config_from_filezQRun commands across TPU VMs for initial setup before running `accelerate launch`.c                    | |                      dt                    }nt          j        dt                    }|                    dd          }|                    dt          d d           |                    d	d d
           |                    dd d           |                    dd          }|                    ddd           |                    dd d           |                    dddd           |                    ddd           |                    ddd           |                    d dd!           | |                    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       S/var/www/html/ai-engine/env/lib/python3.11/site-packages/accelerate/commands/tpu.pytpu_command_parserr"      s   &&|&NN()HVbccc++[ K =	     k    
 l    
 ((:effHf    
 Y    
 I	     K    
  Z    
 ,-v     !5666M    c                    d }| j         $t          j                            t                    rut          | j                   }| j        s|j        | j        s|j        | _        | j        s|j        |j        | _        | j	        s|j	        | _	        | j
        s|j
        | _
        | j        dk    rd| _        nI| j        dk    rd| _        n6t          t          | j                  t                    rd| j         | _        | j        s| j        st          d          | j        rXt!          | j                  5 }|                                                                g| _        d d d            n# 1 swxY w Y   t          | j        d         t&                    rd | j        D             | _        d	g}| j        r|d
| j         gz  }|| j        z  }d                    |          | _        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                    |                      d S t3          j        |           t1          d           d S )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.r   c                     g | ]	}|D ]}|
S  r'   ).0cmdlines      r!   
<listcomp>z(tpu_command_launcher.<locals>.<listcomp>x   s%    EEEEEEEEEr#   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new_cmdr)   s        r!   r   r   Z   s   H #rw~~6I'J'J#()9::  	6X%:%Ft|%F ( 5D| 	- 1 =#,DL} 	.$-DM} 	.$-DM%''"U		 H	,	,"1	E$122G	<	< K"J1H"J"J cT\ cabbb 3$#$$ 	3FFHH//112DL	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 $,q/4(( FEEEEEG ><4#:<<==t|G99W%%DL *C~ y C z (#(()))N3	
#$$$$$s   7-E00E47E4c                  h    t                      } |                                 }t          |           d S N)r"   
parse_argsr   )r   rJ   s     r!   mainrQ      s2    !!FDr#   rO   )r   r4   rH   packaging.versionr   r   &accelerate.commands.config.config_argsr   r   r   r"   r   rQ   r'   r#   r!   <module>rT      s   "  				     , , , , , , , , ] ] ] ] ] ] ] ] c: : : :z<% <% <%~    r#   