o
    Zh                     @   s    d dl mZ dd Zdd ZdS )    )ceilc                    s   t td| dd t |  D g }D ]}|dkr(||vr(|| qfdd D } fddD }t|dkrItdt| t|dkrWtdt| t|dkretd	t| d S )
Nr   c                 S   s   g | ]	}|D ]}|qqS  r   ).0Zsublistitemr   r   V/var/www/auris/lib/python3.10/site-packages/transformers/utils/model_parallel_utils.py
<listcomp>   s    z%assert_device_map.<locals>.<listcomp>   c                       g | ]}| vr|qS r   r   r   i)device_map_blocksr   r   r          c                    r	   r   r   r
   )blocksr   r   r      r   zDuplicate attention blocks specified in device_map. Attention blocks must be specified to one device. These attention blocks were specified more than once: zThere are attention blocks for this model that are not specified in the device_map. Add these attention blocks to a device on the device_map: zdThe device_map contains more attention blocks than this model has. Remove these from the device_map:)listrangevaluescountappendlen
ValueErrorstr)Z
device_mapZ
num_blocksZduplicate_blocksr   Zmissing_blocksZextra_blocksr   )r   r   r   assert_device_map   s8   
r   c                    sJ   t t|  tt| t|  fddtd| D }tt||S )zEReturns a dictionary of layers distributed evenly across all devices.c                    s   g | ]
} ||  qS r   r   r
   ZlayersZn_blocksr   r   r   5   s    z"get_device_map.<locals>.<listcomp>r   )r   r   intr   r   dictzip)Zn_layersZdevicesZlayers_listr   r   r   get_device_map1   s   r   N)mathr   r   r   r   r   r   r   <module>   s   