





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


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

__A    :   Tuple          =       {
    "facebook/opt-125m": "https://huggingface.co/facebook/opt-125m/blob/main/config.json",
    "facebook/opt-350m": "https://huggingface.co/facebook/opt-350m/blob/main/config.json",
    "facebook/opt-1.3b": "https://huggingface.co/facebook/opt-1.3b/blob/main/config.json",
    "facebook/opt-2.7b": "https://huggingface.co/facebook/opt-2.7b/blob/main/config.json",
    "facebook/opt-6.7b": "https://huggingface.co/facebook/opt-6.7b/blob/main/config.json",
    "facebook/opt-13b": "https://huggingface.co/facebook/opt-13b/blob/main/config.json",
}

class      A_	(a_      ):
	UpperCAmelCase__ =      '''opt'''
	UpperCAmelCase__ =      ['''past_key_values''']
	def __init__(   self							, _A=5_0_2_7_2							, _A=7_6_8							, _A=1_2							, _A=3_0_7_2							, _A=2_0_4_8							, _A=True							, _A=False							, _A=None							, _A=0.1							, _A=0.0							, _A=1_2							, _A="relu"							, _A=0.0							, _A=0.02							, _A=True							, _A=1							, _A=2							, _A=2							, _A=True							, _A=True							, **_A							, ):






						'''simple docstring'''







						super().__init__(
						    pad_token_id=_A							, bos_token_id=_A							, eos_token_id=_A							, **_A							, )
						UpperCAmelCase       		=    vocab_size
						UpperCAmelCase       		=    max_position_embeddings
						UpperCAmelCase       		=    num_attention_heads
						UpperCAmelCase       		=    word_embed_proj_dim if word_embed_proj_dim is not None else hidden_size
						UpperCAmelCase       		=    ffn_dim
						UpperCAmelCase       		=    hidden_size
						UpperCAmelCase       		=    num_hidden_layers
						UpperCAmelCase       		=    dropout
						UpperCAmelCase       		=    attention_dropout
						UpperCAmelCase       		=    activation_function
						UpperCAmelCase       		=    init_std
						UpperCAmelCase       		=    layerdrop
						UpperCAmelCase       		=    use_cache
						UpperCAmelCase       		=    do_layer_norm_before
						# We keep these variables at `True` for backward compatibility.
						UpperCAmelCase       		=    enable_bias
						UpperCAmelCase       		=    layer_norm_elementwise_affine

						# Note that the only purpose of `_remove_final_layer_norm` is to keep backward compatibility
						# with checkpoints that have been fine-tuned before transformers v4.20.1
						# see https://github.com/facebookresearch/metaseq/pull/164
						UpperCAmelCase       		=    _remove_final_layer_norm










import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard

class      A_	(unittest.TestCase      ):
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    {
				    '''model_details''': {
				        '''Organization''': '''testing''',
				        '''Model date''': '''today''',
				        '''Model version''': '''v2.1, Developed by Test Corp in 2019.''',
				        '''Architecture''': '''Convolutional Neural Network.''',
				    },
				    '''metrics''': '''BLEU and ROUGE-1''',
				    '''evaluation_data''': {
				        '''Datasets''': {'''BLEU''': '''My-great-dataset-v1''', '''ROUGE-1''': '''My-short-dataset-v2.1'''},
				        '''Preprocessing''': '''See details on https://arxiv.org/pdf/1810.03993.pdf''',
				    },
				    '''training_data''': {
				        '''Dataset''': '''English Wikipedia dump dated 2018-12-01''',
				        '''Preprocessing''': (
				            '''Using SentencePiece vocabulary of size 52k tokens. See details on'''
				            ''' https://arxiv.org/pdf/1810.03993.pdf'''
				        ),
				    },
				    '''quantitative_analyses''': {'''BLEU''': 55.1, '''ROUGE-1''': 7_6},
				}
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)
				self.assertTrue(hasattr(_A							, '''model_details'''		)		)
				self.assertTrue(hasattr(_A							, '''intended_use'''		)		)
				self.assertTrue(hasattr(_A							, '''factors'''		)		)
				self.assertTrue(hasattr(_A							, '''metrics'''		)		)
				self.assertTrue(hasattr(_A							, '''evaluation_data'''		)		)
				self.assertTrue(hasattr(_A							, '''training_data'''		)		)
				self.assertTrue(hasattr(_A							, '''quantitative_analyses'''		)		)
				self.assertTrue(hasattr(_A							, '''ethical_considerations'''		)		)
				self.assertTrue(hasattr(_A							, '''caveats_and_recommendations'''		)		)
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)
				UpperCAmelCase       		=    json.loads(modelcard.to_json_string()		)
				for key, value in self.inputs_dict.items():
							self.assertEqual(obj[key]							, _A		)
	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)

				with tempfile.TemporaryDirectory() as tmpdirname:
							UpperCAmelCase       		=    os.path.join(_A							, '''modelcard.json'''		)
							model_card_first.to_json_file(_A		)
							UpperCAmelCase       		=    ModelCard.from_json_file(_A		)

				self.assertEqual(model_card_second.to_dict()							, model_card_first.to_dict()		)







	def 					_lowercase    (   self		):






				'''simple docstring'''







				UpperCAmelCase       		=    ModelCard.from_dict(self.inputs_dict		)

				with tempfile.TemporaryDirectory() as tmpdirname:
							model_card_first.save_pretrained(_A		)
							UpperCAmelCase       		=    ModelCard.from_pretrained(_A		)

				self.assertEqual(model_card_second.to_dict()							, model_card_first.to_dict()		)



