a
    Ad                     @   s~   d dl Z d dlZd dlZg Zdd ZddeeddddZd	d
 Zdde	dddZ
i Ze	dddZdd Zdd ZdS )    Nc                  C   sf   t  \} }}|d u rd S tr.td |kr.d S ddlm} t||| ttdkrbtd d S )Nr   )sysinfo   )	sysexc_infoexception_recordsmodulesr   appendformat_exceptionlenpop)_etbr    r   6/var/www/html/stable-diffusion-webui/modules/errors.pyrecord_exception	   s    r   F)r   )messager   returnc                C   sT   t   |  D ]}td|tjd q|rPttt dtjd tdtjd dS )zD
    Print an error message to stderr, with optional traceback.
    z***filez    z---N)	r   
splitlinesprintr   stderrtextwrapindent	traceback
format_exc)r   r   liner   r   r   report   s    r   c                 C   sf   t   |  d}tdd |D }td| tjd |D ]}t|tjd q<td| tjd d S )N
c                 S   s   g | ]}t |qS r   )r   ).0xr   r   r   
<listcomp>*       z+print_error_explanation.<locals>.<listcomp>=r   )r   stripsplitmaxr   r   r   )r   linesZmax_lenr   r   r   r   print_error_explanation&   s    r*   )full_traceback)r   c                C   s   t   t|pd dt| j tjd tj| }|rVt	t
 d d |j |_t| dtjd t| }d|v rtd d S )	Nerrorz: r    )sepr   zxcopying a param with shape torch.Size([640, 1024]) from checkpoint, the shape in current model is torch.Size([640, 768])z
The most likely cause of this is you are trying to load Stable Diffusion 2.0 model without specifying its config file.
See https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#stable-diffusion-20 for how to solve this.
        )r   r   type__name__r   r   r   TracebackExceptionfrom_exceptionStackSummaryextract_stackstackformatstrr*   )r   taskr+   ter   r   r   r   display2   s    "r;   c                 C   s(   t   |tv rd S t| | dt|< d S )N   )r   already_displayedr;   )r   r9   r   r   r   display_onceG   s
    
r>   c              
   C   s>   z
|   W n. t y8 } zt|| W Y d }~n
d }~0 0 d S )N)	Exceptionr;   )coder9   r   r   r   r   runR   s    
rA   c                  C   s   ddl m}  ddlm} dd l}dd l}d}d}d}| |j| |k rftd|j d| d		  |j
rdd l}| |j| |k rtd
|j d| d	  |j|krtd|j d| d	  d S )Nr   )version)sharedz2.0.0z0.0.20z3.41.2z
You are running torch z+.
The program is tested to work with torch a2  .
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.

Use --skip-version-check commandline argument to disable this check.
        z
You are running xformers z..
The program is tested to work with xformers z.
To reinstall the desired version, run with commandline flag --reinstall-xformers.

Use --skip-version-check commandline argument to disable this check.
            z
You are running gradio z..
The program is designed to work with gradio av  .
Using a different version of gradio is extremely likely to break the program.

Reasons why you have the mismatched gradio version can be:
  - you use --skip-install flag.
  - you use webui.py to start the program instead of launch.py.
  - an extension installs the incompatible gradio version.

Use --skip-version-check commandline argument to disable this check.
        )	packagingrB   r   rC   torchgradioparse__version__r*   r&   Zxformers_availablexformers)rB   rC   rE   rF   Zexpected_torch_versionZexpected_xformers_versionZexpected_gradio_versionrI   r   r   r   check_versionsY   s6    

rJ   )r   r   r   r   r   r8   boolr   r*   r?   r;   r=   r>   rA   rJ   r   r   r   r   <module>   s   