






'''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 		UpperCamelCase__    (unittest.TestCase			):






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  {
								    '''task_specific_params''': {
								        '''summarization''': {'''length_penalty''': 1.0, '''max_length''': 1_28, '''min_length''': 12, '''num_beams''': 4},
								        '''summarization_cnn''': {'''length_penalty''': 2.0, '''max_length''': 1_42, '''min_length''': 56, '''num_beams''': 4},
								        '''summarization_xsum''': {'''length_penalty''': 1.0, '''max_length''': 62, '''min_length''': 11, '''num_beams''': 6},
								    }
								}
								lowerCamelCase__         =  {
								    '''task_specific_params.summarization.length_penalty''': 1.0,
								    '''task_specific_params.summarization.max_length''': 1_28,
								    '''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''': 1_42,
								    '''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       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								self.assertTrue(np.allclose(transpose(UpperCamelCase__       )   ,x.transpose()       )       )

								lowerCamelCase__         =  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       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								lowerCamelCase__         =  torch.tensor(UpperCamelCase__       )
								self.assertTrue(np.allclose(transpose(UpperCamelCase__       )   ,transpose(UpperCamelCase__       ).numpy()       )       )

								lowerCamelCase__         =  np.random.randn(3   ,4   ,5       )
								lowerCamelCase__         =  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       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								lowerCamelCase__         =  tf.constant(UpperCamelCase__       )
								self.assertTrue(np.allclose(transpose(UpperCamelCase__       )   ,transpose(UpperCamelCase__       ).numpy()       )       )

								lowerCamelCase__         =  np.random.randn(3   ,4   ,5       )
								lowerCamelCase__         =  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       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								lowerCamelCase__         =  jnp.array(UpperCamelCase__       )
								self.assertTrue(np.allclose(transpose(UpperCamelCase__       )   ,np.asarray(transpose(UpperCamelCase__       )       )       )       )

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






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								self.assertTrue(np.allclose(reshape(UpperCamelCase__   ,(4, 3)       )   ,np.reshape(UpperCamelCase__   ,(4, 3)       )       )       )

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






		@require_torch
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								lowerCamelCase__         =  torch.tensor(UpperCamelCase__       )
								self.assertTrue(np.allclose(reshape(UpperCamelCase__   ,(4, 3)       )   ,reshape(UpperCamelCase__   ,(4, 3)       ).numpy()       )       )

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






		@require_tf
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								lowerCamelCase__         =  tf.constant(UpperCamelCase__       )
								self.assertTrue(np.allclose(reshape(UpperCamelCase__   ,(4, 3)       )   ,reshape(UpperCamelCase__   ,(4, 3)       ).numpy()       )       )

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






		@require_flax
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								lowerCamelCase__         =  jnp.array(UpperCamelCase__       )
								self.assertTrue(np.allclose(reshape(UpperCamelCase__   ,(4, 3)       )   ,np.asarray(reshape(UpperCamelCase__   ,(4, 3)       )       )       )       )

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






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  np.random.randn(1   ,3   ,4       )
								self.assertTrue(np.allclose(squeeze(UpperCamelCase__       )   ,np.squeeze(UpperCamelCase__       )       )       )

								lowerCamelCase__         =  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       ):
								lowerCamelCase__         =  np.random.randn(1   ,3   ,4       )
								lowerCamelCase__         =  torch.tensor(UpperCamelCase__       )
								self.assertTrue(np.allclose(squeeze(UpperCamelCase__       )   ,squeeze(UpperCamelCase__       ).numpy()       )       )

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






		@require_tf
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  np.random.randn(1   ,3   ,4       )
								lowerCamelCase__         =  tf.constant(UpperCamelCase__       )
								self.assertTrue(np.allclose(squeeze(UpperCamelCase__       )   ,squeeze(UpperCamelCase__       ).numpy()       )       )

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






		@require_flax
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  np.random.randn(1   ,3   ,4       )
								lowerCamelCase__         =  jnp.array(UpperCamelCase__       )
								self.assertTrue(np.allclose(squeeze(UpperCamelCase__       )   ,np.asarray(squeeze(UpperCamelCase__       )       )       )       )

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






		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  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       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								lowerCamelCase__         =  torch.tensor(UpperCamelCase__       )
								self.assertTrue(np.allclose(expand_dims(UpperCamelCase__   ,axis=1       )   ,expand_dims(UpperCamelCase__   ,axis=1       ).numpy()       )       )






		@require_tf
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								lowerCamelCase__         =  tf.constant(UpperCamelCase__       )
								self.assertTrue(np.allclose(expand_dims(UpperCamelCase__   ,axis=1       )   ,expand_dims(UpperCamelCase__   ,axis=1       ).numpy()       )       )






		@require_flax
		def 			UpperCamelCase_					(      self       ):
								lowerCamelCase__         =  np.random.randn(3   ,4       )
								lowerCamelCase__         =  jnp.array(UpperCamelCase__       )
								self.assertTrue(np.allclose(expand_dims(UpperCamelCase__   ,axis=1       )   ,np.asarray(expand_dims(UpperCamelCase__   ,axis=1       )       )       )       )









'''simple docstring'''







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


UpperCamelCase    :      Tuple  			=		logging.get_logger(__name__)

UpperCamelCase    :      List[str]  			=		{
    'naver-clova-ix/donut-base': 'https://huggingface.co/naver-clova-ix/donut-base/resolve/main/config.json',
    # See all Donut models at https://huggingface.co/models?filter=donut-swin
}




class 		UpperCamelCase__    (a			):




		'''simple docstring'''





		_UpperCamelCase				  =					'donut-swin'

		_UpperCamelCase				  =					{
		    'num_attention_heads': 'num_heads',
		    'num_hidden_layers': 'num_layers',
		}






		def __init__(      self   ,_lowerCAmelCase=2_24   ,_lowerCAmelCase=4   ,_lowerCAmelCase=3   ,_lowerCAmelCase=96   ,_lowerCAmelCase=[2, 2, 6, 2]   ,_lowerCAmelCase=[3, 6, 12, 24]   ,_lowerCAmelCase=7   ,_lowerCAmelCase=4.0   ,_lowerCAmelCase=True   ,_lowerCAmelCase=0.0   ,_lowerCAmelCase=0.0   ,_lowerCAmelCase=0.1   ,_lowerCAmelCase="gelu"   ,_lowerCAmelCase=False   ,_lowerCAmelCase=0.02   ,_lowerCAmelCase=1E-5   ,**_lowerCAmelCase   ,):
								super().__init__(**_lowerCAmelCase       )

								lowerCamelCase__         =  image_size
								lowerCamelCase__         =  patch_size
								lowerCamelCase__         =  num_channels
								lowerCamelCase__         =  embed_dim
								lowerCamelCase__         =  depths
								lowerCamelCase__         =  len(_lowerCAmelCase       )
								lowerCamelCase__         =  num_heads
								lowerCamelCase__         =  window_size
								lowerCamelCase__         =  mlp_ratio
								lowerCamelCase__         =  qkv_bias
								lowerCamelCase__         =  hidden_dropout_prob
								lowerCamelCase__         =  attention_probs_dropout_prob
								lowerCamelCase__         =  drop_path_rate
								lowerCamelCase__         =  hidden_act
								lowerCamelCase__         =  use_absolute_embeddings
								lowerCamelCase__         =  layer_norm_eps
								lowerCamelCase__         =  initializer_range
								# we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
								# this indicates the channel dimension after the last stage of the model
								lowerCamelCase__         =  int(embed_dim * 2 ** (len(_lowerCAmelCase       ) - 1)       )

