U
    0-e                     @   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 k	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 k	r|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)Z
subparsersparserZconfig_argsZpod_args r   X/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/accelerate/commands/tpu.pytpu_command_parser   st       r   c                 C   s  d }| j d k	stjtrvt| j }| jsB|jd k	rB| jsB|j| _| jsZ|jd k	rZ|j| _| j	sh|j	| _	| j
sv|j
| _
| jdkrd| _n0| jdkrd| _ntt| jtrd| j | _| js| jstd| jrt| jd}|  g| _W 5 Q R X t| jd trd	d
 | jD | _dg}| jr>|d| j g7 }|| j7 }d|| _dg}| jrl|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; ZgcloudalphaZcomputeZtpusztpu-vmsshz--zoner   z--workerallzRunning  zSuccessfully setup pod.)config_fileospathisfiler   r   Zcommand_filecommandcommandsZtpu_nameZtpu_zoneZaccelerate_version
isinstancer   r   
ValueErroropenread
splitlineslistZinstall_acceleratejoinZ	use_alphadebugprint
subprocessrun)argsdefaultsfZnew_cmdr"   r   r   r   r   Z   sd    





r   c                  C   s   t  } |  }t| d S )N)r   
parse_argsr   )r   r:   r   r   r   main   s    r>   )N)r   r*   r8   Zpackaging.versionr   r   Z&accelerate.commands.config.config_argsr   r   r   r   r   r>   r   r   r   r   <module>   s   
=?