o
    ÚÜÓh®  ã                	   @   sN   d dl mZ d dlmZmZ dgZ	d	dejdee deee  f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u r$|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   Ú
device_idxÚpipe_idxÚbalanced_pipeÚ
num_layersÚlayersÚiÚdevice© r   ú[/var/www/html/ai/venv/lib/python3.10/site-packages/torch/distributed/pipeline/sync/utils.pyr      s   


)N)	Útorchr   Útypingr   r   Ú__all__r   Úintr   r   r   r   r   Ú<module>   s    ýÿþ
ý