





'''simple docstring'''







from typing import Optional

from torch import nn

from .transformer_ad import TransformeraDModel, TransformeraDModelOutput
class 							__SCREAMING_SNAKE_CASE    (nn.Module ):






				"""simple docstring"""







				def __init__(    self	:   Tuple   ,							__a	:   int = 16   ,							__a	:   int = 88   ,							__a	:   Optional[int] = None   ,							__a	:   int = 1   ,							__a	:   float = 0.0   ,							__a	:   int = 32   ,							__a	:   Optional[int] = None   ,							__a	:   bool = False   ,							__a	:   Optional[int] = None   ,							__a	:   Optional[int] = None   ,							__a	:   str = "geglu"   ,							__a	:   Optional[int] = None   ,							):
								super().__init__()
								_a				      =					nn.ModuleList(
								    [
								        TransformeraDModel(
								            num_attention_heads=__a   ,							attention_head_dim=__a   ,							in_channels=__a   ,							num_layers=__a   ,							dropout=__a   ,							norm_num_groups=__a   ,							cross_attention_dim=__a   ,							attention_bias=__a   ,							sample_size=__a   ,							num_vector_embeds=__a   ,							activation_fn=__a   ,							num_embeds_ada_norm=__a   ,							)
								        for _ in range(2   )
								    ]   )

								# Variables that can be set by a pipeline:

								# The ratio of transformer1 to transformer2's output states to be combined during inference
								_a				      =					0.5

								# The shape of `encoder_hidden_states` is expected to be
								# `(batch_size, condition_lengths[0]+condition_lengths[1], num_features)`
								_a				      =					[77, 2_57]

								# Which transformer to use to encode which condition.
								# E.g. `(1, 0)` means that we'll use `transformers[1](conditions[0])` and `transformers[0](conditions[1])`
								_a				      =					[1, 0]




				def     UpperCamelCase__  (    self	:   Union[str, Any]   ,							__a	:   Tuple   ,							__a	:   str   ,							__a	:   int=None   ,							__a	:   int=None   ,							__a	:   Dict=None   ,							__a	:   bool = True   ,							):
								_a				      =					hidden_states

								_a				      =					[]
								_a				      =					0
								# attention_mask is not used yet
								for i in range(2   ):
												# for each of the two transformers, pass the corresponding condition tokens
												_a				      =					encoder_hidden_states[:, tokens_start : tokens_start + self.condition_lengths[i]]
												_a				      =					self.transformer_index_for_condition[i]
												_a				      =					self.transformers[transformer_index](
												    __a   ,							encoder_hidden_states=__a   ,							timestep=__a   ,							cross_attention_kwargs=__a   ,							return_dict=__a   ,							)[0]
												encoded_states.append(encoded_state - input_states   )
												tokens_start += self.condition_lengths[i]

								_a				      =					encoded_states[0] * self.mix_ratio + encoded_states[1] * (1 - self.mix_ratio)
								_a				      =					output_states + input_states

								if not return_dict:
												return (output_states,)

								return TransformeraDModelOutput(sample=__a   )




'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_speech_available, is_torch_available


__A   :    str											= {
    "configuration_audio_spectrogram_transformer": [
        "AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "ASTConfig",
    ]
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __A   :    List[str]											= [
      "AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
      "ASTForAudioClassification",
      "ASTModel",
      "ASTPreTrainedModel",
  ]

try:
  if not is_speech_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __A   :    Union[str, Any]											= ["ASTFeatureExtractor"]

if TYPE_CHECKING:
  from .configuration_audio_spectrogram_transformer import (
      AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
      ASTConfig,
  )

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_audio_spectrogram_transformer import (
        AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
        ASTForAudioClassification,
        ASTModel,
        ASTPreTrainedModel,
    )

  try:
    if not is_speech_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .feature_extraction_audio_spectrogram_transformer import ASTFeatureExtractor


else:
  import sys

  __A   :    List[Any]											= _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



