



'''simple docstring'''







import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad





class 						_SCREAMING_SNAKE_CASE      ( unittest.TestCase						):






			"""simple docstring"""







			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		10


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		[1, 2, 3, 4]
				__lowerCamelCase		       =		[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
				self.assertEqual(truncate_or_pad(__lowerCamelCase       , self.block_size       , 0    )       , __lowerCamelCase    )


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				__lowerCamelCase		       =		[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				self.assertEqual(truncate_or_pad(__lowerCamelCase       , self.block_size       , 0    )       , __lowerCamelCase    )


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
				__lowerCamelCase		       =		[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				self.assertEqual(truncate_or_pad(__lowerCamelCase       , self.block_size       , 0    )       , __lowerCamelCase    )


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		'''It was the year of Our Lord one thousand seven hundred and
        seventy-five.\n\nSpiritual revelations were conceded to England at that
        favoured period, as at this.'''
				__lowerCamelCase		       =		process_story(__lowerCamelCase    )
				self.assertEqual(__lowerCamelCase       , []    )


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		''''''
				__lowerCamelCase		       =		process_story(__lowerCamelCase    )
				self.assertEqual(__lowerCamelCase       , []    )
				self.assertEqual(__lowerCamelCase       , []    )


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		(
				    '''It was the year of Our Lord one thousand seven hundred and '''
				    '''seventy-five\n\nSpiritual revelations were conceded to England '''
				    '''at that favoured period, as at this.\n@highlight\n\nIt was the best of times'''
				)
				__lowerCamelCase		       =		process_story(__lowerCamelCase    )

				__lowerCamelCase		       =		[
				    '''It was the year of Our Lord one thousand seven hundred and seventy-five.''',
				    '''Spiritual revelations were conceded to England at that favoured period, as at this.''',
				]
				self.assertEqual(__lowerCamelCase       , __lowerCamelCase    )

				__lowerCamelCase		       =		['''It was the best of times.''']
				self.assertEqual(__lowerCamelCase       , __lowerCamelCase    )


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		torch.tensor([1, 2, 3, 4]    )
				__lowerCamelCase		       =		torch.tensor([1, 1, 1, 1]    )
				np.testing.assert_array_equal(build_mask(__lowerCamelCase       , 0    ).numpy()       , expected.numpy()    )


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		torch.tensor([1, 2, 3, 4, 23, 23, 23]    )
				__lowerCamelCase		       =		torch.tensor([1, 1, 1, 1, 0, 0, 0]    )
				np.testing.assert_array_equal(build_mask(__lowerCamelCase       , 23    ).numpy()       , expected.numpy()    )


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		torch.tensor([8, 2, 3, 4, 1, 1, 1]    )
				__lowerCamelCase		       =		torch.tensor([1, 1, 1, 1, 0, 0, 0]    )
				np.testing.assert_array_equal(build_mask(__lowerCamelCase       , 1    ).numpy()       , expected.numpy()    )


			def 						_lowerCamelCase       (   self    ):







				"""simple docstring"""



				__lowerCamelCase		       =		1_01
				__lowerCamelCase		       =		torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 1_01, 5, 6], [1, 1_01, 3, 4, 1_01, 6]]    )
				__lowerCamelCase		       =		torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]    )

				__lowerCamelCase		       =		compute_token_type_ids(__lowerCamelCase       , __lowerCamelCase    )
				np.testing.assert_array_equal(__lowerCamelCase       , __lowerCamelCase    )





'''simple docstring'''





from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


if TYPE_CHECKING:
    from ... import FeatureExtractionMixin, TensorType

__lowerCamelCase												=						logging.get_logger(__name__)

__lowerCamelCase												=						{
    '''openai/imagegpt-small''': '''''',
    '''openai/imagegpt-medium''': '''''',
    '''openai/imagegpt-large''': '''''',
}




class 				UpperCAmelCase			(			_snake_case						):
 UpperCAmelCase				=					"imagegpt"
 UpperCAmelCase				=					["past_key_values"]
 UpperCAmelCase				=					{
     "hidden_size": "n_embd",
     "max_position_embeddings": "n_positions",
     "num_attention_heads": "n_head",
     "num_hidden_layers": "n_layer",
 }


 def __init__(      self							:	List[Any]			,       __lowerCamelCase							:	List[Any]=5_1_2 + 1			,       __lowerCamelCase							:	Dict=3_2 * 3_2			,       __lowerCamelCase							:	List[str]=5_1_2			,       __lowerCamelCase							:	List[Any]=2_4			,       __lowerCamelCase							:	Any=8			,       __lowerCamelCase							:	Tuple=None			,       __lowerCamelCase							:	Any="quick_gelu"			,       __lowerCamelCase							:	Optional[int]=0.1			,       __lowerCamelCase							:	str=0.1			,       __lowerCamelCase							:	int=0.1			,       __lowerCamelCase							:	Tuple=1e-5			,       __lowerCamelCase							:	Dict=0.02			,       __lowerCamelCase							:	Tuple=True			,       __lowerCamelCase							:	str=True			,       __lowerCamelCase							:	Union[str, Any]=False			,       __lowerCamelCase							:	Union[str, Any]=False			,       __lowerCamelCase							:	Dict=False			,       **__lowerCamelCase							:	str			,       ):
    UpperCAmelCase__	:Dict      =      vocab_size
    UpperCAmelCase__	:str      =      n_positions
    UpperCAmelCase__	:Tuple      =      n_embd
    UpperCAmelCase__	:Dict      =      n_layer
    UpperCAmelCase__	:List[Any]      =      n_head
    UpperCAmelCase__	:str      =      n_inner
    UpperCAmelCase__	:Optional[Any]      =      activation_function
    UpperCAmelCase__	:str      =      resid_pdrop
    UpperCAmelCase__	:Optional[Any]      =      embd_pdrop
    UpperCAmelCase__	:Tuple      =      attn_pdrop
    UpperCAmelCase__	:int      =      layer_norm_epsilon
    UpperCAmelCase__	:List[Any]      =      initializer_range
    UpperCAmelCase__	:List[Any]      =      scale_attn_weights
    UpperCAmelCase__	:List[str]      =      use_cache
    UpperCAmelCase__	:Tuple      =      scale_attn_by_inverse_layer_idx
    UpperCAmelCase__	:Union[str, Any]      =      reorder_and_upcast_attn
    UpperCAmelCase__	:List[Any]      =      tie_word_embeddings

    super().__init__(tie_word_embeddings=__lowerCamelCase			,       **__lowerCamelCase )




class 				UpperCAmelCase			(			_snake_case						):


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	str ):
    return OrderedDict(
        [
            ('''input_ids''', {0: '''batch''', 1: '''sequence'''}),
        ] )





 def        __SCREAMING_SNAKE_CASE					(      self							:	Dict			,       __lowerCamelCase							:	"FeatureExtractionMixin"			,       __lowerCamelCase							:	int = 1			,       __lowerCamelCase							:	int = -1			,       __lowerCamelCase							:	bool = False			,       __lowerCamelCase							:	Optional["TensorType"] = None			,       __lowerCamelCase							:	int = 3			,       __lowerCamelCase							:	int = 3_2			,       __lowerCamelCase							:	int = 3_2			,       ):
    UpperCAmelCase__	:Tuple      =      self._generate_dummy_images(__lowerCamelCase			,       __lowerCamelCase			,       __lowerCamelCase			,       __lowerCamelCase )
    UpperCAmelCase__	:Dict      =      dict(preprocessor(images=__lowerCamelCase			,       return_tensors=__lowerCamelCase ) )

    return inputs



