Ë
    P/æjÑg  ã                   óÎ   — d Z ddl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 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mZmZmZmZ  G d„ dej8                  «      Zy)zB
This code contains the spectrogram and Hybrid version of Demucs.
é    N)Úwiener)Únn)Ú
functional)ÚFraction)Ú	rearrangeé   )ÚCrossTransformerEncoder)Úrescale_module)Úcapture_init)ÚspectroÚispectro)Úpad1dÚScaledEmbeddingÚ	HEncLayerÚ	MultiWrapÚ	HDecLayerc            ?       óà   ‡ — e Zd ZdZedddddddddd	ddd
dddddd	ddd	d	dddddddddddddddddddddddddg d¢dddddddddddddf>ˆ fd„	«       Zd „ Zd(d!„Zd"„ Zd#„ Z	d$„ Z
d%efd&„Zd'„ Zˆ xZS ))ÚHTDemucsaV  
    Spectrogram and hybrid Demucs model.
    The spectrogram model has the same structure as Demucs, except the first few layers are over the
    frequency axis, until there is only 1 frequency, and then it moves to time convolutions.
    Frequency layers can still access information across time steps thanks to the DConv residual.

    Hybrid model have a parallel time branch. At some layer, the time branch has the same stride
    as the frequency branch and then the two are combined. The opposite happens in the decoder.

    Models can either use naive iSTFT from masking, Wiener filtering ([Ulhih et al. 2017]),
    or complex as channels (CaC) [Choi et al. 2020]. Wiener filtering is based on
    Open Unmix implementation [Stoter et al. 2019].

    The loss is always on the temporal domain, by backpropagating through the above
    output methods and iSTFT. This allows to define hybrid models nicely. However, this breaks
    a bit Wiener filtering, as doing more iteration at test time will change the spectrogram
    contribution, without changing the one from the waveform, which will lead to worse performance.
    I tried using the residual option in OpenUnmix Wiener implementation, but it didn't improve.
    CaC on the other hand provides similar performance for hybrid, and works naturally with
    hybrid models.

    This model also uses frequency embeddings are used to improve efficiency on convolutions
    over the freq. axis, following [Isik et al. 2020] (https://arxiv.org/pdf/2008.04470.pdf).

    Unlike classic Demucs, there is no resampling here, and normalization is always applied.
    é   é0   Ni   r   FTé   é   gš™™™™™É?é
   é   r   gü©ñÒMbP?é   Úsing      @g        i'  g     ˆÃ@ç      ð?)g     ˆ³@r   gffffffö?Údiagé*   iô  éd   gffffffî?gš™™™™™¹?iD¬  c@                 óf  •— t         ‰U| �  «        |
| _        |	| _        || _        || _        || _        || _        || _        || _	        || _
        || _        |=| _        |>| _        |?| _        || _        |dz  | _        || _        || _        d| _        ||k(  sJ ‚t)        j*                  «       | _        t)        j*                  «       | _        t)        j*                  «       | _        t)        j*                  «       | _        |}@|@}A| j                  rAdz  }A|xs |}B|}C|dz  }Dt5        |«      D �]ÿ  }E|E|k\  }FDdkD  }G|}H|}I|GsDdk(  sJ ‚|dz  }I|}Hd}Jd}KGrD|k  rD}Id}Jd}KIHGJF|||||ddœdœ}Lt7        |L«      }Md	|Md
<   ||Md<   ||Md<   d|Md<   t7        |L«      }Nd}O|rE|k  rd}OdNd<   Krt9        BC«      }C|C}Bt;        ACf|dz  |dœL¤Ž}PGr/t;        @Bf|dz  |KdœM¤Ž}Q| j0                  j=                  |Q«       Ort?        P|«      }P| j,                  j=                  P«       Ed	k(  r5| j                  tA        | j
                  «      z  }@|@}A| j                  rAdz  }AtC        CAf|dz  Ed	k(  |dœN¤Ž}ROrt?        R|«      }RGr4tC        B@f|dz  KEd	k(  |dœM¤Ž}S| j2                  jE                  d	|S«       | j.                  jE                  d	R«       B}@C}AtG        ||Bz  «      }BtG        ||Cz  «      }CGrD|k  rd}DnD|z  }DEd	k(  s�Œá|s�ŒåtI        DA||¬«      | _        || _%        �Œ |<rtM        | |<¬«       |||dz
  z  z  }T|rrt)        jN                  T|d«      | _(        t)        jN                  ||Td«      | _)        t)        jN                  |T|d«      | _*        t)        jN                  ||Td«      | _+        |}T|d	kD  rltY        d4i dT“d|“d| “d|!“d|“d|;“d|"“d|#“d|$“d|%“d|&“d |'“d!|(“d"|)“d#|*“d$|+“d%|,“d&|-“d'|/“d(|.“d)|0“d*|1“d+|2“d,|3“d-|4“d.|5“d/|6“d0|7“d1|8“d2|9“d3|:“Ž| _-        yd| _-        y)5a  
        Args:
            sources (list[str]): list of source names.
            audio_channels (int): input/output audio channels.
            channels (int): initial number of hidden channels.
            channels_time: if not None, use a different `channels` value for the time branch.
            growth: increase the number of hidden channels by this factor at each layer.
            nfft: number of fft bins. Note that changing this require careful computation of
                various shape parameters and will not work out of the box for hybrid models.
            wiener_iters: when using Wiener filtering, number of iterations at test time.
            end_iters: same but at train time. For a hybrid model, must be equal to `wiener_iters`.
            wiener_residual: add residual source before wiener filtering.
            cac: uses complex as channels, i.e. complex numbers are 2 channels each
                in input and output. no further processing is done before ISTFT.
            depth (int): number of layers in the encoder and in the decoder.
            rewrite (bool): add 1x1 convolution to each layer.
            multi_freqs: list of frequency ratios for splitting frequency bands with `MultiWrap`.
            multi_freqs_depth: how many layers to wrap with `MultiWrap`. Only the outermost
                layers will be wrapped.
            freq_emb: add frequency embedding after the first frequency layer if > 0,
                the actual value controls the weight of the embedding.
            emb_scale: equivalent to scaling the embedding learning rate
            emb_smooth: initialize the embedding with a smooth one (with respect to frequencies).
            kernel_size: kernel_size for encoder and decoder layers.
            stride: stride for encoder and decoder layers.
            time_stride: stride for the final time layer, after the merge.
            context: context for 1x1 conv in the decoder.
            context_enc: context for 1x1 conv in the encoder.
            norm_starts: layer at which group norm starts being used.
                decoder layers are numbered in reverse order.
            norm_groups: number of groups for group norm.
            dconv_mode: if 1: dconv in encoder only, 2: decoder only, 3: both.
            dconv_depth: depth of residual DConv branch.
            dconv_comp: compression of DConv branch.
            dconv_attn: adds attention layers in DConv branch starting at this layer.
            dconv_lstm: adds a LSTM layer in DConv branch starting at this layer.
            dconv_init: initial scale for the DConv branch LayerScale.
            bottom_channels: if >0 it adds a linear layer (1x1 Conv) before and after the
                transformer in order to change the number of channels
            t_layers: number of layers in each branch (waveform and spec) of the transformer
            t_emb: "sin", "cape" or "scaled"
            t_hidden_scale: the hidden scale of the Feedforward parts of the transformer
                for instance if C = 384 (the number of channels in the transformer) and
                t_hidden_scale = 4.0 then the intermediate layer of the FFN has dimension
                384 * 4 = 1536
            t_heads: number of heads for the transformer
            t_dropout: dropout in the transformer
            t_max_positions: max_positions for the "scaled" positional embedding, only
                useful if t_emb="scaled"
            t_norm_in: (bool) norm before addinf positional embedding and getting into the
                transformer layers
            t_norm_in_group: (bool) if True while t_norm_in=True, the norm is on all the
                timesteps (GroupNorm with group=1)
            t_group_norm: (bool) if True, the norms of the Encoder Layers are on all the
                timesteps (GroupNorm with group=1)
            t_norm_first: (bool) if True the norm is before the attention and before the FFN
            t_norm_out: (bool) if True, there is a GroupNorm (group=1) at the end of each layer
            t_max_period: (float) denominator in the sinusoidal embedding expression
            t_weight_decay: (float) weight decay for the transformer
            t_lr: (float) specific learning rate for the transformer
            t_layer_scale: (bool) Layer Scale for the transformer
            t_gelu: (bool) activations of the transformer are GeLU if True, ReLU else
            t_weight_pos_embed: (float) weighting of the positional embedding
            t_cape_mean_normalize: (bool) if t_emb="cape", normalisation of positional embeddings
                see: https://arxiv.org/abs/2106.03143
            t_cape_augment: (bool) if t_emb="cape", must be True during training and False
                during the inference, see: https://arxiv.org/abs/2106.03143
            t_cape_glob_loc_scale: (list of 3 floats) if t_emb="cape", CAPE parameters
                see: https://arxiv.org/abs/2106.03143
            t_sparse_self_attn: (bool) if True, the self attentions are sparse
            t_sparse_cross_attn: (bool) if True, the cross-attentions are sparse (don't use it
                unless you designed really specific masks)
            t_mask_type: (str) can be "diag", "jmask", "random", "global" or any combination
                with '_' between: i.e. "diag_jmask_random" (note that this is permutation
                invariant i.e. "diag_jmask_random" is equivalent to "jmask_random_diag")
            t_mask_random_seed: (int) if "random" is in t_mask_type, controls the seed
                that generated the random part of the mask
            t_sparse_attn_window: (int) if "diag" is in t_mask_type, for a query (i), and
                a key (j), the mask is True id |i-j|<=t_sparse_attn_window
            t_global_window: (int) if "global" is in t_mask_type, mask[:t_global_window, :]
                and mask[:, :t_global_window] will be True
            t_sparsity: (float) if "random" is in t_mask_type, t_sparsity is the sparsity
                level of the random part of the mask.
            t_cross_first: (bool) if True cross attention is the first layer of the
                transformer (False seems to be better)
            rescale: weight rescaling trick
            use_train_segment: (bool) if True, the actual size that is used during the
                training is used during inference.
        r   Nr   r   TF)ÚdepthÚcompressÚinitÚgelu)Úkernel_sizeÚstrideÚfreqÚpadÚnormÚrewriteÚnorm_groupsÚdconv_kwr   r(   r&   r'   r)   Úcontext_freq)ÚdconvÚcontext)r/   r0   Úempty)r/   Úlastr0   )r/   r1   r2   r0   )ÚsmoothÚscale)Ú	referenceÚdimÚembÚhidden_scaleÚ	num_headsÚ
num_layersÚcross_firstÚdropoutÚmax_positionsÚnorm_inÚnorm_in_groupÚ
group_normÚ
norm_firstÚnorm_outÚ
max_periodÚweight_decayÚlrÚlayer_scaler%   Úsin_random_shiftÚweight_pos_embedÚcape_mean_normalizeÚcape_augmentÚcape_glob_loc_scaleÚsparse_self_attnÚsparse_cross_attnÚ	mask_typeÚmask_random_seedÚsparse_attn_windowÚglobal_windowÚsparsityÚauto_sparsity© ).ÚsuperÚ__init__ÚcacÚwiener_residualÚaudio_channelsÚsourcesr&   r0   r'   r"   Úbottom_channelsÚchannelsÚ
samplerateÚsegmentÚuse_train_segmentÚnfftÚ
hop_lengthÚwiener_itersÚ	end_itersÚfreq_embr   Ú
ModuleListÚencoderÚdecoderÚtencoderÚtdecoderÚrangeÚdictÚmaxr   Úappendr   Úlenr   ÚinsertÚintr   Úfreq_emb_scaler
   ÚConv1dÚchannel_upsamplerÚchannel_downsamplerÚchannel_upsampler_tÚchannel_downsampler_tr	   Úcrosstransformer)VÚselfrZ   rY   r\   Úchannels_timeÚgrowthr`   rb   rc   rX   rW   r"   r+   Úmulti_freqsÚmulti_freqs_depthrd   Ú	emb_scaleÚ
emb_smoothr&   Útime_strider'   r0   Úcontext_encÚnorm_startsr,   Ú
dconv_modeÚdconv_depthÚ
dconv_compÚ
dconv_initr[   Út_layersÚt_embÚt_hidden_scaleÚt_headsÚ	t_dropoutÚt_max_positionsÚ	t_norm_inÚt_norm_in_groupÚt_group_normÚt_norm_firstÚ
t_norm_outÚt_max_periodÚt_weight_decayÚt_lrÚt_layer_scaleÚt_geluÚt_weight_pos_embedÚt_sin_random_shiftÚt_cape_mean_normalizeÚt_cape_augmentÚt_cape_glob_loc_scaleÚt_sparse_self_attnÚt_sparse_cross_attnÚt_mask_typeÚt_mask_random_seedÚt_sparse_attn_windowÚt_global_windowÚ
t_sparsityÚt_auto_sparsityÚt_cross_firstÚrescaler]   r^   r_   ÚchinÚchin_zÚchoutÚchout_zÚfreqsÚindexr*   r(   ÚstriÚkerr)   Ú	last_freqÚkwÚkwtÚkw_decÚmultiÚencÚtencÚdecÚtdecÚtransformer_channelsÚ	__class__sV                                                                                        €úR/root/repos/pocs/video-evals/.venv/lib/python3.12/site-packages/demucs/htdemucs.pyrV   zHTDemucs.__init__7   sÐ  ø€ ôP 	‰ÑÔØˆŒØ.ˆÔØ,ˆÔØˆŒØ&ˆÔØˆŒØˆŒØˆŒ
Ø.ˆÔØ ˆŒØ$ˆŒØˆŒØ!2ˆÔØˆŒ	Ø !™)ˆŒØ(ˆÔØ"ˆŒØˆŒØ˜yÒ(Ð(Ð(ä—}‘}“ˆŒÜ—}‘}“ˆŒäŸ™›ˆŒÜŸ™›ˆŒàˆØˆØ�8Š8Ø�a‰KˆFØÒ) ˆØˆØ˜‘	ˆä˜5“\ó i	/ˆEØ˜KÑ'ˆDØ˜1‘9ˆDØˆDØˆCÙØ ’zÐ!�zØ! A‘o�Ø"�àˆCØˆIÙ˜ Ò,Ø�Ø�Ø �	ð  #ØØØØØ"Ø*à(Ø *Ø&Ø ñ	ñˆBô �r“(ˆCØˆC�‰KØ!,ˆC�ÑØ"ˆC�‰MØˆC�‰JÜ˜"“XˆFØˆEÙ˜uÐ'8Ò8Ø�Ø).��~Ñ&áÜ˜e WÓ-�Ø�äØ˜ðØ'1°A¡~¸{ñØNPñˆCñ Ü ØØðð % q™.Ø'Ø#ñð ñ�ð —‘×$Ñ$ TÔ*áÜ  [Ó1�Ø�L‰L×Ñ Ô$Ø˜ŠzØ×*Ñ*¬S°·±Ó->Ñ>�Ø�Ø—8’8Ø˜a‘K�FÜØØðð ! 1‘nØ˜a‘ZØñð ñˆCñ Ü  [Ó1�ÙÜ ØØðð % q™.Ø#Ø !™Ø#ñð ñ�ð —‘×$Ñ$ Q¨Ô-Ø�L‰L×Ñ  3Ô'àˆDØˆFÜ˜ ™Ó'ˆEÜ˜& 7Ñ*Ó+ˆGÙØ˜KÒ'Ø‘Eà˜fÑ$�EØ˜Œz›hÜ /Ø˜6¨*¸Iô!�”ð '/�Ö#ðSi	/ñV Ü˜4¨7Õ3à'¨&°U¸Q±YÑ*?Ñ?ÐÙÜ%'§Y¡YÐ/CÀ_ÐVWÓ%XˆDÔ"Ü')§y¡yØÐ!5°qó(ˆDÔ$ô (*§y¡yØ$ o°qó(ˆDÔ$ô *,¯©ØÐ!5°qó*ˆDÔ&ð $3Ð à�aŠ<Ü$;ò  %Ù(ð %áð %ñ ,ð %ñ "ð	 %ñ
 $ð %ñ *ð %ñ "ð %ñ .ð %ñ "ð %ñ .ð %ñ (ð %ñ (ð %ñ $ð %ñ (ð %ñ ,ð %ñ  ð! %ñ" *ð# %ñ$ ð% %ñ& "4ð' %ñ( "4ð) %ñ* %:ð+ %ñ, ,ð- %ñ. %:ð/ %ñ0 "4ð1 %ñ2 #6ð3 %ñ4 &ð5 %ñ6 "4ð7 %ñ8 $8ð9 %ñ: .ð; %ñ< $ð= %ñ> .ð? %ˆDÕ!ðD %)ˆDÕ!ó    c                 ó²  — | j                   }| j                  }|}||dz  k(  sJ ‚t        t        j                  |j
                  d   |z  «      «      }|dz  dz  }t        |||||z  z   |j
                  d   z
  fd¬«      }t        |||«      dd d…d d …f   }|j
                  d   |dz   k(  sJ |j
                  |j
                  |f«       ‚|ddd|z   …f   }|S )Nr   éÿÿÿÿr   r   Úreflect)Úmode.)ra   r`   rp   ÚmathÚceilÚshaper   r   )rx   ÚxÚhlr`   Úx0Úler)   Úzs           r¸   Ú_speczHTDemucs._spec¤  sæ   € Ø�_‰_ˆØ�y‰yˆØˆð �T˜Q‘YŠÐˆÜ”—‘˜1Ÿ7™7 2™;¨Ñ+Ó,Ó-ˆØ�A‰g˜‰kˆÜ�!�c˜3  b¡™=¨1¯7©7°2©;Ñ6Ð7¸iÔHˆä�A�t˜RÓ   c r cª1 Ñ-ˆØ�w‰w�r‰{˜b 1™fÒ$Ð< q§w¡w°·±¸Ð&<Ó<Ð$Øˆc�1�a˜"‘f�9ˆnÑˆØˆr¹   c                 ó  — | j                   d|z  z  }t        j                  |d«      }t        j                  |d«      }|dz  dz  }|t        t	        j
                  ||z  «      «      z  d|z  z   }t        |||¬«      }|d|||z   …f   }|S )Nr   )r   r   r   r   )r   r   r   r   )Úlength.)ra   ÚFr)   rp   r¾   r¿   r   )rx   rÅ   rÈ   r4   rÂ   r)   rÄ   rÁ   s           r¸   Ú_ispeczHTDemucs._ispecº  s‘   € Ø�_‰_  E¡Ñ*ˆÜ�E‰E�!�\Ó"ˆÜ�E‰E�!�VÓˆØ�A‰g˜‰kˆØ”#”d—i‘i ¨¡Ó,Ó-Ñ-°°C±Ñ7ˆÜ�Q˜ 2Ô&ˆØˆc�3˜˜f™Ð$Ð$Ñ%ˆØˆr¹   c                 óâ   — | j                   rR|j                  \  }}}}t        j                  |«      j	                  ddddd«      }|j                  ||dz  ||«      }|S |j                  «       }|S )Nr   r   r   r   r   )rW   rÀ   ÚtorchÚview_as_realÚpermuteÚreshapeÚabs)rx   rÅ   ÚBÚCÚFrÚTÚms          r¸   Ú
_magnitudezHTDemucs._magnitudeÄ  sp   € ð �8Š8ØŸ'™'‰KˆAˆq�"�aÜ×"Ñ" 1Ó%×-Ñ-¨a°°A°q¸!Ó<ˆAØ—	‘	˜!˜Q ™U B¨Ó*ˆAð ˆð —‘“ˆAØˆr¹   c                 ó˜  — | j                   }| j                  ra|j                  \  }}}}}|j                  ||dd||«      j	                  dddddd«      }	t        j                  |	j                  «       «      }	|	S | j                  r| j                  }|dk  r"|d d …d f   }|d|j                  «       z   z  |z  S | j                  |||«      S )	Nr»   r   r   r   r   r   r   g:Œ0âŽyE>)rb   rW   rÀ   ÚviewrÎ   rÌ   Úview_as_complexÚ
contiguousÚtrainingrc   rÐ   Ú_wiener)
rx   rÅ   rÕ   ÚnitersrÑ   ÚSrÒ   rÓ   rÔ   Úouts
             r¸   Ú_maskzHTDemucs._maskÏ  sÃ   € ð ×"Ñ"ˆØ�8Š8ØŸW™W‰NˆAˆq�!�R˜Ø—&‘&˜˜A˜r 1 b¨!Ó,×4Ñ4°Q¸¸1¸aÀÀAÓFˆCÜ×'Ñ'¨¯©Ó(8Ó9ˆCØˆJØ�=Š=Ø—^‘^ˆFØ�AŠ:Ø’!�T�'‘
ˆAØ˜˜qŸu™u›w™Ñ'¨!Ñ+Ð+à—<‘<  1 fÓ-Ð-r¹   c                 ó  — |j                   }d}| j                  }|j                  \  }}}	}
}|j                  ddddd«      }t	        j
                  |j                  dddd«      «      }g }t        |«      D ]‡  }d}g }t        d||«      D ]K  }t        |||z   «      }t        |||f   |||f   ||¬«      }|j                  |j                  dd	«      «       ŒM |j                  t	        j                  |d¬
«      «       Œ‰ t	        j                  t	        j                  |d«      «      }|j                  ddddd«      j                  «       }|r|d d …d d…f   }t        |j                  «      |||	|
|gk(  sJ ‚|j!                  |«      S )Ni,  r   r   r   r   r   )Úresidualr»   éþÿÿÿ)r6   )ÚdtyperX   rÀ   rÎ   rÌ   rÍ   rj   Úslicer   rm   Ú	transposeÚcatrÙ   ÚstackrÚ   ÚlistÚto)rx   Úmag_outÚmix_stftrÝ   r$   Úwiener_win_lenrâ   rÑ   rÞ   rÒ   ÚFqrÔ   ÚoutsÚsampleÚposrß   ÚframeÚz_outs                     r¸   rÜ   zHTDemucs._wienerà  s‰  € à�~‰~ˆØˆØ×'Ñ'ˆà Ÿ™‰ˆˆ1ˆa��QØ—/‘/ ! Q¨¨1¨aÓ0ˆÜ×%Ñ% h×&6Ñ&6°q¸!¸QÀÓ&BÓCˆàˆÜ˜A“hò 	/ˆFØˆCØˆCÜ˜Q  >Ó2ò 4�Ü˜c 3¨Ñ#7Ó8�ÜØ˜F E˜MÑ*Ø˜V U˜]Ñ+ØØ%ô	�ð —
‘
˜5Ÿ?™?¨2¨rÓ2Õ3ð4ð �K‰KœŸ	™	 #¨1Ô-Õ.ð	/ô ×#Ñ#¤E§K¡K°°aÓ$8Ó9ˆØ�k‰k˜!˜Q  1 aÓ(×3Ñ3Ó5ˆÙØ’a˜˜"˜�f‘+ˆCÜ�C—I‘I‹ 1 a¨¨B°Ð"2Ò2Ð2Ð2Ø�v‰v�d‹|Ðr¹   rÈ   c                 ó’   — | j                   s|S t        | j                  | j                  z  «      }||k  rt	        d|› d|› �«      ‚|S )zÝ
        Return a length that is appropriate for evaluation.
        In our case, always return the training length, unless
        it is smaller than the given length, in which case this
        raises an error.
        zGiven length z  is longer than training length )r_   rp   r^   r]   Ú
ValueError)rx   rÈ   Útraining_lengths      r¸   Úvalid_lengthzHTDemucs.valid_lengthÿ  s]   € ð ×%Ò%ØˆMÜ˜dŸl™l¨T¯_©_Ñ<Ó=ˆØ˜VÒ#ÜØ# F 8ð ,'Ø'6Ð&7ð9ó:ð :ð Ðr¹   c                 ó  — |j                   d   }d }| j                  r“| j                  r)t        |j                   d   | j                  «      | _        n^t        | j
                  | j                  z  «      }|j                   d   |k  r*|j                   d   }t        j                  |d||z
  f«      }| j                  |«      }| j                  |«      j                  |j                  «      }|}|j                   \  }}	}
}|j                  dd¬«      }|j                  dd¬«      }||z
  d|z   z  }|}|j                  dd¬«      }|j                  dd¬«      }||z
  d|z   z  }g }g }g }g }t        | j                   «      D �]7  \  }}|j#                  |j                   d   «       d }|t%        | j&                  «      k  rU|j#                  |j                   d   «       | j&                  |   } ||«      }|j(                  s|j#                  |«       n|} |||«      }|dk(  r…| j*                  �yt-        j.                  |j                   d   |j                  ¬	«      }| j+                  |«      j1                  «       d d d …d d …d f   j3                  |«      }|| j4                  |z  z   }|j#                  |«       �Œ: | j6                  r¶| j8                  rM|j                   \  }}}}t;        |d
«      }| j=                  |«      }t;        |d|¬«      }| j?                  |«      }| j7                  ||«      \  }}| j8                  r<t;        |d
«      }| jA                  |«      }t;        |d¬«      }| jC                  |«      }t        | jD                  «      D ]ä  \  }}|jG                  d«      }  ||| |jG                  d«      «      \  }}!| jH                  t%        | jJ                  «      z
  }"||"k\  sŒ[| jJ                  ||"z
     }#|jG                  d«      }$|#j(                  r=|!j                   d   dk(  sJ |!j                   «       ‚|!d d …d d …df   }! |#|!d |$«      \  }}%ŒÇ|jG                  d«      }  |#|| |$«      \  }}%Œæ t%        |«      dk(  sJ ‚t%        |«      dk(  sJ ‚t%        |«      dk(  sJ ‚t%        | jL                  «      }&|jO                  ||&d|
|«      }||d d …d f   z  |d d …d f   z   }|j                  jP                  dk(  }'|'r|jS                  «       }| jU                  ||«      }(| j                  r2| j                  r| jW                  |(|«      }n%| jW                  |(«      }n| jW                  |(|«      }|'r|j                  d«      }| j                  r6| j                  r|jO                  ||&d|«      }n)|jO                  ||&d«      }n|jO                  ||&d|«      }||d d …d f   z  |d d …d f   z   }||z   }|r	|dd |…f   }|S )Nr»   r   )r   r   r   T)r6   Úkeepdimgñhãˆµøä>)r   r   rã   )Údevicezb c f t-> b c (f t)zb c (f t)-> b c f t)Úfr   r   Úmps.),rÀ   r_   rÛ   r   r]   r^   rp   rÉ   r)   rÆ   rÖ   rê   rú   ÚmeanÚstdÚ	enumeraterf   rm   rn   rh   r1   rd   rÌ   ÚarangeÚtÚ	expand_asrq   rw   r[   r   rs   ru   rt   rv   rg   Úpopr"   ri   rZ   rØ   ÚtypeÚcpurà   rÊ   ))rx   ÚmixrÈ   Úlength_pre_padrö   rÅ   ÚmagrÁ   rÑ   rÒ   rî   rÔ   rý   rþ   ÚxtÚmeantÚstdtÚsavedÚsaved_tÚlengthsÚ	lengths_tÚidxÚencodeÚinjectr³   Úfrsr7   ÚbÚcrû   r  ÚdecodeÚskipÚpreÚoffsetrµ   Úlength_tÚ_rÞ   Úx_is_mpsÚzouts)                                            r¸   ÚforwardzHTDemucs.forward  sŸ  € Ø—‘˜2‘ˆØˆØ×!Ò!Ø�}Š}Ü'¨¯	©	°"©°t·±ÓG�•ä"% d§l¡l°T·_±_Ñ&DÓ"E�Ø—9‘9˜R‘= ?Ò2Ø%(§Y¡Y¨r¡]�NÜŸ%™%  a¨¸>Ñ)IÐ%JÓK�CØ�J‰J�s‹OˆØ�o‰o˜aÓ ×#Ñ# C§J¡JÓ/ˆØˆà—g‘g‰ˆˆ1ˆb�!ð �v‰v˜)¨TˆvÓ2ˆØ�e‰e˜	¨4ˆeÓ0ˆØ�‰X˜$ ™*Ñ%ˆð ˆØ—‘˜F¨D�Ó1ˆØ�v‰v˜&¨$ˆvÓ/ˆØ�5‰j˜T D™[Ñ)ˆð ˆØˆØˆØˆ	Ü$ T§\¡\Ó2ó 	‰KˆC�Ø�N‰N˜1Ÿ7™7 2™;Ô'ØˆFØ”S˜Ÿ™Ó'Ò'à× Ñ  §¡¨"¡Ô.Ø—}‘} SÑ)�Ù˜"“X�Ø—z’zà—N‘N 2Õ&ð  �FÙ�q˜&Ó!ˆAØ�aŠx˜DŸM™MÐ5ô —l‘l 1§7¡7¨2¡;°q·x±xÔ@�Ø—m‘m CÓ(×*Ñ*Ó,¨T²1²a¸Ð-=Ñ>×HÑHÈÓK�Ø˜×+Ñ+¨cÑ1Ñ1�à�L‰L˜ŽOð/	ð0 × Ò Ø×#Ò#ØŸW™W‘
��1�a˜Ü˜aÐ!6Ó7�Ø×*Ñ*¨1Ó-�Ü˜aÐ!6¸!Ô<�Ø×-Ñ-¨bÓ1�à×)Ñ)¨!¨RÓ0‰EˆAˆrà×#Ò#Ü˜aÐ!6Ó7�Ø×,Ñ,¨QÓ/�Ü˜aÐ!6¸!Ô<�Ø×/Ñ/°Ó3�ä$ T§\¡\Ó2ò 	5‰KˆC�Ø—9‘9˜R“=ˆDÙ˜A˜t W§[¡[°£_Ó5‰FˆAˆsð —Z‘Z¤# d§m¡mÓ"4Ñ4ˆFØ�f‹}Ø—}‘} S¨6¡\Ñ2�Ø$Ÿ=™=¨Ó,�Ø—:’:ØŸ9™9 Q™<¨1Ò,Ð7¨c¯i©iÓ7Ð,Øša¢ A˜g™,�CÙ   d¨HÓ5‘E�B™à"Ÿ;™; r›?�DÙ   T¨8Ó4‘E�B™ð!	5ô& �5‹z˜QŠÐˆÜ�9‹~ Ò"Ð"Ð"Ü�7‹|˜qÒ Ð Ð ä�—‘ÓˆØ�F‰F�1�a˜˜R Ó#ˆØ�’A�t�G‘Ñ˜t¢A t G™}Ñ,ˆð —8‘8—=‘= EÑ)ˆÙØ—‘“ˆAà�z‰z˜!˜QÓˆØ×!Ò!Ø�}Š}Ø—K‘K  fÓ-‘à—K‘K  oÓ6‘à—‘˜D &Ó)ˆAñ Ø—‘�U“ˆAà×!Ò!Ø�}Š}Ø—W‘W˜Q  2 vÓ.‘à—W‘W˜Q  2 Ó7‘à—‘˜˜A˜r 6Ó*ˆBØ�$’q˜$�w‘-Ñ %ª¨4¨¡.Ñ0ˆØ�‰FˆÙØ�#�˜�Ð&Ñ'ˆAØˆr¹   )Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rV   rÆ   rÊ   rÖ   rà   rÜ   rp   r÷   r  Ú__classcell__)r·   s   @r¸   r   r      s  ø„ ñð6 ð
 ØØØàØØØØàØàØØØØàØØØØàØàØØØààØØØØØØØØØØØØØØØØØØ"ØÚ0Ø Ø!ØØØ ØØØàààØØôYj)ó ðj)òXó,ò	ò.ò"ð> 3ó ö Er¹   r   )r"  r¾   Úopenunmix.filteringr   rÌ   r   Útorch.nnr   rÉ   Ú	fractionsr   Úeinopsr   Útransformerr	   Údemucsr
   Ústatesr   Úspecr   r   Úhdemucsr   r   r   r   r   ÚModuler   rT   r¹   r¸   ú<module>r.     sE   ðñó å &Û Ý Ý $Ý Ý å 0å "Ý  ß #ß LÕ Lôy	ˆr�y‰yõ y	r¹   