

'''simple docstring'''





# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse

from .config import config_command_parser
from .config_args import default_config_file, load_config_from_file  # noqa: F401
from .default import default_command_parser
from .update import update_command_parser






def 				_lowerCAmelCase			(   __magic_name__						:     Any=None						)				->  Any:
						lowercase :							Union[str, Any]    		=argparse.ArgumentParser(add_help=__magic_name__   , allow_abbrev=__magic_name__						)
						# The main config parser
						lowercase :							int    		=config_command_parser(__magic_name__						)
						# The subparser to add commands to
						lowercase :							str    		=config_parser.add_subparsers(title='''subcommands'''   , dest='''subcommand'''						)

						# Then add other parsers with the parent parser
						default_command_parser(__magic_name__   , parents=[parent_parser]						)
						update_command_parser(__magic_name__   , parents=[parent_parser]						)

						return config_parser






def 				_lowerCAmelCase			(   )				->  List[str]:
						lowercase :							Dict    		=get_config_parser()
						lowercase :							str    		=config_parser.parse_args()

						if not hasattr(__magic_name__   , '''func'''						):
												config_parser.print_help()
												exit(1						)

						# Run
						args.func(__magic_name__						)


if __name__ == "__main__":
							main()








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

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






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






def 				_lowerCAmelCase			(   __magic_name__						:     Dict						)				->  List[str]:
						def replace(__magic_name__						:     Optional[int]   , __magic_name__						:     Optional[Any]						):
												for rule, replacement in rules:
																		if _match(__magic_name__   , __magic_name__						):
																								return replacement
												return val

						return replace






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





