a
    d
                     @   sZ   d dl mZmZmZ d dlZd dlmZ G dd deZeee	ee f edddZ
dS )	    )DictListUnionN)Acceleratorc                   @   s   e Zd ZdZejddddZddddZee	e
eee
 f e
d	d
dZee	e
eee
 f eej d	ddZee
dddZeedddZeeddddZdS )CPUAcceleratorzAccelerator for CPU devices.N)devicereturnc                 C   s   |j dkrtd| ddS )zd
        Raises:
            ValueError:
                If the selected device is not CPU.
        cpuzDevice should be CPU, got z	 instead.N)type
ValueError)selfr    r   j/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lightning_fabric/accelerators/cpu.pysetup_device   s    
zCPUAccelerator.setup_device)r   c                 C   s   d S )Nr   )r   r   r   r   teardown!   s    zCPUAccelerator.teardown)devicesr   c                 C   s   t | } | S )z!Accelerator device parsing logic.)_parse_cpu_coresr   r   r   r   parse_devices$   s    zCPUAccelerator.parse_devicesc                 C   s   t | } tdg|  S )z*Gets parallel devices for the Accelerator.r	   )r   torchr   r   r   r   r   get_parallel_devices*   s    z#CPUAccelerator.get_parallel_devicesc                   C   s   dS )z!Get the devices when set to auto.   r   r   r   r   r   auto_device_count0   s    z CPUAccelerator.auto_device_countc                   C   s   dS )z&CPU is always available for execution.Tr   r   r   r   r   is_available5   s    zCPUAccelerator.is_available)accelerator_registryr   c                 C   s   |j d| | jjd d S )Nr	   )description)register	__class____name__)clsr   r   r   r   register_accelerators:   s
    z$CPUAccelerator.register_accelerators)r   
__module____qualname____doc__r   r   r   r   staticmethodr   intstrr   r   r   r   boolr   classmethodr   r    r   r   r   r   r      s   	 &r   )	cpu_coresr   c                 C   s<   t | tr|   rt| } t | tr0| dkr8td| S )aT  Parses the cpu_cores given in the format as accepted by the ``devices`` argument in the
    :class:`~pytorch_lightning.trainer.Trainer`.

    Args:
        cpu_cores: An int > 0.

    Returns:
        An int representing the number of processes

    Raises:
        MisconfigurationException:
            If cpu_cores is not an int > 0
    r   z>`devices` selected with `CPUAccelerator` should be an int > 0.)
isinstancer&   stripisdigitr%   	TypeError)r)   r   r   r   r   C   s
    r   )typingr   r   r   r   Z)lightning_fabric.accelerators.acceleratorr   r   r%   r&   r   r   r   r   r   <module>   s   .