




"""simple docstring"""


from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, Encoder, VectorQuantizer


@dataclass
class _lowerCamelCase    (					a_						):
   _lowerCamelCase    :torch.FloatTensor






class _lowerCamelCase    (					a_       ,	a_						):






   @register_to_config
   def __init__(		self       :		Optional[Any]   ,     UpperCamelCase       :		int = 3   ,     UpperCamelCase       :		int = 3   ,     UpperCamelCase       :		Tuple[str] = ("DownEncoderBlock2D",)   ,     UpperCamelCase       :		Tuple[str] = ("UpDecoderBlock2D",)   ,     UpperCamelCase       :		Tuple[int] = (64,)   ,     UpperCamelCase       :		int = 1   ,     UpperCamelCase       :		str = "silu"   ,     UpperCamelCase       :		int = 3   ,     UpperCamelCase       :		int = 32   ,     UpperCamelCase       :		int = 2_56   ,     UpperCamelCase       :		int = 32   ,     UpperCamelCase       :		Optional[int] = None   ,     UpperCamelCase       :		float = 0.1_8215   ,     UpperCamelCase       :		str = "group"   ,     )			->						Tuple:

         """simple docstring"""
         super().__init__()

         # pass init params to Encoder
         lowerCAmelCase__      :			Optional[int]   =	Encoder(
             in_channels=UpperCamelCase   ,     out_channels=UpperCamelCase   ,     down_block_types=UpperCamelCase   ,     block_out_channels=UpperCamelCase   ,     layers_per_block=UpperCamelCase   ,     act_fn=UpperCamelCase   ,     norm_num_groups=UpperCamelCase   ,     double_z=UpperCamelCase   ,     )

         lowerCAmelCase__      :			List[str]   =	vq_embed_dim if vq_embed_dim is not None else latent_channels

         lowerCAmelCase__      :			Union[str, Any]   =	nn.Convad(UpperCamelCase   ,     UpperCamelCase   ,     1   )
         lowerCAmelCase__      :			List[str]   =	VectorQuantizer(UpperCamelCase   ,     UpperCamelCase   ,     beta=0.25   ,     remap=UpperCamelCase   ,     sane_index_shape=UpperCamelCase   )
         lowerCAmelCase__      :			Dict   =	nn.Convad(UpperCamelCase   ,     UpperCamelCase   ,     1   )

         # pass init params to Decoder
         lowerCAmelCase__      :			int   =	Decoder(
             in_channels=UpperCamelCase   ,     out_channels=UpperCamelCase   ,     up_block_types=UpperCamelCase   ,     block_out_channels=UpperCamelCase   ,     layers_per_block=UpperCamelCase   ,     act_fn=UpperCamelCase   ,     norm_num_groups=UpperCamelCase   ,     norm_type=UpperCamelCase   ,     )






   @apply_forward_hook
   def 	_lowerCAmelCase   (		self       :		Optional[Any]   ,     UpperCamelCase       :		torch.FloatTensor   ,     UpperCamelCase       :		bool = True   )			->						VQEncoderOutput:

         """simple docstring"""
         lowerCAmelCase__      :			Union[str, Any]   =	self.encoder(UpperCamelCase   )
         lowerCAmelCase__      :			str   =	self.quant_conv(UpperCamelCase   )

         if not return_dict:
               return (h,)

         return VQEncoderOutput(latents=UpperCamelCase   )






   @apply_forward_hook
   def 	_lowerCAmelCase   (		self       :		str   ,     UpperCamelCase       :		torch.FloatTensor   ,     UpperCamelCase       :		bool = False   ,     UpperCamelCase       :		bool = True   )			->						Union[DecoderOutput, torch.FloatTensor]:

         """simple docstring"""
         # also go through quantization layer
         if not force_not_quantize:
               lowerCAmelCase__      :			Any   =	self.quantize(UpperCamelCase   )
         else:
               lowerCAmelCase__      :			List[str]   =	h
         lowerCAmelCase__      :			int   =	self.post_quant_conv(UpperCamelCase   )
         lowerCAmelCase__      :			Union[str, Any]   =	self.decoder(UpperCamelCase   ,     quant if self.config.norm_type == """spatial""" else None   )

         if not return_dict:
               return (dec,)

         return DecoderOutput(sample=UpperCamelCase   )






   def 	_lowerCAmelCase   (		self       :		List[Any]   ,     UpperCamelCase       :		torch.FloatTensor   ,     UpperCamelCase       :		bool = True   )			->						Union[DecoderOutput, torch.FloatTensor]:

         """simple docstring"""
         lowerCAmelCase__      :			int   =	sample
         lowerCAmelCase__      :			Dict   =	self.encode(UpperCamelCase   ).latents
         lowerCAmelCase__      :			int   =	self.decode(UpperCamelCase   ).sample

         if not return_dict:
               return (dec,)

         return DecoderOutput(sample=UpperCamelCase   )











"""simple docstring"""


import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, ClassLabel, Features
from .base import TaskTemplate


@dataclass(frozen=a_						)
class _lowerCamelCase    (					a_						):
   _lowerCamelCase    :str     				=     field(default="audio-classification"       ,	metadata={"include_in_asdict_even_if_is_default": True}						)
   _lowerCamelCase    :ClassVar[Features]     				=     Features({"audio": Audio()}						)
   _lowerCamelCase    :ClassVar[Features]     				=     Features({"labels": ClassLabel}						)
   _lowerCamelCase    :str     				=     "audio"
   _lowerCamelCase    :str     				=     "labels"






   def 	_lowerCAmelCase   (		self       :		str   ,     UpperCamelCase       :		Optional[int]   )			->						Union[str, Any]:

         """simple docstring"""
         if self.label_column not in features:
               raise ValueError(f"""Column {self.label_column} is not present in features."""   )
         if not isinstance(features[self.label_column]   ,     UpperCamelCase   ):
               raise ValueError(f"""Column {self.label_column} is not a ClassLabel."""   )
         lowerCAmelCase__      :			str   =	copy.deepcopy(self   )
         lowerCAmelCase__      :			Optional[int]   =	self.label_schema.copy()
         lowerCAmelCase__      :			List[Any]   =	features[self.label_column]
         lowerCAmelCase__      :			Optional[int]   =	label_schema
         return task_template






   @property
   def 	_lowerCAmelCase   (		self       :		List[Any]   )			->						Dict[str, str]:

         """simple docstring"""
         return {
             self.audio_column: "audio",
             self.label_column: "labels",
         }





