Ë
    T^(hÈk  ã                   ó¨  — d Z ddlmZ ddlmZmZmZ ddlZddlZddlm	Z	 ddl
mZmZ ddlmZmZmZmZ d	d
lmZ  ej(                  e«      ZdZdZe G d„ de«      «       Z G d„ de	j4                  «      Z G d„ de	j4                  «      Z G d„ de	j4                  «      Z G d„ de	j4                  «      ZdZdZ  ede«       G d„ de«      «       Z!dgZ"y)zPyTorch UnivNetModel model.é    )Ú	dataclass)ÚOptionalÚTupleÚUnionN)Únné   )ÚModelOutputÚPreTrainedModel)Úadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚloggingÚreplace_return_docstringsé   )ÚUnivNetConfigr   zdg845/univnet-devc                   ób   — e Zd ZU dZdZeej                     ed<   dZ	eej                     ed<   y)ÚUnivNetModelOutputa  
    Output class for the [`UnivNetModel`], which includes the generated audio waveforms and the original unpadded
    lengths of those waveforms (so that the padding can be removed by [`UnivNetModel.batch_decode`]).

    Args:
        waveforms (`torch.FloatTensor` of shape `(batch_size, sequence_length)`):
            Batched 1D (mono-channel) output audio waveforms.
        waveform_lengths (`torch.FloatTensor` of shape `(batch_size,)`):
            The batched length in samples of each unpadded waveform in `waveforms`.
    NÚ	waveformsÚwaveform_lengths)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚtorchÚFloatTensorÚ__annotations__r   © ó    új/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/univnet/modeling_univnet.pyr   r   $   s4   … ñ	ð .2€Iˆx˜×)Ñ)Ñ*Ó1Ø48Ð�h˜u×0Ñ0Ñ1Ô8r   r   c                   óT   ‡ — e Zd ZdZdefˆ fd„Zdej                  fd„Zd„ Z	d„ Z
ˆ xZS )Ú#UnivNetKernelPredictorResidualBlockzô
    Implementation of the residual block for the kernel predictor network inside each location variable convolution
    block (LVCBlock).

    Parameters:
        config: (`UnivNetConfig`):
            Config for the `UnivNetModel` model.
    Úconfigc                 ó
  •— t         ‰| �  «        |j                  | _        |j                  | _        |j                  | _        |j                  | _        | j
                  dz
  dz  }t        j                  | j                  «      | _        t        j                  | j                  | j                  | j
                  |d¬«      | _        t        j                  | j                  | j                  | j
                  |d¬«      | _        y )Nr   é   T©ÚpaddingÚbias)ÚsuperÚ__init__Úmodel_in_channelsÚchannelsÚkernel_predictor_conv_sizeÚkernel_sizeÚkernel_predictor_dropoutÚdropout_probÚleaky_relu_sloper   ÚDropoutÚdropoutÚConv1dÚconv1Úconv2)Úselfr!   r%   Ú	__class__s      €r   r(   z,UnivNetKernelPredictorResidualBlock.__init__?   sÂ   ø€ ô 	‰ÑÔØ×0Ñ0ˆŒØ!×<Ñ<ˆÔØ"×;Ñ;ˆÔØ &× 7Ñ 7ˆÔà×#Ñ# aÑ'¨AÑ-ˆä—z‘z $×"3Ñ"3Ó4ˆŒÜ—Y‘Y˜tŸ}™}¨d¯m©m¸T×=MÑ=MÐW^ÐeiÔjˆŒ
Ü—Y‘Y˜tŸ}™}¨d¯m©m¸T×=MÑ=MÐW^ÐeiÔjˆ�
r   Úhidden_statesc                 ó  — |}| j                  |«      }| j                  |«      }t        j                  j	                  || j
                  «      }| j                  |«      }t        j                  j	                  || j
                  «      }||z   S ©N)r1   r3   r   Ú
functionalÚ
leaky_relur/   r4   )r5   r7   Úresiduals      r   Úforwardz+UnivNetKernelPredictorResidualBlock.forwardO   st   € à ˆØŸ™ ]Ó3ˆØŸ
™
 =Ó1ˆÜŸ™×0Ñ0°À×@UÑ@UÓVˆØŸ
™
 =Ó1ˆÜŸ™×0Ñ0°À×@UÑ@UÓVˆØ˜xÑ'Ð'r   c                 ó  — t         j                  j                  }t        t         j                  j                  d«      r$t         j                  j                  j                  } || j
                  «        || j                  «       y ©NÚweight_norm)r   Úutilsr@   ÚhasattrÚparametrizationsr3   r4   ©r5   r@   s     r   Úapply_weight_normz5UnivNetKernelPredictorResidualBlock.apply_weight_normY   sR   € Ü—h‘h×*Ñ*ˆÜ”2—8‘8×,Ñ,¨mÔ<ÜŸ(™(×3Ñ3×?Ñ?ˆKá�D—J‘JÔÙ�D—J‘JÕr   c                 ó¨   — t         j                  j                  | j                  «       t         j                  j                  | j                  «       y r9   )r   rA   Úremove_weight_normr3   r4   ©r5   s    r   rG   z6UnivNetKernelPredictorResidualBlock.remove_weight_norma   s.   € Ü
�‰×#Ñ# D§J¡JÔ/Ü
�‰×#Ñ# D§J¡JÕ/r   )r   r   r   r   r   r(   r   r   r=   rE   rG   Ú__classcell__©r6   s   @r   r    r    5   s3   ø„ ñðkàõkð ( U×%6Ñ%6ó (ò ö0r   r    c                   ób   ‡ — e Zd ZdZ	 	 d
dededefˆ fd„Zdej                  fd„Z	d„ Z
d	„ Zˆ xZS )ÚUnivNetKernelPredictora  
    Implementation of the kernel predictor network which supplies the kernel and bias for the location variable
    convolutional layers (LVCs) in each UnivNet LVCBlock.

    Based on the KernelPredictor implementation in
    [maum-ai/univnet](https://github.com/maum-ai/univnet/blob/9bb2b54838bb6d7ce767131cc7b8b61198bc7558/model/lvcnet.py#L7).

    Parameters:
        config: (`UnivNetConfig`):
            Config for the `UnivNetModel` model.
        conv_kernel_size (`int`, *optional*, defaults to 3):
            The kernel size for the location variable convolutional layer kernels (convolutional weight tensor).
        conv_layers (`int`, *optional*, defaults to 4):
            The number of location variable convolutional layers to output kernels and biases for.
    r!   Úconv_kernel_sizeÚconv_layersc                 óî  •— t         ‰| �  «        |j                  | _        d|j                  z  | _        || _        || _        | j                  | j                  z  | j
                  z  | j                  z  | _        | j                  | j                  z  | _        |j                  | _
        |j                  | _        |j                  | _        |j                  | _        |j"                  | _        | j                  dz
  dz  }t%        j&                  | j                  | j                  ddd¬«      | _        t%        j*                  t-        | j                   «      D �cg c]  }t/        |«      ‘Œ c}«      | _        t%        j&                  | j                  | j                  | j                  |d¬«      | _        t%        j&                  | j                  | j                  | j                  |d¬«      | _        y c c}w )Nr#   r   é   Tr$   )r'   r(   Úmodel_hidden_channelsÚconv_in_channelsÚconv_out_channelsrM   rN   Úkernel_channelsÚbias_channelsÚnum_mel_binsÚresnet_in_channelsÚ kernel_predictor_hidden_channelsÚresnet_hidden_channelsr+   Úresnet_kernel_sizeÚkernel_predictor_num_blocksÚ
num_blocksr/   r   r2   Ú
input_convÚ
ModuleListÚranger    Ú	resblocksÚkernel_convÚ	bias_conv)r5   r!   rM   rN   r%   Ú_r6   s         €r   r(   zUnivNetKernelPredictor.__init__w   s¨  ø€ ô 	‰ÑÔà &× <Ñ <ˆÔØ!" V×%AÑ%AÑ!AˆÔØ 0ˆÔØ&ˆÔð ×!Ñ! D×$:Ñ$:Ñ:¸T×=RÑ=RÑRÐUY×UeÑUeÑeð 	Ôð "×3Ñ3°d×6FÑ6FÑFˆÔà"(×"5Ñ"5ˆÔØ&,×&MÑ&MˆÔ#Ø"(×"CÑ"CˆÔØ ×<Ñ<ˆŒà &× 7Ñ 7ˆÔà×*Ñ*¨QÑ.°1Ñ4ˆäŸ)™) D×$;Ñ$;¸T×=XÑ=XÐZ[ÐefÐmqÔrˆŒäŸ™Ô]bÐcg×crÑcrÓ]sÖ'tÐXYÔ(KÈFÕ(SÒ'tÓuˆŒäŸ9™9Ø×'Ñ'¨×)=Ñ)=¸t×?VÑ?VÐ`gÐnrô
ˆÔô Ÿ™Ø×'Ñ'¨×);Ñ);¸T×=TÑ=TÐ^eÐlpô
ˆ�ùò (us   ÅG2Úspectrogramc                 ó  — |j                   \  }}}| j                  |«      }t        j                  j	                  || j
                  «      }| j                  D ]
  } ||«      }Œ | j                  |«      }| j                  |«      }|j                  || j                  | j                  | j                  | j                  |«      j                  «       }	|j                  || j                  | j                  |«      j                  «       }
|	|
fS )a­  
        Maps a conditioning log-mel spectrogram to a tensor of convolutional kernels and biases, for use in location
        variable convolutional layers. Note that the input spectrogram should have shape (batch_size, input_channels,
        seq_length).

        Args:
            spectrogram (`torch.FloatTensor` of shape `(batch_size, input_channels, seq_length)`):
                Tensor containing the log-mel spectrograms.

        Returns:
            Tuple[`torch.FloatTensor, `torch.FloatTensor`]: tuple of tensors where the first element is the tensor of
            location variable convolution kernels of shape `(batch_size, self.conv_layers, self.conv_in_channels,
            self.conv_out_channels, self.conv_kernel_size, seq_length)` and the second element is the tensor of
            location variable convolution biases of shape `(batch_size, self.conv_layers. self.conv_out_channels,
            seq_length)`.
        )Úshaper]   r   r:   r;   r/   r`   ra   rb   ÚviewrN   rR   rS   rM   Ú
contiguous)r5   rd   Ú
batch_sizerc   Ú
seq_lengthr7   ÚresblockÚkernel_hidden_statesÚbias_hidden_statesÚkernelsÚbiasess              r   r=   zUnivNetKernelPredictor.forward�   s	  € ð" %0×$5Ñ$5Ñ!ˆ
�A�zàŸ™¨Ó4ˆÜŸ™×0Ñ0°À×@UÑ@UÓVˆàŸ™ò 	4ˆHÙ$ ]Ó3‰Mð	4ð  $×/Ñ/°Ó>ÐØ!Ÿ^™^¨MÓ:Ðð '×+Ñ+ØØ×ÑØ×!Ñ!Ø×"Ñ"Ø×!Ñ!Øó
÷ ‰*‹,ð 	ð $×(Ñ(ØØ×ÑØ×"Ñ"Øó	
÷
 ‰*‹,ð 	ð ˜ˆÐr   c                 óv  — t         j                  j                  }t        t         j                  j                  d«      r$t         j                  j                  j                  } || j
                  «       | j                  D ]  }|j                  «        Œ  || j                  «        || j                  «       y r?   )
r   rA   r@   rB   rC   r]   r`   rE   ra   rb   ©r5   r@   Úlayers      r   rE   z(UnivNetKernelPredictor.apply_weight_normË   s   € Ü—h‘h×*Ñ*ˆÜ”2—8‘8×,Ñ,¨mÔ<ÜŸ(™(×3Ñ3×?Ñ?ˆKá�D—O‘OÔ$Ø—^‘^ò 	&ˆEØ×#Ñ#Õ%ð	&á�D×$Ñ$Ô%Ù�D—N‘NÕ#r   c                 ó<  — t         j                  j                  | j                  «       | j                  D ]  }|j                  «        Œ t         j                  j                  | j
                  «       t         j                  j                  | j                  «       y r9   )r   rA   rG   r]   r`   ra   rb   ©r5   rr   s     r   rG   z)UnivNetKernelPredictor.remove_weight_normÖ   se   € Ü
�‰×#Ñ# D§O¡OÔ4Ø—^‘^ò 	'ˆEØ×$Ñ$Õ&ð	'ä
�‰×#Ñ# D×$4Ñ$4Ô5Ü
�‰×#Ñ# D§N¡NÕ3r   )r   é   ©r   r   r   r   r   Úintr(   r   r   r=   rE   rG   rI   rJ   s   @r   rL   rL   f   sO   ø„ ñð& !"Øñ	$
àð$
ð ð$
ð õ	$
ðL, 5×#4Ñ#4ó ,ò\	$ö4r   rL   c                   ó¢   ‡ — e Zd ZdZdededefˆ fd„Zdd„Z	 	 ddej                  dej                  d	ej                  ded
ef
d„Z
d„ Zd„ Zˆ xZS )ÚUnivNetLvcResidualBlocka•  
    Implementation of the location variable convolution (LVC) residual block for the UnivNet residual network.

    Parameters:
        config: (`UnivNetConfig`):
            Config for the `UnivNetModel` model.
        kernel_size (`int`):
            The kernel size for the dilated 1D convolutional layer.
        dilation (`int`):
            The dilation for the dilated 1D convolutional layer.
    r!   r,   Údilationc                 óN  •— t         ‰| �  «        |j                  | _        || _        || _        |j                  | _        | j
                  | j                  dz
  z  dz  }t        j                  | j                  | j                  | j                  || j
                  ¬«      | _	        y )Nr   r#   )r%   rz   )
r'   r(   rQ   Úhidden_channelsr,   rz   r/   r   r2   Úconv)r5   r!   r,   rz   r%   r6   s        €r   r(   z UnivNetLvcResidualBlock.__init__ë   sŽ   ø€ ô 	‰ÑÔØ%×;Ñ;ˆÔØ&ˆÔØ ˆŒØ &× 7Ñ 7ˆÔà—-‘- 4×#3Ñ#3°aÑ#7Ñ8¸AÑ=ˆä—I‘IØ× Ñ Ø× Ñ Ø×ÑØØ—]‘]ô
ˆ�	r   c                 ó¶  — |}t         j                  j                  || j                  «      }| j	                  |«      }t         j                  j                  || j                  «      }| j                  ||||¬«      }t        j                  |d d …d | j                  …d d …f   «      t        j                  |d d …| j                  d …d d …f   «      z  }||z   }|S ©N)Úhop_size)
r   r:   r;   r/   r}   Úlocation_variable_convolutionr   Úsigmoidr|   Útanh)r5   r7   Úkernelr&   r€   r<   s         r   r=   zUnivNetLvcResidualBlock.forward  sÌ   € Ø ˆÜŸ™×0Ñ0°À×@UÑ@UÓVˆØŸ	™	 -Ó0ˆÜŸ™×0Ñ0°À×@UÑ@UÓVˆØ×:Ñ:¸=È&ÐRVÐaiÐ:ÓjˆäŸ™ m²AÐ7M¸×9MÑ9MÐ7MÊqÐ4PÑ&QÓRÔUZ×U_ÑU_Øš!˜T×1Ñ1Ñ3²QÐ6Ñ7óV
ñ 
ˆð ! =Ñ0ˆàÐr   r7   r„   r&   r€   c                 óF  — |j                   \  }}}|j                   \  }}}	}
}|||z  k7  rt        d||z  › d|› d�«      ‚|t        |
dz
  dz  «      z  }t        j                  j                  |||fdd«      }|j                  d|d|z  z   |«      }||k  r$t        j                  j                  |d|fdd«      }|j                  d||«      }|d	d	…d	d	…d	d	…d	d	…d	|…f   }|j                  dd
«      }|j                  d
|
d«      }t        j                  d||«      }|j                  t        j                  ¬«      }|j                  d«      j                  d«      j                  t        j                  ¬«      }||z   }|j                  «       j                  ||	d«      }|S )u¼  
        Performs location-variable convolution operation on the input sequence (hidden_states) using the local
        convolution kernel. This was introduced in [LVCNet: Efficient Condition-Dependent Modeling Network for Waveform
        Generation](https://arxiv.org/abs/2102.10815) by Zhen Zheng, Jianzong Wang, Ning Cheng, and Jing Xiao.

        Time: 414 Î¼s Â± 309 ns per loop (mean Â± std. dev. of 7 runs, 1000 loops each), test on NVIDIA V100.

        Args:
            hidden_states (`torch.FloatTensor` of shape `(batch_size, in_channels, in_length)`):
                The input sequence of shape (batch, in_channels, in_length).
            kernel (`torch.FloatTensor` of shape `(batch_size, in_channels, out_channels, kernel_size, kernel_length)`):
                The local convolution kernel of shape (batch, in_channels, out_channels, kernel_size, kernel_length).
            bias (`torch.FloatTensor` of shape `(batch_size, out_channels, kernel_length)`):
                The bias for the local convolution of shape (batch, out_channels, kernel_length).
            dilation (`int`, *optional*, defaults to 1):
                The dilation of convolution.
            hop_size (`int`, *optional*, defaults to 256):
                The hop_size of the conditioning sequence.
        Returns:
            `torch.FloatTensor`: the output sequence after performing local convolution with shape (batch_size,
            out_channels, in_length).
        z#Dim 2 of `hidden_states` should be z
) but got zX. Please check `hidden_states` or `kernel` and `hop_size` to make sure they are correct.r   r#   Úconstantr   r   Nru   zbildsk,biokl->bolsd)Úmemory_formatéÿÿÿÿ)rf   Ú
ValueErrorrw   r   r:   ÚpadÚunfoldÚ	transposer   ÚeinsumÚtoÚchannels_last_3dÚ	unsqueezerh   rg   )r5   r7   r„   r&   rz   r€   Úbatchrc   Ú	in_lengthÚout_channelsr,   Úkernel_lengthr%   Úoutput_hidden_statess                 r   r�   z5UnivNetLvcResidualBlock.location_variable_convolution  sÇ  € ð< ,×1Ñ1Ñˆˆq�)Ø=C¿\¹\Ñ:ˆˆq�, ¨]Ø˜¨Ñ1Ò2ÜØ5°mÀhÑ6NÐ5OÈzÐZcÐYdð e]ð ]óð ð
 œS +°¡/°QÑ!6Ó7Ñ7ˆô Ÿ™×)Ñ)¨-¸'À7Ð9KÈZÐYZÓ[ˆà%×,Ñ,¨Q°¸1¸w¹;Ñ0FÈÓQˆà�hÒÜŸM™M×-Ñ-¨m¸aÀ¸]ÈJÐXYÓZˆMà%×,Ñ,¨Q°¸(ÓCˆØ%¢aªªAªq°)°8°)Ð&;Ñ<ˆà%×/Ñ/°°1Ó5ˆà%×,Ñ,¨Q°¸QÓ?ˆô  %Ÿ|™|Ð,AÀ=ÐRXÓYÐà3×6Ñ6ÄU×E[ÑE[Ð6Ó\ÐØ�~‰~˜bÓ!×+Ñ+¨BÓ/×2Ñ2Ä×AWÑAWÐ2ÓXˆØ3°dÑ:ÐØ3×>Ñ>Ó@×EÑEÀeÈ\Ð[]Ó^Ðà#Ð#r   c                 óì   — t         j                  j                  }t        t         j                  j                  d«      r$t         j                  j                  j                  } || j
                  «       y r?   )r   rA   r@   rB   rC   r}   rD   s     r   rE   z)UnivNetLvcResidualBlock.apply_weight_normR  sF   € Ü—h‘h×*Ñ*ˆÜ”2—8‘8×,Ñ,¨mÔ<ÜŸ(™(×3Ñ3×?Ñ?ˆKá�D—I‘IÕr   c                 óV   — t         j                  j                  | j                  «       y r9   )r   rA   rG   r}   rH   s    r   rG   z*UnivNetLvcResidualBlock.remove_weight_normY  s   € Ü
�‰×#Ñ# D§I¡IÕ.r   ©é   )r   r™   )r   r   r   r   r   rw   r(   r=   r   r   r�   rE   rG   rI   rJ   s   @r   ry   ry   Þ   sˆ   ø„ ñ
ð
àð
ð ð
ð õ	
ó,ð* Øñ?$à×(Ñ(ð?$ð ×!Ñ!ð?$ð ×Ñð	?$ð
 ð?$ð ó?$òBö/r   ry   c                   óx   ‡ — e Zd ZdZ	 ddededefˆ fd„Zdej                  dej                  fd„Z	d	„ Z
d
„ Zˆ xZS )ÚUnivNetLvcBlocka#  
    Implementation of the location variable convolution (LVC) residual block of the UnivNet residual block. Includes a
    `UnivNetKernelPredictor` inside to predict the kernels and biases of the LVC layers.

    Based on LVCBlock in
    [maum-ai/univnet](https://github.com/maum-ai/univnet/blob/9bb2b54838bb6d7ce767131cc7b8b61198bc7558/model/lvcnet.py#L98)

    Parameters:
        config (`UnivNetConfig`):
            Config for the `UnivNetModel` model.
        layer_id (`int`):
            An integer corresponding to the index of the current LVC resnet block layer. This should be between 0 and
            `len(config.resblock_stride_sizes) - 1)` inclusive.
        lvc_hop_size (`int`, *optional*, defaults to 256):
            The hop size for the location variable convolutional layers.
    r!   Úlayer_idÚlvc_hop_sizec                 ó  •— t         ‰| �  «        |j                  | _        |j                  |   | _        |j                  |   | _        |j                  |   | _	        || _
        |j                  | _        t        | j                  «      | _        t        j                  | j                  | j                  d| j                  z  | j                  | j                  dz  | j                  dz  z   | j                  dz  ¬«      | _        t#        || j
                  | j                  «      | _        t        j&                  t)        | j                  «      D �cg c]&  }t+        || j
                  | j                  |   «      ‘Œ( c}«      | _        y c c}w )Nr#   )Ústrider%   Úoutput_padding)r'   r(   rQ   r|   Úresblock_kernel_sizesr,   Úresblock_stride_sizesrŸ   Úresblock_dilation_sizesÚ	dilationsÚcond_hop_lengthr/   Úlenr\   r   ÚConvTranspose1dÚ	convt_prerL   Úkernel_predictorr^   r_   ry   r`   )r5   r!   rœ   r�   Úir6   s        €r   r(   zUnivNetLvcBlock.__init__o  s<  ø€ ô 	‰ÑÔØ%×;Ñ;ˆÔØ!×7Ñ7¸ÑAˆÔØ×2Ñ2°8Ñ<ˆŒØ×7Ñ7¸ÑAˆŒØ+ˆÔØ &× 7Ñ 7ˆÔÜ˜dŸn™nÓ-ˆŒä×+Ñ+Ø× Ñ Ø× Ñ Ø�—‘‰OØ—;‘;Ø—K‘K 1Ñ$ t§{¡{°Q¡Ñ6ØŸ;™;¨™?ô
ˆŒô !7°v¸t×?OÑ?OÐQU×Q`ÑQ`Ó aˆÔäŸ™Ü[`Ðae×apÑapÓ[qÖrÐVWÔ$ V¨T×-=Ñ-=¸t¿~¹~ÈaÑ?PÕQÒró
ˆ�ùÚrs   Å+Fr7   rd   c           	      óR  — t         j                  j                  || j                  «      }| j	                  |«      }| j                  |«      \  }}t        | j                  «      D ]?  \  }}|d d …|d d …d d …d d …d d …f   }|d d …|d d …d d …f   } ||||| j                  ¬«      }ŒA |S r   )	r   r:   r;   r/   r¨   r©   Ú	enumerater`   r¥   )	r5   r7   rd   rn   ro   rª   rk   r„   r&   s	            r   r=   zUnivNetLvcBlock.forward�  s§   € ô Ÿ™×0Ñ0°À×@UÑ@UÓVˆØŸ™ }Ó5ˆà×/Ñ/°Ó<‰ˆ�ä$ T§^¡^Ó4ò 	a‰KˆAˆxØšQ ¢1¢aªªAÐ-Ñ.ˆFØš!˜Q¢¢1˜*Ñ%ˆDÙ$ ]°F¸DÈ4×K_ÑK_Ô`‰Mð	að
 Ðr   c                 ób  — t         j                  j                  }t        t         j                  j                  d«      r$t         j                  j                  j                  } || j
                  «       | j                  j                  «        | j                  D ]  }|j                  «        Œ y r?   )	r   rA   r@   rB   rC   r¨   r©   rE   r`   rq   s      r   rE   z!UnivNetLvcBlock.apply_weight_normœ  sw   € Ü—h‘h×*Ñ*ˆÜ”2—8‘8×,Ñ,¨mÔ<ÜŸ(™(×3Ñ3×?Ñ?ˆKá�D—N‘NÔ#Ø×Ñ×/Ñ/Ô1Ø—^‘^ò 	&ˆEØ×#Ñ#Õ%ñ	&r   c                 óÌ   — t         j                  j                  | j                  «       | j                  j                  «        | j
                  D ]  }|j                  «        Œ y r9   )r   rA   rG   r¨   r©   r`   rt   s     r   rG   z"UnivNetLvcBlock.remove_weight_norm¦  sI   € Ü
�‰×#Ñ# D§N¡NÔ3Ø×Ñ×0Ñ0Ô2Ø—^‘^ò 	'ˆEØ×$Ñ$Õ&ñ	'r   r˜   rv   rJ   s   @r   r›   r›   ]  sW   ø„ ñð*  ñ	
àð
ð ð
ð õ	
ð< U×%6Ñ%6ð ÀU×EVÑEVó ò&ö'r   r›   aL  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`UnivNetConfig`]):
            Model configuration class with all the parameters of the model. Initializing with a config file does not
            load the weights associated with the model, only the configuration. Check out the
            [`~PreTrainedModel.from_pretrained`] method to load the model weights.
aR  
    Converts a noise waveform and a conditioning spectrogram to a speech waveform. Passing a batch of log-mel
    spectrograms returns a batch of speech waveforms. Passing a single, un-batched log-mel spectrogram returns a
    single, un-batched speech waveform.

    Args:
        input_features (`torch.FloatTensor`):
            Tensor containing the log-mel spectrograms. Can be batched and of shape `(batch_size, sequence_length,
            config.num_mel_channels)`, or un-batched and of shape `(sequence_length, config.num_mel_channels)`.
        noise_sequence (`torch.FloatTensor`, *optional*):
            Tensor containing a noise sequence of standard Gaussian noise. Can be batched and of shape `(batch_size,
            sequence_length, config.model_in_channels)`, or un-batched and of shape (sequence_length,
            config.model_in_channels)`. If not supplied, will be randomly generated.
        padding_mask (`torch.BoolTensor`, *optional*):
            Mask indicating which parts of each sequence are padded. Mask values are selected in `[0, 1]`:

            - 1 for tokens that are **not masked**
            - 0 for tokens that are **masked**

            The mask can be batched and of shape `(batch_size, sequence_length)` or un-batched and of shape
            `(sequence_length,)`.
        generator (`torch.Generator`, *optional*):
            A [torch generator](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make generation
            deterministic.
        return_dict:
            Whether to return a [`~utils.ModelOutput`] subclass instead of a plain tuple.
zUnivNet GAN vocoder.c                   ó$  ‡ — e Zd ZeZdZdefˆ fd„Z ee«       e	e
e¬«      	 	 	 	 ddej                  deej                     deej                     deej                     dee   d	eeej                     e
f   fd
„«       «       Zd„ Zd„ Zd„ Zˆ xZS )ÚUnivNetModelÚinput_featuresr!   c                 ó^  •— t         ‰| �  |«       t        |j                  «      | _        |j
                  | _        t        j                  |j                  |j                  dddd¬«      | _
        t        |j                  «      }d}g }|j                  D ]  }||z  }|j                  |«       Œ t        j                  t        |«      D �cg c]  }t        ||||   ¬«      ‘Œ c}«      | _        t        j                  |j                  dddd¬«      | _        | j%                  «        y c c}w )Né   r   r   Úreflect)r,   rŸ   r%   Úpadding_mode)rœ   r�   )r%   rµ   )r'   r(   r¦   r¡   Únum_kernelsr/   r   r2   r)   rQ   Úconv_prer¢   Úappendr^   r_   r›   r`   Ú	conv_postÚ	post_init)r5   r!   Ú
num_layersÚ
hop_lengthÚhop_lengthsrŸ   rª   r6   s          €r   r(   zUnivNetModel.__init__ã  s  ø€ Ü‰Ñ˜Ô ä˜v×;Ñ;Ó<ˆÔØ &× 7Ñ 7ˆÔäŸ	™	Ø×$Ñ$Ø×(Ñ(ØØØØ"ô
ˆŒô ˜×5Ñ5Ó6ˆ
Øˆ
ØˆØ×2Ñ2ò 	+ˆFØ# fÑ,ˆJØ×Ñ˜zÕ*ð	+ô Ÿ™ô ˜zÓ*öð ô  ØØØ!,¨Q¡öòó	
ˆŒô Ÿ™ 6×#?Ñ#?ÀÀAÈqÐ_hÔiˆŒð 	�‰Õùòs   ÃD*)Úoutput_typeÚconfig_classÚnoise_sequenceÚpadding_maskÚ	generatorÚreturn_dictÚreturnc                 óš  — |�|n| j                   j                  }|j                  «       dk(  }|s|j                  d«      }|j                  \  }}}	|�'|j                  «       dk(  }
|
sX|j                  d«      }nF||| j                   j
                  f}t        j                  |||j                  |j                  ¬«      }|j                  d   }|dkD  r|dk(  r|j                  |dd«      }n|dkD  r|dk(  r|j                  |dd«      }||k7  rt        d|› d|› d�«      ‚|�J|j                  «       dk(  r|j                  d«      }|j                  d   }||k7  rt        d	|› d|› d�«      ‚|j                  d
d«      }|j                  d
d«      }| j                  |«      }| j                  D ]  } |||«      }Œ t        j                   j#                  || j$                  «      }| j'                  |«      }t        j(                  |«      }|j+                  d«      }d}|�t        j,                  |d¬«      }|s||f}|S t/        ||¬«      S )a“  
        Returns:

        Example:

         ```python
         >>> from transformers import UnivNetFeatureExtractor, UnivNetModel
         >>> from datasets import load_dataset, Audio

         >>> model = UnivNetModel.from_pretrained("dg845/univnet-dev")
         >>> feature_extractor = UnivNetFeatureExtractor.from_pretrained("dg845/univnet-dev")

         >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
         >>> # Resample the audio to the feature extractor's sampling rate.
         >>> ds = ds.cast_column("audio", Audio(sampling_rate=feature_extractor.sampling_rate))
         >>> inputs = feature_extractor(
         ...     ds[0]["audio"]["array"], sampling_rate=ds[0]["audio"]["sampling_rate"], return_tensors="pt"
         ... )
         >>> audio = model(**inputs).waveforms
         >>> list(audio.shape)
         [1, 140288]
         ```
        Nr   r   )rÂ   ÚdtypeÚdevicer   z&The batch size of `noise_sequence` is z+ and the batch size of `input_features` is z', but the two are expected to be equal.z$The batch size of `padding_mask` is r#   )Údim)r   r   )r!   Úuse_return_dictrÈ   r�   rf   r)   r   ÚrandnrÆ   rÇ   Úrepeatr‰   rŒ   r·   r`   r   r:   r;   r/   r¹   rƒ   ÚsqueezeÚsumr   )r5   r±   rÀ   rÁ   rÂ   rÃ   Úspectrogram_batchedÚspectrogram_batch_sizeÚspectrogram_lengthrc   Únoise_sequence_batchedÚnoise_sequence_shapeÚnoise_sequence_batch_sizeÚpadding_mask_batch_sizer7   rk   Úwaveformr   Úoutputss                      r   r=   zUnivNetModel.forward
  s¬  € ðB &1Ð%<‘kÀ$Ç+Á+×B]ÑB]ˆð -×0Ñ0Ó2°aÑ7ÐÙ"Ø+×5Ñ5°aÓ8ˆNØ8F×8LÑ8LÑ5ÐÐ 2°AàÐ%Ø%3×%7Ñ%7Ó%9¸QÑ%>Ð"Ù)Ø!/×!9Ñ!9¸!Ó!<‘ð %;Ð<NÐPT×P[ÑP[×PmÑPmÐ#nÐ Ü"Ÿ[™[Ø$°	À×AUÑAUÐ^l×^sÑ^sôˆNð %3×$8Ñ$8¸Ñ$;Ð!à! AÒ%Ð*CÀqÒ*Hà+×2Ñ2Ð3IÈ1ÈaÓP‰NØ&¨Ò*Ð/EÈÒ/Jà+×2Ñ2Ð3LÈaÐQRÓSˆNà$Ð(>Ò>ÜØ8Ð9RÐ8Sð T(Ø(>Ð'?Ð?fðhóð ð
 Ð#Ø×ÑÓ! QÒ&Ø+×5Ñ5°aÓ8�Ø&2×&8Ñ&8¸Ñ&;Ð#Ø&Ð*@Ò@Ü Ø:Ð;RÐ:Sð T,Ø,BÐ+CÐCjðlóð ð '×0Ñ0°°AÓ6ˆØ'×1Ñ1°!°QÓ7ˆàŸ™ mÓ4ˆàŸ™ò 	DˆHÙ$ ]°NÓC‰Mð	Dô Ÿ™×0Ñ0°À×@UÑ@UÓVˆØŸ™ }Ó5ˆÜŸ
™
 =Ó1ˆð !×(Ñ(¨Ó+ˆð  ÐØÐ#ä$Ÿy™y¨¸1Ô=ÐáØÐ!1Ð2ˆGØˆNä!ØØ-ô
ð 	
r   c                 óP  — t        |t        j                  t        j                  t        j                  f«      rm|j
                  j                  j                  d| j                  j                  ¬«       |j                  �%|j                  j                  j                  «        yyy)zInitialize the weights.g        )ÚmeanÚstdN)Ú
isinstancer   ÚLinearr2   r§   ÚweightÚdataÚnormal_r!   Úinitializer_ranger&   Úzero_)r5   Úmodules     r   Ú_init_weightszUnivNetModel._init_weightsv  ss   € ä�fœrŸy™y¬"¯)©)´R×5GÑ5GÐHÔIØ�M‰M×Ñ×&Ñ&¨C°T·[±[×5RÑ5RÐ&ÔSØ�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ð Jr   c                 óR  — t         j                  j                  }t        t         j                  j                  d«      r$t         j                  j                  j                  } || j
                  «       | j                  D ]  }|j                  «        Œ  || j                  «       y r?   )	r   rA   r@   rB   rC   r·   r`   rE   r¹   rq   s      r   rE   zUnivNetModel.apply_weight_norm}  sq   € Ü—h‘h×*Ñ*ˆÜ”2—8‘8×,Ñ,¨mÔ<ÜŸ(™(×3Ñ3×?Ñ?ˆKá�D—M‘MÔ"Ø—^‘^ò 	&ˆEØ×#Ñ#Õ%ð	&á�D—N‘NÕ#r   c                 óê   — t         j                  j                  | j                  «       | j                  D ]  }|j                  «        Œ t         j                  j                  | j
                  «       y r9   )r   rA   rG   r·   r`   r¹   rt   s     r   rG   zUnivNetModel.remove_weight_norm‡  sM   € Ü
�‰×#Ñ# D§M¡MÔ2Ø—^‘^ò 	'ˆEØ×$Ñ$Õ&ð	'ä
�‰×#Ñ# D§N¡NÕ3r   )NNNN)r   r   r   r   r¿   Úmain_input_namer(   r   ÚUNIVNET_INPUTS_DOCSTRINGr   r   Ú_CONFIG_FOR_DOCr   r   r   Ú	GeneratorÚboolr   r   r=   râ   rE   rG   rI   rJ   s   @r   r°   r°   Û  sç   ø„ ð
 !€LØ&€Oð%˜}õ %ñN +Ð+CÓDÙÐ+=ÈOÔ\ð 7;Ø48Ø/3Ø&*ñh
à×)Ñ)ðh
ð ! ×!2Ñ!2Ñ3ðh
ð ˜u×0Ñ0Ñ1ð	h
ð
 ˜EŸO™OÑ,ðh
ð ˜d‘^ðh
ð 
ˆu�U×&Ñ&Ñ'Ð);Ð;Ñ	<òh
ó ]ó Eðh
òT)ò$ö4r   r°   )#r   Údataclassesr   Útypingr   r   r   r   Útorch.utils.checkpointr   Úmodeling_utilsr	   r
   rA   r   r   r   r   Úconfiguration_univnetr   Ú
get_loggerr   Úloggerrç   Ú_CHECKPOINT_FOR_DOCr   ÚModuler    rL   ry   r›   ÚUNIVNET_START_DOCSTRINGræ   r°   Ú__all__r   r   r   ú<module>rõ      sò   ðñ "å !ß )Ñ )ã Û Ý ç :ß tÓ tÝ 0ð 
ˆ×	Ñ	˜HÓ	%€ð "€à)Ð ð ô9˜ó 9ó ð9ô .0¨"¯)©)ô .0ôbu4˜RŸY™Yô u4ôp|/˜bŸi™iô |/ô~M'�b—i‘iô M'ð`Ð ð"Ð ñ: ØØóôl4�?ó l4ó	ðl4ð^ Ð
�r   