a
    d?                     @   sJ   d dl Z d dlmZ d dlmZ deeeedddZee	dd	d
Z
dS )    N)Any)_get_device_indexF)deviceoptional	allow_cpureturnc                 C   s   t | tr| S t | tr"t| } t | tjrd|rL| jdvrdtd| n| jdkrdtd| tj	 st | tj
jr| jS t| ||S )a  Gets the device index from :attr:`device`, which can be a torch.device
    object, a Python integer, or ``None``.

    If :attr:`device` is a torch.device object, returns the device index if it
    is a CUDA device. Note that for a CUDA device without a specified index,
    i.e., ``torch.device('cuda')``, this will return the current default CUDA
    device if :attr:`optional` is ``True``. If :attr:`allow_cpu` is ``True``,
    CPU devices will be accepted and ``-1`` will be returned in this case.

    If :attr:`device` is a Python integer, it is returned as is.

    If :attr:`device` is ``None``, this will return the current default CUDA
    device if :attr:`optional` is ``True``.
    )cudacpuz*Expected a cuda or cpu device, but got: {}r   z#Expected a cuda device, but got: {})
isinstanceintstrtorchr   type
ValueErrorformatZjitZis_scriptingr   idx_torch_get_device_index)r   r   r    r   Z/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torch/cuda/_utils.pyr      s    





r   )namer   c                 C   s*   t ddd}t| tf|d|ddS )Nis_initc                    s    fdd}|S )Nc                    s&    r| j j}n| j}td|d S )Nz(Tried to instantiate dummy base class {})	__class____name__RuntimeErrorr   )objargskwargs
class_namer   r   r   err_fn)   s    
z/_dummy_type.<locals>.get_err_fn.<locals>.err_fnr   )r   r   r   r   r   
get_err_fn(   s    z_dummy_type.<locals>.get_err_fnTF)__init____new__)boolr   object)r   r    r   r   r   _dummy_type'   s    	r%   )FF)r   typingr   Ztorch._utilsr   r   r#   r   r   r   r%   r   r   r   r   <module>   s      