o
    h                     @   sZ   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dZ
dd Zd	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                 C   s   | d ur| j dtd}ntjdtd}|dd}|jdtd dd |jd	d d
d |jdd dd |dd}|jdddd |jdd dd |jddddd |jdddd |jdddd |jd dd!d | d urs|jtd" |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_args r   M/var/www/html/ai/venv/lib/python3.10/site-packages/accelerate/commands/tpu.pytpu_command_parser   sn   r!   c                 C   s  d }| j d ustjtr;t| j }| js!|jd ur!| js!|j| _| js-|jd ur-|j| _| j	s4|j	| _	| j
s;|j
| _
| jdkrDd| _n| jdkrMd| _ntt| jtr\d| j | _| jsf| jsftd| jrt| jd}|  g| _W d    n1 sw   Y  t| jd trd	d
 | jD | _dg}| jr|d| j g7 }|| j7 }d|| _dg}| jr|dg7 }|dddd| j	d| j
d| jddg7 }| jrtdd|  d S t| t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.rr   c                 S   s   g | ]	}|D ]}|qqS r   r   ).0cmdliner   r   r    
<listcomp>x   s    z(tpu_command_launcher.<locals>.<listcomp>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%   r   r   r    r   Z   sf   





r   c                  C   s   t  } |  }t| d S N)r!   
parse_argsr   )r   rF   r   r   r    main   s   rL   rJ   )r   r0   rD   packaging.versionr   r   &accelerate.commands.config.config_argsr   r   r   r!   r   rL   r   r   r   r    <module>   s   
=?