
    Pi                     v    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 ddl	m
Z
 d Z G d d	ej                  ZdS )
    N)nn   )WNConv1dEncoderBlock)Activation1d)activationsc                     t          | t          j                  rMt          j                            | j        d           t          j                            | j        d           d S d S )Ng{Gz?)stdr   )
isinstancer   Conv1dinittrunc_normal_weight	constant_biasms    j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/neucodec/codec_encoder.pyinit_weightsr      s]    !RY %
ahD111
!&!$$$$$% %    c                   P     e Zd Zdg ddddddf fd	Zd Zd	 Zd
 Zd Zd Z xZ	S )CodecEncoder0   )   r      r      )r      	   i      @   c                 B   t                                                       t          j        |          | _        || _        || _        |}t          d|dd          g| _        t          |          D ]+\  }	}
|dz  }| xj        t          ||
|          gz  c_        ,t          j        | j         | _        t          t          j        |d          	          t          ||dd          g| _        t          j        | j         | _        |                                  d S )
Nr      r   )kernel_sizepaddingr   )stride	dilationsT)alpha_logscale)
activation)super__init__npprod
hop_lengthngf	up_ratiosr   conv_blocks	enumerater   r   
Sequentialr   r   	SnakeBetaconv_final_blockreset_parameters)selfr.   r/   r&   
hidden_dimdepthheadspos_meb_dimd_modelir%   	__class__s              r   r*   zCodecEncoder.__init__   s4    	'),,"$QQJJJK"9-- 	 	IAvqLGWVyIII!  =$*:; &0NNN   WjaCCC	!
 !#t/D Er   c                     |                      |          }|                     |          }|                    ddd          }|S )Nr   r   r   )r0   r4   permuter6   xs     r   forwardzCodecEncoder.forward6   sB    Q!!!$$IIaAr   c                 ,    |                      |          S N)blockr@   s     r   	inferencezCodecEncoder.inference<   s    zz!}}r   c                 6    d }|                      |           dS )z:Remove weight normalization module from all of the layers.c                 r    	 t           j        j                            |            d S # t          $ r Y d S w xY wrD   )torchr   utilsremove_weight_norm
ValueErrorr   s    r   _remove_weight_normz<CodecEncoder.remove_weight_norm.<locals>._remove_weight_normB   sG    11!44444   s   $( 
66Napply)r6   rM   s     r   rK   zCodecEncoder.remove_weight_norm?   s,    	 	 	 	

&'''''r   c                 6    d }|                      |           dS )z9Apply weight normalization module from all of the layers.c                     t          | t          j                  r&t          j        j                            |            d S d S rD   )r   r   r   rI   rJ   weight_normr   s    r   _apply_weight_normz:CodecEncoder.apply_weight_norm.<locals>._apply_weight_normM   s>    !RY'' .**1-----. .r   NrN   )r6   rS   s     r   apply_weight_normzCodecEncoder.apply_weight_normJ   s,    	. 	. 	. 	

%&&&&&r   c                 :    |                      t                     d S rD   )rO   r   )r6   s    r   r5   zCodecEncoder.reset_parametersS   s    

<     r   )
__name__
__module____qualname__r*   rB   rF   rK   rT   r5   __classcell__)r=   s   @r   r   r      s         !//"  "  "  "  "  " H    	( 	( 	(' ' '! ! ! ! ! ! !r   r   )rI   numpyr+   r   moduler   r   alias_free_torchr    r   r   Moduler    r   r   <module>r`      s               * * * * * * * * * * * * * *      % % %C! C! C! C! C!29 C! C! C! C! C!r   