




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
lowercase__				:      Tuple	   = object()

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

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

def  SCREAMING_SNAKE_CASE							(       __UpperCamelCase)      ->					Tuple:
     def replace(__UpperCamelCase		, __UpperCamelCase):
          for rule, replacement in rules:
               if _match(__UpperCamelCase		, __UpperCamelCase):
                    return replacement
          return val

     return replace

def  SCREAMING_SNAKE_CASE							(       )      ->					Union[str, Any]:
     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  SCREAMING_SNAKE_CASE							(       __UpperCamelCase)      ->					List[Any]:
     a     =				_get_partition_rules()
     a     =				_replacement_rules(__UpperCamelCase)
     a     =				{k: _unmatched for k in flatten_dict(__UpperCamelCase)}
     a     =				{k: replace(__UpperCamelCase		, __UpperCamelCase) for k, v in initd.items()}
     assert _unmatched not in result.values(), "Incomplete partition spec."
     return freeze(unflatten_dict(__UpperCamelCase))







import math
import sys

def  SCREAMING_SNAKE_CASE							(       __UpperCamelCase)      ->					int:
     if number != int(__UpperCamelCase):
          raise ValueError("the value of input must be a natural number")
     if number < 0:
          raise ValueError("the value of input must not be a negative number")
     if number == 0:
          return 1
     a     =				[-1] * (number + 1)
     a     =				0
     for i in range(1		, number + 1):
          a     =				sys.maxsize
          a     =				int(math.sqrt(__UpperCamelCase))
          for j in range(1		, root + 1):
               a     =				1 + answers[i - (j**2)]
               a     =				min(__UpperCamelCase		, __UpperCamelCase)
          a     =				answer
     return answers[number]


if __name__ == "__main__":
   import doctest

   doctest.testmod()

