


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

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


def        a__     (					UpperCamelCase_						:      Optional[int],   UpperCamelCase_						:      Union[str, Any]						):
   UpperCAmelCase__	:Any      =      tuple((re.compile(x + '''$'''						) for x in qs)						)
   for i in range(len(UpperCamelCase_						) - len(UpperCamelCase_						) + 1						):
      UpperCAmelCase__	:List[str]      =      [x.match(UpperCamelCase_						) for x, y in zip(UpperCamelCase_,   ks[i:]						)]
      if matches and all(UpperCamelCase_						):
         return True
   return False


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

   return replace


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







'''simple docstring'''





from .glue import GlueDataset, GlueDataTrainingArguments
from .language_modeling import (
    LineByLineTextDataset,
    LineByLineWithRefDataset,
    LineByLineWithSOPTextDataset,
    TextDataset,
    TextDatasetForNextSentencePrediction,
)
from .squad import SquadDataset, SquadDataTrainingArguments



