




import re

from flax.core.frozen_dict import freeze
from flax.traverse_util import flatten_dict, unflatten_dict
from jax.experimental import PartitionSpec as P


# Sentinels
lowerCamelCase	:	Optional[int]				=   object()

# For specifying empty leaf dict `{}`
lowerCamelCase	:	Optional[int]				=   object()




def 						SCREAMING_SNAKE_CASE__ (   lowercase						,lowercase					)  ->       str:
   snake_case				:    int           =	tuple((re.compile(x + """$"""					) for x in qs)					)
   for i in range(len(lowercase					) - len(lowercase					) + 1					):
      snake_case				:    str           =	[x.match(lowercase					) for x, y in zip(lowercase						,ks[i:]					)]
      if matches and all(lowercase					):
         return True
   return False




def 						SCREAMING_SNAKE_CASE__ (   lowercase					)  ->       str:
   def replace(lowercase						,lowercase					):
      for rule, replacement in rules:
         if _match(lowercase						,lowercase					):
            return replacement
      return val

   return replace




def 						SCREAMING_SNAKE_CASE__ (   )  ->       List[str]:
   return [
       # embeddings
       (("transformer", "wpe", "embedding"), P("""mp"""						,lowercase					)),
       (("transformer", "wte", "embedding"), P("""mp"""						,lowercase					)),
       # atention
       (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(lowercase						,"""mp"""					)),
       (("attention", "out_proj", "kernel"), P("""mp"""						,lowercase					)),
       (("attention", "out_proj", "bias"), None),
       # mlp
       (("mlp", "c_fc", "kernel"), P(lowercase						,"""mp"""					)),
       (("mlp", "c_fc", "bias"), P("""mp"""					)),
       (("mlp", "c_proj", "kernel"), P("""mp"""						,lowercase					)),
       (("mlp", "c_proj", "bias"), None),
       # layer norms
       ((r"ln_\d+", "bias"), None),
       ((r"\d+", r"ln_\d+", "scale"), None),
       (("ln_f", "bias"), None),
       (("ln_f", "scale"), None),
   ]




def 						SCREAMING_SNAKE_CASE__ (   lowercase					)  ->       List[str]:
   snake_case				:    Optional[int]           =	_get_partition_rules()
   snake_case				:    Dict           =	_replacement_rules(lowercase					)
   snake_case				:    Union[str, Any]           =	{k: _unmatched for k in flatten_dict(lowercase					)}
   snake_case				:    Tuple           =	{k: replace(lowercase						,lowercase					) for k, v in initd.items()}
   assert _unmatched not in result.values(), "Incomplete partition spec."
   return freeze(unflatten_dict(lowercase					)					)











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__ (   )  ->       List[Any]:
   with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT					):
      with pytest.raises(lowercase					):
         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__ (   )  ->       Any:
   with offline(OfflineSimulationMode.CONNECTION_FAILS					):
      with pytest.raises(requests.exceptions.ConnectionError					):
         requests.request("""GET"""						,"""https://huggingface.co"""					)




def 						SCREAMING_SNAKE_CASE__ (   )  ->       int:
   with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1					):
      with pytest.raises(lowercase					):
         http_head("""https://huggingface.co"""					)





