




'''simple docstring'''


import unittest

import numpy as np

from transformers.testing_utils import require_flax, require_tf, require_torch
from transformers.utils import (
    expand_dims,
    flatten_dict,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    reshape,
    squeeze,
    transpose,
)


if is_flax_available():
  import jax.numpy as jnp

if is_tf_available():
  import tensorflow as tf

if is_torch_available():
  import torch





class  __lowercase    (	unittest.TestCase			):







   def 		UpperCamelCase__      (						self   )					->     Optional[int]:
     __a								=       {
         'task_specific_params': {
             'summarization': {'length_penalty': 1.0, 'max_length': 128, 'min_length': 12, 'num_beams': 4},
             'summarization_cnn': {'length_penalty': 2.0, 'max_length': 142, 'min_length': 56, 'num_beams': 4},
             'summarization_xsum': {'length_penalty': 1.0, 'max_length': 62, 'min_length': 11, 'num_beams': 6},
         }
     }
     __a								=       {
         'task_specific_params.summarization.length_penalty': 1.0,
         'task_specific_params.summarization.max_length': 128,
         'task_specific_params.summarization.min_length': 12,
         'task_specific_params.summarization.num_beams': 4,
         'task_specific_params.summarization_cnn.length_penalty': 2.0,
         'task_specific_params.summarization_cnn.max_length': 142,
         'task_specific_params.summarization_cnn.min_length': 56,
         'task_specific_params.summarization_cnn.num_beams': 4,
         'task_specific_params.summarization_xsum.length_penalty': 1.0,
         'task_specific_params.summarization_xsum.max_length': 62,
         'task_specific_params.summarization_xsum.min_length': 11,
         'task_specific_params.summarization_xsum.num_beams': 6,
     }

     self.assertEqual(flatten_dict(UpperCamelCase   )   ,				UpperCamelCase   )







   def 		UpperCamelCase__      (						self   )					->     List[str]:
     __a								=       np.random.randn(3   ,				4   )
     self.assertTrue(np.allclose(transpose(UpperCamelCase   )   ,				x.transpose()   )   )

     __a								=       np.random.randn(3   ,				4   ,				5   )
     self.assertTrue(np.allclose(transpose(UpperCamelCase   ,				axes=(1, 2, 0)   )   ,				x.transpose((1, 2, 0)   )   )   )







   @require_torch
   def 		UpperCamelCase__      (						self   )					->     Tuple:
     __a								=       np.random.randn(3   ,				4   )
     __a								=       torch.tensor(UpperCamelCase   )
     self.assertTrue(np.allclose(transpose(UpperCamelCase   )   ,				transpose(UpperCamelCase   ).numpy()   )   )

     __a								=       np.random.randn(3   ,				4   ,				5   )
     __a								=       torch.tensor(UpperCamelCase   )
     self.assertTrue(np.allclose(transpose(UpperCamelCase   ,				axes=(1, 2, 0)   )   ,				transpose(UpperCamelCase   ,				axes=(1, 2, 0)   ).numpy()   )   )







   @require_tf
   def 		UpperCamelCase__      (						self   )					->     List[str]:
     __a								=       np.random.randn(3   ,				4   )
     __a								=       tf.constant(UpperCamelCase   )
     self.assertTrue(np.allclose(transpose(UpperCamelCase   )   ,				transpose(UpperCamelCase   ).numpy()   )   )

     __a								=       np.random.randn(3   ,				4   ,				5   )
     __a								=       tf.constant(UpperCamelCase   )
     self.assertTrue(np.allclose(transpose(UpperCamelCase   ,				axes=(1, 2, 0)   )   ,				transpose(UpperCamelCase   ,				axes=(1, 2, 0)   ).numpy()   )   )







   @require_flax
   def 		UpperCamelCase__      (						self   )					->     Union[str, Any]:
     __a								=       np.random.randn(3   ,				4   )
     __a								=       jnp.array(UpperCamelCase   )
     self.assertTrue(np.allclose(transpose(UpperCamelCase   )   ,				np.asarray(transpose(UpperCamelCase   )   )   )   )

     __a								=       np.random.randn(3   ,				4   ,				5   )
     __a								=       jnp.array(UpperCamelCase   )
     self.assertTrue(np.allclose(transpose(UpperCamelCase   ,				axes=(1, 2, 0)   )   ,				np.asarray(transpose(UpperCamelCase   ,				axes=(1, 2, 0)   )   )   )   )







   def 		UpperCamelCase__      (						self   )					->     str:
     __a								=       np.random.randn(3   ,				4   )
     self.assertTrue(np.allclose(reshape(UpperCamelCase   ,				(4, 3)   )   ,				np.reshape(UpperCamelCase   ,				(4, 3)   )   )   )

     __a								=       np.random.randn(3   ,				4   ,				5   )
     self.assertTrue(np.allclose(reshape(UpperCamelCase   ,				(12, 5)   )   ,				np.reshape(UpperCamelCase   ,				(12, 5)   )   )   )







   @require_torch
   def 		UpperCamelCase__      (						self   )					->     List[Any]:
     __a								=       np.random.randn(3   ,				4   )
     __a								=       torch.tensor(UpperCamelCase   )
     self.assertTrue(np.allclose(reshape(UpperCamelCase   ,				(4, 3)   )   ,				reshape(UpperCamelCase   ,				(4, 3)   ).numpy()   )   )

     __a								=       np.random.randn(3   ,				4   ,				5   )
     __a								=       torch.tensor(UpperCamelCase   )
     self.assertTrue(np.allclose(reshape(UpperCamelCase   ,				(12, 5)   )   ,				reshape(UpperCamelCase   ,				(12, 5)   ).numpy()   )   )







   @require_tf
   def 		UpperCamelCase__      (						self   )					->     List[Any]:
     __a								=       np.random.randn(3   ,				4   )
     __a								=       tf.constant(UpperCamelCase   )
     self.assertTrue(np.allclose(reshape(UpperCamelCase   ,				(4, 3)   )   ,				reshape(UpperCamelCase   ,				(4, 3)   ).numpy()   )   )

     __a								=       np.random.randn(3   ,				4   ,				5   )
     __a								=       tf.constant(UpperCamelCase   )
     self.assertTrue(np.allclose(reshape(UpperCamelCase   ,				(12, 5)   )   ,				reshape(UpperCamelCase   ,				(12, 5)   ).numpy()   )   )







   @require_flax
   def 		UpperCamelCase__      (						self   )					->     Tuple:
     __a								=       np.random.randn(3   ,				4   )
     __a								=       jnp.array(UpperCamelCase   )
     self.assertTrue(np.allclose(reshape(UpperCamelCase   ,				(4, 3)   )   ,				np.asarray(reshape(UpperCamelCase   ,				(4, 3)   )   )   )   )

     __a								=       np.random.randn(3   ,				4   ,				5   )
     __a								=       jnp.array(UpperCamelCase   )
     self.assertTrue(np.allclose(reshape(UpperCamelCase   ,				(12, 5)   )   ,				np.asarray(reshape(UpperCamelCase   ,				(12, 5)   )   )   )   )







   def 		UpperCamelCase__      (						self   )					->     int:
     __a								=       np.random.randn(1   ,				3   ,				4   )
     self.assertTrue(np.allclose(squeeze(UpperCamelCase   )   ,				np.squeeze(UpperCamelCase   )   )   )

     __a								=       np.random.randn(1   ,				4   ,				1   ,				5   )
     self.assertTrue(np.allclose(squeeze(UpperCamelCase   ,				axis=2   )   ,				np.squeeze(UpperCamelCase   ,				axis=2   )   )   )







   @require_torch
   def 		UpperCamelCase__      (						self   )					->     List[str]:
     __a								=       np.random.randn(1   ,				3   ,				4   )
     __a								=       torch.tensor(UpperCamelCase   )
     self.assertTrue(np.allclose(squeeze(UpperCamelCase   )   ,				squeeze(UpperCamelCase   ).numpy()   )   )

     __a								=       np.random.randn(1   ,				4   ,				1   ,				5   )
     __a								=       torch.tensor(UpperCamelCase   )
     self.assertTrue(np.allclose(squeeze(UpperCamelCase   ,				axis=2   )   ,				squeeze(UpperCamelCase   ,				axis=2   ).numpy()   )   )







   @require_tf
   def 		UpperCamelCase__      (						self   )					->     Tuple:
     __a								=       np.random.randn(1   ,				3   ,				4   )
     __a								=       tf.constant(UpperCamelCase   )
     self.assertTrue(np.allclose(squeeze(UpperCamelCase   )   ,				squeeze(UpperCamelCase   ).numpy()   )   )

     __a								=       np.random.randn(1   ,				4   ,				1   ,				5   )
     __a								=       tf.constant(UpperCamelCase   )
     self.assertTrue(np.allclose(squeeze(UpperCamelCase   ,				axis=2   )   ,				squeeze(UpperCamelCase   ,				axis=2   ).numpy()   )   )







   @require_flax
   def 		UpperCamelCase__      (						self   )					->     Tuple:
     __a								=       np.random.randn(1   ,				3   ,				4   )
     __a								=       jnp.array(UpperCamelCase   )
     self.assertTrue(np.allclose(squeeze(UpperCamelCase   )   ,				np.asarray(squeeze(UpperCamelCase   )   )   )   )

     __a								=       np.random.randn(1   ,				4   ,				1   ,				5   )
     __a								=       jnp.array(UpperCamelCase   )
     self.assertTrue(np.allclose(squeeze(UpperCamelCase   ,				axis=2   )   ,				np.asarray(squeeze(UpperCamelCase   ,				axis=2   )   )   )   )







   def 		UpperCamelCase__      (						self   )					->     Optional[int]:
     __a								=       np.random.randn(3   ,				4   )
     self.assertTrue(np.allclose(expand_dims(UpperCamelCase   ,				axis=1   )   ,				np.expand_dims(UpperCamelCase   ,				axis=1   )   )   )







   @require_torch
   def 		UpperCamelCase__      (						self   )					->     Optional[int]:
     __a								=       np.random.randn(3   ,				4   )
     __a								=       torch.tensor(UpperCamelCase   )
     self.assertTrue(np.allclose(expand_dims(UpperCamelCase   ,				axis=1   )   ,				expand_dims(UpperCamelCase   ,				axis=1   ).numpy()   )   )







   @require_tf
   def 		UpperCamelCase__      (						self   )					->     Union[str, Any]:
     __a								=       np.random.randn(3   ,				4   )
     __a								=       tf.constant(UpperCamelCase   )
     self.assertTrue(np.allclose(expand_dims(UpperCamelCase   ,				axis=1   )   ,				expand_dims(UpperCamelCase   ,				axis=1   ).numpy()   )   )







   @require_flax
   def 		UpperCamelCase__      (						self   )					->     Optional[int]:
     __a								=       np.random.randn(3   ,				4   )
     __a								=       jnp.array(UpperCamelCase   )
     self.assertTrue(np.allclose(expand_dims(UpperCamelCase   ,				axis=1   )   ,				np.asarray(expand_dims(UpperCamelCase   ,				axis=1   )   )   )   )









'''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

UpperCAmelCase_					=   logging.get_logger(__name__)

UpperCAmelCase_					=   {
    "openai/imagegpt-small": "",
    "openai/imagegpt-medium": "",
    "openai/imagegpt-large": "",
}





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







   def __init__(						self   ,				UpperCamelCase=512 + 1   ,				UpperCamelCase=32 * 32   ,				UpperCamelCase=512   ,				UpperCamelCase=24   ,				UpperCamelCase=8   ,				UpperCamelCase=None   ,				UpperCamelCase="quick_gelu"   ,				UpperCamelCase=0.1   ,				UpperCamelCase=0.1   ,				UpperCamelCase=0.1   ,				UpperCamelCase=1e-5   ,				UpperCamelCase=0.02   ,				UpperCamelCase=True   ,				UpperCamelCase=True   ,				UpperCamelCase=False   ,				UpperCamelCase=False   ,				UpperCamelCase=False   ,				**UpperCamelCase   ,				)					->     int:
     __a								=       vocab_size
     __a								=       n_positions
     __a								=       n_embd
     __a								=       n_layer
     __a								=       n_head
     __a								=       n_inner
     __a								=       activation_function
     __a								=       resid_pdrop
     __a								=       embd_pdrop
     __a								=       attn_pdrop
     __a								=       layer_norm_epsilon
     __a								=       initializer_range
     __a								=       scale_attn_weights
     __a								=       use_cache
     __a								=       scale_attn_by_inverse_layer_idx
     __a								=       reorder_and_upcast_attn
     __a								=       tie_word_embeddings

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





class  __lowercase    (	__magic_name__			):







   @property
   def 		UpperCamelCase__      (						self   )					->     Mapping[str, Mapping[int, str]]:
     return OrderedDict(
         [
             ('input_ids', {0: 'batch', 1: 'sequence'}),
         ]   )







   def 		UpperCamelCase__      (						self   ,				UpperCamelCase   ,				UpperCamelCase = 1   ,				UpperCamelCase = -1   ,				UpperCamelCase = False   ,				UpperCamelCase = None   ,				UpperCamelCase = 3   ,				UpperCamelCase = 32   ,				UpperCamelCase = 32   ,				)					->     Mapping[str, Any]:
     __a								=       self._generate_dummy_images(UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   )
     __a								=       dict(preprocessor(images=UpperCamelCase   ,				return_tensors=UpperCamelCase   )   )

     return inputs



