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


__UpperCAmelCase												=False




class   a__				(       unittest.TestCase			):
     pass




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






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[str]   ):





         """simple docstring"""



         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  VersatileDiffusionPipeline.from_pretrained('''shi-labs/versatile-diffusion'''  ,    torch_dtype=torch.floataa   )
         pipe.to(a   )
         pipe.set_progress_bar_config(disable=a   )

         __lowerCamelCase          =  load_image(
             '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''   )

         __lowerCamelCase          =  torch.manual_seed(0   )
         __lowerCamelCase          =  pipe.dual_guided(
             prompt='''first prompt'''  ,    image=a  ,    text_to_image_strength=0.75  ,    generator=a  ,    guidance_scale=7.5  ,    num_inference_steps=2  ,    output_type='''numpy'''  ,    ).images

         with tempfile.TemporaryDirectory() as tmpdirname:
             pipe.save_pretrained(a   )
             __lowerCamelCase          =  VersatileDiffusionPipeline.from_pretrained(a  ,    torch_dtype=torch.floataa   )
         pipe.to(a   )
         pipe.set_progress_bar_config(disable=a   )

         __lowerCamelCase          =  generator.manual_seed(0   )
         __lowerCamelCase          =  pipe.dual_guided(
             prompt='''first prompt'''  ,    image=a  ,    text_to_image_strength=0.75  ,    generator=a  ,    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        SCREAMING_SNAKE_CASE__       (			self		:		List[Any]   ):





         """simple docstring"""



         __lowerCamelCase          =  VersatileDiffusionPipeline.from_pretrained('''shi-labs/versatile-diffusion'''  ,    torch_dtype=torch.floataa   )
         pipe.to(a   )
         pipe.set_progress_bar_config(disable=a   )

         __lowerCamelCase          =  '''cyberpunk 2077'''
         __lowerCamelCase          =  load_image(
             '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg'''   )
         __lowerCamelCase          =  torch.manual_seed(0   )
         __lowerCamelCase          =  pipe.dual_guided(
             prompt=a  ,    image=a  ,    text_to_image_strength=0.75  ,    generator=a  ,    guidance_scale=7.5  ,    num_inference_steps=50  ,    output_type='''numpy'''  ,    ).images

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

         assert image.shape == (1, 5_12, 5_12, 3)
         __lowerCamelCase          =  np.array([0.14_48, 0.16_19, 0.17_41, 0.10_86, 0.11_47, 0.11_28, 0.11_99, 0.11_65, 0.10_01]   )

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

         __lowerCamelCase          =  '''A painting of a squirrel eating a burger '''
         __lowerCamelCase          =  torch.manual_seed(0   )
         __lowerCamelCase          =  pipe.text_to_image(
             prompt=a  ,    generator=a  ,    guidance_scale=7.5  ,    num_inference_steps=50  ,    output_type='''numpy'''   ).images

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

         assert image.shape == (1, 5_12, 5_12, 3)
         __lowerCamelCase          =  np.array([0.33_67, 0.31_69, 0.26_56, 0.38_70, 0.47_90, 0.37_96, 0.40_09, 0.48_78, 0.47_78]   )

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

         __lowerCamelCase          =  pipe.image_variation(a  ,    generator=a  ,    output_type='''numpy'''   ).images

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

         assert image.shape == (1, 5_12, 5_12, 3)
         __lowerCamelCase          =  np.array([0.30_76, 0.31_23, 0.32_84, 0.37_82, 0.37_70, 0.38_94, 0.42_97, 0.43_31, 0.44_56]   )

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

'''simple docstring'''




import functools
import operator

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


__UpperCAmelCase												=logging.get_logger(__name__)

__UpperCAmelCase												={
    "microsoft/unispeech-sat-base-100h-libri-ft": (
        "https://huggingface.co/microsoft/unispeech-sat-base-100h-libri-ft/resolve/main/config.json"
    ),
    # See all UniSpeechSat models at https://huggingface.co/models?filter=unispeech_sat
}




class    a__				(       UpperCAmelCase__			):
     lowerCamelCase  :					List[Any]							="unispeech-sat"






     def __init__(			self		:		Dict  ,    a		:		str=32  ,    a		:		Any=7_68  ,    a		:		Optional[Any]=12  ,    a		:		Optional[int]=12  ,    a		:		int=30_72  ,    a		:		int="gelu"  ,    a		:		Dict=0.1  ,    a		:		Dict=0.1  ,    a		:		List[Any]=0.1  ,    a		:		Tuple=0.0  ,    a		:		Optional[Any]=0.0  ,    a		:		Tuple=0.1  ,    a		:		List[Any]=0.1  ,    a		:		str=0.02  ,    a		:		List[Any]=1e-5  ,    a		:		int="group"  ,    a		:		Union[str, Any]="gelu"  ,    a		:		Optional[int]=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)  ,    a		:		List[Any]=(5, 2, 2, 2, 2, 2, 2)  ,    a		:		int=(10, 3, 3, 3, 3, 2, 2)  ,    a		:		Optional[Any]=False  ,    a		:		Any=1_28  ,    a		:		Tuple=16  ,    a		:		str=False  ,    a		:		Optional[Any]=True  ,    a		:		Dict=0.05  ,    a		:		List[Any]=10  ,    a		:		Any=2  ,    a		:		Optional[Any]=0.0  ,    a		:		Optional[Any]=10  ,    a		:		Any=0  ,    a		:		Any=3_20  ,    a		:		str=2  ,    a		:		List[str]=0.1  ,    a		:		List[str]=1_00  ,    a		:		List[str]=2_56  ,    a		:		str=2_56  ,    a		:		Dict=0.1  ,    a		:		Optional[Any]="mean"  ,    a		:		str=False  ,    a		:		Tuple=False  ,    a		:		Optional[Any]=2_56  ,    a		:		int=(5_12, 5_12, 5_12, 5_12, 15_00)  ,    a		:		int=(5, 3, 3, 1, 1)  ,    a		:		Any=(1, 2, 3, 1, 1)  ,    a		:		Union[str, Any]=5_12  ,    a		:		Optional[int]=0  ,    a		:		Optional[int]=1  ,    a		:		Optional[int]=2  ,    a		:		int=5_04  ,    **a		:		Dict  ,    ):





         """simple docstring"""



         super().__init__(**a  ,    pad_token_id=a  ,    bos_token_id=a  ,    eos_token_id=a   )
         __lowerCamelCase          =  hidden_size
         __lowerCamelCase          =  feat_extract_norm
         __lowerCamelCase          =  feat_extract_activation
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  conv_bias
         __lowerCamelCase          =  num_conv_pos_embeddings
         __lowerCamelCase          =  num_conv_pos_embedding_groups
         __lowerCamelCase          =  len(self.conv_dim   )
         __lowerCamelCase          =  num_hidden_layers
         __lowerCamelCase          =  intermediate_size
         __lowerCamelCase          =  hidden_act
         __lowerCamelCase          =  num_attention_heads
         __lowerCamelCase          =  hidden_dropout
         __lowerCamelCase          =  attention_dropout
         __lowerCamelCase          =  activation_dropout
         __lowerCamelCase          =  feat_proj_dropout
         __lowerCamelCase          =  final_dropout
         __lowerCamelCase          =  layerdrop
         __lowerCamelCase          =  layer_norm_eps
         __lowerCamelCase          =  initializer_range
         __lowerCamelCase          =  vocab_size
         __lowerCamelCase          =  num_clusters
         __lowerCamelCase          =  do_stable_layer_norm
         __lowerCamelCase          =  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
         __lowerCamelCase          =  apply_spec_augment
         __lowerCamelCase          =  mask_time_prob
         __lowerCamelCase          =  mask_time_length
         __lowerCamelCase          =  mask_time_min_masks
         __lowerCamelCase          =  mask_feature_prob
         __lowerCamelCase          =  mask_feature_length
         __lowerCamelCase          =  mask_feature_min_masks

         # parameters for pretraining with codevector quantized representations
         __lowerCamelCase          =  num_codevectors_per_group
         __lowerCamelCase          =  num_codevector_groups
         __lowerCamelCase          =  contrastive_logits_temperature
         __lowerCamelCase          =  feat_quantizer_dropout
         __lowerCamelCase          =  num_negatives
         __lowerCamelCase          =  codevector_dim
         __lowerCamelCase          =  proj_codevector_dim
         __lowerCamelCase          =  diversity_loss_weight

         # ctc loss
         __lowerCamelCase          =  ctc_loss_reduction
         __lowerCamelCase          =  ctc_zero_infinity

         # SequenceClassification-specific parameter. Feel free to ignore for other classes.
         __lowerCamelCase          =  classifier_proj_size

         # XVector-specific parameters. Feel free to ignore for other classes.
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  list(a   )
         __lowerCamelCase          =  xvector_output_dim






     @property
     def        SCREAMING_SNAKE_CASE__       (			self		:		Any   ):





         """simple docstring"""



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