Ë
    ÜÓ^j¸b  ã                   ó†  — d Z ddlmZ ddlZddlmZ ddlmZ ddlmZ ddl	m
Z
mZ d	d
lmZ  ej                  e«      Z e
d¬«      e G d„ de«      «       «       Z G d„ dej$                  «      Z G d„ dej$                  «      Z G d„ dej$                  «      Z G d„ dej$                  «      Ze
 G d„ de«      «       ZdgZy)zPyTorch UnivNetModel model.é    )Ú	dataclassN)Únné   )ÚModelOutput)ÚPreTrainedModel)Úauto_docstringÚloggingé   )ÚUnivNetConfigzÝ
    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`]).
    )Úcustom_introc                   ób   — e Zd ZU dZdZej                  dz  ed<   dZej                  dz  ed<   y)ÚUnivNetModelOutputa"  
    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   ÚtorchÚFloatTensorÚ__annotations__r   © ó    úw/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/univnet/modeling_univnet.pyr   r      s4   … ñð +/€Iˆu× Ñ  4Ñ'Ó.Ø15Ð�e×'Ñ'¨$Ñ.Ô5r   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)r-   r/   r   Ú
functionalÚ
leaky_relur+   r0   )r1   r3   Úresiduals      r   Úforwardz+UnivNetKernelPredictorResidualBlock.forwardK   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Úparametrizationsr/   r0   ©r1   r<   s     r   Úapply_weight_normz5UnivNetKernelPredictorResidualBlock.apply_weight_normU   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 r5   )r   r=   Úremove_weight_normr/   r0   ©r1   s    r   rC   z6UnivNetKernelPredictorResidualBlock.remove_weight_norm]   s.   € Ü
�‰×#Ñ# D§J¡JÔ/Ü
�‰×#Ñ# D§J¡JÕ/r   )r   r   r   r   r   r$   r   r   r9   rA   rC   Ú__classcell__©r2   s   @r   r   r   1   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_channelsrI   rJ   Ú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   r.   Ú
input_convÚ
ModuleListÚranger   Ú	resblocksÚkernel_convÚ	bias_conv)r1   r   rI   rJ   r!   Ú_r2   s         €r   r$   zUnivNetKernelPredictor.__init__s   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)`.
        )ÚshaperY   r   r6   r7   r+   r\   r]   r^   ÚviewrJ   rN   rO   rI   Ú
contiguous)r1   r`   Ú
batch_sizer_   Ú
seq_lengthr3   ÚresblockÚkernel_hidden_statesÚbias_hidden_statesÚkernelsÚbiasess              r   r9   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   r=   r<   r>   r?   rY   r\   rA   r]   r^   ©r1   r<   Úlayers      r   rA   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 r5   )r   r=   rC   rY   r\   r]   r^   ©r1   rn   s     r   rC   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   r9   rA   rC   rE   rF   s   @r   rH   rH   b   sO   ø„ ñð& !"Øñ	$
àð$
ð ð$
ð õ	$
ðL, 5×#4Ñ#4ó ,ò\	$ö4r   rH   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!   rv   )
r#   r$   rM   Úhidden_channelsr(   rv   r+   r   r.   Úconv)r1   r   r(   rv   r!   r2   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   r6   r7   r+   ry   Úlocation_variable_convolutionr   Úsigmoidrx   Útanh)r1   r3   Úkernelr"   r|   r8   s         r   r9   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   r3   r€   r"   r|   c                 ó®  — |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                  d«      j                  d«      }||z   }|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://huggingface.co/papers/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   Nrq   zbildsk,biokl->bolsdéÿÿÿÿ)rb   Ú
ValueErrorrs   r   r6   ÚpadÚunfoldÚ	transposer   ÚeinsumÚ	unsqueezerc   )r1   r3   r€   r"   rv   r|   Úbatchr_   Ú	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Ðà�~‰~˜bÓ!×+Ñ+¨BÓ/ˆØ3°dÑ:ÐØ3×8Ñ8¸ÀÈbÓQÐà#Ð#r   c                 óì   — t         j                  j                  }t        t         j                  j                  d«      r$t         j                  j                  j                  } || j
                  «       y r;   )r   r=   r<   r>   r?   ry   r@   s     r   rA   z)UnivNetLvcResidualBlock.apply_weight_normM  sF   € Ü—h‘h×*Ñ*ˆÜ”2—8‘8×,Ñ,¨mÔ<ÜŸ(™(×3Ñ3×?Ñ?ˆKá�D—I‘IÕr   c                 óV   — t         j                  j                  | j                  «       y r5   )r   r=   rC   ry   rD   s    r   rC   z*UnivNetLvcResidualBlock.remove_weight_normT  s   € Ü
�‰×#Ñ# D§I¡IÕ.r   ©é   )r
   r’   )r   r   r   r   r   rs   r$   r9   r   r   r}   rA   rC   rE   rF   s   @r   ru   ru   Ú   sˆ   ø„ ñ
ð
àð
ð ð
ð õ	
ó,ð* Øñ>$à×(Ñ(ð>$ð ×!Ñ!ð>$ð ×Ñð	>$ð
 ð>$ð ó>$ò@ö/r   ru   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$   rM   rx   Úresblock_kernel_sizesr(   Úresblock_stride_sizesr˜   Úresblock_dilation_sizesÚ	dilationsÚcond_hop_lengthr+   ÚlenrX   r   ÚConvTranspose1dÚ	convt_prerH   Úkernel_predictorrZ   r[   ru   r\   )r1   r   r•   r–   Úir2   s        €r   r$   zUnivNetLvcBlock.__init__j  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r3   r`   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   r6   r7   r+   r¡   r¢   Ú	enumerater\   rž   )	r1   r3   r`   rj   rk   r£   rg   r€   r"   s	            r   r9   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   r=   r<   r>   r?   r¡   r¢   rA   r\   rm   s      r   rA   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 r5   )r   r=   rC   r¡   r¢   r\   rp   s     r   rC   z"UnivNetLvcBlock.remove_weight_norm¡  sI   € Ü
�‰×#Ñ# D§N¡NÔ3Ø×Ñ×0Ñ0Ô2Ø—^‘^ò 	'ˆEØ×$Ñ$Õ&ñ	'r   r‘   rr   rF   s   @r   r”   r”   X  sW   ø„ ñð*  ñ	
àð
ð ð
ð õ	
ð< U×%6Ñ%6ð ÀU×EVÑEVó ò&ö'r   r”   c                   ó   ‡ — e Zd ZU eed<   dZdZdefˆ fd„Ze	 	 	 	 dde	j                  de	j                  dz  de	j                  dz  de	j                  dz  d	edz  d
ee	j                     ez  fd„«       Zd„ Zd„ Zˆ xZS )ÚUnivNetModelr   Úinput_featuresÚaudioc                 ó^  •— 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   r.   r%   rM   Úconv_prer›   ÚappendrZ   r[   r”   r\   Ú	conv_postÚ	post_init)r1   r   Ú
num_layersÚ
hop_lengthÚhop_lengthsr˜   r£   r2   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*NÚ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´  
        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.

        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   r»   rÀ   r‰   rb   r%   r   Úrandnr¾   r¿   Úrepeatr„   r‡   r±   r\   r   r6   r7   r+   r³   r   ÚsqueezeÚsumr   )r1   rª   r¸   r¹   rº   r»   ÚkwargsÚspectrogram_batchedÚspectrogram_batch_sizeÚspectrogram_lengthr_   Únoise_sequence_batchedÚnoise_sequence_shapeÚnoise_sequence_batch_sizeÚpadding_mask_batch_sizer3   rg   Úwaveformr   Úoutputss                       r   r9   zUnivNetModel.forwardÕ  s¬  € ðb &1Ð%<‘kÀ$Ç+Á+×BYÑBYˆð -×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                 óR  — t         j                  j                  }t        t         j                  j                  d«      r$t         j                  j                  j                  } || j
                  «       | j                  D ]  }|j                  «        Œ  || j                  «       y r;   )	r   r=   r<   r>   r?   r±   r\   rA   r³   rm   s      r   rA   zUnivNetModel.apply_weight_normQ  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 r5   )r   r=   rC   r±   r\   r³   rp   s     r   rC   zUnivNetModel.remove_weight_norm[  sM   € Ü
�‰×#Ñ# D§M¡MÔ2Ø—^‘^ò 	'ˆEØ×$Ñ$Õ&ð	'ä
�‰×#Ñ# D§N¡NÕ3r   )NNNN)r   r   r   r   r   Úmain_input_nameÚinput_modalitiesr$   r   r   r   Ú	GeneratorÚboolÚtupler   r9   rA   rC   rE   rF   s   @r   r©   r©   ¨  sÊ   ø… àÓØ&€OØÐð%˜}õ %ðN ð 48Ø15Ø,0Ø#'ñy
à×)Ñ)ðy
ð ×)Ñ)¨DÑ0ðy
ð ×'Ñ'¨$Ñ.ð	y
ð
 —?‘? TÑ)ðy
ð ˜D‘[ðy
ð 
ˆu× Ñ Ñ	!Ð$6Ñ	6òy
ó ðy
òv$ö4r   r©   )r   Údataclassesr   r   r   Úmodeling_outputsr   Úmodeling_utilsr   r=   r   r	   Úconfiguration_univnetr   Ú
get_loggerr   Úloggerr   ÚModuler   rH   ru   r”   r©   Ú__all__r   r   r   ú<module>rÞ      sÕ   ðñ "å !ã Ý å +Ý -ß ,Ý 0ð 
ˆ×	Ñ	˜HÓ	%€ñ ðôð ô	6˜ó 	6ó óð	6ô.0¨"¯)©)ô .0ôbu4˜RŸY™Yô u4ôp{/˜bŸi™iô {/ô|M'�b—i‘iô M'ð` ôv4�?ó v4ó ðv4ðr Ð
�r   