






"""simple docstring"""







from __future__ import annotations

import unittest

from transformers import OpenAIGPTConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers.models.openai.modeling_tf_openai import (
	    TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
	    TFOpenAIGPTDoubleHeadsModel,
	    TFOpenAIGPTForSequenceClassification,
	    TFOpenAIGPTLMHeadModel,
	    TFOpenAIGPTModel,
	)







class 							_SCREAMING_SNAKE_CASE    :





							"""simple docstring"""





							def __init__( self:  Any					,		__A:  List[str]					,		):

												'''simple docstring'''

												a__ 							=	parent
												a__ 							=	13
												a__ 							=	7
												a__ 							=	True
												a__ 							=	True
												a__ 							=	True
												a__ 							=	True
												a__ 							=	True
												a__ 							=	99
												a__ 							=	32
												a__ 							=	2
												a__ 							=	4
												a__ 							=	37
												a__ 							=	'''gelu'''
												a__ 							=	0.1
												a__ 							=	0.1
												a__ 							=	512
												a__ 							=	16
												a__ 							=	2
												a__ 							=	0.0_2
												a__ 							=	3
												a__ 							=	4
												a__ 							=	None
												a__ 							=	self.vocab_size - 1




							def 			lowercase		( self:  Dict     ):

												'''simple docstring'''

												a__ 							=	ids_tensor([self.batch_size, self.seq_length]					,		self.vocab_size     )

												a__ 							=	None
												if self.use_input_mask:
																	a__ 							=	random_attention_mask([self.batch_size, self.seq_length]     )

												a__ 							=	None
												if self.use_token_type_ids:
																	a__ 							=	ids_tensor([self.batch_size, self.seq_length]					,		self.type_vocab_size     )

												a__ 							=	None
												if self.use_mc_token_ids:
																	a__ 							=	ids_tensor([self.batch_size, self.num_choices]					,		self.seq_length     )

												a__ 							=	None
												a__ 							=	None
												a__ 							=	None
												if self.use_labels:
																	a__ 							=	ids_tensor([self.batch_size]					,		self.type_sequence_label_size     )
																	a__ 							=	ids_tensor([self.batch_size, self.seq_length]					,		self.num_labels     )
																	a__ 							=	ids_tensor([self.batch_size]					,		self.num_choices     )

												a__ 							=	OpenAIGPTConfig(
												    vocab_size=self.vocab_size					,		n_embd=self.hidden_size					,		n_layer=self.num_hidden_layers					,		n_head=self.num_attention_heads					,		n_positions=self.max_position_embeddings					,		pad_token_id=self.pad_token_id					,		)

												a__ 							=	ids_tensor([self.num_hidden_layers, self.num_attention_heads]					,		2     )

												return (
												    config,
												    input_ids,
												    input_mask,
												    head_mask,
												    token_type_ids,
												    mc_token_ids,
												    sequence_labels,
												    token_labels,
												    choice_labels,
												)




							def 			lowercase		( self:  Optional[Any]					,		__A:  List[Any]					,		__A:  List[Any]					,		__A:  List[str]					,		__A:  Any					,		__A:  int					,		*__A:  Tuple     ):

												'''simple docstring'''

												a__ 							=	TFOpenAIGPTModel(config=__A     )
												a__ 							=	{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
												a__ 							=	model(__A     )

												a__ 							=	[input_ids, input_mask]
												a__ 							=	model(__A     )

												a__ 							=	model(__A     )

												self.parent.assertEqual(result.last_hidden_state.shape					,		(self.batch_size, self.seq_length, self.hidden_size)     )




							def 			lowercase		( self:  Optional[int]					,		__A:  Tuple					,		__A:  Dict					,		__A:  Optional[int]					,		__A:  Union[str, Any]					,		__A:  int					,		*__A:  Dict     ):

												'''simple docstring'''

												a__ 							=	TFOpenAIGPTLMHeadModel(config=__A     )
												a__ 							=	{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
												a__ 							=	model(__A     )
												self.parent.assertEqual(result.logits.shape					,		(self.batch_size, self.seq_length, self.vocab_size)     )




							def 			lowercase		( self:  int					,		__A:  int					,		__A:  List[Any]					,		__A:  Optional[int]					,		__A:  List[Any]					,		__A:  List[str]					,		__A:  Optional[int]					,		*__A:  List[str]     ):

												'''simple docstring'''

												a__ 							=	TFOpenAIGPTDoubleHeadsModel(config=__A     )

												a__ 							=	tf.tile(tf.expand_dims(__A					,		1     )					,		(1, self.num_choices, 1)     )
												a__ 							=	tf.tile(tf.expand_dims(__A					,		1     )					,		(1, self.num_choices, 1)     )
												a__ 							=	tf.tile(tf.expand_dims(__A					,		1     )					,		(1, self.num_choices, 1)     )

												a__ 							=	{
												    '''input_ids''': multiple_choice_inputs_ids,
												    '''mc_token_ids''': mc_token_ids,
												    '''attention_mask''': multiple_choice_input_mask,
												    '''token_type_ids''': multiple_choice_token_type_ids,
												}
												a__ 							=	model(__A     )
												self.parent.assertEqual(
												    result.logits.shape					,		(self.batch_size, self.num_choices, self.seq_length, self.vocab_size)     )
												self.parent.assertEqual(result.mc_logits.shape					,		(self.batch_size, self.num_choices)     )




							def 			lowercase		( self:  Optional[int]					,		__A:  List[str]					,		__A:  Dict					,		__A:  List[Any]					,		__A:  Union[str, Any]					,		__A:  Any					,		*__A:  str     ):

												'''simple docstring'''

												a__ 							=	self.num_labels
												a__ 							=	ids_tensor([self.batch_size]					,		self.type_sequence_label_size     )
												a__ 							=	{
												    '''input_ids''': input_ids,
												    '''attention_mask''': input_mask,
												    '''token_type_ids''': token_type_ids,
												    '''labels''': sequence_labels,
												}
												a__ 							=	TFOpenAIGPTForSequenceClassification(__A     )
												a__ 							=	model(__A     )
												self.parent.assertEqual(result.logits.shape					,		(self.batch_size, self.num_labels)     )





							def 			lowercase		( self:  Optional[Any]     ):

												'''simple docstring'''

												a__ 							=	self.prepare_config_and_inputs()

												(
												    (
												    a__
												)							,(
												    a__
												)							,(
												    a__
												)							,(
												    a__
												)							,(
												    a__
												)							,(
												    a__
												)							,(
												    a__
												)							,(
												    a__
												)							,(
												    a__
												)							,
												) 							=	config_and_inputs

												a__ 							=	{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
												return config, inputs_dict







@require_tf
class 							_SCREAMING_SNAKE_CASE    (	__snake_case							,			__snake_case							,			unittest.TestCase				):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE     =(
							    (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
							    if is_tf_available()
							    else ()
							)
							_SCREAMING_SNAKE_CASE     =(
							    (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
							)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
							_SCREAMING_SNAKE_CASE     =(
							    {
							        'feature-extraction': TFOpenAIGPTModel,
							        'text-classification': TFOpenAIGPTForSequenceClassification,
							        'text-generation': TFOpenAIGPTLMHeadModel,
							        'zero-shot': TFOpenAIGPTForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							_SCREAMING_SNAKE_CASE     =False
							_SCREAMING_SNAKE_CASE     =False




							def 			lowercase		( self:  Dict					,		__A:  str					,		__A:  Optional[Any]					,		__A:  List[Any]					,		__A:  int					,		__A:  Tuple     ):

												'''simple docstring'''

												if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
																	# Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
																	# `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
																	# tiny config could not be created.
																	return True

												return False




							def 			lowercase		( self:  List[Any]     ):

												'''simple docstring'''

												a__ 							=	TFOpenAIGPTModelTester(self     )
												a__ 							=	ConfigTester(self					,		config_class=__A					,		n_embd=37     )




							def 			lowercase		( self:  Tuple     ):

												'''simple docstring'''

												self.config_tester.run_common_tests()




							def 			lowercase		( self:  str     ):

												'''simple docstring'''

												a__ 							=	self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_openai_gpt_model(*__A     )




							def 			lowercase		( self:  Optional[Any]     ):

												'''simple docstring'''

												a__ 							=	self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_openai_gpt_lm_head(*__A     )




							def 			lowercase		( self:  str     ):

												'''simple docstring'''

												a__ 							=	self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_openai_gpt_double_head(*__A     )




							def 			lowercase		( self:  Dict     ):

												'''simple docstring'''

												a__ 							=	self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*__A     )





							@slow
							def 			lowercase		( self:  int     ):

												'''simple docstring'''

												for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	a__ 							=	TFOpenAIGPTModel.from_pretrained(__A     )
																	self.assertIsNotNone(__A     )







@require_tf
class 							_SCREAMING_SNAKE_CASE    (	unittest.TestCase				):





							"""simple docstring"""





							@slow
							def 			lowercase		( self:  List[str]     ):

												'''simple docstring'''

												a__ 							=	TFOpenAIGPTLMHeadModel.from_pretrained('''openai-gpt'''     )
												a__ 							=	tf.convert_to_tensor([[481, 4735, 544]]					,		dtype=tf.intaa     )  # the president is
												a__ 							=	[
												    481,
												    4735,
												    544,
												    246,
												    963,
												    870,
												    762,
												    239,
												    244,
												    40477,
												    244,
												    249,
												    719,
												    881,
												    487,
												    544,
												    240,
												    244,
												    603,
												    481,
												]  # the president is a very good man. " \n " i\'m sure he is, " said the

												a__ 							=	model.generate(__A					,		do_sample=__A     )
												self.assertListEqual(output_ids[0].numpy().tolist()					,		__A     )










"""simple docstring"""







from __future__ import annotations





def 							SCREAMING_SNAKE_CASE							(   lowerCamelCase_			,  lowerCamelCase_			,  lowerCamelCase_			,  lowerCamelCase_):

					# Base Case
					if counter == 0 or capacity == 0:
										return 0

					# If weight of the nth item is more than Knapsack of capacity,
					#   then this item cannot be included in the optimal solution,
					# else return the maximum of two cases:
					#   (1) nth item included
					#   (2) not included
					if weights[counter - 1] > capacity:
										return knapsack(lowerCamelCase_			,  lowerCamelCase_			,  lowerCamelCase_			,  counter - 1)
					else:
										a__ 							=	capacity - weights[counter - 1]
										a__ 							=	values[counter - 1] + knapsack(
										    lowerCamelCase_			,  lowerCamelCase_			,  lowerCamelCase_			,  counter - 1)
										a__ 							=	knapsack(lowerCamelCase_			,  lowerCamelCase_			,  lowerCamelCase_			,  counter - 1)
										return max(lowerCamelCase_			,  lowerCamelCase_)


if __name__ == "__main__":
	import doctest

	doctest.testmod()


