ó
    ˆŽ¡j“A ã                   óˆ  • S r SSKrSSKJr  SSKJr  SSKrSSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJr  SSKJrJrJrJr  SSKJ r   \RB                  " \"5      r# " S S\RH                  5      r% " S S\RH                  5      r& " S S\RH                  5      r' " S S\RH                  5      r( " S S\RH                  5      r) " S S\RH                  5      r*  SzS\RH                  S\RV                  S\RV                  S\RV                  S \RV                  S-  S!\,S-  S"\,S#\\   4S$ jjr- " S% S&\RH                  5      r. " S' S(\RH                  5      r/ " S) S*\RH                  5      r0 " S+ S,\RH                  5      r1 " S- S.\RH                  5      r2 " S/ S0\RH                  5      r3 " S1 S2\RH                  5      r4\ " S3 S4\
5      5       r5 " S5 S6\RH                  5      r6   S{S7\RV                  S8\,S9\7S-  S:\8S;\94
S< jjr:  S|S7\RV                  S=\7\9-  S9\7S-  S;\94S> jjr; " S? S@\RH                  5      r< " SA SB\RH                  5      r= " SC SD\RH                  5      r> " SE SF\RH                  5      r? " SG SH\RH                  5      r@\" SISJ9\ " SK SL\5      5       5       rA " SM SN\55      rB\" SOSJ9\ " SP SQ\5      5       5       rC\" SRSJ9 " SS ST\55      5       rD\" SUSJ9\ " SV SW\5      5       5       rE\" SXSJ9 " SY SZ\55      5       rF\" S[SJ9\ " S\ S]\5      5       5       rG\" S^SJ9\ " S_ S`\5      5       5       rH\" S^SJ9\ " Sa Sb\5      5       5       rISc\R”                  R–                  Sd\RV                  Se\RV                  4Sf jrLS}Sg\RV                  Sh\RV                  S-  Se\RV                  4Si jjrM " Sj Sk\55      rN\" SlSJ9\ " Sm Sn\5      5       5       rO " So Sp\55      rP\" SqSJ9\ " Sr Ss\5      5       5       rQ " St Su\RH                  5      rR\" SvSJ9 " Sw Sx\55      5       rS/ SyQrTg)~zPyTorch PatchTSMixer model.é    N)ÚCallable)Ú	dataclass)ÚPreTrainedModel)ÚModelOutputé   )Úinitialization)ÚFlashAttentionKwargs)ÚALL_ATTENTION_FUNCTIONS)ÚUnpack)ÚNegativeBinomialOutputÚNormalOutputÚStudentTOutput)ÚTransformersKwargsÚauto_docstringÚcan_return_tupleÚloggingé   )ÚPatchTSMixerConfigc                   ó>   ^ • \ rS rSrSrS\S\4U 4S jjrS rSrU =r	$ )ÚPatchTSMixerGatedAttentioné&   z‡
Module that applies gated attention to input data.

Args:
    in_size (`int`): The input size.
    out_size (`int`): The output size.
Úin_sizeÚout_sizec                 óŠ   >• [         TU ]  5         [        R                  " X5      U l        [        R
                  " SS9U l        g )Néÿÿÿÿ©Údim)ÚsuperÚ__init__ÚnnÚLinearÚ
attn_layerÚSoftmaxÚattn_softmax)Úselfr   r   Ú	__class__s      €ÚÄC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\transformers/models/patchtsmixer/modeling_patchtsmixer.pyr   Ú#PatchTSMixerGatedAttention.__init__/   s/   ø€ Ü‰ÑÔÜŸ)š) GÓ6ˆŒÜŸJšJ¨2Ñ.ˆÕó    c                 óN   • U R                  U R                  U5      5      nX-  nU$ ©N)r$   r"   )r%   ÚinputsÚattn_weights      r'   ÚforwardÚ"PatchTSMixerGatedAttention.forward4   s(   € Ø×'Ñ'¨¯©¸Ó(?Ó@ˆØÑ%ˆØˆr)   )r"   r$   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úintr   r.   Ú__static_attributes__Ú__classcell__©r&   s   @r'   r   r   &   s%   ø† ñð/ ð /¨s÷ /÷
ð r)   r   c                   óV   ^ • \ rS rSrSrS\4U 4S jjrS\R                  4S jr	Sr
U =r$ )ÚPatchTSMixerBatchNormé;   zH
Compute batch normalization over the sequence length (time) dimension.
Úconfigc                 ó~   >• [         TU ]  5         [        R                  " UR                  UR
                  S9U l        g )N©Úeps)r   r   r    ÚBatchNorm1dÚd_modelÚnorm_epsÚ	batchnorm©r%   r<   r&   s     €r'   r   ÚPatchTSMixerBatchNorm.__init__@   s(   ø€ Ü‰ÑÔÜŸš¨¯©¸F¿O¹OÑLˆ�r)   r,   c                 ól   • UR                  SS5      nU R                  U5      nUR                  SS5      $ )zÓ
Parameters:
    inputs (`torch.Tensor` of shape `(batch_size, sequence_length, d_model)`):
        input for Batch norm calculation
Returns:
    `torch.Tensor` of shape `(batch_size, sequence_length, d_model)`
r   é   )Ú	transposerC   )r%   r,   Úoutputs      r'   r.   ÚPatchTSMixerBatchNorm.forwardD   s7   € ð ×!Ñ! ! QÓ'ˆØ—‘ Ó'ˆØ×Ñ  1Ó%Ð%r)   )rC   ©r0   r1   r2   r3   r4   r   r   ÚtorchÚTensorr.   r6   r7   r8   s   @r'   r:   r:   ;   s,   ø† ñðMÐ1÷ Mð
&˜eŸl™l÷ 
&ò 
&r)   r:   c                   ó†   ^ • \ rS rSrSrS\4U 4S jjr\S\S\R                  4S j5       r
S\R                  4S jrS	rU =r$ )
ÚPatchTSMixerPositionalEncodingéQ   z
Class for positional encoding
r<   c                 óú   >• [         TU ]  5         UR                  (       a  U R                  U5      U l        g [
        R                  " [        R                  " UR                  UR                  5      5      U l        g r+   )r   r   Úuse_positional_encodingÚ_init_peÚposition_encr    Ú	ParameterrL   ÚzerosÚnum_patchesrA   rD   s     €r'   r   Ú'PatchTSMixerPositionalEncoding.__init__V   sN   ø€ Ü‰ÑÔà×)×)Ø $§¡¨fÓ 5ˆDÕä "§¢¬U¯[ª[¸×9KÑ9KÈVÏ^É^Ó-\Ó ]ˆDÕr)   Úreturnc                 ód  • U R                   S:X  a@  [        R                  " [        R                  " U R
                  U R                  5      SS9nU$ U R                   S:X  Ga8  [        R                  " U R
                  U R                  5      n[        R                  " SU R
                  5      R                  S5      n[        R                  " [        R                  " SU R                  S5      [        R                  " S5      U R                  -  * -  5      n[        R                  " X#-  5      US S 2SS S24'   [        R                  " X#-  5      US S 2SS S24'   XR                  5       -
  nXR!                  5       S	-  -  n[        R                  " US
S9nU$ [#        U R                    S35      e)NÚrandomT©Úrequires_gradÚsincosr   r   rG   g     ˆÃ@é
   FzN is not a valid positional encoder. Available types are 'random' and 'sincos'.)Úpositional_encoding_typer    rU   rL   ÚrandnrW   rA   rV   ÚarangeÚ	unsqueezeÚexpÚmathÚlogÚsinÚcosÚmeanÚstdÚ
ValueError)r<   rT   ÚpositionÚdiv_terms       r'   rS   Ú'PatchTSMixerPositionalEncoding._init_pe^   sn  € ð ×*Ñ*¨hÓ6ÜŸ<š<¬¯ª°F×4FÑ4FÈÏÉÓ(WÐgkÑlˆLð Ðð ×,Ñ,°Ô8Ü Ÿ;š; v×'9Ñ'9¸6¿>¹>ÓJˆLÜ—|’| A v×'9Ñ'9Ó:×DÑDÀQÓGˆHÜ—y’y¤§¢¨a°·±ÀÓ!CÌÏÊÐQXÓHYÐ\b×\jÑ\jÑHjÐFkÑ!kÓlˆHÜ$)§I¢I¨hÑ.AÓ$BˆLš˜A˜D˜q˜D˜Ñ!Ü$)§I¢I¨hÑ.AÓ$BˆLš˜A˜D˜q˜D˜Ñ!Ø'×*;Ñ*;Ó*=Ñ=ˆLØ'×+;Ñ+;Ó+=ÀÑ+BÑCˆLÜŸ<š<¨ÀEÑJˆLð
 Ðô Ø×2Ñ2Ð3ð  4Bð  Cóð r)   Úpatch_inputc                 ó"   • XR                   -   nU$ r+   ©rT   )r%   ro   Úhidden_states      r'   r.   Ú&PatchTSMixerPositionalEncoding.forwardr   s   € à"×%6Ñ%6Ñ6ˆØÐr)   rq   )r0   r1   r2   r3   r4   r   r   Ústaticmethodr    rU   rS   rL   rM   r.   r6   r7   r8   s   @r'   rO   rO   Q   sS   ø† ñð^Ð1÷ ^ð ðÐ+ð °·±ó ó ðð& 5§<¡<÷ ò r)   rO   c                   óV   ^ • \ rS rSrSrS\4U 4S jjrS\R                  4S jr	Sr
U =r$ )ÚPatchTSMixerNormLayeréx   zUNormalization block

Args:
    config (`PatchTSMixerConfig`):
        Configuration.
r<   c                 óþ   >• [         TU ]  5         UR                  U l        SUR                  R                  5       ;   a  [	        U5      U l        g [        R                  " UR                  UR                  S9U l        g )NÚbatchr>   )
r   r   Únorm_mlpÚlowerr:   Únormr    Ú	LayerNormrA   rB   rD   s     €r'   r   ÚPatchTSMixerNormLayer.__init__€   sT   ø€ Ü‰ÑÔàŸ™ˆŒà�f—o‘o×+Ñ+Ó-Ó-Ü-¨fÓ5ˆD�IäŸš V§^¡^¸¿¹ÑIˆD�Ir)   r,   c                 ól  • SU R                   R                  5       ;   a„  [        R                  " UUR                  S   UR                  S   -  UR                  S   UR                  S   45      nU R                  U5      n[        R                  " X!R                  5      nU$ U R                  U5      nU$ )zæ
Args:
    inputs (`torch.Tensor` of shape `((batch_size, num_channels, num_patches, d_model))`):
        Input to the normalization layer.
Returns:
    `torch.Tensor` of shape `((batch_size, num_channels, num_patches, d_model))`
ry   r   r   rG   r   )rz   r{   rL   ÚreshapeÚshaper|   )r%   r,   Úinputs_reshapeds      r'   r.   ÚPatchTSMixerNormLayer.forwardŠ   s�   € ð �d—m‘m×)Ñ)Ó+Ó+ä#ŸmšmØà—L‘L ‘O f§l¡l°1¡oÑ5Ø—L‘L ‘OØ—L‘L ‘OðóˆOð #Ÿi™i¨Ó8ˆOô —]’] ?·L±LÓAˆFð
 ˆð —Y‘Y˜vÓ&ˆFàˆr)   )r|   rz   rK   r8   s   @r'   rv   rv   x   s,   ø† ñðJÐ1÷ Jð˜eŸl™l÷ ò r)   rv   c                   óJ   ^ • \ rS rSrU 4S jrS\R                  4S jrSrU =r	$ )ÚPatchTSMixerMLPé©   c                 ó>  >• [         TU ]  5         XR                  -  n[        R                  " X5      U l        [        R                  " UR                  5      U l        [        R                  " XB5      U l	        [        R                  " UR                  5      U l
        g r+   )r   r   Úexpansion_factorr    r!   Úfc1ÚDropoutÚdropoutÚdropout1Úfc2Údropout2)r%   Úin_featuresÚout_featuresr<   Ú
num_hiddenr&   s        €r'   r   ÚPatchTSMixerMLP.__init__ª   sd   ø€ Ü‰ÑÔØ ×#:Ñ#:Ñ:ˆ
Ü—9’9˜[Ó5ˆŒÜŸ
š
 6§>¡>Ó2ˆŒÜ—9’9˜ZÓ6ˆŒÜŸ
š
 6§>¡>Ó2ˆ�r)   r,   c                 óÄ   • U R                  [        R                  R                  U R	                  U5      5      5      nU R                  U5      nU R                  U5      nU$ )z¼
Args:
    inputs (`torch.Tensor` of shape `((batch_size, num_channels, num_patches, d_model))`):
        Input to the MLP layer.
Returns:
    `torch.Tensor` of the same shape as `inputs`
)rŒ   r    Ú
functionalÚgelur‰   r�   rŽ   )r%   r,   s     r'   r.   ÚPatchTSMixerMLP.forward²   sK   € ð —‘œrŸ}™}×1Ñ1°$·(±(¸6Ó2BÓCÓDˆØ—‘˜&Ó!ˆØ—‘˜vÓ&ˆØˆr)   )rŒ   rŽ   r‰   r�   )
r0   r1   r2   r3   r   rL   rM   r.   r6   r7   r8   s   @r'   r…   r…   ©   s   ø† õ3ð˜eŸl™l÷ ò r)   r…   c                   óV   ^ • \ rS rSrSrS\4U 4S jjrS\R                  4S jr	Sr
U =r$ )Ú$PatchTSMixerChannelFeatureMixerBlockéÀ   zzThis module mixes the features in the channel dimension.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.
r<   c                 ó  >• [         TU ]  5         [        U5      U l        UR                  U l        [        UR                  UR                  US9U l        UR                  (       a$  [        UR                  UR                  S9U l	        g g ©N©r�   r�   r<   ©r   r   )
r   r   rv   r|   Ú
gated_attnr…   Únum_input_channelsÚmlpr   Úgating_blockrD   s     €r'   r   Ú-PatchTSMixerChannelFeatureMixerBlock.__init__È   sv   ø€ Ü‰ÑÔä)¨&Ó1ˆŒ	Ø ×+Ñ+ˆŒÜ"Ø×1Ñ1Ø×2Ñ2Øñ
ˆŒð ××Ü :Ø×1Ñ1¸F×<UÑ<Uñ!ˆDÕð r)   r,   c                 óê   • UnU R                  U5      nUR                  SSSS5      nU R                  (       a  U R                  U5      nU R	                  U5      nUR                  SSSS5      nX-   nU$ )z»
Args:
    inputs (`torch.Tensor` of shape `((batch_size, num_channels, num_patches, d_model))`):
        input to the MLP layer
Returns:
    `torch.Tensor` of the same shape as `inputs`
r   r   rG   r   )r|   Úpermuterž   r¡   r    )r%   r,   ÚresidualÚouts       r'   r.   Ú,PatchTSMixerChannelFeatureMixerBlock.forwardØ   sq   € ð ˆØ—‘˜6Ó"ˆà—‘  1 a¨Ó+ˆà�?�?Ø×&Ñ& vÓ.ˆFà—‘˜&Ó!ˆà—‘  1 a¨Ó+ˆàÑˆØˆ
r)   ©rž   r¡   r    r|   rK   r8   s   @r'   r˜   r˜   À   s*   ø† ñðÐ1÷ ð ˜eŸl™l÷ ò r)   r˜   ÚmoduleÚqueryÚkeyÚvalueÚattention_maskÚscalingr‹   Úkwargsc                 óŽ  • Uc  UR                  S5      S-  n[        R                  " XR                  SS5      5      U-  nUb  X„-   n[        R
                  R                  USS9n[        R
                  R                  X†U R                  S9n[        R                  " Xƒ5      n	U	R                  SS5      R                  5       n	X˜4$ )Nr   ç      à¿rG   r   r   )ÚpÚtrainingr   )
ÚsizerL   ÚmatmulrH   r    r”   Úsoftmaxr‹   r³   Ú
contiguous)
r©   rª   r«   r¬   r­   r®   r‹   r¯   Úattn_weightsÚattn_outputs
             r'   Úeager_attention_forwardrº   ñ   s±   € ð �Ø—*‘*˜R“. DÑ(ˆô —<’< §}¡}°Q¸Ó':Ó;¸gÑE€LàÑ!Ø#Ñ4ˆä—=‘=×(Ñ(¨¸2Ð(Ð>€LÜ—=‘=×(Ñ(¨È6Ï?É?Ð(Ð[€Lä—,’,˜|Ó3€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€KàÐ$Ð$r)   c                   ó  ^ • \ rS rSrSr     SS\S\S\S\S\S	\S
\S-  4U 4S jjjr	   SS\
R                  S\
R                  S-  S\
R                  S-  S\S-  S\\   S\\
R                  \
R                  S-  4   4S jjrSrU =r$ )ÚPatchTSMixerAttentioni  z=Multi-headed attention from 'Attention Is All You Need' paperNÚ	embed_dimÚ	num_headsr‹   Ú
is_decoderÚbiasÚ	is_causalr<   c                 óæ  >• [         TU ]  5         Xl        X l        X0l        X-  U l        Xpl        U R
                  U-  U R                  :w  a  [        SU R                   SU S35      eU R
                  S-  U l        X@l	        X`l
        [        R                  " XUS9U l        [        R                  " XUS9U l        [        R                  " XUS9U l        [        R                  " XUS9U l        g )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: ú).r±   )rÀ   )r   r   r½   r¾   r‹   Úhead_dimr<   rk   r®   r¿   rÁ   r    r!   Úk_projÚv_projÚq_projÚout_proj)	r%   r½   r¾   r‹   r¿   rÀ   rÁ   r<   r&   s	           €r'   r   ÚPatchTSMixerAttention.__init__  sÎ   ø€ ô 	‰ÑÔØ"ŒØ"ŒØŒØ!Ñ.ˆŒØŒà�M‰M˜IÑ%¨$¯.©.Ó8ÜØMÈdÏnÉnÐM]Ø$ Y K¨rð3óð ð —}‘} dÑ*ˆŒØ$ŒØ"Œä—i’i 	¸4Ñ@ˆŒÜ—i’i 	¸4Ñ@ˆŒÜ—i’i 	¸4Ñ@ˆŒÜŸ	š	 )¸TÑBˆ�r)   Úhidden_statesÚkey_value_statesr­   Úoutput_attentionsr¯   rY   c                 ó  • USLnUR                   SS n/ UQSPU R                  P7nU R                  U5      R                  U5      R	                  SS5      n	U(       a  UOUn
/ U
R                   SS QSPU R                  P7nU R                  U
5      R                  U5      R	                  SS5      nU R                  U
5      R                  U5      R	                  SS5      n[        R                  " U R                  R                  [        5      nU" U U	UUU4U R                  (       d  SOU R                  U R                  US.UD6u  nnUR                  " / UQSP76 R!                  5       nU R#                  U5      nUU4$ )z#Input shape: Batch x Time x ChannelNr   r   rG   ç        )r‹   r®   rÌ   )r�   rÄ   rÇ   ÚviewrH   rÅ   rÆ   r
   Úget_interfacer<   Ú_attn_implementationrº   r³   r‹   r®   r€   r·   rÈ   )r%   rÊ   rË   r­   rÌ   r¯   Úis_cross_attentionÚinput_shapeÚhidden_shapeÚquery_statesÚcurrent_statesÚkv_shapeÚ
key_statesÚvalue_statesÚattention_interfacer¹   r¸   s                    r'   r.   ÚPatchTSMixerAttention.forward0  s†  € ð .°TÐ9Ðð $×)Ñ)¨#¨2Ð.ˆà8˜Ð8 bÐ8¨$¯-©-Ñ8ˆð —{‘{ =Ó1×6Ñ6°|ÓD×NÑNÈqÐRSÓTˆæ-?Ñ)À]ˆØB�^×)Ñ)¨#¨2Ð.ÐB°ÐB°D·M±MÑBˆØ—[‘[ Ó0×5Ñ5°hÓ?×IÑIÈ!ÈQÓOˆ
Ø—{‘{ >Ó2×7Ñ7¸ÓA×KÑKÈAÈqÓQˆä(?×(MÒ(MØ�K‰K×,Ñ,Ô.Eó)
Ðñ %8ØØØØØð
%
ð  $Ÿ}Ÿ}‘C°$·,±,Ø—L‘LØ/ñ
%
ð ñ
%
Ñ!ˆ�\ð "×)Ò)Ð;¨;Ð;¸Ò;×FÑFÓHˆØ—m‘m KÓ0ˆà˜LÐ(Ð(r)   )r<   r‹   r½   rÄ   rÁ   r¿   rÅ   r¾   rÈ   rÇ   r®   rÆ   )rÎ   FTFN)NNF)r0   r1   r2   r3   r4   r5   ÚfloatÚboolr   r   rL   rM   r   r	   Útupler.   r6   r7   r8   s   @r'   r¼   r¼     sú   ø† ÙGð Ø ØØØ,0ñCàðCð ðCð ð	Cð
 ðCð ðCð ðCð # TÑ)÷Cð CðD 15Ø.2Ø).ñ0)à—|‘|ð0)ð  Ÿ,™,¨Ñ-ð0)ð Ÿ™ tÑ+ð	0)ð
   $™;ð0)ð Ð-Ñ.ð0)ð 
ˆu�|‰|˜UŸ\™\¨DÑ0Ð0Ñ	1÷0)ó 0)r)   r¼   c                   ó:   ^ • \ rS rSrSrS\4U 4S jjrS rSrU =r	$ )ÚPatchMixerBlockic  zhThis module mixes the patch dimension.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.
r<   c                 óØ  >• [         TU ]  5         [        U5      U l        UR                  U l        UR
                  U l        [        UR                  UR                  US9U l        UR
                  (       a#  [        UR                  UR                  S9U l
        UR                  (       a@  [        UR                  UR                  UR                  US9U l        [        U5      U l        g g )Nrœ   r�   )r½   r¾   r‹   r<   )r   r   rv   r|   Ú	self_attnrž   r…   rW   r    r   r¡   r¼   rA   Úself_attn_headsr‹   Úself_attn_layerÚ	norm_attnrD   s     €r'   r   ÚPatchMixerBlock.__init__k  s¿   ø€ Ü‰ÑÔä)¨&Ó1ˆŒ	à×)Ñ)ˆŒØ ×+Ñ+ˆŒä"Ø×*Ñ*Ø×+Ñ+Øñ
ˆŒð ××Ü :À6×CUÑCUÐ`f×`rÑ`rÑ sˆDÔà××Ü#8Ø Ÿ.™.Ø ×0Ñ0ØŸ™Øñ	$ˆDÔ ô 3°6Ó:ˆD�Nð r)   c                 óÜ  • UnU R                  U5      nU R                  (       aG  UR                  u  p4pVUR                  X4-  XV5      nU R	                  USS9u  p‰UR                  X4XV5      nUR                  SS5      nU R                  U5      nU R                  (       a  U R                  U5      nUR                  SS5      nU R                  (       a  U R                  UW-   5      nX-   n
U
$ )zj
Args:
    hidden_state (`torch.Tensor`): Input tensor.

Returns:
    `torch.Tensor`: Transformed tensor.
F)rÌ   rG   r   )
r|   râ   r�   r€   rä   rH   r    rž   r¡   rå   )r%   rr   r¥   Ú
batch_sizeÚn_varsrW   rA   Úhidden_state_reshapedÚx_attnÚ_r¦   s              r'   r.   ÚPatchMixerBlock.forward…  sá   € ð  ˆà—y‘y Ó.ˆà�>�>Ø7C×7IÑ7IÑ4ˆJ Ø$0×$8Ñ$8¸Ñ9LÈkÓ$cÐ!à×,Ñ,Ð-BÐV[Ð,Ð\‰IˆFØ—^‘^ J¸ÓMˆFð $×-Ñ-¨a°Ó3ˆØ—x‘x Ó-ˆà�?�?Ø×,Ñ,¨\Ó:ˆLð $×-Ñ-¨a°Ó3ˆà�>�>ØŸ>™>¨,¸Ñ*?Ó@ˆLàÑ%ˆØˆ
r)   )rž   r¡   r    r|   rå   râ   rä   ©
r0   r1   r2   r3   r4   r   r   r.   r6   r7   r8   s   @r'   rà   rà   c  s   ø† ñð;Ð1÷ ;÷4!ð !r)   rà   c                   óV   ^ • \ rS rSrSrS\4U 4S jjrS\R                  4S jr	Sr
U =r$ )ÚFeatureMixerBlocki©  zrThis module mixes the hidden feature dimension.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.

r<   c                 ó  >• [         TU ]  5         [        U5      U l        UR                  U l        [        UR                  UR                  US9U l        UR                  (       a$  [        UR                  UR                  S9U l	        g g r›   )
r   r   rv   r|   rž   r…   rA   r    r   r¡   rD   s     €r'   r   ÚFeatureMixerBlock.__init__²  sn   ø€ Ü‰ÑÔä)¨&Ó1ˆŒ	à ×+Ñ+ˆŒä"ØŸ™ØŸ™Øñ
ˆŒð ××Ü :À6Ç>Á>Ð\b×\jÑ\jÑ kˆDÕð r)   Úhiddenc                 óš   • UnU R                  U5      nU R                  U5      nU R                  (       a  U R                  U5      nX-   nU$ )ú§
Args:
    hidden (`torch.Tensor` of shape `(batch_size, num_patches, d_model)`):
        Input tensor to the layer.

Returns:
    `torch.Tensor`: Transformed tensor.
)r|   r    rž   r¡   )r%   ró   r¥   r¦   s       r'   r.   ÚFeatureMixerBlock.forwardÂ  sI   € ð ˆØ—‘˜6Ó"ˆØ—‘˜&Ó!ˆà�?�?Ø×&Ñ& vÓ.ˆFàÑˆØˆ
r)   r¨   rK   r8   s   @r'   rð   rð   ©  s,   ø† ñðlÐ1÷ lð ˜eŸl™l÷ ò r)   rð   c                   óV   ^ • \ rS rSrSrS\4U 4S jjrS\R                  4S jr	Sr
U =r$ )ÚPatchTSMixerLayeriÖ  z�
The `PatchTSMixer` layer that does all three kinds of mixing.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.

r<   c                 óº   >• [         TU ]  5         [        US9U l        [	        US9U l        UR                  U l        UR                  S:X  a  [        US9U l        g g )N©r<   Úmix_channel)	r   r   rà   Úpatch_mixerrð   Úfeature_mixerÚmoder˜   Úchannel_feature_mixerrD   s     €r'   r   ÚPatchTSMixerLayer.__init__à  sR   ø€ Ü‰ÑÔä*°&Ñ9ˆÔÜ.°fÑ=ˆÔà—K‘KˆŒ	à�;‰;˜-Ó'Ü)MÐU[Ñ)\ˆDÕ&ð (r)   ró   c                 óŒ   • U R                   S:X  a  U R                  U5      nU R                  U5      nU R                  U5      nU$ )rõ   rû   )rþ   rÿ   rü   rý   )r%   ró   s     r'   r.   ÚPatchTSMixerLayer.forwardë  sE   € ð �9‰9˜Ó%Ø×/Ñ/°Ó7ˆFà×!Ñ! &Ó)ˆØ×#Ñ# FÓ+ˆØˆr)   )rÿ   rý   rþ   rü   rK   r8   s   @r'   rø   rø   Ö  s,   ø† ñð	]Ð1÷ 	]ð˜eŸl™l÷ ò r)   rø   c                   óF   ^ • \ rS rSrSrS\4U 4S jjrSS\4S jjrSr	U =r
$ )	ÚPatchTSMixerBlockiü  z{The main computing framework of the `PatchTSMixer` model.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.
r<   c           	      ó¼   >• [         TU ]  5         UR                  n[        R                  " [        U5       Vs/ s H  n[        US9PM     sn5      U l        g s  snf ©Nrú   )r   r   Ú
num_layersr    Ú
ModuleListÚrangerø   Úmixers)r%   r<   r  rì   r&   s       €r'   r   ÚPatchTSMixerBlock.__init__  sI   ø€ Ü‰ÑÔà×&Ñ&ˆ
ä—m’mÌuÐU_ÔO`Ó$aÒO`È!Ô%6¸fÔ%EÑO`Ñ$aÓbˆ�ùÒ$as   ¹AÚoutput_hidden_statesc                 ó�   • / nUnU R                    H%  nU" U5      nU(       d  M  UR                  U5        M'     U(       a  XC4$ US4$ )a3  
Args:
    hidden_state (`torch.Tensor`): The input tensor.
    output_hidden_states (`bool`, *optional*, defaults to False.):
        Whether to output the hidden states as well.

Returns:
    `torch.Tensor`: The embedding. `list`: List of all hidden states if `output_hidden_states` is set to
    `True`.
N)r
  Úappend)r%   rr   r  Úall_hidden_statesÚ	embeddingÚmods         r'   r.   ÚPatchTSMixerBlock.forward  sR   € ð Ðà ˆ	à—;”;ˆCÙ˜I›ˆIß#Ð#Ø!×(Ñ(¨Ö3ñ ö
  ØÐ/Ð/à˜d�?Ð"r)   )r
  ©F)r0   r1   r2   r3   r4   r   r   rÝ   r.   r6   r7   r8   s   @r'   r  r  ü  s(   ø† ñðcÐ1÷ cñ#¸$÷ #ó #r)   r  c                   ó>   ^ • \ rS rSrSrSS\4U 4S jjjrS rSrU =r	$ )ÚPatchTSMixerForPredictionHeadi%  zaPrediction Head for Forecasting

Args:
    config (`PatchTSMixerConfig`):
        Configuration.
r<   c                 óê  >• [         TU ]  5         UR                  U l        U R                  b  U R                  R                  5         [        R
                  " UR                  5      U l        Uc>  [        R                  " UR                  UR                  -  UR                  5      U l        O-UR                  UR                  UR                  -  5      U l        [        R                  " SS9U l        g )Néþÿÿÿ©Ú	start_dim)r   r   Úprediction_channel_indicesÚsortr    rŠ   Úhead_dropoutÚdropout_layerr!   rW   rA   Úprediction_lengthÚbase_forecast_blockÚget_parameter_projectionÚFlattenÚflatten)r%   r<   Údistribution_outputr&   s      €r'   r   Ú&PatchTSMixerForPredictionHead.__init__-  s·   ø€ Ü‰ÑÔà*0×*KÑ*KˆÔ'à×*Ñ*Ñ6Ø×+Ñ+×0Ñ0Ô2äŸZšZ¨×(;Ñ(;Ó<ˆÔØÑ&Ü')§y¢y°&×2DÑ2DÀvÇ~Á~Ñ2UÐX^×XpÑXpÓ'qˆDÕ$à':×'SÑ'SØ×"Ñ" V§^¡^Ñ3ó(ˆDÔ$ô —z’z¨BÑ/ˆ�r)   c                 óv  ^ • T R                  U5      nT R                  U5      nT R                  U5      n[        U[        5      (       a  [	        S U 5       5      nOUR                  SS5      nT R                  b=  [        U[        5      (       a  [	        U 4S jU 5       5      nU$ UST R                  4   nU$ )a:  

Args:
    hidden_features (`torch.Tensor` of shape `(batch_size, num_patch, d_model)` in `flatten` mode
        or `(batch_size, n_vars, num_patch, d_model)` in `common_channel`/`mix_channel` mode.): Input hidden
        features.

Returns:
    `torch.Tensor` of shape `(batch_size, prediction_length, nvars)`.

c              3   óD   #   • U  H  oR                  S S5      v •  M     g7f)r   r  N)rH   )Ú.0Úzs     r'   Ú	<genexpr>Ú8PatchTSMixerForPredictionHead.forward.<locals>.<genexpr>P  s   é € ÐCº(°QŸ[™[¨¨R×0Ð0º(ùs   ‚ r   r  c              3   óD   >#   • U  H  oS TR                   4   v •  M     g7f).N)r  )r'  r(  r%   s     €r'   r)  r*  V  s!   øé € Ð [ÒRZÈQ 3¨×(GÑ(GÐ#GÖ!HÒRZùs   ƒ .)r"  r  r  Ú
isinstancerÞ   rH   r  ©r%   Úhidden_featuresÚforecasts   `  r'   r.   Ú%PatchTSMixerForPredictionHead.forward?  s¯   ø€ ð Ÿ,™, Ó7ˆØ×,Ñ,¨_Ó=ˆØ×+Ñ+¨OÓ<ˆÜ�h¤×&Ñ&ÜÑC¹(ÓCÓC‰Hà×)Ñ)¨"¨bÓ1ˆHà×*Ñ*Ñ6Ü˜(¤E×*Ñ*Ü Ô [ÑRZÓ [Ó[�ð ˆð $ C¨×)HÑ)HÐ$HÑI�àˆr)   )r  r  r"  r  r+   rî   r8   s   @r'   r  r  %  s$   ø† ññ0Ð1÷ 0ð 0÷$ð r)   r  c                   ó>   ^ • \ rS rSrSrSS\4U 4S jjjrS rSrU =r	$ )ÚPatchTSMixerLinearHeadi]  zpLinear head for Classification and Regression.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.
r<   c                 ó\  >• [         TU ]  5         UR                  U l        UR                  U l        UR                  c  UR                  nOSnX l        UcA  [        R                  " UR                  UR                  -  U-  UR                  5      U l        O0UR                  UR                  UR                  -  U-  5      U l        UR                  c  [        R                  " SS9U l        O[        R                  " SS9U l        [        R                  " UR                   5      U l        g )Nr   éýÿÿÿr  r  )r   r   Úhead_aggregationÚoutput_rangerW   r#  r    r!   rA   rŸ   Únum_targetsÚ
projectionr   r!  r"  rŠ   r  r‹   )r%   r<   r#  Ú
mul_factorr&   s       €r'   r   ÚPatchTSMixerLinearHead.__init__e  sñ   ø€ Ü‰ÑÔà &× 7Ñ 7ˆÔØ"×/Ñ/ˆÔà×"Ñ"Ñ*Ø×+Ñ+‰JàˆJØ#6Ô ØÑ&Ü ŸišiØ—‘ ×!:Ñ!:Ñ:¸ZÑGØ×"Ñ"óˆD�Oð
 2×JÑJØ—‘ ×!:Ñ!:Ñ:¸ZÑGóˆDŒOð ×"Ñ"Ñ*ÜŸ:š:°Ñ3ˆD�LäŸ:š:°Ñ3ˆDŒLä—z’z &×"5Ñ"5Ó6ˆ�r)   c                 ó0  • UR                  SS5      nU R                  S:X  a  US   nOIU R                  S:X  a  UR                  SS9R                  nOU R                  S:X  a  UR	                  SS9nU R
                  (       a  U R                  U5      nU R                  U5      nU R                  U5      nU R                  cS  U R                  bF  [        R                  " U5      U R                  S   U R                  S	   -
  -  U R                  S	   -   nU$ )
a1  
Args:
    hidden_features (`torch.Tensor` of shape `(batch_size x num_patch x d_model)` in `flatten` mode
        or `(batch_size x n_vars x num_patch x d_model)` in `common_channel`/`mix_channel` mode.): Input hidden
        features.

Returns:
    `torch.Tensor` of shape `(batch_size x num_targets)`.
r   r  Úuse_last).r   Úmax_poolr   Úavg_poolr   r   )rH   r5  ÚmaxÚvaluesri   r"  r‹   r8  r#  r6  rL   Úsigmoid)r%   r.  s     r'   r.   ÚPatchTSMixerLinearHead.forward�  s
  € ð *×3Ñ3°B¸Ó;ˆØ× Ñ  JÓ.à-¨gÑ6‰OØ×"Ñ" jÓ0à-×1Ñ1°bÐ1Ð9×@Ñ@‰OØ×"Ñ" jÓ0à-×2Ñ2°rÐ2Ð:ˆOà�<�<Ø"Ÿl™l¨?Ó;ˆOØŸ,™, Ó7ˆØŸ/™/¨/Ó:ˆà×$Ñ$Ñ,°4×3DÑ3DÑ3Pä—’˜oÓ.°$×2CÑ2CÀAÑ2FÈ×IZÑIZÐ[\ÑI]Ñ2]Ñ^Ðae×arÑarÐstÑauÑuð ð Ðr)   )r#  r‹   r"  r5  r6  r8  r+   rî   r8   s   @r'   r2  r2  ]  s$   ø† ññ7Ð1÷ 7ð 7÷8 ð  r)   r2  c                   ól   ^ • \ rS rSr% \\S'   SrSrSrSr	\
R                  " 5       U 4S j5       rSrU =r$ )	ÚPatchTSMixerPreTrainedModeli¤  r<   ÚmodelÚpast_values)ÚtimeFc                 óš  >• [         TU ]  U5        [        U[        5      (       a<  U R                  R
                  S:X  a!  [        R                  " UR                  SSS9  gg[        U[        5      (       aU  [        R                  " UR                  R                  5        [        R                  " UR                  R                  5        gg)zInitialize weightsr[   rÎ   gš™™™™™¹?)ri   rj   N)r   Ú_init_weightsr,  rO   r<   r`   ÚinitÚnormal_rT   r:   Úzeros_rC   rÀ   Úones_Úweight)r%   r©   r&   s     €r'   rI  Ú)PatchTSMixerPreTrainedModel._init_weights­  s‘   ø€ ô 	‰Ñ˜fÔ%Ü�fÔ<×=Ñ=à�{‰{×3Ñ3°xÓ?Ü—’˜V×0Ñ0°sÀÓDð @ä˜Ô 5×6Ñ6Ü�KŠK˜×(Ñ(×-Ñ-Ô.Ü�JŠJ�v×'Ñ'×.Ñ.Õ/ð 7r)   © )r0   r1   r2   r3   r   Ú__annotations__Úbase_model_prefixÚmain_input_nameÚinput_modalitiesÚsupports_gradient_checkpointingrL   Úno_gradrI  r6   r7   r8   s   @r'   rD  rD  ¤  s:   ø‡ ð ÓØÐØ#€OØ ÐØ&+Ð#à
‡]‚]ƒ_ô	0ó ö	0r)   rD  c                   ó:   ^ • \ rS rSrSrS\4U 4S jjrS rSrU =r	$ )ÚPatchTSMixerPretrainHeadiº  zSPretraining head.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.
r<   c                 óÌ   >• [         TU ]  5         [        R                  " UR                  5      U l        [        R                  " UR                  UR                  5      U l	        g r+   )
r   r   r    rŠ   r  r  r!   rA   Úpatch_lengthÚbase_pt_blockrD   s     €r'   r   Ú!PatchTSMixerPretrainHead.__init__Â  sB   ø€ Ü‰ÑÔäŸZšZ¨×(;Ñ(;Ó<ˆÔÜŸYšY v§~¡~°v×7JÑ7JÓKˆÕr)   c                 óJ   • U R                  U5      nU R                  U5      nU$ )aG  
Args:
    hidden_features (`torch.Tensor` of shape `(batch_size x num_patch x d_model)` in `flatten` mode
        or `(batch_size x n_vars x num_patch x d_model)` in `common_channel`/`mix_channel` mode.): Input hidden
        features.

Returns:
    `torch.Tensor` of shape `(batch_size x n_vars x num_patch x patch_length)`.
)r  r[  r-  s      r'   r.   Ú PatchTSMixerPretrainHead.forwardÈ  s)   € ð ×,Ñ,¨_Ó=ˆØ×%Ñ% oÓ6ˆØˆr)   )r[  r  rî   r8   s   @r'   rX  rX  º  s!   ø† ñðLÐ1÷ L÷ð r)   rX  r,   Ú
mask_ratioÚunmasked_channel_indicesÚchannel_consistent_maskingÚ
mask_valuec                 ó˜  • US:  d  US:¼  a  [        SU S35      eU R                  u  pVpxU R                  n	[        USU-
  -  5      n
U(       a*  [        R
                  " USXyS9nUR                  SUS5      nO[        R
                  " XVXyS9n[        R                  " XVXyS9nSUSS2SS2SU
24'   [        R                  " USS9n[        R                  " USS9n[        R                  " USUS	9nUR                  S5      R                  SSSU5      nUb  SUSS2USS2SS24'   U R                  UR                  5       U5      nXüS
   4$ )a†  random_masking: Mask the input considering the control variables.

Args:
    inputs (`torch.Tensor` of shape `(batch_size, num_channels, sequence_length, num_features)`):
        The input tensor to mask.
    mask_ratio (`float`):
        Masking ratio applied to mask the input data during random pretraining. It is the number between 0 and 1.
    unmasked_channel_indices (list, *optional*):
        Indices of channels that will not be masked.
    channel_consistent_masking (bool, *optional*, defaults to `False`):
        When true, masking will be same across all channels of a timeseries. Otherwise, masking positions will vary
        across channels.
    mask_value (int, *optional*, defaults to 0):
        Define the value of masked patches for pretraining.

Returns:
    `tuple(torch.Tensor)`: inputs_mask, masked input, same shape as input Tensor and mask tensor of shape [bs x c x
    n]
r   r   zMask ratio z has to be between 0 and 1.©ÚdeviceNr   r   )r   Úindex©.r   )rk   r�   re  r5   rL   ÚrandÚrepeatÚonesÚargsortÚgatherrc   Úmasked_fillrÝ   )r,   r_  r`  ra  rb  rè   Únum_channelsÚsequence_lengthÚnum_featuresre  Úlen_keepÚnoiseÚmaskÚids_shuffleÚids_restoreÚinputs_masks                   r'   Úrandom_maskingrw  Ù  sA  € ð4 �Aƒ~˜ q›Ü˜; z lÐ2MÐNÓOÐOà>D¿l¹lÑ;€J˜oØ�]‰]€Fä�? a¨*¡nÑ5Ó6€Hæ!Ü—
’
˜: q¨/ÑIˆØ—‘˜Q ¨aÓ0‰ô —
’
˜:°_ÑTˆô �:Š:�j°ÑO€DØ€DŠŠAˆy�ˆyˆÑô —-’- ¨2Ñ.€KÜ—-’- °Ñ4€Kä�<Š<˜ "¨KÑ8€DØ�>‰>˜"Ó×$Ñ$ Q¨¨1¨lÓ;€DØÑ+Ø23ˆŠQÐ(ª!ªQÐ.Ñ/à×$Ñ$ T§Y¡Y£[°*Ó=€KØ˜V™Ð$Ð$r)   Únum_forecast_mask_patchesc                 óP  • [        U[        5      (       a  U/nU Vs/ s H  nSPM     nnU R                  u  pgp‰[        R                  " XgX€R
                  S9n
/ nSn[        U5      n[        X5       HG  u  pïUS::  d  Xè:¼  a  [        SU S35      e[        Xo-  U-  5      nUR                  XïU/5        UU-  nMI     [        US S9nXÆ:  a  US   S   Xl-
  -   US   S'   OXÆ:”  a  US	   S   XÆ-
  -   US	   S'   SnU H  u  nnnUU-   nSU
UU2S
S
2U* S
24'   UnM     [        R                  " U
R                  S   5      nU
U   n
U
R                  S	5      R                  SSSU	5      n
Ub  SU
S
S
2US
S
2S
S
24'   U R                  U
R                  5       U5      nUU
S   4$ s  snf )ai  Forecast masking that masks the last K patches where K is from the num_forecast_mask_patches.
If num_forecast_mask_patches is a list, samples in the batch will be randomly masked by numbers defined in the list.

Parameters:
    inputs (`torch.Tensor`):
        Input of shape `(bs, num_channels, num_patch, patch_length)`
    num_forecast_mask_patches (`list`):
        Number of patches to be masked at the end of each batch sample. e.g. 4 or [3, 5].
    unmasked_channel_indices (`list`, *optional*):
        Indices of channels that are not masked.
    mask_value (`int`, *optional*, defaults to 0):
        Values in the masked patches will be filled by `mask_value`.

Returns:
    `tuple(torch.Tensor)`: inputs_mask, masked input, same shape as inputs Tensor and Mask tensor of shape `(bs,
    num_channels , num_patch)` or `(bs, tsg1, tsg2, num_channels, num_patch)`
r   rd  r   znum_forecast_mask_patches z6 should be greater than 0 and less than total patches.c                 ó   • U S   $ ©NrG   rP  )Úxs    r'   Ú<lambda>Ú"forecast_masking.<locals>.<lambda>@  s   € ¨!¨Aª$r)   )r«   rG   r   Nrg  )r,  r5   r�   rL   rV   re  ÚsumÚziprk   r  ÚsortedÚrandpermrc   ri  rm  rÝ   )r,   rx  r`  rb  rì   Úforecast_mask_ratiosrè   rn  ro  rp  rs  Út_listÚtotal_lengthÚtotal_ratiorZ  ÚratioÚtemp_lenÚbatch1Ú	patch_lenÚbatch2Úpermrv  s                         r'   Úforecast_maskingr�    sí  € ô0 Ð+¬S×1Ñ1Ø%>Ð$?Ð!Ù'@ÓAÒ'@ !›AÑ'@ÐÐAà>D¿l¹lÑ;€J˜oÜ�;Š;�z°ÏÉÑW€Dà€FØ€LÜÐ*Ó+€Kä"Ð#<ÖSÑˆØ˜1Ó Ó ?ÜØ,¨\¨NÐ:pÐqóð ô �zÑ)¨KÑ7Ó8ˆØ�‰�|¨HÐ5Ô6Ø˜Ñ Šñ  Tô �F¡Ñ/€FàÓ Ø˜a‘y ‘| zÑ'@ÑAˆˆq‰	�!ŠØ	Ó	"Ø˜r™
 1™¨Ñ)BÑCˆˆr‰
�1‰à€FÛ"(Ñˆ	�1�hØ˜(Ñ"ˆØ./ˆˆV�Fˆ]šA 	˜z™{Ð*Ñ+ØŠñ #)ô
 �>Š>˜$Ÿ*™* Q™-Ó(€DØ�‰:€Dà�>‰>˜"Ó×$Ñ$ Q¨¨1¨lÓ;€DØÑ+Ø23ˆŠQÐ(ª!ªQÐ.Ñ/à×$Ñ$ T§Y¡Y£[°*Ó=€KØ˜˜V™Ð$Ð$ùòO Bs   �F#c                   óV   ^ • \ rS rSrSrS\4U 4S jjrS\R                  4S jr	Sr
U =r$ )ÚPatchTSMixerPatchifyiY  z£
A class to patchify the time series sequence into different patches

Returns:
    `torch.Tensor` of shape `(batch_size, num_channels, num_patches, patch_length)`
r<   c                 ó  >• [         TU ]  5         UR                  U l        UR                  U l        UR
                  U l        U R                  U R                  ::  a&  [        SU R                   SU R                   S35      e[        U R                  U R                  5      U R                  -
  U R
                  -  S-   U l        U R                  U R
                  U R                  S-
  -  -   nU R                  U-
  U l	        g )NzSequence length (z+) has to be greater than the patch length (Ú)r   )
r   r   Úcontext_lengthro  rZ  Úpatch_striderk   r?  rW   Úsequence_start)r%   r<   Únew_sequence_lengthr&   s      €r'   r   ÚPatchTSMixerPatchify.__init__a  sò   ø€ Ü‰ÑÔà%×4Ñ4ˆÔØ"×/Ñ/ˆÔØ"×/Ñ/ˆÔà×Ñ 4×#4Ñ#4Ó4ÜØ# D×$8Ñ$8Ð#9Ð9dÐei×evÑevÐdwÐwxÐyóð ô
   × 4Ñ 4°d×6GÑ6GÓHÈ4×K\ÑK\Ñ\Ðae×arÑarÑrÐuvÑvˆÔØ"×/Ñ/°$×2CÑ2CÀt×GWÑGWÐZ[ÑG[Ñ2\Ñ\ÐØ"×2Ñ2Ð5HÑHˆÕr)   rF  c                 ó4  • UR                   S   nX R                  :w  a  [        SU SU R                   S35      eUSS2U R                  S2SS24   nUR	                  SU R
                  U R                  S9nUR                  SS5      R                  5       nU$ )zñ
Parameters:
    past_values (`torch.Tensor` of shape `(batch_size, sequence_length, num_channels)`, *required*):
        Input for patchification

Returns:
    `torch.Tensor` of shape `(batch_size, num_channels, num_patches, patch_length)`
r  zInput sequence length (z%) doesn't match model configuration (rÃ   N)Ú	dimensionr´   Ústepr4  )	r�   ro  rk   r”  ÚunfoldrZ  r“  rH   r·   )r%   rF  ro  rI   s       r'   r.   ÚPatchTSMixerPatchify.forwardr  s¦   € ð &×+Ñ+¨BÑ/ˆØ×2Ñ2Ó2ÜØ)¨/Ð):Ð:_Ð`d×`tÑ`tÐ_uÐuwÐxóð ð šQ × 3Ñ 3Ñ 5²qÐ8Ñ9ˆà—‘¨°$×2CÑ2CÈ$×J[ÑJ[�Ð\ˆà×!Ñ! " bÓ)×4Ñ4Ó6ˆØˆr)   )rW   rZ  r“  ro  r”  rK   r8   s   @r'   r�  r�  Y  s,   ø† ñðIÐ1÷ Ið" 5§<¡<÷ ò r)   r�  c                   óV   ^ • \ rS rSrSrS\4U 4S jjrS\R                  4S jr	Sr
U =r$ )ÚPatchTSMixerMaskingiŠ  ap  
Class to perform random or forecast masking.

Parameters:
    config (`PatchTSMixerConfig`): model config
Returns:
    x_mask (`torch.Tensor` of shape `(batch_size, num_channels, num_patches, patch_length)`)
        Masked patched input
    mask (`torch.Tensor` of shape `(batch_size, num_channels, num_patches)`)
        Bool tensor indicating True on masked points
r<   c                 ó>  >• [         TU ]  5         UR                  U l        UR                  U l        UR                  U l        UR
                  U l        UR                  U l        UR                  U l        U R                  b  [        U R                  5      U l        g g r+   )	r   r   Úrandom_mask_ratiora  Ú	mask_typerx  r`  rb  r�  rD   s     €r'   r   ÚPatchTSMixerMasking.__init__—  s„   ø€ Ü‰ÑÔØ!'×!9Ñ!9ˆÔØ*0×*KÑ*KˆÔ'Ø×)Ñ)ˆŒØ)/×)IÑ)IˆÔ&Ø(.×(GÑ(GˆÔ%Ø ×+Ñ+ˆŒØ×(Ñ(Ñ4Ü,2°4×3PÑ3PÓ,QˆDÕ)ð 5r)   ro   c                 ód  • U R                   S:X  a8  [        UU R                  U R                  U R                  U R
                  S9u  p#OVU R                   S:X  a-  [        UU R                  U R                  U R
                  S9u  p#O[        SU R                    S35      eUR                  5       nX#4$ )aœ  
Parameters:
    patch_input (`torch.Tensor` of shape `(batch_size, num_channels, num_patches, patch_length)`, *required*):
        Patch input

Return:
    masked_input (`torch.Tensor` of shape `(batch_size, num_channels, num_patches, patch_length)`)
        Masked patched input
    mask (`torch.Tensor` of shape `(batch_size, num_channels, num_patches)`)
        Bool tensor indicating True on masked points

r[   )r,   r_  r`  ra  rb  r/  )r,   rx  r`  rb  zInvalid mask type Ú.)
r   rw  rŸ  r`  ra  rb  r�  rx  rk   rÝ   )r%   ro   Úmasked_inputrs  s       r'   r.   ÚPatchTSMixerMasking.forward¢  s¯   € ð �>‰>˜XÓ%Ü!/Ø"Ø×1Ñ1Ø)-×)FÑ)FØ+/×+JÑ+JØŸ?™?ñ"ÑˆL˜$ð �^‰^˜zÓ)Ü!1Ø"Ø*.×*HÑ*HØ)-×)FÑ)FØŸ?™?ñ	"ÑˆL˜$ô Ð1°$·.±.Ð1AÀÐCÓDÐDð �y‰y‹{ˆØÐ!Ð!r)   )ra  r   rb  rx  rŸ  r`  rK   r8   s   @r'   r�  r�  Š  s,   ø† ñ
ð	RÐ1÷ 	Rð!" 5§<¡<÷ !"ò !"r)   r�  c            	       óº   ^ • \ rS rSrSrS\4U 4S jjrS\R                  S\R                  S\	\R                  \R                  \R                  4   4S jr
S	rU =r$ )
ÚPatchTSMixerStdScaleriÇ  z±
Standardize features by calculating the mean and scaling along the first dimension, and then normalizes it by
subtracting from the mean and dividing by the standard deviation.
r<   c                 ó  >• [         TU ]  5         [        US5      (       a  UR                  OSU l        [        US5      (       a  UR
                  OSU l        [        US5      (       a  UR                  U l        g SU l        g )NÚscaling_dimr   ÚkeepdimTÚminimum_scalegñhãˆµøä>)r   r   Úhasattrr©  r   rª  r«  rD   s     €r'   r   ÚPatchTSMixerStdScaler.__init__Í  sd   ø€ Ü‰ÑÔÜ)0°¸×)GÑ)G�6×%Ò%ÈQˆŒÜ)0°¸×)CÑ)C�v—~’~ÈˆŒÜ5<¸VÀ_×5UÑ5U˜V×1Ñ1ˆÕÐ[_ˆÕr)   ÚdataÚobserved_indicatorrY   c                 ór  • UR                  U R                  U R                  S9nUR                  S5      nX-  R                  U R                  U R                  S9U-  nX-
  U-  S-  R                  U R                  U R                  S9U-  n[        R
                  " XPR                  -   5      nX-
  U-  XF4$ )áó  
Parameters:
    data (`torch.Tensor` of shape `(batch_size, sequence_length, num_input_channels)`):
        input for Batch norm calculation
    observed_indicator (`torch.BoolTensor` of shape `(batch_size, sequence_length, num_input_channels)`):
        Calculating the scale on the observed indicator.
Returns:
    tuple of `torch.Tensor` of shapes
        (`(batch_size, sequence_length, num_input_channels)`,`(batch_size, 1, num_input_channels)`,
        `(batch_size, 1, num_input_channels)`)
©rª  ç      ð?rG   )r  r   rª  Ú	clamp_minrL   Úsqrtr«  )r%   r®  r¯  ÚdenominatorÚlocÚvarianceÚscales          r'   r.   ÚPatchTSMixerStdScaler.forwardÓ  s³   € ð )×,Ñ,¨T¯X©X¸t¿|¹|Ð,ÐLˆØ!×+Ñ+¨CÓ0ˆØÑ(×-Ñ-¨d¯h©hÀÇÁÐ-ÐMÐP[Ñ[ˆà‘jÐ$6Ñ6¸1Ñ<×AÑAÀ$Ç(Á(ÐTX×T`ÑT`ÐAÐaÐdoÑoˆÜ—
’
˜8×&8Ñ&8Ñ8Ó9ˆØ‘
˜eÑ# SÐ/Ð/r)   )r   rª  r«  ©r0   r1   r2   r3   r4   r   r   rL   rM   rÞ   r.   r6   r7   r8   s   @r'   r§  r§  Ç  sY   ø† ñð
`Ð1÷ `ð0Ø—L‘Lð0Ø6;·l±lð0à	ˆu�|‰|˜UŸ\™\¨5¯<©<Ð7Ñ	8÷0ò 0r)   r§  c            	       óº   ^ • \ rS rSrSrS\4U 4S jjrS\R                  S\R                  S\	\R                  \R                  \R                  4   4S jr
S	rU =r$ )
ÚPatchTSMixerMeanScalerië  z~
Computes a scaling factor as the weighted average absolute value along the first dimension, and scales the data
accordingly.
r<   c                 óN  >• [         TU ]  5         [        US5      (       a  UR                  OSU l        [        US5      (       a  UR
                  OSU l        [        US5      (       a  UR                  OSU l        [        US5      (       a  UR                  U l        g S U l        g )Nr©  r   rª  Tr«  ç»½×Ùß|Û=Údefault_scale)r   r   r¬  r©  r   rª  r«  rÀ  rD   s     €r'   r   ÚPatchTSMixerMeanScaler.__init__ñ  s�   ø€ Ü‰ÑÔÜ)0°¸×)GÑ)G�6×%Ò%ÈQˆŒÜ)0°¸×)CÑ)C�v—~’~ÈˆŒÜ5<¸VÀ_×5UÑ5U˜V×1Ò1Ð[`ˆÔÜ5<¸VÀ_×5UÑ5U˜V×1Ñ1ˆÕÐ[_ˆÕr)   r®  r¯  rY   c                 ó°  • X-  R                  5       R                  U R                  SS9nUR                  U R                  SS9nU[        R                  " USS9-  nU R
                  cL  UR                  SS9n[        R                  " UR                  S5      SS9n[        R                  " Xg-  5      nO#U R
                  [        R                  " U5      -  n[        R                  " US:„  XX5      n[        R                  " XPR                  S9nX-  n	U R                  (       d  UR                  U R                  S9nU	[        R                  " U5      U4$ )r±  Tr²  r   ©Úminr   r   )Úabsr  r   rL   ÚclamprÀ  ÚsqueezeÚ	ones_likeÚwherer«  rª  Ú
zeros_like)
r%   r®  r¯  Úts_sumÚnum_observedr¹  Ú	batch_sumÚbatch_observationsrÀ  Úscaled_datas
             r'   r.   ÚPatchTSMixerMeanScaler.forwardø  s"  € ð Ñ+×0Ñ0Ó2×6Ñ6°t·x±xÈÐ6ÐNˆØ)×-Ñ-¨d¯h©hÀÐ-ÐEˆàœŸš \°qÑ9Ñ9ˆð ×ÑÑ%ØŸ
™
 q˜
Ð)ˆIÜ!&§¢¨\×-=Ñ-=¸aÓ-@ÀaÑ!HÐÜ!ŸMšM¨)Ñ*HÓI‰Mà ×.Ñ.´·²ÀÓ1GÑGˆMô —’˜L¨1Ñ,¨eÓCˆô —’˜E×'9Ñ'9Ñ:ˆØ‘lˆà�|�|Ø—M‘M d§h¡h�MÐ/ˆEàœE×,Ò,¨UÓ3°UÐ:Ð:r)   )rÀ  r   rª  r«  r»  r8   s   @r'   r½  r½  ë  sY   ø† ñð
`Ð1÷ `ð&;Ø—L‘Lð&;Ø6;·l±lð&;à	ˆu�|‰|˜UŸ\™\¨5¯<©<Ð7Ñ	8÷&;ò &;r)   r½  c            
       óÆ   ^ • \ rS rSrSrS\4U 4S jjr SS\R                  S\R                  S-  S\	\R                  \R                  \R                  4   4S	 jjr
S
rU =r$ )ÚPatchTSMixerNOPScaleri"  zt
Assigns a scaling factor equal to 1 along the first dimension, and therefore applies no scaling to the input data.
r<   c                 ó¾   >• [         TU ]  5         [        US5      (       a  UR                  OSU l        [        US5      (       a  UR
                  U l        g SU l        g )Nr©  r   rª  T)r   r   r¬  r©  r   rª  rD   s     €r'   r   ÚPatchTSMixerNOPScaler.__init__'  sF   ø€ Ü‰ÑÔÜ)0°¸×)GÑ)G�6×%Ò%ÈQˆŒÜ)0°¸×)CÑ)C�v—~‘~ˆ�Èˆ�r)   Nr®  r¯  rY   c                 óæ   • [         R                  " USS9R                  U R                  U R                  S9n[         R
                  " USS9R                  U R                  U R                  S9nXU4$ )aP  
Parameters:
    data (`torch.Tensor` of shape `(batch_size, sequence_length, num_input_channels)`):
        input for Batch norm calculation
Returns:
    tuple of `torch.Tensor` of shapes
        (`(batch_size, sequence_length, num_input_channels)`,`(batch_size, 1, num_input_channels)`,
        `(batch_size, 1, num_input_channels)`)
Fr\   ©r   rª  )rL   rÈ  ri   r   rª  rÊ  )r%   r®  r¯  r¹  r·  s        r'   r.   ÚPatchTSMixerNOPScaler.forward,  sg   € ô —’ °EÑ:×?Ñ?ÀDÇHÁHÐVZ×VbÑVbÐ?ÐcˆÜ×Ò˜t°5Ñ9×>Ñ>À4Ç8Á8ÐUY×UaÑUaÐ>ÐbˆØ˜%ÐÐr)   rÖ  r+   r»  r8   s   @r'   rÒ  rÒ  "  se   ø† ñðNÐ1÷ Nð MQñ Ø—L‘Lð Ø6;·l±lÀTÑ6Ið à	ˆu�|‰|˜UŸ\™\¨5¯<©<Ð7Ñ	8÷ ó  r)   rÒ  zS
    Base class for `PatchTSMixerEncoderOutput`, with potential hidden states.
    )Úcustom_introc                   óp   • \ rS rSr% SrSr\R                  S-  \S'   Sr	\
\R                     S-  \S'   Srg)ÚPatchTSMixerEncoderOutputi=  a  
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_channels, num_patches, d_model)`):
    Hidden-state at the output of the last layer of the model.
hidden_states (`tuple(torch.FloatTensor)`, *optional*):
    Hidden-states of the model at the output of each layer.
NÚlast_hidden_staterÊ   rP  )r0   r1   r2   r3   r4   rÛ  rL   ÚFloatTensorrQ  rÊ   rÞ   r6   rP  r)   r'   rÚ  rÚ  =  s9   ‡ ñð 37Ð�u×(Ñ(¨4Ñ/Ó6Ø59€M�5˜×*Ñ*Ñ+¨dÑ2Ö9r)   rÚ  c            	       ó~   ^ • \ rS rSrSrS\4U 4S jjr\\ SS\	R                  S\S-  S\4S	 jj5       5       rS
rU =r$ )ÚPatchTSMixerEncoderiO  zœ
Encoder for PatchTSMixer which inputs patched time-series and outputs patched embeddings.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.
r<   c                 ó  >• [         TU ]  U5        [        R                  " UR                  UR
                  5      U l        UR                  (       a  [        US9U l	        OS U l	        [        US9U l        U R                  5         g r  )r   r   r    r!   rZ  rA   ÚpatcherrR   rO   Úpositional_encoderr  Úmlp_mixer_encoderÚ	post_initrD   s     €r'   r   ÚPatchTSMixerEncoder.__init__X  sc   ø€ Ü‰Ñ˜Ô ä—y’y ×!4Ñ!4°f·n±nÓEˆŒØ×)×)Ü&DÈFÑ&SˆDÕ#à&*ˆDÔ#Ü!2¸&Ñ!AˆÔð 	�‰Õr)   NrF  r  rY   c                 óÊ   • Ub  UOU R                   R                  nU R                  U5      nU R                  b  U R                  U5      nU R	                  XBS9u  pV[        XVS9$ )a�  
past_values (`torch.FloatTensor` of shape `(batch_size, seq_length, num_input_channels)`):
    Context values of the time series. For a pretraining task, this denotes the input time series to
    predict the masked portion. For a forecasting task, this denotes the history/past time series values.
    Similarly, for classification or regression tasks, it denotes the appropriate context values of the
    time series.

    For univariate time series, `num_input_channels` dimension should be 1. For multivariate time series,
    it is greater than 1.

Returns:
    `torch.FloatTensor` of shape `(batch_size, n_vars, num_patches, d_model)`
©r  )rÛ  rÊ   )r<   r  rà  rá  râ  rÚ  )r%   rF  r  r¯   ÚpatchesrÛ  rÊ   s          r'   r.   ÚPatchTSMixerEncoder.forwarde  so   € ð. %9Ñ$DÑ È$Ï+É+×JjÑJjð 	ð
 —,‘,˜{Ó+ˆð ×"Ñ"Ñ.Ø×-Ñ-¨gÓ6ˆGà+/×+AÑ+AÀ'Ð+AÐ+uÑ(Ðä(Ð;LÑjÐjr)   )râ  rà  rá  r+   )r0   r1   r2   r3   r4   r   r   r   r   rL   rM   rÝ   rÚ  r.   r6   r7   r8   s   @r'   rÞ  rÞ  O  s_   ø† ñðÐ1÷ ð Øð -1ñ!kà—\‘\ð!kð # T™kð!kð
 
#ô!kó ó ö!kr)   rÞ  zG
    Base class for model's outputs, with potential hidden states.
    c                   ó  • \ rS rSr% SrSr\R                  S-  \S'   Sr	\
\R                     S-  \S'   Sr\R                  S-  \S'   Sr\R                  S-  \S'   Sr\R                  S-  \S'   Sr\R                  S-  \S	'   S
rg)ÚPatchTSMixerModelOutputi‹  aÔ  
last_hidden_state (`torch.FloatTensor`  of shape `(batch_size, num_channels, num_patches, d_model)`):
    Hidden-state at the output of the last layer of the model.
hidden_states (`tuple(torch.FloatTensor)`, *optional*):
    Hidden-states of the model at the output of each layer.
patch_input (`torch.FloatTensor` of shape `(batch_size, num_channels, num_patches, patch_length)`):
    Patched input data to the model.
mask (`torch.FloatTensor` of shape `(batch_size, num_channels, num_patches)`, *optional*):
    Bool Tensor indicating True in masked patches and False otherwise.
loc (`torch.FloatTensor` of shape `(batch_size, 1, num_channels)`, *optional*):
    Gives the mean of the context window per channel. Used for revin denorm outside the model, if revin
    enabled.
scale (`torch.FloatTensor` of shape `(batch_size, 1, num_channels)`, *optional*):
    Gives the std dev of the context window per channel. Used for revin denorm outside the model, if revin
    enabled.
NrÛ  rÊ   ro   rs  r·  r¹  rP  )r0   r1   r2   r3   r4   rÛ  rL   rÜ  rQ  rÊ   rÞ   ro   rs  r·  r¹  r6   rP  r)   r'   rê  rê  ‹  s�   ‡ ñð" 37Ð�u×(Ñ(¨4Ñ/Ó6Ø59€M�5˜×*Ñ*Ñ+¨dÑ2Ó9Ø,0€K�×"Ñ" TÑ)Ó0Ø%)€Dˆ%×
Ñ
˜dÑ
"Ó)Ø$(€Cˆ×	Ñ	˜TÑ	!Ó(Ø&*€Eˆ5×Ñ˜tÑ#Ö*r)   rê  z=
    The PatchTSMixer Model for time-series forecasting.
    c                   ó¢   ^ • \ rS rSrSS\S\4U 4S jjjr\\  SS\	R                  S\	R                  S-  S\S-  S	\4S
 jj5       5       rSrU =r$ )ÚPatchTSMixerModeli«  r<   Ú
mask_inputc                 ó€  >• [         TU ]  U5        [        U5      U l        [	        U5      U l        USL a  [        U5      U l        OSU l        UR                  S:X  a  [        U5      U l
        O@UR                  S:X  d  UR                  SL a  [        U5      U l
        O[        U5      U l
        U R                  5         g)z}
mask_input (bool, *optional*, defaults to `False`):
    Whether to mask the input using the [`PatchTSMixerMasking`] module.
TNri   rj   )r   r   rÞ  Úencoderr�  Úpatchingr�  Úmaskingr®   r½  Úscalerr§  rÒ  rã  )r%   r<   rí  r&   s      €r'   r   ÚPatchTSMixerModel.__init__±  s˜   ø€ ô
 	‰Ñ˜Ô ä*¨6Ó2ˆŒÜ,¨VÓ4ˆŒà˜ÒÜ.¨vÓ6ˆD�LàˆDŒLà�>‰>˜VÓ#Ü0°Ó8ˆD�KØ�^‰^˜uÓ$¨¯©¸$Ò(>Ü/°Ó7ˆD�Kä/°Ó7ˆDŒKð 	�‰Õr)   NrF  Úobserved_maskr  rY   c           	      óš  • Ub  UOU R                   R                  nSnUc  [        R                  " U5      nU R	                  X5      u  pgnU R                  U5      n	U	n
U R                  b  U R                  U	5      u  p¥U R                  U
US9n[        U[        5      (       a  [        U6 n[        UR                  UR                  U	UUUS9$ )a‹  
past_values (`torch.FloatTensor` of shape `(batch_size, seq_length, num_input_channels)`):
    Context values of the time series. For a pretraining task, this denotes the input time series to predict
    the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly,
    for classification or regression tasks, it denotes the appropriate context values of the time series.

    For univariate time series, `num_input_channels` dimension should be 1. For multivariate time series, it is
    greater than 1.
observed_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length, num_input_channels)`, *optional*):
    Boolean mask to indicate which `past_values` were observed and which were missing. Mask values selected
    in `[0, 1]`:
    - 1 for values that are **observed**,
    - 0 for values that are **missing** (i.e. NaNs that were replaced by zeros).
Nræ  )rÛ  rÊ   ro   rs  r·  r¹  )r<   r  rL   rÈ  rò  rð  rñ  rï  r,  rÞ   rÚ  rê  rÛ  rÊ   )r%   rF  rô  r  r¯   rs  Úscaled_past_valuesr·  r¹  Ú	patched_xÚ	enc_inputÚencoder_outputs               r'   r.   ÚPatchTSMixerModel.forwardÊ  sÚ   € ð0 %9Ñ$DÑ È$Ï+É+×JjÑJjð 	ð ˆØÑ Ü!ŸOšO¨KÓ8ˆMØ)-¯©°[Ó)PÑ&Ð à—M‘MÐ"4Ó5ˆ	àˆ	Ø�<‰<Ñ#Ø"Ÿl™l¨9Ó5‰OˆIð Ÿ™ØØ!5ð &ð 
ˆô
 �n¤e×,Ñ,Ü6¸ÐGˆNä&Ø,×>Ñ>Ø(×6Ñ6Ø!ØØØñ
ð 	
r)   )rï  rñ  rð  rò  r  ©NN)r0   r1   r2   r3   r   rÝ   r   r   r   rL   rM   rê  r.   r6   r7   r8   s   @r'   rì  rì  «  sw   ø† ñÐ1ð ¸t÷ ð ð2 Øð .2Ø,0ñ	5
à—\‘\ð5
ð —|‘| dÑ*ð5
ð # T™kð	5
ð 
!ô5
ó ó ö5
r)   rì  z>
    Output type of [`PatchTSMixerForPreTrainingOutput`].
    c                   óÀ   • \ rS rSr% SrSr\R                  S-  \S'   Sr	\R                  S-  \S'   Sr
\R                  S-  \S'   Sr\\R                     S-  \S'   Srg)	Ú PatchTSMixerForPreTrainingOutputi  a  
loss (*optional*, returned when `y` is provided, `torch.FloatTensor` of shape `()`):
    Total loss
prediction_outputs (`torch.FloatTensor` of shape `(batch_size, num_input_channels, num_patches, patch_length)`):
    Prediction output from the pretrain head.
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_input_channels, num_patches, d_model)`):
    Backbone embeddings before passing through the head.
hidden_states (`tuple(torch.FloatTensor)`, *optional*):
    Hidden-states of the model at the output of each layer.
NÚlossÚprediction_outputsrÛ  rÊ   rP  ©r0   r1   r2   r3   r4   rþ  rL   rÜ  rQ  rÿ  rÛ  rÊ   rÞ   r6   rP  r)   r'   rý  rý    ód   ‡ ñ	ð &*€Dˆ%×
Ñ
˜dÑ
"Ó)Ø37Ð˜×)Ñ)¨DÑ0Ó7Ø26Ð�u×(Ñ(¨4Ñ/Ó6Ø59€M�5˜×*Ñ*Ñ+¨dÑ2Ö9r)   rý  z.
    `PatchTSMixer` for mask pretraining.
    c                   ó    ^ • \ rS rSrS\4U 4S jjr\\   SS\R                  S\R                  S-  S\
S-  S\
S	\4
S
 jj5       5       rSrU =r$ )ÚPatchTSMixerForPretrainingi  r<   c                 ó    >• [         TU ]  U5        [        USS9U l        [	        US9U l        UR                  U l        U R                  5         g )NT)rí  rú   )r   r   rì  rE  rX  ÚheadÚmasked_lossrã  rD   s     €r'   r   Ú#PatchTSMixerForPretraining.__init__"  sD   ø€ Ü‰Ñ˜Ô Ü& v¸$Ñ?ˆŒ
Ü,°FÑ;ˆŒ	Ø!×-Ñ-ˆÔð 	�‰Õr)   NrF  rô  r  Úreturn_lossrY   c                 ó†  • Ub  UOU R                   R                  nU R                  SL a  [        R                  R                  SS9nO[        R                  R                  SS9nU R                  UUUS9n[        U[        5      (       a  [        U6 nU R                  UR                  5      nUSL a  U" X‡R                  5      n	OSn	U R                  SL aK  U	bH  U	R                  SS9UR                  -  R                  5       UR                  R                  5       S	-   -  n	[!        U	UUR                  UR"                  S
9$ )aä  
past_values (`torch.FloatTensor` of shape `(batch_size, seq_length, num_input_channels)`):
    Context values of the time series. For a pretraining task, this denotes the input time series to predict
    the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly,
    for classification or regression tasks, it denotes the appropriate context values of the time series.

    For univariate time series, `num_input_channels` dimension should be 1. For multivariate time series, it is
    greater than 1.
observed_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length, num_input_channels)`, *optional*):
    Boolean mask to indicate which `past_values` were observed and which were missing. Mask values selected
    in `[0, 1]`:
    - 1 for values that are **observed**,
    - 0 for values that are **missing** (i.e. NaNs that were replaced by zeros).
return_loss (`bool`,  *optional*):
    Whether to return the loss in the `forward` call.
NTÚnone©Ú	reductionri   ©rô  r  r   r   r¿  ©rþ  rÿ  rÛ  rÊ   )r<   r  r  rL   r    ÚMSELossrE  r,  rÞ   rê  r  rÛ  ro   ri   rs  r  rý  rÊ   )
r%   rF  rô  r  r  r¯   rþ  Úmodel_outputÚx_hatÚloss_vals
             r'   r.   Ú"PatchTSMixerForPretraining.forward+  s<  € ð6 %9Ñ$DÑ È$Ï+É+×JjÑJjð 	ð ×Ñ˜tÒ#Ü—8‘8×#Ñ#¨fÐ#Ð5‰Dä—8‘8×#Ñ#¨fÐ#Ð5ˆDð —z‘zØØ'Ø!5ð "ð 
ˆô
 �l¤E×*Ñ*Ü2°LÐAˆLà—	‘	˜,×8Ñ8Ó9ˆà˜$ÒÙ˜E×#;Ñ#;Ó<‰HàˆHð ×Ñ˜tÒ#¨Ñ(<Ø Ÿ™¨"˜Ð-°×0AÑ0AÑA×FÑFÓHÈL×L]ÑL]×LaÑLaÓLcÐfkÑLkÑlˆHä/ØØ$Ø*×<Ñ<Ø&×4Ñ4ñ	
ð 	
r)   )r  r  rE  ©NNT)r0   r1   r2   r3   r   r   r   r   rL   rM   rÝ   rý  r.   r6   r7   r8   s   @r'   r  r    sx   ø† ðÐ1÷ ð Øð .2Ø,0Ø ñ:
à—\‘\ð:
ð —|‘| dÑ*ð:
ð # T™kð	:
ð
 ð:
ð 
*ô:
ó ó ö:
r)   r  z=
    Output type of [`PatchTSMixerForPredictionOutput`].
    c                   ó  • \ rS rSr% SrSr\R                  S-  \S'   Sr	\R                  S-  \S'   Sr
\R                  S-  \S'   Sr\\R                     S-  \S'   Sr\R                  S-  \S'   Sr\R                  S-  \S	'   S
rg)ÚPatchTSMixerForPredictionOutputij  a  
loss (*optional*, returned when `y` is provided, `torch.FloatTensor` of shape `()`):
    Total loss.
prediction_outputs (`torch.FloatTensor` of shape `(batch_size, prediction_length, num_input_channels)`):
    Prediction output from the forecast head.
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_input_channels, num_patches, d_model)`):
    Backbone embeddings before passing through the head.
hidden_states (`tuple(torch.FloatTensor)`, *optional*):
    Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
loc (`torch.FloatTensor`, *optional* of shape `(batch_size, 1, num_input_channels)`):
    Input mean
scale (`torch.FloatTensor`, *optional* of shape `(batch_size, 1, num_input_channels)`):
    Input std dev
Nrþ  rÿ  rÛ  rÊ   r·  r¹  rP  )r0   r1   r2   r3   r4   rþ  rL   rÜ  rQ  rÿ  rÛ  rÊ   rÞ   r·  r¹  r6   rP  r)   r'   r  r  j  sŽ   ‡ ñð &*€Dˆ%×
Ñ
˜dÑ
"Ó)Ø37Ð˜×)Ñ)¨DÑ0Ó7Ø26Ð�u×(Ñ(¨4Ñ/Ó6Ø59€M�5˜×*Ñ*Ñ+¨dÑ2Ó9Ø$(€Cˆ×	Ñ	˜TÑ	!Ó(Ø&*€Eˆ5×Ñ˜tÑ#Ö*r)   r  zƒ
    Base class for time series model's predictions outputs that contains the sampled values from the chosen
    distribution.
    c                   óB   • \ rS rSr% SrSr\R                  S-  \S'   Sr	g)Ú"SamplePatchTSMixerPredictionOutputiˆ  úœ
sequences (`torch.FloatTensor` of shape `(batch_size, num_samples, prediction_length, number_channels)`):
    Sampled values from the chosen distribution.
NÚ	sequencesrP  ©
r0   r1   r2   r3   r4   r  rL   rÜ  rQ  r6   rP  r)   r'   r  r  ˆ  ó   ‡ ñð
 +/€Iˆu× Ñ  4Ñ'Ö.r)   r  c                   óB   • \ rS rSr% SrSr\R                  S-  \S'   Sr	g)Ú"SamplePatchTSMixerRegressionOutputi˜  r  Nr  rP  r  rP  r)   r'   r  r  ˜  r  r)   r  ÚinputÚtargetrY   c                 ó&   • U R                  U5      * $ )z[
Computes the negative log likelihood loss from input distribution with respect to target.
)Úlog_prob)r  r   s     r'   Únllr#  ©  s   € ð �N‰N˜6Ó"Ð"Ð"r)   Úinput_tensorÚweightsc                 óR  • Ub–  [         R                  " US:g  X-  [         R                  " U 5      5      n[         R                  " U(       a  UR	                  US9OUR	                  5       SS9nU(       a  UR	                  US9U-  $ UR	                  5       U-  $ U R                  US9$ )a:  
Computes the weighted average of a given tensor across a given `dim`, masking values associated with weight zero,
meaning instead of `nan * 0 = nan` you will get `0 * 0 = 0`.

Args:
    input_tensor (`torch.FloatTensor`):
        Input tensor, of which the average must be computed.
    weights (`torch.FloatTensor`, *optional*):
        Weights tensor, of the same shape as `input_tensor`.
    dim (`int`, *optional*):
        The dim along which to average `input_tensor`.

Returns:
    `torch.FloatTensor`: The tensor with values averaged along the specified `dim`.
r   r   r³  rÃ  )rL   rÉ  rÊ  rÆ  r  ri   )r$  r%  r   Úweighted_tensorÚsum_weightss        r'   Úweighted_averager)  ±  s™   € ð  ÑÜŸ+š+ g°¡l°LÑ4JÌE×L\ÒL\Ð]iÓLjÓkˆÜ—k’k¾# '§+¡+°# +Ñ"6À7Ç;Á;Ã=ÐVYÑZˆÞ03�×#Ñ#¨Ð#Ð,ÐR]Ñ]Ð]¸×9LÑ9LÓ9NÐR]Ñ]Ð]à× Ñ  SÐ Ð)Ð)r)   c                   ó6  ^ • \ rS rSrSrS\4U 4S jjr\\    SS\	R                  S\	R                  S-  S\	R                  S-  S	\S-  S
\S\4S jj5       5       r\	R                  " 5        SS\	R                  S\	R                  S-  S\4S jj5       rSrU =r$ )ÚPatchTSMixerForPredictioniÉ  z„
`PatchTSMixer` for forecasting application.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.

Returns:
    `None`.
r<   c                 óì  >• [         TU ]  U5        UR                  U l        UR                  U l        UR                  U l        UR                  S:X  a  S U l        O`UR                  n[        [        [        S.nUR                  UR
                  5      nUb  U" US9U l        O[        SUR
                   35      e[        U5      U l        [        UU R
                  S9U l        U R!                  5         g )NÚmse©Ú	student_tÚnormalÚnegative_binomialr   úUnknown distribution output ©r<   r#  )r   r   rþ  r  Únum_parallel_samplesr#  r  r   r   r   Úgetrk   rì  rE  r  r  rã  )r%   r<   r   Údistribution_output_mapÚoutput_classr&   s        €r'   r   Ú"PatchTSMixerForPrediction.__init__Õ  sÜ   ø€ Ü‰Ñ˜Ô Ø—K‘KˆŒ	Ø*0×*KÑ*KˆÔ'Ø$*×$?Ñ$?ˆÔ!à�;‰;˜%ÓØ'+ˆDÕ$à×*Ñ*ˆCä+Ü&Ü%;ñ'Ð#ð
 3×6Ñ6°v×7QÑ7QÓRˆLØÑ'Ù+7¸CÑ+@�Õ(ä Ð#?À×@ZÑ@ZÐ?[Ð!\Ó]Ð]ä& vÓ.ˆŒ
Ü1ØØ $× 8Ñ 8ñ
ˆŒ	ð 	�‰Õr)   NrF  rô  Úfuture_valuesr  r  rY   c           	      óD  • U R                   S:X  a  [        R                  " SS9nO"U R                   S:X  a  [        nO[	        S5      eUb  UOU R
                  R                  nU R                  UUUS9n[        U[        5      (       a  [        U6 nU R                  UR                  5      n	Sn
U R                  bã  U R                  (       ay  U R                  R                  U	UR                   SU R                  4   UR"                  SU R                  4   S	9nUb(  US
L a#  U" UUSU R                  4   5      n
[%        U
5      n
OßX˜R"                  SU R                  4   -  UR                   SU R                  4   -   n	Ub  US
L a  U" X“SU R                  4   5      n
O†U R                  (       aJ  U R                  R                  X˜R                   UR"                  S	9nUb  US
L a  U" X³5      n
[%        U
5      n
O+X˜R"                  -  UR                   -   n	Ub  US
L a  U" X“5      n
U R                  b7  UR                   SU R                  4   nUR"                  SU R                  4   nOUR                   nUR"                  n['        U
U	UR                  UR(                  UUS9$ )a  
past_values (`torch.FloatTensor` of shape `(batch_size, seq_length, num_input_channels)`):
    Context values of the time series. For a pretraining task, this denotes the input time series to predict
    the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly,
    for classification or regression tasks, it denotes the appropriate context values of the time series.

    For univariate time series, `num_input_channels` dimension should be 1. For multivariate time series, it is
    greater than 1.
observed_mask (`torch.FloatTensor` of shape `(batch_size, sequence_length, num_input_channels)`, *optional*):
    Boolean mask to indicate which `past_values` were observed and which were missing. Mask values selected
    in `[0, 1]`:
    - 1 for values that are **observed**,
    - 0 for values that are **missing** (i.e. NaNs that were replaced by zeros).
future_values (`torch.FloatTensor` of shape `(batch_size, target_len, num_input_channels)` for forecasting,:
    `(batch_size, num_targets)` for regression, or `(batch_size,)` for classification, *optional*):
    Target values of the time series, that serve as labels for the model. The `future_values` is what the
    Transformer needs during training to learn to output, given the `past_values`. Note that, this is NOT
    required for a pretraining task.

    For a forecasting task, the shape is be `(batch_size, target_len, num_input_channels)`. Even if we want
    to forecast only specific channels by setting the indices in `prediction_channel_indices` parameter,
    pass the target data with all channels, as channel Filtering for both prediction and target will be
    manually applied before the loss computation.
return_loss (`bool`,  *optional*):
    Whether to return the loss in the `forward` call.
r-  ri   r  r#  ú2Invalid loss function: Allowed values: mse and nllNr  .©r·  r¹  T)rþ  rÿ  rÛ  rÊ   r·  r¹  )rþ  r    r  r#  rk   r<   r  rE  r,  rÞ   rê  r  rÛ  r  r#  Údistributionr·  r¹  r)  r  rÊ   )r%   rF  rô  r9  r  r  r¯   rþ  r  Úy_hatr  r=  r·  r¹  s                 r'   r.   Ú!PatchTSMixerForPrediction.forwardó  sÅ  € ðJ �9‰9˜ÓÜ—:’:¨Ñ/‰DØ�Y‰Y˜%ÓÜ‰DäÐQÓRÐRð %9Ñ$DÑ È$Ï+É+×JjÑJjð 	ð
 —z‘zØØ'Ø!5ð "ð 
ˆô
 �l¤E×*Ñ*Ü2°LÐAˆLð —	‘	˜,×8Ñ8Ó9ˆàˆØ×*Ñ*Ñ6Ø×'×'Ø#×7Ñ7×DÑDØØ$×(Ñ(¨¨d×.MÑ.MÐ)MÑNØ&×,Ñ,¨S°$×2QÑ2QÐ-QÑRð  Eð  �ð
 !Ñ,°ÀÒ1DÙ#Ø$Ø% c¨4×+JÑ+JÐ&JÑKó �Hô
  0°Ó9�Høð ×.Ñ.¨s°D×4SÑ4SÐ/SÑTÑTØ"×&Ñ& s¨D×,KÑ,KÐ'KÑLñMð ð !Ñ,°ÀÒ1DÙ# E¸¸d×>]Ñ>]Ð9]Ñ+^Ó_�Høà×'×'Ø#×7Ñ7×DÑDØ×/Ñ/°|×7IÑ7Ið  Eð  �ð !Ñ,°ÀÒ1DÙ# LÓ@�HÜ/°Ó9�Høà× 2Ñ 2Ñ2°\×5EÑ5EÑE�Ø Ñ,°ÀÒ1DÙ# EÓ9�Hà×*Ñ*Ñ6Ø×"Ñ" 3¨×(GÑ(GÐ#GÑHˆCØ ×&Ñ& s¨D×,KÑ,KÐ'KÑL‰Eà×"Ñ"ˆCØ ×&Ñ&ˆEä.ØØ$Ø*×<Ñ<Ø&×4Ñ4ØØñ
ð 	
r)   c                 ó4  • U R                   nU " USUSS9nU R                  R                  UR                  UR                  UR
                  S9n[        U5       Vs/ s H  oeR                  5       PM     nn[        R                  " USS9n[        US9$ s  snf )aX  
Generate sequences of sample predictions from a model with a probability distribution head.

Args:
    past_values (`torch.FloatTensor` of shape `(batch_size, sequence_length, num_input_channels)`):
        Past values of the time series that serves as context in order to predict the future.

    observed_mask (`torch.BoolTensor` of shape `(batch_size, sequence_length, num_input_channels)`, *optional*):
        Boolean mask to indicate which `past_values` were observed and which were missing. Mask values selected
        in `[0, 1]`:

        - 1 for values that are **observed**,
        - 0 for values that are **missing** (i.e. NaNs that were replaced by zeros).

Return:
    [`SamplePatchTSMixerPredictionOutput`] where the outputs `sequences` tensor will have shape `(batch_size,
    number of samples, prediction_length, num_input_channels)`.
NF)rF  r9  rô  r  r<  r   r   ©r  )r4  r#  r=  rÿ  r·  r¹  r	  ÚsamplerL   Ústackr  )r%   rF  rô  r4  Úoutputsr=  rì   Úsampless           r'   ÚgenerateÚ"PatchTSMixerForPrediction.generateb  s¢   € ð2  $×8Ñ8Ðñ Ø#ØØ'Ø!&ñ	
ˆð ×/Ñ/×<Ñ<Ø×&Ñ&¨G¯K©K¸w¿}¹}ð =ð 
ˆô
 38Ð8LÔ2MÓNÒ2M¨Q×&Ñ&Ö(Ñ2MˆÐNô —+’+˜g¨1Ñ-ˆÜ1¸GÑDÐDùò	 Os   ÁB)r#  r  rþ  rE  r4  r  )NNNTr+   )r0   r1   r2   r3   r4   r   r   r   r   rL   rM   rÝ   r  r.   rV  r  rF  r6   r7   r8   s   @r'   r+  r+  É  sé   ø† ñ	ðÐ1÷ ð< Øð .2Ø-1Ø,0Ø ñk
à—\‘\ðk
ð —|‘| dÑ*ðk
ð —|‘| dÑ*ð	k
ð
 # T™kðk
ð ðk
ð 
)ôk
ó ó ðk
ðZ ‡]‚]ƒ_ð .2ñ-Eà—\‘\ð-Eð —|‘| dÑ*ð-Eð 
,ô	-Eó ö-Er)   r+  zK
    Output type of [`PatchTSMixerForTimeSeriesClassificationOutput`].
    c                   óÀ   • \ rS rSr% SrSr\R                  S-  \S'   Sr	\R                  S-  \S'   Sr
\R                  S-  \S'   Sr\\R                     S-  \S'   Srg)	Ú-PatchTSMixerForTimeSeriesClassificationOutputi“  a,  
loss (*optional*, returned when `y` is provided, `torch.FloatTensor` of shape `()`):
    Total loss.
prediction_outputs (`torch.FloatTensor` of shape `(batch_size, num_labels)`):
    Prediction output from the classification head.
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_input_channels, num_patches, d_model)`):
    Backbone embeddings before passing through the head.
hidden_states (`tuple(torch.FloatTensor)`, *optional*):
    Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
Nrþ  rÿ  rÛ  rÊ   rP  r   rP  r)   r'   rI  rI  “  r  r)   rI  c                   ó¤   ^ • \ rS rSrSrS\4U 4S jjr\\   SS\	R                  S\	R                  S-  S\S-  S	\S
\4
S jj5       5       rSrU =r$ )Ú'PatchTSMixerForTimeSeriesClassificationi«  z‡
`PatchTSMixer` for classification application.

Args:
    config (`PatchTSMixerConfig`):
        Configuration.

Returns:
    `None`.
r<   c                 óö   >• [         TU ]  U5        [        U5      U l        [	        US9U l        UR                  S;   a$  [        UR                  UR                  S9U l
        OS U l
        U R                  5         g )Nrú   ©rj   ri   T©rA   rW   )r   r   rì  rE  r2  r  r®   ÚInjectScalerStatistics4DrA   rW   Úinject_scalerã  rD   s     €r'   r   Ú0PatchTSMixerForTimeSeriesClassification.__init__·  sh   ø€ Ü‰Ñ˜Ô ä& vÓ.ˆŒ
Ü*Øñ
ˆŒ	ð �>‰>Ð2Ó2Ü 8ÀÇÁÐ]c×]oÑ]oÑ pˆDÕà $ˆDÔð 	�‰Õr)   NrF  Útarget_valuesr  r  rY   c                 óì  • [         R                  R                  5       nUb  UOU R                  R                  nU R                  UUS9n[        U[        5      (       a  [        U6 nU R                  b4  U R                  UR                  UR                  UR                  S9Ul
        U R                  UR                  5      nUb  USL a	  U" X‚5      n	OSn	[        U	UUR                  UR                  S9$ )aH  
past_values (`torch.FloatTensor` of shape `(batch_size, seq_length, num_input_channels)`):
    Context values of the time series. For a pretraining task, this denotes the input time series to predict
    the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly,
    for classification or regression tasks, it denotes the appropriate context values of the time series.

    For univariate time series, `num_input_channels` dimension should be 1. For multivariate time series, it is
    greater than 1.
target_values (`torch.FloatTensor` of shape `(batch_size, target_len, num_input_channels)` for forecasting,
    `(batch_size, num_targets)` for regression, or `(batch_size,)` for classification, *optional*):
    Target
    values of the time series, that serve as labels for the model. The `target_values` is what the
    Transformer needs during training to learn to output, given the `past_values`. Note that, this is NOT
    required for a pretraining task.

    For a forecasting task, the shape is be `(batch_size, target_len, num_input_channels)`. Even if we want
    to forecast only specific channels by setting the indices in `prediction_channel_indices` parameter,
    pass the target data with all channels, as channel Filtering for both prediction and target will be
    manually applied before the loss computation.

    For a classification task, it has a shape of `(batch_size,)`.

    For a regression task, it has a shape of `(batch_size, num_targets)`.
return_loss (`bool`, *optional*):
    Whether to return the loss in the `forward` call.
Nræ  r<  Tr  )rL   r    ÚCrossEntropyLossr<   r  rE  r,  rÞ   rê  rP  rÛ  r·  r¹  r  rI  rÊ   )
r%   rF  rR  r  r  r¯   rþ  r  r>  r  s
             r'   r.   Ú/PatchTSMixerForTimeSeriesClassification.forwardÆ  sý   € ôJ �x‰x×(Ñ(Ó*ˆð %9Ñ$DÑ È$Ï+É+×JjÑJjð 	ð —z‘zØØ!5ð "ð 
ˆô �l¤E×*Ñ*Ü2°LÐAˆLà×ÑÑ(Ø-1×->Ñ->Ø×.Ñ.Ø ×$Ñ$Ø"×(Ñ(ð .?ð .ˆLÔ*ð —	‘	˜,×8Ñ8Ó9ˆàÑ$¨¸Ò)<Ù˜EÓ1‰HàˆHä<ØØ$Ø*×<Ñ<Ø&×4Ñ4ñ	
ð 	
r)   )r  rP  rE  r  )r0   r1   r2   r3   r4   r   r   r   r   rL   rM   rÝ   rI  r.   r6   r7   r8   s   @r'   rK  rK  «  s„   ø† ñ	ðÐ1÷ ð Øð .2Ø,0Ø ñC
à—\‘\ðC
ð —|‘| dÑ*ðC
ð # T™kð	C
ð
 ðC
ð 
7ôC
ó ó öC
r)   rK  z=
    Output type of [`PatchTSMixerForRegressionOutput`].
    c                   óÀ   • \ rS rSr% SrSr\R                  S-  \S'   Sr	\R                  S-  \S'   Sr
\R                  S-  \S'   Sr\\R                     S-  \S'   Srg)	ÚPatchTSMixerForRegressionOutputi  a)  
loss (*optional*, returned when `y` is provided, `torch.FloatTensor` of shape `()`):
    Total loss.
regression_outputs (`torch.FloatTensor` of shape `(batch_size, num_targets)`):
    Prediction output from the regression head.
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_input_channels, num_patches, d_model)`):
    Backbone embeddings before passing through the head.
hidden_states (`tuple(torch.FloatTensor)`, *optional*):
    Hidden-states of the model at the output of each layer plus the optional initial embedding outputs.
Nrþ  Úregression_outputsrÛ  rÊ   rP  )r0   r1   r2   r3   r4   rþ  rL   rÜ  rQ  rX  rÛ  rÊ   rÞ   r6   rP  r)   r'   rW  rW    r  r)   rW  c                   óŽ   ^ • \ rS rSrSS\S\S\4U 4S jjjrS\R                  S\R                  S\R                  4S	 jrS
r	U =r
$ )rO  i&  rA   rW   Ú	expansionc                 ó(  >• [         TU ]  5         [        R                  " US-   X1-  5      U l        [        R                  " X1-  U5      U l        [        R                  " SSU-  5      U l        [        R                  " SU-  S5      U l        X l        g r{  )	r   r   r    r!   Úinverse_trans_expansionÚinverse_trans_compressionÚmap_scale_expansionÚmap_scale_compressionrW   )r%   rA   rW   rZ  r&   s       €r'   r   Ú!InjectScalerStatistics4D.__init__'  sr   ø€ Ü‰ÑÔä')§y¢y°¸1±¸iÑ>QÓ'RˆÔ$Ü)+¯ª°9Ñ3FÈÓ)PˆÔ&Ü#%§9¢9¨Q°°I±Ó#>ˆÔ Ü%'§Y¢Y¨q°9©}¸aÓ%@ˆÔ"Ø&Õr)   r,   r·  r¹  c                 óê  • UR                  SS5      nUR                  S5      nUR                  SSU R                  S5      nUR                  SS5      nUR                  S5      nUR                  SSU R                  S5      n[        R
                  " XE/SS9nU R                  U5      nU R                  U5      n[        R
                  " X/SS9nU R                  U5      nU R                  U5      nU$ )aQ  
Args:
    inputs (`torch.Tensor` of shape `(batch_size, num_input_channels, num_patch, d_model)`)
    loc (`torch.Tensor` of shape `(batch_size, 1, num_input_channels)`)
    scale (`torch.Tensor` of shape `(batch_size, 1, num_input_channels)`)
Returns:
    `torch.Tensor` of shape `(batch_size, num_input_channels, num_patch, d_model)`
r   r  r   r   )
rH   rc   ri  rW   rL   Úcatr^  r_  r\  r]  )r%   r,   r·  r¹  ri   ÚstdevÚconcat_statss          r'   r.   Ú InjectScalerStatistics4D.forward0  sÞ   € ð �}‰}˜R Ó$ˆØ�~‰~˜bÓ!ˆØ�{‰{˜1˜a ×!1Ñ!1°1Ó5ˆà—‘  BÓ'ˆØ—‘ Ó#ˆØ—‘˜Q  4×#3Ñ#3°QÓ7ˆä—y’y $ °BÑ7ˆà×/Ñ/°Ó=ˆØ×1Ñ1°,Ó?ˆä—’˜FÐ1°rÑ:ˆØ×-Ñ-¨fÓ5ˆØ×/Ñ/°Ó7ˆàˆr)   )r]  r\  r_  r^  rW   )rG   )r0   r1   r2   r3   r5   r   rL   rM   r.   r6   r7   r8   s   @r'   rO  rO  &  sM   ø† ñ' ð '°#ð 'À#÷ 'ð 'ð˜eŸl™lð °·±ð ÀeÇlÁl÷ ò r)   rO  z4
    `PatchTSMixer` for regression application.
    c                   óî   ^ • \ rS rSrS\4U 4S jjr\\   SS\R                  S\R                  S-  S\
S-  S\
S	\4
S
 jj5       5       r\R                  " 5       S\R                  S	\4S j5       rSrU =r$ )ÚPatchTSMixerForRegressioniN  r<   c                 ó^  >• [         TU ]  U5        [        U5      U l        UR                  U l        UR
                  U l        UR                  U l        UR                  S:X  a  S U l        O^[        [        [        S.nUR                  UR
                  5      nUb  U" UR                  S9U l        O[        SUR
                   35      eUR                  S;   a$  [        UR                  UR                   S9U l        OS U l        [%        UU R
                  S9U l        U R)                  5         g )Nr-  r.  r   r2  rM  rN  r3  )r   r   rì  rE  rþ  r#  r4  r   r   r   r5  r7  rk   r®   rO  rA   rW   rP  r2  r  rã  )r%   r<   r6  r7  r&   s       €r'   r   Ú"PatchTSMixerForRegression.__init__T  s  ø€ Ü‰Ñ˜Ô ä& vÓ.ˆŒ
à—K‘KˆŒ	Ø#)×#=Ñ#=ˆÔ à$*×$?Ñ$?ˆÔ!à�;‰;˜%ÓØ'+ˆDÕ$ô ,Ü&Ü%;ñ'Ð#ð
 3×6Ñ6°v×7QÑ7QÓRˆLØÑ'Ù+7¸F×<NÑ<NÑ+O�Õ(ä Ð#?À×@ZÑ@ZÐ?[Ð!\Ó]Ð]à�>‰>Ð2Ó2Ü 8ÀÇÁÐ]c×]oÑ]oÑ pˆDÕà $ˆDÔä*ØØ $× 8Ñ 8ñ
ˆŒ	ð 	�‰Õr)   NrF  rR  r  r  rY   c                 ó\  ^ • T R                   S:X  a  [        R                  " SS9nO"T R                   S:X  a  [        nO[	        S5      eUb  UOT R
                  R                  nT R                  UUS9n[        U[        5      (       a  [        U6 nT R                  b4  T R                  UR                  UR                  UR                  S9Ul        T R                  UR                  5      nUbœ  US	L a—  T R                   (       a}  T R                   S
:X  a)  ["        R$                  " US:  5      (       a  ['        S5      eT R                   R)                  U5      n	[        U 4S jU 5       5      nU" X’5      n
[+        U
5      n
OU" X‚5      n
OSn
[-        U
UUR                  UR.                  S9$ )aD  
past_values (`torch.FloatTensor` of shape `(batch_size, seq_length, num_input_channels)`):
    Context values of the time series. For a pretraining task, this denotes the input time series to predict
    the masked portion. For a forecasting task, this denotes the history/past time series values. Similarly,
    for classification or regression tasks, it denotes the appropriate context values of the time series.

    For univariate time series, `num_input_channels` dimension should be 1. For multivariate time series, it is
    greater than 1.
target_values (`torch.FloatTensor` of shape `(batch_size, target_len, num_input_channels)` for forecasting,
    `(batch_size, num_targets)` for regression, or `(batch_size,)` for classification, *optional*):
    Target values of the time series, that serve as labels for the model. The `target_values` is what the
    Transformer needs during training to learn to output, given the `past_values`. Note that, this is NOT
    required for a pretraining task.

    For a forecasting task, the shape is be `(batch_size, target_len, num_input_channels)`. Even if we want
    to forecast only specific channels by setting the indices in `prediction_channel_indices` parameter,
    pass the target data with all channels, as channel Filtering for both prediction and target will be
    manually applied before the loss computation.

    For a classification task, it has a shape of `(batch_size,)`.

    For a regression task, it has a shape of `(batch_size, num_targets)`.
return_loss (`bool`, *optional*):
    Whether to return the loss in the `forward` call.
r-  ri   r  r#  r;  Nræ  r<  Tr1  r   zDtarget_values cannot be negative for negative_binomial distribution.c              3   ón   >#   • U  H*  oR                  S TR                  R                  5      v •  M,     g7f)r   N)rÏ   r<   r7  )r'  Úitemr%   s     €r'   r)  Ú4PatchTSMixerForRegression.forward.<locals>.<genexpr>½  s)   øé € ÐWÒQVÈŸi™i¨¨D¯K©K×,CÑ,C×DÐDÒQVùs   ƒ25)rþ  rX  rÛ  rÊ   )rþ  r    r  r#  rk   r<   r  rE  r,  rÞ   rê  rP  rÛ  r·  r¹  r  r#  rL   ÚanyÚ	Exceptionr=  r)  rW  rÊ   )r%   rF  rR  r  r  r¯   rþ  r  r>  r=  r  s   `          r'   r.   Ú!PatchTSMixerForRegression.forwardy  s—  ø€ ðH �9‰9˜ÓÜ—:’:¨Ñ/‰DØ�Y‰Y˜%ÓÜ‰DäÐQÓRÐRð %9Ñ$DÑ È$Ï+É+×JjÑJjð 	ð —z‘zØØ!5ð "ð 
ˆô �l¤E×*Ñ*Ü2°LÐAˆLà×ÑÑ(Ø-1×->Ñ->Ø×.Ñ.Ø ×$Ñ$Ø"×(Ñ(ð .?ð .ˆLÔ*ð —	‘	˜,×8Ñ8Ó9ˆàÑ$¨¸Ò)<Ø×'×'Ø×+Ñ+Ð/BÓBÄuÇyÂyÐQ^ÐabÑQb×GcÑGcÜ#Ð$jÓkÐkØ#×7Ñ7×DÑDÀUÓK�äÔWÑQVÓWÓW�Ù Ó<�ä+¨HÓ5‘á Ó5‘àˆHä.ØØ$Ø*×<Ñ<Ø&×4Ñ4ñ	
ð 	
r)   c                 óR  • U R                   nU " USSS9nU R                  R                  UR                  5      n[	        U5       Vs/ s H  oTR                  5       PM     nn[        R                  " USS9R                  SX R                  R                  5      n[        US9$ s  snf )aÊ  
Generate sequences of sample predictions from a model with a probability distribution head.

Args:
    past_values (`torch.FloatTensor` of shape `(batch_size, sequence_length, num_input_channels)`):
        Past values of the time series that serves as context in order to predict the target values.

Return:
    [`SamplePatchTSMixerRegressionOutput`] where the outputs `sequences` tensor will have shape `(batch_size,
    number of samples, num_targets)`.
NF)rF  rR  r  r   r   r   rA  )r4  r#  r=  rX  r	  rB  rL   rC  rÏ   r<   r7  r  )r%   rF  r4  rD  r=  rì   rE  s          r'   rF  Ú"PatchTSMixerForRegression.generateÍ  s©   € ð"  $×8Ñ8Ðñ Ø#ØØ!&ñ
ˆð ×/Ñ/×<Ñ<¸W×=WÑ=WÓXˆô ,1Ð1EÔ+Fó
Ú+F a×ÑÖ!Ñ+Fð 	ð 
ô
 —+’+˜g¨1Ñ-×2Ñ2°2Ð7KÏ[É[×MdÑMdÓeˆÜ1¸GÑDÐDùò
s   ÁB$)r#  r  rP  rþ  rE  r4  r  )r0   r1   r2   r3   r   r   r   r   rL   rM   rÝ   rW  r.   rV  r  rF  r6   r7   r8   s   @r'   rg  rg  N  sµ   ø† ð#Ð1÷ #ðJ Øð .2Ø,0Ø ñP
à—\‘\ðP
ð —|‘| dÑ*ðP
ð # T™kð	P
ð
 ðP
ð 
)ôP
ó ó ðP
ðd ‡]‚]ƒ_ð#Eà—\‘\ð#Eð 
,ó#Eó ö#Er)   rg  )rD  rì  r  r+  rK  rg  )NrÎ   )NFr   )Nr   rû  )Ur4   re   Úcollections.abcr   Údataclassesr   rL   Útorch.nnr    Útransformers.modeling_utilsr   Útransformers.utilsr   Ú r   rJ  Úmodeling_flash_attention_utilsr	   Úmodeling_utilsr
   Úprocessing_utilsr   Útime_series_utilsr   r   r   Úutilsr   r   r   r   Úconfiguration_patchtsmixerr   Ú
get_loggerr0   ÚloggerÚModuler   r:   rO   rv   r…   r˜   rM   rÜ   rº   r¼   rà   rð   rø   r  r  r2  rD  rX  ÚlistrÝ   r5   rw  r�  r�  r�  r§  r½  rÒ  rÚ  rÞ  rê  rì  rý  r  r  r  r  ÚdistributionsÚDistributionr#  r)  r+  rI  rK  rW  rO  rg  Ú__all__rP  r)   r'   Ú<module>r†     sQ  ðñ "ã Ý $Ý !ã Ý å 7Ý *å &Ý BÝ 5Ý &ß UÑ Uß RÓ RÝ :ð 
×	Ò	˜HÓ	%€ô §¡ô ô*&˜BŸI™Iô &ô,$ R§Y¡Yô $ôN.˜BŸI™Iô .ôb�b—i‘iô ô.-¨2¯9©9ô -ðn !Øñ%Ø�I‰Ið%à�<‰<ð%ð 
�‰ð%ð �<‰<ð	%ð
 —L‘L 4Ñ'ð%ð �T‰\ð%ð ð%ð Ð'Ñ(õ%ô:R)˜BŸI™Iô R)ôjC�b—i‘iô CôL*˜Ÿ	™	ô *ôZ#˜Ÿ	™	ô #ôL&#˜Ÿ	™	ô &#ôR5 B§I¡Iô 5ôpD˜RŸY™Yô DðN ô0 /ó 0ó ð0ô*˜rŸy™yô ðD -1Ø',Øñ7%Ø�L‰Lð7%àð7%ð # T™kð7%ð !%ð	7%ð
 õ7%ð| -1Øñ	A%Ø�L‰LðA%à# c™zðA%ð # T™kðA%ð õ	A%ôJ-˜2Ÿ9™9ô -ôb9"˜"Ÿ)™)ô 9"ôz 0˜BŸI™Iô  0ôH3;˜RŸY™Yô 3;ôn ˜BŸI™Iô  ñ6 ðñð
 ô	: ó 	:ó óð	:ô9kÐ5ô 9kñx ðñð
 ô+˜kó +ó óð+ñ4 ðñô
Q
Ð3ó Q
óð
Q
ñh ðñð
 ô: {ó :ó óð:ñ$ ðñô
F
Ð!<ó F
óð
F
ñR ðñð
 ô+ kó +ó óð+ñ0 ðñð ô/¨ó /ó óð/ñ ðñð ô/¨ó /ó óð/ð#ˆu×"Ñ"×/Ñ/ð #¸¿¹ð #È%Ï,É,ô #ñ* 5§<¡<ð *¸%¿,¹,ÈÑ:Mð *Ðch×coÑcoõ *ô0GEÐ ;ô GEñT ðñð
 ô:°Kó :ó óð:ô$`
Ð.Iô `
ñF ðñð
 ô: kó :ó óð:ô$%˜rŸy™yô %ñP ðñô
^EÐ ;ó ^Eóð
^EòB�r)   