





import functools
import operator

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


__A							   =							logging.get_logger(__name__)

__A							   =							{
    "asapp/sew-d-tiny-100k": "https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json",
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}



class   _SCREAMING_SNAKE_CASE		(      __SCREAMING_SNAKE_CASE       ):







 '''simple docstring'''
 lowercase_						=     "sew-d"

 def __init__(self							:  Optional[int]			,					UpperCAmelCase_							:  str=32			,					UpperCAmelCase_							:  str=768			,					UpperCAmelCase_							:  Any=12			,					UpperCAmelCase_							:  Optional[Any]=12			,					UpperCAmelCase_							:  Optional[Any]=3_072			,					UpperCAmelCase_							:  Tuple=2			,					UpperCAmelCase_							:  List[Any]=512			,					UpperCAmelCase_							:  Union[str, Any]=256			,					UpperCAmelCase_							:  int=True			,					UpperCAmelCase_							:  List[Any]=True			,					UpperCAmelCase_							:  int=("p2c", "c2p")			,					UpperCAmelCase_							:  Tuple="layer_norm"			,					UpperCAmelCase_							:  Any="gelu_python"			,					UpperCAmelCase_							:  Tuple=0.1			,					UpperCAmelCase_							:  Any=0.1			,					UpperCAmelCase_							:  Optional[Any]=0.1			,					UpperCAmelCase_							:  List[Any]=0.0			,					UpperCAmelCase_							:  Dict=0.1			,					UpperCAmelCase_							:  int=0.02			,					UpperCAmelCase_							:  List[str]=1E-7			,					UpperCAmelCase_							:  List[Any]=1E-5			,					UpperCAmelCase_							:  Union[str, Any]="group"			,					UpperCAmelCase_							:  List[Any]="gelu"			,					UpperCAmelCase_							:  Any=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512)			,					UpperCAmelCase_							:  str=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1)			,					UpperCAmelCase_							:  Optional[Any]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1)			,					UpperCAmelCase_							:  Optional[Any]=False			,					UpperCAmelCase_							:  Tuple=128			,					UpperCAmelCase_							:  Optional[int]=16			,					UpperCAmelCase_							:  int=True			,					UpperCAmelCase_							:  Tuple=0.05			,					UpperCAmelCase_							:  Union[str, Any]=10			,					UpperCAmelCase_							:  int=2			,					UpperCAmelCase_							:  List[Any]=0.0			,					UpperCAmelCase_							:  Any=10			,					UpperCAmelCase_							:  Union[str, Any]=0			,					UpperCAmelCase_							:  List[str]="mean"			,					UpperCAmelCase_							:  Dict=False			,					UpperCAmelCase_							:  Optional[int]=False			,					UpperCAmelCase_							:  Dict=256			,					UpperCAmelCase_							:  Union[str, Any]=0			,					UpperCAmelCase_							:  Tuple=1			,					UpperCAmelCase_							:  int=2			,					**UpperCAmelCase_							:  Tuple			,					)			->str:



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_			,					pad_token_id=UpperCAmelCase_			,					bos_token_id=UpperCAmelCase_			,					eos_token_id=UpperCAmelCase_)
   lowerCamelCase__: str         =hidden_size
   lowerCamelCase__: int         =feat_extract_norm
   lowerCamelCase__: str         =feat_extract_activation
   lowerCamelCase__: List[Any]         =list(UpperCAmelCase_)
   lowerCamelCase__: Dict         =list(UpperCAmelCase_)
   lowerCamelCase__: Tuple         =list(UpperCAmelCase_)
   lowerCamelCase__: str         =conv_bias
   lowerCamelCase__: Any         =num_conv_pos_embeddings
   lowerCamelCase__: List[Any]         =num_conv_pos_embedding_groups
   lowerCamelCase__: Optional[int]         =len(self.conv_dim)
   lowerCamelCase__: Tuple         =num_hidden_layers
   lowerCamelCase__: Tuple         =intermediate_size
   lowerCamelCase__: Optional[Any]         =squeeze_factor
   lowerCamelCase__: int         =max_position_embeddings
   lowerCamelCase__: Dict         =position_buckets
   lowerCamelCase__: List[Any]         =share_att_key
   lowerCamelCase__: Optional[Any]         =relative_attention
   lowerCamelCase__: List[str]         =norm_rel_ebd
   lowerCamelCase__: List[Any]         =list(UpperCAmelCase_)
   lowerCamelCase__: Optional[int]         =hidden_act
   lowerCamelCase__: str         =num_attention_heads
   lowerCamelCase__: str         =hidden_dropout
   lowerCamelCase__: List[str]         =attention_dropout
   lowerCamelCase__: str         =activation_dropout
   lowerCamelCase__: int         =feat_proj_dropout
   lowerCamelCase__: Tuple         =final_dropout
   lowerCamelCase__: Any         =layer_norm_eps
   lowerCamelCase__: Optional[Any]         =feature_layer_norm_eps
   lowerCamelCase__: Dict         =initializer_range
   lowerCamelCase__: int         =vocab_size

   if (
       (len(self.conv_stride) != self.num_feat_extract_layers)
       or (len(self.conv_kernel) != self.num_feat_extract_layers)
       or (len(self.conv_dim) != self.num_feat_extract_layers)
   ):
     raise ValueError(
         "Configuration for convolutional layers is incorrect."
         "It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,"
         F"""but is `len(config.conv_dim) = {len(self.conv_dim)}`, `len(config.conv_stride)"""
         F"""= {len(self.conv_stride)}`, `len(config.conv_kernel) = {len(self.conv_kernel)}`.""")

   # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
   lowerCamelCase__: Any         =apply_spec_augment
   lowerCamelCase__: List[Any]         =mask_time_prob
   lowerCamelCase__: Optional[int]         =mask_time_length
   lowerCamelCase__: Optional[Any]         =mask_time_min_masks
   lowerCamelCase__: Tuple         =mask_feature_prob
   lowerCamelCase__: int         =mask_feature_length
   lowerCamelCase__: Optional[int]         =mask_feature_min_masks

   # ctc loss
   lowerCamelCase__: Dict         =ctc_loss_reduction
   lowerCamelCase__: Any         =ctc_zero_infinity

   # sequence classification
   lowerCamelCase__: Any         =use_weighted_layer_sum
   lowerCamelCase__: Optional[Any]         =classifier_proj_size







 @property
 def 				SCREAMING_SNAKE_CASE_   (self							:  Optional[int])			->Optional[Any]:



   '''simple docstring'''



   return functools.reduce(operator.mul			,					self.conv_stride			,					1)



"""simple docstring"""


import unittest

import torch

from diffusers import VQModel
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()



class 	__a	(   _lowerCAmelCase     ,  _lowerCAmelCase     ,  unittest.TestCase						):
       UpperCamelCase_		:       Any				=      VQModel
       UpperCamelCase_		:       Dict				=      '''sample'''






       @property
       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[str]							,   UpperCAmelCase_			:				List[str]=(32, 32)      )->	List[str]:







              """simple docstring"""
              UpperCamelCase       			=		4
              UpperCamelCase       			=		3

              UpperCamelCase       			=		floats_tensor((batch_size, num_channels) + sizes      ).to(UpperCAmelCase_      )

              return {"sample": image}






       @property
       def 						_SCREAMING_SNAKE_CASE							(	self			:				int      )->	List[Any]:







              """simple docstring"""
              return (3, 32, 32)






       @property
       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	Tuple:







              """simple docstring"""
              return (3, 32, 32)






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[Any]      )->	Optional[int]:







              """simple docstring"""
              UpperCamelCase       			=		{
                  "block_out_channels": [32, 64],
                  "in_channels": 3,
                  "out_channels": 3,
                  "down_block_types": ["DownEncoderBlock2D", "DownEncoderBlock2D"],
                  "up_block_types": ["UpDecoderBlock2D", "UpDecoderBlock2D"],
                  "latent_channels": 3,
              }
              UpperCamelCase       			=		self.dummy_input
              return init_dict, inputs_dict






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Any      )->	List[Any]:







              """simple docstring"""
              pass






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Any      )->	str:







              """simple docstring"""
              pass






       def 						_SCREAMING_SNAKE_CASE							(	self			:				Optional[int]      )->	List[Any]:







              """simple docstring"""
              UpperCamelCase			,							UpperCamelCase       			=		VQModel.from_pretrained("fusing/vqgan-dummy"							,   output_loading_info=UpperCAmelCase_      )
              self.assertIsNotNone(UpperCAmelCase_      )
              self.assertEqual(len(loading_info["missing_keys"]      )							,   0      )

              model.to(UpperCAmelCase_      )
              UpperCamelCase       			=		model(**self.dummy_input      )

              assert image is not None, "Make sure output is not None"






       def 						_SCREAMING_SNAKE_CASE							(	self			:				List[Any]      )->	List[str]:







              """simple docstring"""
              UpperCamelCase       			=		VQModel.from_pretrained("fusing/vqgan-dummy"      )
              model.to(UpperCAmelCase_      ).eval()

              torch.manual_seed(0      )
              if torch.cuda.is_available():
                     torch.cuda.manual_seed_all(0      )

              UpperCamelCase       			=		torch.randn(1							,   model.config.in_channels							,   model.config.sample_size							,   model.config.sample_size      )
              UpperCamelCase       			=		image.to(UpperCAmelCase_      )
              with torch.no_grad():
                     UpperCamelCase       			=		model(UpperCAmelCase_      ).sample

              UpperCamelCase       			=		output[0, -1, -3:, -3:].flatten().cpu()
              # fmt: off
              UpperCamelCase       			=		torch.tensor([-0.0153, -0.4044, -0.1880, -0.5161, -0.2418, -0.4072, -0.1612, -0.0633, -0.0143]      )
              # fmt: on
              self.assertTrue(torch.allclose(UpperCAmelCase_							,   UpperCAmelCase_							,   atol=1e-3      )      )





