


"""simple docstring"""






import functools
import operator

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


UpperCamelCase__				:Tuple			   =	logging.get_logger(__name__)

UpperCamelCase__				:Optional[int]			   =	{
    """facebook/wav2vec2-base-960h""": """https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json""",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}






class      A(  lowerCamelCase__		):

		"""simple docstring"""





		A    =							"wav2vec2"
		def __init__( self					,				SCREAMING_SNAKE_CASE__=32					,				SCREAMING_SNAKE_CASE__=7_68					,				SCREAMING_SNAKE_CASE__=12					,				SCREAMING_SNAKE_CASE__=12					,				SCREAMING_SNAKE_CASE__=30_72					,				SCREAMING_SNAKE_CASE__="gelu"					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=0.0_2					,				SCREAMING_SNAKE_CASE__=1E-5					,				SCREAMING_SNAKE_CASE__="group"					,				SCREAMING_SNAKE_CASE__="gelu"					,				SCREAMING_SNAKE_CASE__=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)					,				SCREAMING_SNAKE_CASE__=(5, 2, 2, 2, 2, 2, 2)					,				SCREAMING_SNAKE_CASE__=(10, 3, 3, 3, 3, 2, 2)					,				SCREAMING_SNAKE_CASE__=False					,				SCREAMING_SNAKE_CASE__=1_28					,				SCREAMING_SNAKE_CASE__=16					,				SCREAMING_SNAKE_CASE__=False					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=0.0_5					,				SCREAMING_SNAKE_CASE__=10					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__=10					,				SCREAMING_SNAKE_CASE__=0					,				SCREAMING_SNAKE_CASE__=3_20					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=1_00					,				SCREAMING_SNAKE_CASE__=2_56					,				SCREAMING_SNAKE_CASE__=2_56					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__="sum"					,				SCREAMING_SNAKE_CASE__=False					,				SCREAMING_SNAKE_CASE__=False					,				SCREAMING_SNAKE_CASE__=2_56					,				SCREAMING_SNAKE_CASE__=(5_12, 5_12, 5_12, 5_12, 15_00)					,				SCREAMING_SNAKE_CASE__=(5, 3, 3, 1, 1)					,				SCREAMING_SNAKE_CASE__=(1, 2, 3, 1, 1)					,				SCREAMING_SNAKE_CASE__=5_12					,				SCREAMING_SNAKE_CASE__=0					,				SCREAMING_SNAKE_CASE__=1					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=False					,				SCREAMING_SNAKE_CASE__=3					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=3					,				SCREAMING_SNAKE_CASE__=None					,				SCREAMING_SNAKE_CASE__=None					,				**SCREAMING_SNAKE_CASE__					,				)      ->	Optional[int]:

					"""simple docstring"""



					super().__init__(**SCREAMING_SNAKE_CASE__					,				pad_token_id=SCREAMING_SNAKE_CASE__					,				bos_token_id=SCREAMING_SNAKE_CASE__					,				eos_token_id=SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Dict					     =	hidden_size
					_UpperCamelCase					:List[Any]					     =	feat_extract_norm
					_UpperCamelCase					:Tuple					     =	feat_extract_activation
					_UpperCamelCase					:Tuple					     =	list(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Optional[int]					     =	list(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Optional[Any]					     =	list(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Tuple					     =	conv_bias
					_UpperCamelCase					:int					     =	num_conv_pos_embeddings
					_UpperCamelCase					:List[str]					     =	num_conv_pos_embedding_groups
					_UpperCamelCase					:List[str]					     =	len(self.conv_dim   )
					_UpperCamelCase					:Dict					     =	num_hidden_layers
					_UpperCamelCase					:Any					     =	intermediate_size
					_UpperCamelCase					:str					     =	hidden_act
					_UpperCamelCase					:Any					     =	num_attention_heads
					_UpperCamelCase					:Optional[Any]					     =	hidden_dropout
					_UpperCamelCase					:int					     =	attention_dropout
					_UpperCamelCase					:List[str]					     =	activation_dropout
					_UpperCamelCase					:Dict					     =	feat_proj_dropout
					_UpperCamelCase					:str					     =	final_dropout
					_UpperCamelCase					:Union[str, Any]					     =	layerdrop
					_UpperCamelCase					:Optional[int]					     =	layer_norm_eps
					_UpperCamelCase					:List[str]					     =	initializer_range
					_UpperCamelCase					:Tuple					     =	vocab_size
					_UpperCamelCase					:Dict					     =	do_stable_layer_norm
					_UpperCamelCase					:Union[str, Any]					     =	use_weighted_layer_sum

					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)`, but is `len(config.conv_dim) ='''
								    f" {len(self.conv_dim   )}`, `len(config.conv_stride) = {len(self.conv_stride   )}`,"
								    f" `len(config.conv_kernel) = {len(self.conv_kernel   )}`."   )

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

					# parameters for pretraining with codevector quantized representations
					_UpperCamelCase					:str					     =	num_codevectors_per_group
					_UpperCamelCase					:Tuple					     =	num_codevector_groups
					_UpperCamelCase					:int					     =	contrastive_logits_temperature
					_UpperCamelCase					:Optional[int]					     =	feat_quantizer_dropout
					_UpperCamelCase					:Tuple					     =	num_negatives
					_UpperCamelCase					:Any					     =	codevector_dim
					_UpperCamelCase					:List[Any]					     =	proj_codevector_dim
					_UpperCamelCase					:Any					     =	diversity_loss_weight

					# ctc loss
					_UpperCamelCase					:str					     =	ctc_loss_reduction
					_UpperCamelCase					:Optional[Any]					     =	ctc_zero_infinity

					# adapter
					_UpperCamelCase					:Optional[Any]					     =	add_adapter
					_UpperCamelCase					:List[str]					     =	adapter_kernel_size
					_UpperCamelCase					:Tuple					     =	adapter_stride
					_UpperCamelCase					:List[str]					     =	num_adapter_layers
					_UpperCamelCase					:Tuple					     =	output_hidden_size or hidden_size
					_UpperCamelCase					:List[str]					     =	adapter_attn_dim

					# SequenceClassification-specific parameter. Feel free to ignore for other classes.
					_UpperCamelCase					:Dict					     =	classifier_proj_size

					# XVector-specific parameters. Feel free to ignore for other classes.
					_UpperCamelCase					:str					     =	list(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:str					     =	list(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Optional[Any]					     =	list(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:List[str]					     =	xvector_output_dim





		@property
		def   _UpperCamelCase( self   )      ->	List[str]:

					"""simple docstring"""



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





"""simple docstring"""






import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()






class      A(  unittest.TestCase		):

		"""simple docstring"""





		@property
		def   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



					torch.manual_seed(0   )
					_UpperCamelCase					:str					     =	UNetaDModel(
					    block_out_channels=(32, 64)					,				layers_per_block=2					,				sample_size=32					,				in_channels=3					,				out_channels=3					,				down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')					,				up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')					,				)
					return model





		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	self.dummy_uncond_unet
					_UpperCamelCase					:List[Any]					     =	KarrasVeScheduler()

					_UpperCamelCase					:Optional[Any]					     =	KarrasVePipeline(unet=SCREAMING_SNAKE_CASE__					,				scheduler=SCREAMING_SNAKE_CASE__   )
					pipe.to(SCREAMING_SNAKE_CASE__   )
					pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:Dict					     =	torch.manual_seed(0   )
					_UpperCamelCase					:List[Any]					     =	pipe(num_inference_steps=2					,				generator=SCREAMING_SNAKE_CASE__					,				output_type='''numpy'''   ).images

					_UpperCamelCase					:List[Any]					     =	torch.manual_seed(0   )
					_UpperCamelCase					:Dict					     =	pipe(num_inference_steps=2					,				generator=SCREAMING_SNAKE_CASE__					,				output_type='''numpy'''					,				return_dict=SCREAMING_SNAKE_CASE__   )[0]

					_UpperCamelCase					:Dict					     =	image[0, -3:, -3:, -1]
					_UpperCamelCase					:List[Any]					     =	image_from_tuple[0, -3:, -3:, -1]

					assert image.shape == (1, 32, 32, 3)
					_UpperCamelCase					:List[Any]					     =	np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]   )

					assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2
					assert np.abs(image_from_tuple_slice.flatten() - expected_slice   ).max() < 1E-2






@slow
@require_torch
class      A(  unittest.TestCase		):

		"""simple docstring"""





		def   _UpperCamelCase( self   )      ->	Union[str, Any]:

					"""simple docstring"""



					_UpperCamelCase					:List[Any]					     =	'''google/ncsnpp-celebahq-256'''
					_UpperCamelCase					:Any					     =	UNetaDModel.from_pretrained(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Optional[int]					     =	KarrasVeScheduler()

					_UpperCamelCase					:Optional[int]					     =	KarrasVePipeline(unet=SCREAMING_SNAKE_CASE__					,				scheduler=SCREAMING_SNAKE_CASE__   )
					pipe.to(SCREAMING_SNAKE_CASE__   )
					pipe.set_progress_bar_config(disable=SCREAMING_SNAKE_CASE__   )

					_UpperCamelCase					:List[str]					     =	torch.manual_seed(0   )
					_UpperCamelCase					:List[Any]					     =	pipe(num_inference_steps=20					,				generator=SCREAMING_SNAKE_CASE__					,				output_type='''numpy'''   ).images

					_UpperCamelCase					:Dict					     =	image[0, -3:, -3:, -1]
					assert image.shape == (1, 2_56, 2_56, 3)
					_UpperCamelCase					:Any					     =	np.array([0.5_7_8, 0.5_8_1_1, 0.5_9_2_4, 0.5_8_0_9, 0.5_8_7, 0.5_8_8_6, 0.5_8_6_1, 0.5_8_0_2, 0.5_8_6]   )

					assert np.abs(image_slice.flatten() - expected_slice   ).max() < 1E-2

