





import functools
import operator

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


snake_case_     :       str						=  logging.get_logger(__name__)

snake_case_     :       int						=  {
    "microsoft/wavlm-base": "https://huggingface.co/microsoft/wavlm-base/resolve/main/config.json",
    # See all WavLM models at https://huggingface.co/models?filter=wavlm
}


class 					__a      (lowerCamelCase     ):
							__a					:   Dict									=       "wavlm"

							def __init__(							self							:     Dict       ,     __magic_name__							:     Any=32       ,     __magic_name__							:     Dict=7_68       ,     __magic_name__							:     int=12       ,     __magic_name__							:     List[str]=12       ,     __magic_name__							:     Optional[int]=30_72       ,     __magic_name__							:     List[str]="gelu"       ,     __magic_name__							:     Dict=0.1       ,     __magic_name__							:     Any=0.1       ,     __magic_name__							:     str=0.1       ,     __magic_name__							:     Any=0.0       ,     __magic_name__							:     List[str]=0.1       ,     __magic_name__							:     Optional[Any]=0.1       ,     __magic_name__							:     Tuple=0.0_2       ,     __magic_name__							:     int=1E-5       ,     __magic_name__							:     str="group"       ,     __magic_name__							:     Tuple="gelu"       ,     __magic_name__							:     int=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)       ,     __magic_name__							:     Any=(5, 2, 2, 2, 2, 2, 2)       ,     __magic_name__							:     Optional[int]=(10, 3, 3, 3, 3, 2, 2)       ,     __magic_name__							:     Optional[int]=False       ,     __magic_name__							:     Dict=1_28       ,     __magic_name__							:     int=16       ,     __magic_name__							:     Tuple=3_20       ,     __magic_name__							:     Any=8_00       ,     __magic_name__							:     Optional[int]=False       ,     __magic_name__							:     Any=True       ,     __magic_name__							:     Tuple=0.0_5       ,     __magic_name__							:     Tuple=10       ,     __magic_name__							:     Union[str, Any]=2       ,     __magic_name__							:     List[str]=0.0       ,     __magic_name__							:     Tuple=10       ,     __magic_name__							:     Optional[Any]=3_20       ,     __magic_name__							:     Tuple=2       ,     __magic_name__							:     Dict=0.1       ,     __magic_name__							:     Any=1_00       ,     __magic_name__							:     Dict=2_56       ,     __magic_name__							:     Any=2_56       ,     __magic_name__							:     Tuple=0.1       ,     __magic_name__							:     Dict="mean"       ,     __magic_name__							:     Dict=False       ,     __magic_name__							:     List[str]=False       ,     __magic_name__							:     int=2_56       ,     __magic_name__							:     Optional[int]=(5_12, 5_12, 5_12, 5_12, 15_00)       ,     __magic_name__							:     Union[str, Any]=(5, 3, 3, 1, 1)       ,     __magic_name__							:     str=(1, 2, 3, 1, 1)       ,     __magic_name__							:     Tuple=5_12       ,     __magic_name__							:     Any=80       ,     __magic_name__							:     Dict=0       ,     __magic_name__							:     List[Any]=1       ,     __magic_name__							:     int=2       ,     __magic_name__							:     List[str]=False       ,     __magic_name__							:     Dict=3       ,     __magic_name__							:     List[Any]=2       ,     __magic_name__							:     str=3       ,     __magic_name__							:     Any=None       ,     **__magic_name__							:     Any       ,     )					->       List[Any]:







													"""simple docstring"""
													super().__init__(**__magic_name__       ,     pad_token_id=__magic_name__       ,     bos_token_id=__magic_name__       ,     eos_token_id=__magic_name__   )
													UpperCAmelCase_			:      Optional[Any]     						=  hidden_size
													UpperCAmelCase_			:      Union[str, Any]     						=  feat_extract_norm
													UpperCAmelCase_			:      Union[str, Any]     						=  feat_extract_activation
													UpperCAmelCase_			:      List[Any]     						=  list(__magic_name__   )
													UpperCAmelCase_			:      Any     						=  list(__magic_name__   )
													UpperCAmelCase_			:      List[str]     						=  list(__magic_name__   )
													UpperCAmelCase_			:      Tuple     						=  conv_bias
													UpperCAmelCase_			:      Any     						=  num_buckets
													UpperCAmelCase_			:      Union[str, Any]     						=  max_bucket_distance
													UpperCAmelCase_			:      Tuple     						=  num_conv_pos_embeddings
													UpperCAmelCase_			:      Optional[Any]     						=  num_conv_pos_embedding_groups
													UpperCAmelCase_			:      Union[str, Any]     						=  len(self.conv_dim   )
													UpperCAmelCase_			:      Union[str, Any]     						=  num_hidden_layers
													UpperCAmelCase_			:      List[Any]     						=  intermediate_size
													UpperCAmelCase_			:      Any     						=  hidden_act
													UpperCAmelCase_			:      List[Any]     						=  num_attention_heads
													UpperCAmelCase_			:      List[str]     						=  hidden_dropout
													UpperCAmelCase_			:      int     						=  attention_dropout
													UpperCAmelCase_			:      int     						=  activation_dropout
													UpperCAmelCase_			:      Optional[int]     						=  feat_proj_dropout
													UpperCAmelCase_			:      Any     						=  final_dropout
													UpperCAmelCase_			:      List[Any]     						=  layerdrop
													UpperCAmelCase_			:      Optional[int]     						=  layer_norm_eps
													UpperCAmelCase_			:      Optional[Any]     						=  initializer_range
													UpperCAmelCase_			:      Optional[int]     						=  num_ctc_classes
													UpperCAmelCase_			:      List[str]     						=  vocab_size
													UpperCAmelCase_			:      Tuple     						=  do_stable_layer_norm
													UpperCAmelCase_			:      List[Any]     						=  use_weighted_layer_sum
													UpperCAmelCase_			:      Dict     						=  classifier_proj_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)`, 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_			:      Optional[int]     						=  apply_spec_augment
													UpperCAmelCase_			:      Optional[Any]     						=  mask_time_prob
													UpperCAmelCase_			:      Dict     						=  mask_time_length
													UpperCAmelCase_			:      Dict     						=  mask_time_min_masks
													UpperCAmelCase_			:      Optional[Any]     						=  mask_feature_prob
													UpperCAmelCase_			:      Union[str, Any]     						=  mask_feature_length

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

													# ctc loss
													UpperCAmelCase_			:      List[Any]     						=  ctc_loss_reduction
													UpperCAmelCase_			:      Union[str, Any]     						=  ctc_zero_infinity

													# adapter
													UpperCAmelCase_			:      Dict     						=  add_adapter
													UpperCAmelCase_			:      Union[str, Any]     						=  adapter_kernel_size
													UpperCAmelCase_			:      str     						=  adapter_stride
													UpperCAmelCase_			:      Any     						=  num_adapter_layers
													UpperCAmelCase_			:      List[Any]     						=  output_hidden_size or hidden_size

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

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



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







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












'''simple docstring'''







import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


snake_case_     :       List[str]						=  False


class 					__a      (unittest.TestCase     ):
							pass





@nightly
@require_torch_gpu
class 					__a      (unittest.TestCase     ):

							def     UpperCAmelCase__	(							self							:     int   )					->       str:







													"""simple docstring"""
													# clean up the VRAM after each test
													super().tearDown()
													gc.collect()
													torch.cuda.empty_cache()

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







													"""simple docstring"""
													UpperCAmelCase_			:      Tuple     						=  VersatileDiffusionPipeline.from_pretrained('''shi-labs/versatile-diffusion'''       ,     torch_dtype=torch.floataa   )
													pipe.to(__magic_name__   )
													pipe.set_progress_bar_config(disable=__magic_name__   )

													UpperCAmelCase_			:      List[Any]     						=  load_image(
													    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''   )

													UpperCAmelCase_			:      Optional[int]     						=  torch.manual_seed(0   )
													UpperCAmelCase_			:      Union[str, Any]     						=  pipe.dual_guided(
													    prompt='''first prompt'''       ,     image=__magic_name__       ,     text_to_image_strength=0.7_5       ,     generator=__magic_name__       ,     guidance_scale=7.5       ,     num_inference_steps=2       ,     output_type='''numpy'''       ,     ).images

													with tempfile.TemporaryDirectory() as tmpdirname:
																			pipe.save_pretrained(__magic_name__   )
																			UpperCAmelCase_			:      Optional[int]     						=  VersatileDiffusionPipeline.from_pretrained(__magic_name__       ,     torch_dtype=torch.floataa   )
													pipe.to(__magic_name__   )
													pipe.set_progress_bar_config(disable=__magic_name__   )

													UpperCAmelCase_			:      Any     						=  generator.manual_seed(0   )
													UpperCAmelCase_			:      Dict     						=  pipe.dual_guided(
													    prompt='''first prompt'''       ,     image=__magic_name__       ,     text_to_image_strength=0.7_5       ,     generator=__magic_name__       ,     guidance_scale=7.5       ,     num_inference_steps=2       ,     output_type='''numpy'''       ,     ).images

													assert np.abs(image - new_image   ).sum() < 1E-5, "Models don't have the same forward pass"



							def     UpperCAmelCase__	(							self							:     str   )					->       Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  VersatileDiffusionPipeline.from_pretrained('''shi-labs/versatile-diffusion'''       ,     torch_dtype=torch.floataa   )
													pipe.to(__magic_name__   )
													pipe.set_progress_bar_config(disable=__magic_name__   )

													UpperCAmelCase_			:      Union[str, Any]     						=  '''cyberpunk 2077'''
													UpperCAmelCase_			:      Union[str, Any]     						=  load_image(
													    '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''   )
													UpperCAmelCase_			:      Tuple     						=  torch.manual_seed(0   )
													UpperCAmelCase_			:      Optional[Any]     						=  pipe.dual_guided(
													    prompt=__magic_name__       ,     image=__magic_name__       ,     text_to_image_strength=0.7_5       ,     generator=__magic_name__       ,     guidance_scale=7.5       ,     num_inference_steps=50       ,     output_type='''numpy'''       ,     ).images

													UpperCAmelCase_			:      List[str]     						=  image[0, 2_53:2_56, 2_53:2_56, -1]

													assert image.shape == (1, 5_12, 5_12, 3)
													UpperCAmelCase_			:      Union[str, Any]     						=  np.array([0.1_4_4_8, 0.1_6_1_9, 0.1_7_4_1, 0.1_0_8_6, 0.1_1_4_7, 0.1_1_2_8, 0.1_1_9_9, 0.1_1_6_5, 0.1_0_0_1]   )

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

													UpperCAmelCase_			:      Tuple     						=  '''A painting of a squirrel eating a burger '''
													UpperCAmelCase_			:      Optional[int]     						=  torch.manual_seed(0   )
													UpperCAmelCase_			:      List[Any]     						=  pipe.text_to_image(
													    prompt=__magic_name__       ,     generator=__magic_name__       ,     guidance_scale=7.5       ,     num_inference_steps=50       ,     output_type='''numpy'''   ).images

													UpperCAmelCase_			:      Tuple     						=  image[0, 2_53:2_56, 2_53:2_56, -1]

													assert image.shape == (1, 5_12, 5_12, 3)
													UpperCAmelCase_			:      Any     						=  np.array([0.3_3_6_7, 0.3_1_6_9, 0.2_6_5_6, 0.3_8_7_0, 0.4_7_9_0, 0.3_7_9_6, 0.4_0_0_9, 0.4_8_7_8, 0.4_7_7_8]   )

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

													UpperCAmelCase_			:      Tuple     						=  pipe.image_variation(__magic_name__       ,     generator=__magic_name__       ,     output_type='''numpy'''   ).images

													UpperCAmelCase_			:      Optional[Any]     						=  image[0, 2_53:2_56, 2_53:2_56, -1]

													assert image.shape == (1, 5_12, 5_12, 3)
													UpperCAmelCase_			:      List[str]     						=  np.array([0.3_0_7_6, 0.3_1_2_3, 0.3_2_8_4, 0.3_7_8_2, 0.3_7_7_0, 0.3_8_9_4, 0.4_2_9_7, 0.4_3_3_1, 0.4_4_5_6]   )

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





