



'''simple docstring'''






from __future__ import annotations

from typing import Any

class 							a__:







    def __init__(      self :  List[Any]						,			__snake_case :  Optional[int] = 6	):
      a						:					Node | None        =     None
      a						:					Node | None        =     None
      self.create_linked_list(__snake_case	)







    def 			lowercase_       (      self :  Optional[Any]						,			__snake_case :  str	):
      a						:					int        =     Node()
      a						:					Any        =     current_node
      a						:					Optional[Any]        =     current_node
      a						:					Tuple        =     current_node
      for _ in range(1						,			__snake_case	):
        a						:					List[str]        =     Node()
        a						:					List[str]        =     current_node
        a						:					List[str]        =     previous_node
        a						:					Dict        =     current_node
      a						:					int        =     self.front
      a						:					Optional[int]        =     previous_node







    def 			lowercase_       (      self :  Dict	):
      return (
          self.front == self.rear
          and self.front is not None
          and self.front.data is None
      )







    def 			lowercase_       (      self :  Tuple	):
      self.check_can_perform_operation()
      return self.front.data if self.front else None







    def 			lowercase_       (      self :  Dict						,			__snake_case :  List[str]	):
      if self.rear is None:
        return

      self.check_is_full()
      if not self.is_empty():
        a						:					int        =     self.rear.next
      if self.rear:
        a						:					Dict        =     data







    def 			lowercase_       (      self :  int	):
      self.check_can_perform_operation()
      if self.rear is None or self.front is None:
        return None
      if self.front == self.rear:
        a						:					int        =     self.front.data
        a						:					List[Any]        =     None
        return data

      a						:					Optional[Any]        =     self.front
      a						:					Dict        =     old_front.next
      a						:					Dict        =     old_front.data
      a						:					List[str]        =     None
      return data







    def 			lowercase_       (      self :  List[str]	):
      if self.is_empty():
        raise Exception('Empty Queue'	)







    def 			lowercase_       (      self :  Any	):
      if self.rear and self.rear.next == self.front:
        raise Exception('Full Queue'	)

class 							a__:







    def __init__(      self :  str	):
      a						:					Any | None        =     None
      a						:					Node | None        =     None
      a						:					Node | None        =     None


if __name__ == "__main__":
     import doctest

     doctest.testmod()




"""simple docstring"""
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    :str     =					object()

# For specifying empty leaf dict `{}`
_lowerCAmelCase    :str     =					object()





def  lowerCamelCase_						(UpperCamelCase__		:		List[str]     ,       UpperCamelCase__		:		int							):
    _UpperCAmelCase							:  Dict											=    tuple((re.compile(x + '''$'''							) for x in qs)							)
    for i in range(len(UpperCamelCase__							) - len(UpperCamelCase__							) + 1							):
        _UpperCAmelCase							:  str											=    [x.match(UpperCamelCase__							) for x, y in zip(UpperCamelCase__     ,       ks[i:]							)]
        if matches and all(UpperCamelCase__							):
            return True
    return False





def  lowerCamelCase_						(UpperCamelCase__		:		List[str]							):
    def replace(UpperCamelCase__		:		List[str]     ,       UpperCamelCase__		:		Tuple							):
        for rule, replacement in rules:
            if _match(UpperCamelCase__     ,       UpperCamelCase__							):
                return replacement
        return val

    return replace





def  lowerCamelCase_						():
    return [
        # embeddings
        (("transformer", "wpe", "embedding"), P('''mp'''     ,       UpperCamelCase__							)),
        (("transformer", "wte", "embedding"), P('''mp'''     ,       UpperCamelCase__							)),
        # atention
        (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(UpperCamelCase__     ,       '''mp'''							)),
        (("attention", "out_proj", "kernel"), P('''mp'''     ,       UpperCamelCase__							)),
        (("attention", "out_proj", "bias"), None),
        # mlp
        (("mlp", "c_fc", "kernel"), P(UpperCamelCase__     ,       '''mp'''							)),
        (("mlp", "c_fc", "bias"), P('''mp'''							)),
        (("mlp", "c_proj", "kernel"), P('''mp'''     ,       UpperCamelCase__							)),
        (("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  lowerCamelCase_						(UpperCamelCase__		:		str							):
    _UpperCAmelCase							:  List[str]											=    _get_partition_rules()
    _UpperCAmelCase							:  List[str]											=    _replacement_rules(UpperCamelCase__							)
    _UpperCAmelCase							:  List[Any]											=    {k: _unmatched for k in flatten_dict(UpperCamelCase__							)}
    _UpperCAmelCase							:  int											=    {k: replace(UpperCamelCase__     ,       UpperCamelCase__							) for k, v in initd.items()}
    assert _unmatched not in result.values(), "Incomplete partition spec."
    return freeze(unflatten_dict(UpperCamelCase__							)							)


