
    g                         d dl mZ d Zd ZdS )    )ceilc                 p   t          t          d|                    d t          |                                           D             g }D ]4}                    |          dk    r||vr|                    |           5fdD             }fdD             }t          |          dk    rt          dt          |          z             t          |          dk    rt          dt          |          z             t          |          dk    rt          dt          |          z             d S )	Nr   c                     g | ]	}|D ]}|
S  r   ).0sublistitems      c/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/utils/model_parallel_utils.py
<listcomp>z%assert_device_map.<locals>.<listcomp>   s&    [[['SZ[[4[[[[       c                     g | ]}|v|	S r   r   )r   idevice_map_blockss     r
   r   z%assert_device_map.<locals>.<listcomp>   s$    FFFA14E+E+Ea+E+E+Er   c                     g | ]}|v|	S r   r   )r   r   blockss     r
   r   z%assert_device_map.<locals>.<listcomp>   s    DDD!AVOOAOOOr   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)
device_map
num_blocksduplicate_blocksr   missing_blocksextra_blocksr   r   s         @@r
   assert_device_mapr       s   %:&&''F[[T*2C2C2E2E-F-F[[[  ' '""1%%))a7G.G.G##A&&&FFFFFFFNDDDD0DDDL
!!FHKL\H]H]^
 
 	
 >a57:>7J7JK
 
 	
 <Ar, 
 
 	
 r   c                    t          t          |                     t          t          | t	          |          z                      fdt          d|           D             }t          t          ||                    S )zEReturns a dictionary of layers distributed evenly across all devices.c                 *    g | ]}||z            S r   r   )r   r   layersn_blockss     r
   r   z"get_device_map.<locals>.<listcomp>6   s'    RRR6!a(l*+RRRr   r   )r   r   intr   r   dictzip)n_layersdeviceslayers_listr#   r$   s      @@r
   get_device_mapr+   2   sw    %//""F43w<</0011HRRRRRU1h5Q5QRRRKG[))***r   N)mathr   r    r+   r   r   r
   <module>r-      sA          
 
 
>+ + + + +r   