a
    d                     @   s   d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlZd dlmZ d dlmZmZ eeZeddd	d
ZddddZedkre  dS )    N)ArgumentParser	NamespacePath)copyfile)List)tqdm)migrate_checkpointpl_legacy_patch)argsreturnc              	   C   s\  t | j }| jdr | jn
d| j }g }| sXtd| d| d td |	 rf|g}|
 rdd tjt|d d|  d	d
D }|std| d| d td td |D ]"}|d}| rqt|| qtd t|D ]L}t  t|}W d    n1 s,0    Y  t| t|| q td d S )N.z	The path zr does not exist. Please provide a valid path to a checkpoint file or a directory containing checkpoints ending in    c                 S   s   g | ]}t |qS  r   ).0pr   r   w/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pytorch_lightning/utilities/upgrade_checkpoint.py
<listcomp>,       z_upgrade.<locals>.<listcomp>z***T)	recursivez#No checkpoint files with extension z were found in z]. HINT: Try setting the `--extension` option to specify the right file extension to look for.z]Creating a backup of the existing checkpoint files before overwriting in the upgrade process.z.bakzUpgrading checkpoints ...zDone.)r   pathabsolute	extension
startswithexists_logerrorexitis_fileis_dirglobstrinfowith_suffixr   r   r
   torchloadr	   save)r   r   r   filesfileZbackup_file
checkpointr   r   r   _upgrade   s@    *


*r+   )r   c                  C   sB   t dd} | jdtdd | jddtdd	d
 |  }t| d S )NzA utility to upgrade old checkpoints to the format of the current Lightning version. This will also save a backup of the original files.)descriptionr   zDPath to a checkpoint file or a directory with checkpoints to upgrade)typehelpz--extensionz-ez.ckptzRThe file extension to look for when searching for checkpoint files in a directory.)r-   defaultr.   )r   add_argumentr"   
parse_argsr+   )parserr   r   r   r   mainF   s    r3   __main__)r!   loggingargparser   r   pathlibr   shutilr   typingr   r%   r   Z%pytorch_lightning.utilities.migrationr	   r
   	getLogger__name__r   r+   r3   r   r   r   r   <module>   s   
)