a
    d                     @   s@   d dl mZ d dlmZ dgZdejee ee dddZdS )    )nn)Listpartition_modelN)modulebalancedevicesc           
      C   sz   d}d}g }|D ]^}g }t |D ]}|| |  |d7 }q |du rH|n|| }	|tj| |	 |d7 }qtj| S )a,  
    Given an :class:`nn.Sequential <torch.nn.Sequential>` module, partitions
    the model across multiple GPU devices according the provided ``balance``
    and ``devices``.

    Args:
        module (:class:`nn.Sequential <torch.nn.Sequential>`):
            Sequential model representing the pipe.
        balance (List[int]):
            List indicating the number of layers in each partition.
        devices (List[int], optional):
            List indicating the device to use for each partition. Defaults to
            ``range(len(balance))``
    r      N)rangeappendr   
Sequentialto)
r   r   r   Z
device_idxZpipe_idxZbalanced_pipeZ
num_layersZlayersiZdevice r   n/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/torch/distributed/pipeline/sync/utils.pyr      s    

)N)Ztorchr   typingr   __all__r   intr   r   r   r   r   <module>   s    