




'''simple docstring'''




import functools
import operator

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


UpperCAmelCase_       				=      logging.get_logger(__name__)

UpperCAmelCase_       				=      {
    'facebook/hubert-base-ls960': 'https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json',
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}

class 						lowerCAmelCase_   ( lowerCamelCase_   ):







  '''simple docstring'''







  lowerCAmelCase_				:					str				     =						"""hubert"""


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






   """simple docstring"""






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

   # ctc loss
   UpperCAmelCase__										=    ctc_loss_reduction
   UpperCAmelCase__										=    ctc_zero_infinity



  @property
  def 							SCREAMING_SNAKE_CASE__			(						self    :	Any ):






   """simple docstring"""






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






'''simple docstring'''




import random
import unittest

import torch

from diffusers import IFImgaImgPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin

@skip_mps
class 						lowerCAmelCase_   ( lowerCamelCase_			,  lowerCamelCase_			,  unittest.TestCase   ):







  '''simple docstring'''







  lowerCAmelCase_				:					Any				     =						IFImgaImgPipeline
  lowerCAmelCase_				:					Dict				     =						TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
  lowerCAmelCase_				:					Union[str, Any]				     =						TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
  lowerCAmelCase_				:					Dict				     =						PipelineTesterMixin.required_optional_params - {"""latents"""}


  def 							SCREAMING_SNAKE_CASE__			(						self    :	Optional[int] ):






   """simple docstring"""






   return self._get_dummy_components()


  def 							SCREAMING_SNAKE_CASE__			(						self    :	Tuple						,		_UpperCAmelCase    :	Any						,		_UpperCAmelCase    :	Any=0 ):






   """simple docstring"""






   if str(_UpperCAmelCase ).startswith("""mps""" ):
    UpperCAmelCase__										=    torch.manual_seed(_UpperCAmelCase )
   else:
    UpperCAmelCase__										=    torch.Generator(device=_UpperCAmelCase ).manual_seed(_UpperCAmelCase )

   UpperCAmelCase__										=    floats_tensor((1, 3, 32, 32)						,		rng=random.Random(_UpperCAmelCase ) ).to(_UpperCAmelCase )

   UpperCAmelCase__										=    {
       """prompt""": """A painting of a squirrel eating a burger""",
       """image""": image,
       """generator""": generator,
       """num_inference_steps""": 2,
       """output_type""": """numpy""",
   }

   return inputs


  def 							SCREAMING_SNAKE_CASE__			(						self    :	List[Any] ):






   """simple docstring"""






   self._test_save_load_optional_components()


  @unittest.skipIf(
      torch_device != """cuda""" or not is_xformers_available()						,		reason="""XFormers attention is only available with CUDA and `xformers` installed"""						,		)
  def 							SCREAMING_SNAKE_CASE__			(						self    :	int ):






   """simple docstring"""






   self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3 )


  @unittest.skipIf(torch_device != """cuda"""						,		reason="""float16 requires CUDA""" )
  def 							SCREAMING_SNAKE_CASE__			(						self    :	int ):






   """simple docstring"""






   super().test_save_load_floataa(expected_max_diff=1E-1 )


  @unittest.skipIf(torch_device != """cuda"""						,		reason="""float16 requires CUDA""" )
  def 							SCREAMING_SNAKE_CASE__			(						self    :	Optional[int] ):






   """simple docstring"""






   super().test_floataa_inference(expected_max_diff=1E-1 )


  def 							SCREAMING_SNAKE_CASE__			(						self    :	List[str] ):






   """simple docstring"""






   self._test_attention_slicing_forward_pass(expected_max_diff=1E-2 )


  def 							SCREAMING_SNAKE_CASE__			(						self    :	int ):






   """simple docstring"""






   self._test_save_load_local()



  def 							SCREAMING_SNAKE_CASE__			(						self    :	Any ):






   """simple docstring"""






   self._test_inference_batch_single_identical(
       expected_max_diff=1E-2						,		)
