





"""simple docstring"""




import functools
import operator

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


UpperCamelCase_									=logging.get_logger(__name__)

UpperCamelCase_									={
    """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    ):
				UpperCamelCase								=   '''wavlm'''






				def __init__(			self		:   str,			lowerCAmelCase__		:   int=3_2,			lowerCAmelCase__		:   Tuple=7_6_8,			lowerCAmelCase__		:   Dict=1_2,			lowerCAmelCase__		:   Union[str, Any]=1_2,			lowerCAmelCase__		:   Optional[Any]=3_0_7_2,			lowerCAmelCase__		:   int="gelu",			lowerCAmelCase__		:   List[Any]=0.1,			lowerCAmelCase__		:   List[str]=0.1,			lowerCAmelCase__		:   int=0.1,			lowerCAmelCase__		:   str=0.0,			lowerCAmelCase__		:   Optional[Any]=0.1,			lowerCAmelCase__		:   Optional[Any]=0.1,			lowerCAmelCase__		:   Union[str, Any]=0.02,			lowerCAmelCase__		:   Tuple=1e-5,			lowerCAmelCase__		:   List[Any]="group",			lowerCAmelCase__		:   int="gelu",			lowerCAmelCase__		:   str=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2),			lowerCAmelCase__		:   List[str]=(5, 2, 2, 2, 2, 2, 2),			lowerCAmelCase__		:   Any=(1_0, 3, 3, 3, 3, 2, 2),			lowerCAmelCase__		:   Tuple=False,			lowerCAmelCase__		:   List[str]=1_2_8,			lowerCAmelCase__		:   Any=1_6,			lowerCAmelCase__		:   Optional[int]=3_2_0,			lowerCAmelCase__		:   List[str]=8_0_0,			lowerCAmelCase__		:   List[str]=False,			lowerCAmelCase__		:   Optional[int]=True,			lowerCAmelCase__		:   Union[str, Any]=0.05,			lowerCAmelCase__		:   Optional[Any]=1_0,			lowerCAmelCase__		:   Optional[int]=2,			lowerCAmelCase__		:   Tuple=0.0,			lowerCAmelCase__		:   str=1_0,			lowerCAmelCase__		:   Optional[int]=3_2_0,			lowerCAmelCase__		:   Optional[Any]=2,			lowerCAmelCase__		:   str=0.1,			lowerCAmelCase__		:   Union[str, Any]=1_0_0,			lowerCAmelCase__		:   Union[str, Any]=2_5_6,			lowerCAmelCase__		:   Dict=2_5_6,			lowerCAmelCase__		:   Tuple=0.1,			lowerCAmelCase__		:   List[str]="mean",			lowerCAmelCase__		:   int=False,			lowerCAmelCase__		:   List[str]=False,			lowerCAmelCase__		:   Optional[Any]=2_5_6,			lowerCAmelCase__		:   List[Any]=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 1_5_0_0),			lowerCAmelCase__		:   List[str]=(5, 3, 3, 1, 1),			lowerCAmelCase__		:   int=(1, 2, 3, 1, 1),			lowerCAmelCase__		:   Tuple=5_1_2,			lowerCAmelCase__		:   Optional[Any]=8_0,			lowerCAmelCase__		:   List[Any]=0,			lowerCAmelCase__		:   Any=1,			lowerCAmelCase__		:   Optional[int]=2,			lowerCAmelCase__		:   str=False,			lowerCAmelCase__		:   int=3,			lowerCAmelCase__		:   Dict=2,			lowerCAmelCase__		:   str=3,			lowerCAmelCase__		:   Any=None,			**lowerCAmelCase__		:   List[str],			)     ->				Union[str, Any]:




										'''simple docstring'''



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

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

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

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

										# SequenceClassification-specific parameter. Feel free to ignore for other classes.
										_UpperCamelCase      : Optional[Any]         =   classifier_proj_size

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






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




										'''simple docstring'''



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










"""simple docstring"""




import math

import torch
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from .attention_processor import Attention
from .embeddings import get_timestep_embedding
from .modeling_utils import ModelMixin




class 			_a						(				_lowerCAmelCase     ,    _lowerCAmelCase    ):






				@register_to_config
				def __init__(			self		:   Any,			lowerCAmelCase__		:   int = 1_2_8,			lowerCAmelCase__		:   int = 2_5_6,			lowerCAmelCase__		:   float = 2_000.0,			lowerCAmelCase__		:   int = 7_6_8,			lowerCAmelCase__		:   int = 1_2,			lowerCAmelCase__		:   int = 1_2,			lowerCAmelCase__		:   int = 6_4,			lowerCAmelCase__		:   int = 2_0_4_8,			lowerCAmelCase__		:   float = 0.1,			)     ->				Any:




										'''simple docstring'''



										super().__init__()

										_UpperCamelCase      : Any         =   nn.Sequential(
										    nn.Linear(lowerCAmelCase__,			d_model * 4,			bias=lowerCAmelCase__							),			nn.SiLU(),			nn.Linear(d_model * 4,			d_model * 4,			bias=lowerCAmelCase__							),			nn.SiLU(),			)

										_UpperCamelCase      : List[Any]         =   nn.Embedding(lowerCAmelCase__,			lowerCAmelCase__							)
										_UpperCamelCase      : List[Any]         =   False

										_UpperCamelCase      : Optional[Any]         =   nn.Linear(lowerCAmelCase__,			lowerCAmelCase__,			bias=lowerCAmelCase__							)

										_UpperCamelCase      : Any         =   nn.Dropout(p=lowerCAmelCase__							)

										_UpperCamelCase      : List[str]         =   nn.ModuleList()
										for lyr_num in range(lowerCAmelCase__							):
																# FiLM conditional T5 decoder
																_UpperCamelCase      : Any         =   DecoderLayer(d_model=lowerCAmelCase__,			d_kv=lowerCAmelCase__,			num_heads=lowerCAmelCase__,			d_ff=lowerCAmelCase__,			dropout_rate=lowerCAmelCase__							)
																self.decoders.append(lowerCAmelCase__							)

										_UpperCamelCase      : Optional[int]         =   TaLayerNorm(lowerCAmelCase__							)

										_UpperCamelCase      : Dict         =   nn.Dropout(p=lowerCAmelCase__							)
										_UpperCamelCase      : Dict         =   nn.Linear(lowerCAmelCase__,			lowerCAmelCase__,			bias=lowerCAmelCase__							)






				def     snake_case     (			self		:   Optional[Any],			lowerCAmelCase__		:   Union[str, Any],			lowerCAmelCase__		:   Optional[int]							)     ->				List[str]:




										'''simple docstring'''



										_UpperCamelCase      : List[Any]         =   torch.mul(query_input.unsqueeze(-1							),			key_input.unsqueeze(-2							)							)
										return mask.unsqueeze(-3							)






				def     snake_case     (			self		:   str,			lowerCAmelCase__		:   Optional[int],			lowerCAmelCase__		:   Optional[Any],			lowerCAmelCase__		:   Optional[Any]							)     ->				Dict:




										'''simple docstring'''



										_UpperCamelCase       ,							_UpperCamelCase       ,							_UpperCamelCase      : Union[str, Any]         =   decoder_input_tokens.shape
										assert decoder_noise_time.shape == (batch,)

										# decoder_noise_time is in [0, 1), so rescale to expected timing range.
										_UpperCamelCase      : Any         =   get_timestep_embedding(
										    decoder_noise_time * self.config.max_decoder_noise_time,			embedding_dim=self.config.d_model,			max_period=self.config.max_decoder_noise_time,			).to(dtype=self.dtype							)

										_UpperCamelCase      : Union[str, Any]         =   self.conditioning_emb(lowerCAmelCase__							).unsqueeze(1							)

										assert conditioning_emb.shape == (batch, 1, self.config.d_model * 4)

										_UpperCamelCase      : int         =   decoder_input_tokens.shape[1]

										# If we want to use relative positions for audio context, we can just offset
										# this sequence by the length of encodings_and_masks.
										_UpperCamelCase      : int         =   torch.broadcast_to(
										    torch.arange(lowerCAmelCase__,			device=decoder_input_tokens.device							),			(batch, seq_length),			)

										_UpperCamelCase      : Dict         =   self.position_encoding(lowerCAmelCase__							)

										_UpperCamelCase      : List[str]         =   self.continuous_inputs_projection(lowerCAmelCase__							)
										inputs += position_encodings
										_UpperCamelCase      : Dict         =   self.dropout(lowerCAmelCase__							)

										# decoder: No padding present.
										_UpperCamelCase      : Tuple         =   torch.ones(
										    decoder_input_tokens.shape[:2],			device=decoder_input_tokens.device,			dtype=inputs.dtype							)

										# Translate encoding masks to encoder-decoder masks.
										_UpperCamelCase      : Tuple         =   [(x, self.encoder_decoder_mask(lowerCAmelCase__,			lowerCAmelCase__							)) for x, y in encodings_and_masks]

										# cross attend style: concat encodings
										_UpperCamelCase      : int         =   torch.cat([x[0] for x in encodings_and_encdec_masks],			dim=1							)
										_UpperCamelCase      : Dict         =   torch.cat([x[1] for x in encodings_and_encdec_masks],			dim=-1							)

										for lyr in self.decoders:
																_UpperCamelCase      : List[Any]         =   lyr(
																    lowerCAmelCase__,			conditioning_emb=lowerCAmelCase__,			encoder_hidden_states=lowerCAmelCase__,			encoder_attention_mask=lowerCAmelCase__,			)[0]

										_UpperCamelCase      : Any         =   self.decoder_norm(lowerCAmelCase__							)
										_UpperCamelCase      : Tuple         =   self.post_dropout(lowerCAmelCase__							)

										_UpperCamelCase      : Union[str, Any]         =   self.spec_out(lowerCAmelCase__							)
										return spec_out




class 			_a						(				nn.Module    ):






				def __init__(			self		:   Union[str, Any],			lowerCAmelCase__		:   List[Any],			lowerCAmelCase__		:   Optional[int],			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   str,			lowerCAmelCase__		:   Union[str, Any]=1e-6							)     ->				Optional[int]:




										'''simple docstring'''



										super().__init__()
										_UpperCamelCase      : Optional[int]         =   nn.ModuleList()

										# cond self attention: layer 0
										self.layer.append(
										    TaLayerSelfAttentionCond(d_model=lowerCAmelCase__,			d_kv=lowerCAmelCase__,			num_heads=lowerCAmelCase__,			dropout_rate=lowerCAmelCase__							)							)

										# cross attention: layer 1
										self.layer.append(
										    TaLayerCrossAttention(
										        d_model=lowerCAmelCase__,			d_kv=lowerCAmelCase__,			num_heads=lowerCAmelCase__,			dropout_rate=lowerCAmelCase__,			layer_norm_epsilon=lowerCAmelCase__,			)							)

										# Film Cond MLP + dropout: last layer
										self.layer.append(
										    TaLayerFFCond(d_model=lowerCAmelCase__,			d_ff=lowerCAmelCase__,			dropout_rate=lowerCAmelCase__,			layer_norm_epsilon=lowerCAmelCase__							)							)






				def     snake_case     (			self		:   Union[str, Any],			lowerCAmelCase__		:   str,			lowerCAmelCase__		:   List[Any]=None,			lowerCAmelCase__		:   List[str]=None,			lowerCAmelCase__		:   List[Any]=None,			lowerCAmelCase__		:   Optional[Any]=None,			lowerCAmelCase__		:   Any=None,			)     ->				List[Any]:




										'''simple docstring'''



										_UpperCamelCase      : List[str]         =   self.layer[0](
										    lowerCAmelCase__,			conditioning_emb=lowerCAmelCase__,			attention_mask=lowerCAmelCase__,			)

										if encoder_hidden_states is not None:
																_UpperCamelCase      : Any         =   torch.where(encoder_attention_mask > 0,			0,			-1e1_0							).to(
																    encoder_hidden_states.dtype							)

																_UpperCamelCase      : int         =   self.layer[1](
																    lowerCAmelCase__,			key_value_states=lowerCAmelCase__,			attention_mask=lowerCAmelCase__,			)

										# Apply Film Conditional Feed Forward layer
										_UpperCamelCase      : Optional[int]         =   self.layer[-1](lowerCAmelCase__,			lowerCAmelCase__							)

										return (hidden_states,)




class 			_a						(				nn.Module    ):






				def __init__(			self		:   Tuple,			lowerCAmelCase__		:   List[Any],			lowerCAmelCase__		:   Tuple,			lowerCAmelCase__		:   Optional[int],			lowerCAmelCase__		:   Optional[int]							)     ->				Optional[Any]:




										'''simple docstring'''



										super().__init__()
										_UpperCamelCase      : int         =   TaLayerNorm(lowerCAmelCase__							)
										_UpperCamelCase      : List[Any]         =   TaFiLMLayer(in_features=d_model * 4,			out_features=lowerCAmelCase__							)
										_UpperCamelCase      : Any         =   Attention(query_dim=lowerCAmelCase__,			heads=lowerCAmelCase__,			dim_head=lowerCAmelCase__,			out_bias=lowerCAmelCase__,			scale_qk=lowerCAmelCase__							)
										_UpperCamelCase      : List[str]         =   nn.Dropout(lowerCAmelCase__							)






				def     snake_case     (			self		:   Optional[int],			lowerCAmelCase__		:   Tuple,			lowerCAmelCase__		:   str=None,			lowerCAmelCase__		:   Union[str, Any]=None,			)     ->				List[str]:




										'''simple docstring'''



										_UpperCamelCase      : Any         =   self.layer_norm(lowerCAmelCase__							)

										if conditioning_emb is not None:
																_UpperCamelCase      : str         =   self.FiLMLayer(lowerCAmelCase__,			lowerCAmelCase__							)

										# Self-attention block
										_UpperCamelCase      : Tuple         =   self.attention(lowerCAmelCase__							)

										_UpperCamelCase      : Dict         =   hidden_states + self.dropout(lowerCAmelCase__							)

										return hidden_states




class 			_a						(				nn.Module    ):






				def __init__(			self		:   Tuple,			lowerCAmelCase__		:   Optional[Any],			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   str,			lowerCAmelCase__		:   Optional[Any],			lowerCAmelCase__		:   Tuple							)     ->				Tuple:




										'''simple docstring'''



										super().__init__()
										_UpperCamelCase      : Any         =   Attention(query_dim=lowerCAmelCase__,			heads=lowerCAmelCase__,			dim_head=lowerCAmelCase__,			out_bias=lowerCAmelCase__,			scale_qk=lowerCAmelCase__							)
										_UpperCamelCase      : Tuple         =   TaLayerNorm(lowerCAmelCase__,			eps=lowerCAmelCase__							)
										_UpperCamelCase      : int         =   nn.Dropout(lowerCAmelCase__							)






				def     snake_case     (			self		:   Optional[Any],			lowerCAmelCase__		:   List[Any],			lowerCAmelCase__		:   str=None,			lowerCAmelCase__		:   Union[str, Any]=None,			)     ->				List[Any]:




										'''simple docstring'''



										_UpperCamelCase      : Optional[int]         =   self.layer_norm(lowerCAmelCase__							)
										_UpperCamelCase      : Tuple         =   self.attention(
										    lowerCAmelCase__,			encoder_hidden_states=lowerCAmelCase__,			attention_mask=attention_mask.squeeze(1							),			)
										_UpperCamelCase      : str         =   hidden_states + self.dropout(lowerCAmelCase__							)
										return layer_output




class 			_a						(				nn.Module    ):






				def __init__(			self		:   Tuple,			lowerCAmelCase__		:   int,			lowerCAmelCase__		:   Tuple,			lowerCAmelCase__		:   Any,			lowerCAmelCase__		:   str							)     ->				Tuple:




										'''simple docstring'''



										super().__init__()
										_UpperCamelCase      : Any         =   TaDenseGatedActDense(d_model=lowerCAmelCase__,			d_ff=lowerCAmelCase__,			dropout_rate=lowerCAmelCase__							)
										_UpperCamelCase      : Optional[int]         =   TaFiLMLayer(in_features=d_model * 4,			out_features=lowerCAmelCase__							)
										_UpperCamelCase      : Union[str, Any]         =   TaLayerNorm(lowerCAmelCase__,			eps=lowerCAmelCase__							)
										_UpperCamelCase      : List[Any]         =   nn.Dropout(lowerCAmelCase__							)






				def     snake_case     (			self		:   Tuple,			lowerCAmelCase__		:   Optional[Any],			lowerCAmelCase__		:   List[str]=None							)     ->				Tuple:




										'''simple docstring'''



										_UpperCamelCase      : Any         =   self.layer_norm(lowerCAmelCase__							)
										if conditioning_emb is not None:
																_UpperCamelCase      : Dict         =   self.film(lowerCAmelCase__,			lowerCAmelCase__							)

										_UpperCamelCase      : str         =   self.DenseReluDense(lowerCAmelCase__							)
										_UpperCamelCase      : str         =   hidden_states + self.dropout(lowerCAmelCase__							)
										return hidden_states




class 			_a						(				nn.Module    ):






				def __init__(			self		:   str,			lowerCAmelCase__		:   List[Any],			lowerCAmelCase__		:   Optional[Any],			lowerCAmelCase__		:   Dict							)     ->				Tuple:




										'''simple docstring'''



										super().__init__()
										_UpperCamelCase      : List[str]         =   nn.Linear(lowerCAmelCase__,			lowerCAmelCase__,			bias=lowerCAmelCase__							)
										_UpperCamelCase      : Optional[int]         =   nn.Linear(lowerCAmelCase__,			lowerCAmelCase__,			bias=lowerCAmelCase__							)
										_UpperCamelCase      : Optional[int]         =   nn.Linear(lowerCAmelCase__,			lowerCAmelCase__,			bias=lowerCAmelCase__							)
										_UpperCamelCase      : List[str]         =   nn.Dropout(lowerCAmelCase__							)
										_UpperCamelCase      : Union[str, Any]         =   NewGELUActivation()






				def     snake_case     (			self		:   str,			lowerCAmelCase__		:   Tuple							)     ->				Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase      : Union[str, Any]         =   self.act(self.wi_a(lowerCAmelCase__							)							)
										_UpperCamelCase      : Dict         =   self.wi_a(lowerCAmelCase__							)
										_UpperCamelCase      : Any         =   hidden_gelu * hidden_linear
										_UpperCamelCase      : Any         =   self.dropout(lowerCAmelCase__							)

										_UpperCamelCase      : Optional[int]         =   self.wo(lowerCAmelCase__							)
										return hidden_states




class 			_a						(				nn.Module    ):






				def __init__(			self		:   Union[str, Any],			lowerCAmelCase__		:   Optional[int],			lowerCAmelCase__		:   Optional[Any]=1e-6							)     ->				Optional[Any]:




										'''simple docstring'''



										super().__init__()
										_UpperCamelCase      : Optional[Any]         =   nn.Parameter(torch.ones(lowerCAmelCase__							)							)
										_UpperCamelCase      : Tuple         =   eps






				def     snake_case     (			self		:   Dict,			lowerCAmelCase__		:   Tuple							)     ->				Any:




										'''simple docstring'''



										_UpperCamelCase      : Optional[Any]         =   hidden_states.to(torch.floataa							).pow(2							).mean(-1,			keepdim=lowerCAmelCase__							)
										_UpperCamelCase      : Union[str, Any]         =   hidden_states * torch.rsqrt(variance + self.variance_epsilon							)

										# convert into half-precision if necessary
										if self.weight.dtype in [torch.floataa, torch.bfloataa]:
																_UpperCamelCase      : int         =   hidden_states.to(self.weight.dtype							)

										return self.weight * hidden_states




class 			_a						(				nn.Module    ):






				def     snake_case     (			self		:   Optional[Any],			lowerCAmelCase__		:   torch.Tensor							)     ->				torch.Tensor:




										'''simple docstring'''



										return 0.5 * input * (1.0 + torch.tanh(math.sqrt(2.0 / math.pi							) * (input + 0.044_715 * torch.pow(lowerCAmelCase__,			3.0							))							))




class 			_a						(				nn.Module    ):






				def __init__(			self		:   List[str],			lowerCAmelCase__		:   Optional[Any],			lowerCAmelCase__		:   int							)     ->				List[Any]:




										'''simple docstring'''



										super().__init__()
										_UpperCamelCase      : Tuple         =   nn.Linear(lowerCAmelCase__,			out_features * 2,			bias=lowerCAmelCase__							)






				def     snake_case     (			self		:   int,			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   Any							)     ->				int:




										'''simple docstring'''



										_UpperCamelCase      : Union[str, Any]         =   self.scale_bias(lowerCAmelCase__							)
										_UpperCamelCase       ,							_UpperCamelCase      : Union[str, Any]         =   torch.chunk(lowerCAmelCase__,			2,			-1							)
										_UpperCamelCase      : Optional[int]         =   x * (1 + scale) + shift
										return x



