
import functools
import operator

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


lowerCamelCase__        =						logging.get_logger(__name__)

lowerCamelCase__        =						{
    """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 	A__				(	__magic_name__      ):
				lowercase            =    'hubert'






				def __init__(		self   : Tuple       ,	a   : Any=32       ,	a   : Optional[int]=768       ,	a   : Dict=12       ,	a   : Union[str, Any]=12       ,	a   : List[str]=3_072       ,	a   : List[Any]="gelu"       ,	a   : Dict=0.1       ,	a   : int=0.1       ,	a   : str=0.1       ,	a   : int=True       ,	a   : Any=0.0       ,	a   : Union[str, Any]=0.1       ,	a   : Optional[int]=0.1       ,	a   : int=0.0_2       ,	a   : Any=1E-5       ,	a   : str="group"       ,	a   : str="gelu"       ,	a   : Union[str, Any]=(512, 512, 512, 512, 512, 512, 512)       ,	a   : Optional[int]=(5, 2, 2, 2, 2, 2, 2)       ,	a   : Optional[Any]=(10, 3, 3, 3, 3, 2, 2)       ,	a   : Any=False       ,	a   : Any=128       ,	a   : List[str]=16       ,	a   : Optional[int]=False       ,	a   : Optional[Any]=True       ,	a   : str=0.0_5       ,	a   : Dict=10       ,	a   : Dict=2       ,	a   : Union[str, Any]=0.0       ,	a   : Optional[int]=10       ,	a   : List[str]=0       ,	a   : Union[str, Any]="sum"       ,	a   : Dict=False       ,	a   : Any=False       ,	a   : Optional[int]=256       ,	a   : Dict=0       ,	a   : Tuple=1       ,	a   : Tuple=2       ,	**a   : Optional[int]       ,	):






							'''simple docstring'''







							super().__init__(**a       ,	pad_token_id=a       ,	bos_token_id=a       ,	eos_token_id=a  )
							lowerCAmelCase__ : Optional[Any]   =						hidden_size
							lowerCAmelCase__ : Union[str, Any]   =						feat_extract_norm
							lowerCAmelCase__ : Tuple   =						feat_extract_activation
							lowerCAmelCase__ : List[str]   =						list(a  )
							lowerCAmelCase__ : Any   =						list(a  )
							lowerCAmelCase__ : Optional[int]   =						list(a  )
							lowerCAmelCase__ : Optional[int]   =						conv_bias
							lowerCAmelCase__ : Optional[Any]   =						num_conv_pos_embeddings
							lowerCAmelCase__ : List[Any]   =						num_conv_pos_embedding_groups
							lowerCAmelCase__ : str   =						len(self.conv_dim  )
							lowerCAmelCase__ : List[Any]   =						num_hidden_layers
							lowerCAmelCase__ : List[str]   =						intermediate_size
							lowerCAmelCase__ : Union[str, Any]   =						hidden_act
							lowerCAmelCase__ : str   =						num_attention_heads
							lowerCAmelCase__ : List[Any]   =						hidden_dropout
							lowerCAmelCase__ : int   =						attention_dropout
							lowerCAmelCase__ : Union[str, Any]   =						activation_dropout
							lowerCAmelCase__ : List[str]   =						feat_proj_layer_norm
							lowerCAmelCase__ : str   =						feat_proj_dropout
							lowerCAmelCase__ : List[str]   =						final_dropout
							lowerCAmelCase__ : int   =						layerdrop
							lowerCAmelCase__ : Union[str, Any]   =						layer_norm_eps
							lowerCAmelCase__ : List[str]   =						initializer_range
							lowerCAmelCase__ : Tuple   =						vocab_size
							lowerCAmelCase__ : Union[str, Any]   =						do_stable_layer_norm
							lowerCAmelCase__ : List[str]   =						use_weighted_layer_sum
							lowerCAmelCase__ : Any   =						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
							lowerCAmelCase__ : str   =						apply_spec_augment
							lowerCAmelCase__ : int   =						mask_time_prob
							lowerCAmelCase__ : Union[str, Any]   =						mask_time_length
							lowerCAmelCase__ : Tuple   =						mask_time_min_masks
							lowerCAmelCase__ : Optional[Any]   =						mask_feature_prob
							lowerCAmelCase__ : Tuple   =						mask_feature_length
							lowerCAmelCase__ : Tuple   =						mask_feature_min_masks

							# ctc loss
							lowerCAmelCase__ : Dict   =						ctc_loss_reduction
							lowerCAmelCase__ : List[Any]   =						ctc_zero_infinity






				@property
				def 				_lowerCamelCase						(		self   : str  ):






							'''simple docstring'''







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

from typing import List, Optional, Tuple, Union

import torch

from ...utils import randn_tensor
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput







class 	A__				(	__magic_name__      ):






				def __init__(		self   : Any       ,	a   : Any       ,	a   : Optional[int]  ):






							'''simple docstring'''







							super().__init__()
							self.register_modules(unet=a       ,	scheduler=a  )






				@torch.no_grad()
				def __call__(		self   : Optional[Any]       ,	a   : int = 1       ,	a   : Optional[Union[torch.Generator, List[torch.Generator]]] = None       ,	a   : int = 1_000       ,	a   : Optional[str] = "pil"       ,	a   : bool = True       ,	):






							'''simple docstring'''







							if isinstance(self.unet.config.sample_size       ,	a  ):
										lowerCAmelCase__ : Union[str, Any]   =						(
										    batch_size,
										    self.unet.config.in_channels,
										    self.unet.config.sample_size,
										    self.unet.config.sample_size,
										)
							else:
										lowerCAmelCase__ : str   =						(batch_size, self.unet.config.in_channels, *self.unet.config.sample_size)

							if self.device.type == "mps":
										# randn does not work reproducibly on mps
										lowerCAmelCase__ : Optional[int]   =						randn_tensor(a       ,	generator=a  )
										lowerCAmelCase__ : Optional[int]   =						image.to(self.device  )
							else:
										lowerCAmelCase__ : Dict   =						randn_tensor(a       ,	generator=a       ,	device=self.device  )

							# set step values
							self.scheduler.set_timesteps(a  )

							for t in self.progress_bar(self.scheduler.timesteps  ):
										# 1. predict noise model_output
										lowerCAmelCase__ : Tuple   =						self.unet(a       ,	a  ).sample

										# 2. compute previous image: x_t -> x_t-1
										lowerCAmelCase__ : Optional[Any]   =						self.scheduler.step(a       ,	a       ,	a       ,	generator=a  ).prev_sample

							lowerCAmelCase__ : str   =						(image / 2 + 0.5).clamp(0       ,	1  )
							lowerCAmelCase__ : Optional[int]   =						image.cpu().permute(0       ,	2       ,	3       ,	1  ).numpy()
							if output_type == "pil":
										lowerCAmelCase__ : int   =						self.numpy_to_pil(a  )

							if not return_dict:
										return (image,)

							return ImagePipelineOutput(images=a  )