





'''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
_SCREAMING_SNAKE_CASE	 =							object()

# For specifying empty leaf dict `{}`
_SCREAMING_SNAKE_CASE	 =							object()


def 	__a(SCREAMING_SNAKE_CASE_  :					Any		,       SCREAMING_SNAKE_CASE_  :					List[Any]    ):



    '''simple docstring'''





    _lowerCAmelCase				=      tuple((re.compile(x + "$"    ) for x in qs)    )
    for i in range(len(SCREAMING_SNAKE_CASE_    ) - len(SCREAMING_SNAKE_CASE_    ) + 1    ):
        _lowerCAmelCase				=      [x.match(SCREAMING_SNAKE_CASE_    ) for x, y in zip(SCREAMING_SNAKE_CASE_		,       ks[i:]    )]
        if matches and all(SCREAMING_SNAKE_CASE_    ):
            return True
    return False


def 	__a(SCREAMING_SNAKE_CASE_  :					List[Any]    ):



    '''simple docstring'''





    def replace(SCREAMING_SNAKE_CASE_  :					Union[str, Any]		,       SCREAMING_SNAKE_CASE_  :					Tuple    ):
        for rule, replacement in rules:
            if _match(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    ):
                return replacement
        return val

    return replace


def 	__a():



    '''simple docstring'''





    return [
        # embeddings
        (("transformer", "wpe", "embedding"), P("mp"		,       SCREAMING_SNAKE_CASE_    )),
        (("transformer", "wte", "embedding"), P("mp"		,       SCREAMING_SNAKE_CASE_    )),
        # atention
        (("attention", "(q_proj|k_proj|v_proj)", "kernel"), P(SCREAMING_SNAKE_CASE_		,       "mp"    )),
        (("attention", "out_proj", "kernel"), P("mp"		,       SCREAMING_SNAKE_CASE_    )),
        (("attention", "out_proj", "bias"), None),
        # mlp
        (("mlp", "c_fc", "kernel"), P(SCREAMING_SNAKE_CASE_		,       "mp"    )),
        (("mlp", "c_fc", "bias"), P("mp"    )),
        (("mlp", "c_proj", "kernel"), P("mp"		,       SCREAMING_SNAKE_CASE_    )),
        (("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 	__a(SCREAMING_SNAKE_CASE_  :					Dict    ):



    '''simple docstring'''





    _lowerCAmelCase				=      _get_partition_rules()
    _lowerCAmelCase				=      _replacement_rules(SCREAMING_SNAKE_CASE_    )
    _lowerCAmelCase				=      {k: _unmatched for k in flatten_dict(SCREAMING_SNAKE_CASE_    )}
    _lowerCAmelCase				=      {k: replace(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    ) for k, v in initd.items()}
    assert _unmatched not in result.values(), "Incomplete partition spec."
    return freeze(unflatten_dict(SCREAMING_SNAKE_CASE_    )    )









'''simple docstring'''


def 	__a(SCREAMING_SNAKE_CASE_  :					int    ):



    '''simple docstring'''





    if not isinstance(SCREAMING_SNAKE_CASE_		,       SCREAMING_SNAKE_CASE_    ):
        raise TypeError("Input value must be an 'int' type"    )

    _lowerCAmelCase				=      0
    while number:
        position += 1
        number >>= 1

    return position


if __name__ == "__main__":
       import doctest

       doctest.testmod()


