U
    Å9%e®  ã                   @   sH   d dl mZ d dlmZmZ dgZdejee eee  dœdd„ZdS )é    )Únn)ÚListÚOptionalÚpartition_modelN)ÚmoduleÚbalanceÚdevicesc           
      C   sz   d}d}g }|D ]^}g }t |ƒD ]}| | | ¡ |d7 }q |dk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   úd/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/torch/distributed/pipeline/sync/utils.pyr      s    

)N)	Ztorchr   Útypingr   r   Ú__all__r   Úintr   r   r   r   r   Ú<module>   s    ý
ý