






'''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
_A			:    Union[str, Any]					  =object()

# For specifying empty leaf dict `{}`
_A			:    Optional[int]					  =object()





def 				SCREAMING_SNAKE_CASE_ (UpperCamelCase       ,    UpperCamelCase   )   -> str:
							lowerCamelCase__      :			Union[str, Any] 						= tuple((re.compile(x + """$"""   ) for x in qs)   )
							for i in range(len(UpperCamelCase   ) - len(UpperCamelCase   ) + 1   ):
														lowerCamelCase__      :			List[Any] 						= [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   )   -> Union[str, Any]:
							def replace(UpperCamelCase       ,    UpperCamelCase   ):
														for rule, replacement in rules:
																					if _match(UpperCamelCase       ,    UpperCamelCase   ):
																												return replacement
														return val

							return replace





def 				SCREAMING_SNAKE_CASE_ ()   -> int:
							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[str]:
							lowerCamelCase__      :			Optional[int] 						= _get_partition_rules()
							lowerCamelCase__      :			Tuple 						= _replacement_rules(UpperCamelCase   )
							lowerCamelCase__      :			str 						= {k: _unmatched for k in flatten_dict(UpperCamelCase   )}
							lowerCamelCase__      :			Tuple 						= {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'''







# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team.
#
# 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.

# this script dumps information about the environment

import os
import platform
import sys


_A			:    Dict					  ='''3'''

print('''Python version:''', sys.version)

print('''OS platform:''', platform.platform())
print('''OS architecture:''', platform.machine())

try:
			import torch

			print('''Torch version:''', torch.__version__)
			print('''Cuda available:''', torch.cuda.is_available())
			print('''Cuda version:''', torch.version.cuda)
			print('''CuDNN version:''', torch.backends.cudnn.version())
			print('''Number of GPUs available:''', torch.cuda.device_count())
except ImportError:
			print('''Torch version:''', None)

try:
			import transformers

			print('''transformers version:''', transformers.__version__)
except ImportError:
			print('''transformers version:''', None)

