import os
import sys
import unittest


__lowerCamelCase    :				List[str]							     =	os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, '''utils'''))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
__lowerCamelCase    :				Union[str, Any]							     =	os.path.join(git_repo_path, '''src''', '''transformers''')

__lowerCamelCase    :				int							     =	'''
{0} = None
'''

__lowerCamelCase    :				List[Any]							     =	'''
class {0}(metaclass=DummyObject):
    _backends = {1}

    def __init__(self, *args, **kwargs):
        requires_backends(self, {1})
'''


__lowerCamelCase    :				Union[str, Any]							     =	'''
def {0}(*args, **kwargs):
    requires_backends({0}, {1})
'''







class __snake_case       (		unittest.TestCase	):




   def 			__a		(					self    :       List[str]   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   find_backend("""    _import_structure[\"models.albert\"].append(\"AlbertTokenizerFast\")"""   )
     self.assertIsNone(_lowercase   )

     SCREAMING_SNAKE_CASE__    							=   find_backend("""    if not is_tokenizers_available():"""   )
     self.assertEqual(_lowercase ,			"""tokenizers"""   )

     SCREAMING_SNAKE_CASE__    							=   find_backend("""    if not is_tensorflow_text_available():"""   )
     self.assertEqual(_lowercase ,			"""tensorflow_text"""   )

     SCREAMING_SNAKE_CASE__    							=   find_backend("""    if not (is_sentencepiece_available() and is_tokenizers_available()):"""   )
     self.assertEqual(_lowercase ,			"""sentencepiece_and_tokenizers"""   )

     SCREAMING_SNAKE_CASE__    							=   find_backend(
         """    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"""   )
     self.assertEqual(_lowercase ,			"""sentencepiece_and_tensorflow_text"""   )

     SCREAMING_SNAKE_CASE__    							=   find_backend(
         """    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):"""   )
     self.assertEqual(_lowercase ,			"""sentencepiece_and_tokenizers_and_vision"""   )




   def 			__a		(					self    :       int   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   read_init()
     # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
     self.assertIn("""torch""" ,			_lowercase   )
     self.assertIn("""tensorflow_text""" ,			_lowercase   )
     self.assertIn("""sentencepiece_and_tokenizers""" ,			_lowercase   )

     # Likewise, we can't assert on the exact content of a key
     self.assertIn("""BertModel""" ,			objects["""torch"""]   )
     self.assertIn("""TFBertModel""" ,			objects["""tf"""]   )
     self.assertIn("""FlaxBertModel""" ,			objects["""flax"""]   )
     self.assertIn("""BertModel""" ,			objects["""torch"""]   )
     self.assertIn("""TFBertTokenizer""" ,			objects["""tensorflow_text"""]   )
     self.assertIn("""convert_slow_tokenizer""" ,			objects["""sentencepiece_and_tokenizers"""]   )




   def 			__a		(					self    :       int   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   create_dummy_object("""CONSTANT""" ,			"""'torch'"""   )
     self.assertEqual(_lowercase ,			"""\nCONSTANT = None\n"""   )

     SCREAMING_SNAKE_CASE__    							=   create_dummy_object("""function""" ,			"""'torch'"""   )
     self.assertEqual(
         _lowercase ,			"""\ndef function(*args, **kwargs):\n    requires_backends(function, 'torch')\n"""   )

     SCREAMING_SNAKE_CASE__    							=   """
class FakeClass(metaclass=DummyObject):
    _backends = 'torch'

    def __init__(self, *args, **kwargs):
        requires_backends(self, 'torch')
"""
     SCREAMING_SNAKE_CASE__    							=   create_dummy_object("""FakeClass""" ,			"""'torch'"""   )
     self.assertEqual(_lowercase ,			_lowercase   )




   def 			__a		(					self    :       str   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   """# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, [\"torch\"])


class FakeClass(metaclass=DummyObject):
    _backends = [\"torch\"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, [\"torch\"])
"""
     SCREAMING_SNAKE_CASE__    							=   create_dummy_files({"""torch""": ["""CONSTANT""", """function""", """FakeClass"""]}   )
     self.assertEqual(dummy_files["""torch"""] ,			_lowercase   )

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCamelCase    :				Optional[int]							     =	logging.get_logger(__name__)

__lowerCamelCase    :				str							     =	{
    '''facebook/nllb-moe-54B''': '''https://huggingface.co/facebook/nllb-moe-54b/resolve/main/config.json''',
}







class __snake_case       (		lowerCamelCase_	):
   lowerCAmelCase_														=							"nllb-moe"
   lowerCAmelCase_														=							["past_key_values"]
   lowerCAmelCase_														=							{"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}




   def __init__(					self    :       int ,			_lowercase    :       Tuple=12_81_12 ,			_lowercase    :       List[Any]=10_24 ,			_lowercase    :       Any=12 ,			_lowercase    :       List[Any]=40_96 ,			_lowercase    :       str=16 ,			_lowercase    :       str=12 ,			_lowercase    :       Optional[int]=40_96 ,			_lowercase    :       List[Any]=16 ,			_lowercase    :       str=0.05 ,			_lowercase    :       Tuple=0.05 ,			_lowercase    :       str=True ,			_lowercase    :       List[str]=True ,			_lowercase    :       Optional[Any]="relu" ,			_lowercase    :       str=10_24 ,			_lowercase    :       Tuple=0.1 ,			_lowercase    :       int=0.1 ,			_lowercase    :       Dict=0.0 ,			_lowercase    :       List[str]=0.02 ,			_lowercase    :       int=2 ,			_lowercase    :       Optional[Any]=True ,			_lowercase    :       List[Any]=False ,			_lowercase    :       List[str]="float32" ,			_lowercase    :       Optional[Any]=False ,			_lowercase    :       str=1_28 ,			_lowercase    :       int=64 ,			_lowercase    :       Optional[int]=4 ,			_lowercase    :       List[str]=4 ,			_lowercase    :       Union[str, Any]=0.0_01 ,			_lowercase    :       List[Any]=0.0_01 ,			_lowercase    :       List[str]="all" ,			_lowercase    :       Optional[Any]=False ,			_lowercase    :       int=False ,			_lowercase    :       Tuple=1.0 ,			_lowercase    :       Optional[int]=0.2 ,			_lowercase    :       Optional[int]=1 ,			_lowercase    :       List[Any]=0 ,			_lowercase    :       List[Any]=2 ,			_lowercase    :       int=False ,			**_lowercase    :       Union[str, Any] ,			):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   vocab_size
     SCREAMING_SNAKE_CASE__    							=   max_position_embeddings
     SCREAMING_SNAKE_CASE__    							=   d_model
     SCREAMING_SNAKE_CASE__    							=   encoder_ffn_dim
     SCREAMING_SNAKE_CASE__    							=   encoder_layers
     SCREAMING_SNAKE_CASE__    							=   encoder_attention_heads
     SCREAMING_SNAKE_CASE__    							=   decoder_ffn_dim
     SCREAMING_SNAKE_CASE__    							=   decoder_layers
     SCREAMING_SNAKE_CASE__    							=   decoder_attention_heads
     SCREAMING_SNAKE_CASE__    							=   dropout
     SCREAMING_SNAKE_CASE__    							=   attention_dropout
     SCREAMING_SNAKE_CASE__    							=   activation_dropout
     SCREAMING_SNAKE_CASE__    							=   activation_function
     SCREAMING_SNAKE_CASE__    							=   init_std
     SCREAMING_SNAKE_CASE__    							=   encoder_layerdrop
     SCREAMING_SNAKE_CASE__    							=   decoder_layerdrop
     SCREAMING_SNAKE_CASE__    							=   use_cache
     SCREAMING_SNAKE_CASE__    							=   encoder_layers
     SCREAMING_SNAKE_CASE__    							=   scale_embedding  # scale factor will be sqrt(d_model) if True
     SCREAMING_SNAKE_CASE__    							=   router_z_loss_coef
     SCREAMING_SNAKE_CASE__    							=   router_aux_loss_coef
     SCREAMING_SNAKE_CASE__    							=   decoder_sparse_step
     SCREAMING_SNAKE_CASE__    							=   encoder_sparse_step
     SCREAMING_SNAKE_CASE__    							=   num_experts
     SCREAMING_SNAKE_CASE__    							=   expert_capacity
     SCREAMING_SNAKE_CASE__    							=   router_bias
     if router_dtype not in ["float32", "float16", "bfloat16"]:
       raise ValueError(f"""`router_dtype` must be one of 'float32', 'float16' or 'bfloat16', got {router_dtype}"""   )
     SCREAMING_SNAKE_CASE__    							=   router_dtype

     SCREAMING_SNAKE_CASE__    							=   router_ignore_padding_tokens
     SCREAMING_SNAKE_CASE__    							=   batch_prioritized_routing
     SCREAMING_SNAKE_CASE__    							=   second_expert_policy
     SCREAMING_SNAKE_CASE__    							=   normalize_router_prob_before_dropping
     SCREAMING_SNAKE_CASE__    							=   moe_eval_capacity_token_fraction
     SCREAMING_SNAKE_CASE__    							=   moe_token_dropout
     SCREAMING_SNAKE_CASE__    							=   output_router_logits
     super().__init__(
         pad_token_id=_lowercase ,			bos_token_id=_lowercase ,			eos_token_id=_lowercase ,			is_encoder_decoder=_lowercase ,			decoder_start_token_id=_lowercase ,			**_lowercase ,			)
