





from math import ceil

def     a_       (					lowerCAmelCase_ :     Tuple,      lowerCAmelCase_ :     Dict      ):
   __lowerCAmelCase				      =      list(range(0,      lowerCAmelCase_      )      )

   __lowerCAmelCase				      =      [item for sublist in list(device_map.values()      ) for item in sublist]

   # Duplicate check
   __lowerCAmelCase				      =      []
   for i in device_map_blocks:
      if device_map_blocks.count(lowerCAmelCase_      ) > 1 and i not in duplicate_blocks:
         duplicate_blocks.append(lowerCAmelCase_      )
    # Missing blocks
   __lowerCAmelCase				      =      [i for i in blocks if i not in device_map_blocks]
   __lowerCAmelCase				      =      [i for i in device_map_blocks if i not in blocks]

   if len(lowerCAmelCase_      ) != 0:
      raise ValueError(
          'Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device.'
          ' These attention blocks were specified more than once: ' + str(lowerCAmelCase_      )      )
   if len(lowerCAmelCase_      ) != 0:
      raise ValueError(
          'There 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: ' + str(lowerCAmelCase_      )      )
   if len(lowerCAmelCase_      ) != 0:
      raise ValueError(
          'The device_map contains more attention blocks than this model has. Remove these from the device_map:'
          + str(lowerCAmelCase_      )      )




def     a_       (					lowerCAmelCase_ :     int,      lowerCAmelCase_ :     Union[str, Any]      ):
   __lowerCAmelCase				      =      list(range(lowerCAmelCase_      )      )
   __lowerCAmelCase				      =      int(ceil(n_layers / len(lowerCAmelCase_      )      )      )
   __lowerCAmelCase				      =      [layers[i : i + n_blocks] for i in range(0,      lowerCAmelCase_,      lowerCAmelCase_      )]

   return dict(zip(lowerCAmelCase_,      lowerCAmelCase_      )      )


'''simple docstring'''






import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline





@pytest.mark.integration
def  _SCREAMING_SNAKE_CASE		(      ):
     with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT				):
          with pytest.raises(__snake_case				):
               requests.request('GET'   ,		'https://huggingface.co'				)
          with pytest.raises(requests.exceptions.ConnectTimeout				):
               requests.request('GET'   ,		'https://huggingface.co'   ,		timeout=1.0				)





@pytest.mark.integration
def  _SCREAMING_SNAKE_CASE		(      ):
     with offline(OfflineSimulationMode.CONNECTION_FAILS				):
          with pytest.raises(requests.exceptions.ConnectionError				):
               requests.request('GET'   ,		'https://huggingface.co'				)





def  _SCREAMING_SNAKE_CASE		(      ):
     with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1				):
          with pytest.raises(__snake_case				):
               http_head('https://huggingface.co'				)



