Ë
    S^(hÄN ã                   ó¼  — d dl Z d dlmZmZ d dlmZmZmZmZm	Z	 d dl
Z
d dlmZ d dlmc mZ ddlmZ ddlmZmZ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! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3m4Z4  e,«       rd dl5m6Z6 ddl7m8Z8  e-jr                  e:«      Z;dZ< G d„ dejz                  «      Z> G d„ dejz                  «      Z?d„ Z@dcd„ZAde
j„                  deCde
j„                  fd„ZD	 dddejz                  d e
j„                  d!e
j„                  d"e
j„                  d#ee
j„                     d$eEd%eEfd&„ZF G d'„ d(ejz                  «      ZG G d)„ d*ejz                  «      ZH G d+„ d,ejz                  «      ZI G d-„ d.ejz                  «      ZJ G d/„ d0ejz                  «      ZK G d1„ d2ejz                  «      ZL G d3„ d4ejz                  «      ZM G d5„ d6ejz                  «      ZN G d7„ d8ejz                  «      ZO G d9„ d:ejz                  «      ZP G d;„ d<ejz                  «      ZQ G d=„ d>ejz                  «      ZR G d?„ d@ej¦                  «      ZT G dA„ dBejz                  «      ZU G dC„ dDejz                  «      ZV G dE„ dFejz                  «      ZW G dG„ dHejz                  «      ZX G dI„ dJejz                  «      ZYdKZZ e)dLeZ«       G dM„ dNe$«      «       Z[ G dO„ dP«      Z\dQZ] e)dRe]«       G dS„ dTe$«      «       Z^ G dU„ dVejz                  «      Z_dWZ` e)dXe]«       G dY„ dZe^«      «       Za G d[„ d\ee(«      Zb G d]„ d^e^e«      Zcd_Zd G d`„ dae^e«      Zeg db¢Zfy)eé    N)Úcached_propertyÚpartial)ÚCallableÚListÚOptionalÚTupleÚUnioné   )ÚACT2FN)ÚCacheÚDynamicCacheÚStaticCache)ÚGenerationMixin)ÚAttentionMaskConverter)ÚFlashAttentionKwargs)ÚBaseModelOutputWithPastÚCausalLMOutputWithPast)ÚROPE_INIT_FUNCTIONSÚdynamic_rope_update)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)Ú
LossKwargsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚcan_return_tupleÚis_torch_flex_attn_availableÚloggingÚreplace_return_docstrings)Údeprecate_kwargé   )Ú
Emu3ConfigÚEmu3TextConfigÚEmu3VQVAEConfig)Ú	BlockMask)Úmake_flex_block_causal_maskr"   c                   ó,   ‡ — e Zd Zdˆ fd„	Zd„ Zd„ Zˆ xZS )ÚEmu3RMSNormc                 óŠ   •— t         ‰| �  «        t        j                  t	        j
                  |«      «      | _        || _        y)z:
        Emu3RMSNorm is equivalent to T5LayerNorm
        N)ÚsuperÚ__init__ÚnnÚ	ParameterÚtorchÚonesÚweightÚvariance_epsilon)ÚselfÚhidden_sizeÚepsÚ	__class__s      €úd/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/emu3/modeling_emu3.pyr+   zEmu3RMSNorm.__init__B   s1   ø€ ô 	‰ÑÔÜ—l‘l¤5§:¡:¨kÓ#:Ó;ˆŒØ #ˆÕó    c                 ó"  — |j                   }|j                  t        j                  «      }|j	                  d«      j                  dd¬«      }|t        j                  || j                  z   «      z  }| j                  |j                  |«      z  S )Né   éÿÿÿÿT)Úkeepdim)	ÚdtypeÚtor.   Úfloat32ÚpowÚmeanÚrsqrtr1   r0   )r2   Úhidden_statesÚinput_dtypeÚvariances       r6   ÚforwardzEmu3RMSNorm.forwardJ   sy   € Ø#×)Ñ)ˆØ%×(Ñ(¬¯©Ó7ˆØ ×$Ñ$ QÓ'×,Ñ,¨R¸Ð,Ó>ˆØ%¬¯©°H¸t×?TÑ?TÑ4TÓ(UÑUˆØ�{‰{˜]×-Ñ-¨kÓ:Ñ:Ð:r7   c                 ó^   — t        | j                  j                  «      › d| j                  › �S )Nz, eps=)Útupler0   Úshaper1   ©r2   s    r6   Ú
extra_reprzEmu3RMSNorm.extra_reprQ   s*   € Ü˜Ÿ™×)Ñ)Ó*Ð+¨6°$×2GÑ2GÐ1HÐIÐIr7   )ç�íµ ÷Æ°>)Ú__name__Ú
__module__Ú__qualname__r+   rE   rJ   Ú__classcell__©r5   s   @r6   r(   r(   A   s   ø„ õ$ò;öJr7   r(   c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚEmu3MLPc                 ó  •— t         ‰| �  «        || _        |j                  | _        |j                  | _        t        j                  | j                  | j                  |j                  ¬«      | _        t        j                  | j                  | j                  |j                  ¬«      | _	        t        j                  | j                  | j                  |j                  ¬«      | _
        t        |j                     | _        y )N©Úbias)r*   r+   Úconfigr3   Úintermediate_sizer,   ÚLinearÚmlp_biasÚ	gate_projÚup_projÚ	down_projr   Ú
hidden_actÚact_fn©r2   rV   r5   s     €r6   r+   zEmu3MLP.__init__V   s¸   ø€ Ü‰ÑÔØˆŒØ!×-Ñ-ˆÔØ!'×!9Ñ!9ˆÔÜŸ™ 4×#3Ñ#3°T×5KÑ5KÐRX×RaÑRaÔbˆŒÜ—y‘y ×!1Ñ!1°4×3IÑ3IÐPV×P_ÑP_Ô`ˆŒÜŸ™ 4×#9Ñ#9¸4×;KÑ;KÐRX×RaÑRaÔbˆŒÜ˜V×.Ñ.Ñ/ˆ�r7   c                 óˆ   — | j                  | j                  | j                  |«      «      | j                  |«      z  «      }|S ©N)r\   r^   rZ   r[   )r2   Úxr\   s      r6   rE   zEmu3MLP.forward`   s6   € Ø—N‘N 4§;¡;¨t¯~©~¸aÓ/@Ó#AÀDÇLÁLÐQRÃOÑ#SÓTˆ	ØÐr7   ©rL   rM   rN   r+   rE   rO   rP   s   @r6   rR   rR   U   s   ø„ ô0ör7   rR   c                 óš   — | dd| j                   d   dz  …f   }| d| j                   d   dz  d…f   }t        j                  | |fd¬«      S )z*Rotates half the hidden dims of the input..Nr:   r9   ©Údim)rH   r.   Úcat)rb   Úx1Úx2s      r6   Úrotate_halfrj   e   sZ   € à	
ˆ3Ð"�!—'‘'˜"‘+ Ñ"Ð"Ð"Ñ	#€BØ	
ˆ3�—‘˜‘˜qÑ Ñ"Ð"Ñ	#€BÜ�9‰9�r�c˜2�Y BÔ'Ð'r7   c                 óž   — |j                  |«      }|j                  |«      }| |z  t        | «      |z  z   }||z  t        |«      |z  z   }||fS )aÛ  Applies Rotary Position Embedding to the query and key tensors.

    Args:
        q (`torch.Tensor`): The query tensor.
        k (`torch.Tensor`): The key tensor.
        cos (`torch.Tensor`): The cosine part of the rotary embedding.
        sin (`torch.Tensor`): The sine part of the rotary embedding.
        position_ids (`torch.Tensor`, *optional*):
            Deprecated and unused.
        unsqueeze_dim (`int`, *optional*, defaults to 1):
            The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
            sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
            that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
            k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
            cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
            the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
    Returns:
        `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
    )Ú	unsqueezerj   )ÚqÚkÚcosÚsinÚposition_idsÚunsqueeze_dimÚq_embedÚk_embeds           r6   Úapply_rotary_pos_embru   l   sY   € ð( �-‰-˜Ó
&€CØ
�-‰-˜Ó
&€CØ�3‰wœ; q›>¨CÑ/Ñ0€GØ�3‰wœ; q›>¨CÑ/Ñ0€GØ�GÐÐr7   rB   Ún_repÚreturnc                 óª   — | j                   \  }}}}|dk(  r| S | dd…dd…ddd…dd…f   j                  |||||«      } | j                  |||z  ||«      S )zÔ
    This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
    num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
    r!   N)rH   ÚexpandÚreshape)rB   rv   ÚbatchÚnum_key_value_headsÚslenÚhead_dims         r6   Ú	repeat_kvr   ‡   so   € ð
 2?×1DÑ1DÑ.€EÐ  hØ�‚zØÐØ!¢!¢Q¨ªa²Ð"2Ñ3×:Ñ:¸5ÐBUÐW\Ð^bÐdlÓm€MØ× Ñ  Ð(;¸eÑ(CÀTÈ8ÓTÐTr7   ÚmoduleÚqueryÚkeyÚvalueÚattention_maskÚscalingÚdropoutc                 óT  — t        || j                  «      }t        || j                  «      }	t        j                  ||j	                  dd«      «      |z  }
|�#|d d …d d …d d …d |j
                  d   …f   }|
|z   }
t        j                  j                  |
dt        j                  ¬«      j                  |j                  «      }
t        j                  j                  |
|| j                  ¬«      }
t        j                  |
|	«      }|j	                  dd«      j                  «       }||
fS )Nr9   r
   éþÿÿÿr:   )rf   r<   )ÚpÚtrainingr!   )r   Únum_key_value_groupsr.   ÚmatmulÚ	transposerH   r,   Ú
functionalÚsoftmaxr>   r=   r<   r†   rŠ   Ú
contiguous)r€   r�   r‚   rƒ   r„   r…   r†   ÚkwargsÚ
key_statesÚvalue_statesÚattn_weightsÚcausal_maskÚattn_outputs                r6   Úeager_attention_forwardr—   “   s  € ô ˜3 × ;Ñ ;Ó<€JÜ˜U F×$?Ñ$?Ó@€Lä—<‘<  z×';Ñ';¸A¸qÓ'AÓBÀWÑL€LØÐ!Ø$¢Qªª1Ð.D°
×0@Ñ0@ÀÑ0DÐ.DÐ%DÑEˆØ# kÑ1ˆä—=‘=×(Ñ(¨¸2ÄUÇ]Á]Ð(ÓS×VÑVÐW\×WbÑWbÓc€LÜ—=‘=×(Ñ(¨¸È6Ï?É?Ð(Ó[€LÜ—,‘,˜|¨\Ó:€KØ×'Ñ'¨¨1Ó-×8Ñ8Ó:€Kà˜Ð$Ð$r7   c                   ó6  ‡ — e Zd ZdZdedefˆ fd„Z	 	 ddej                  de	ej                  ej                  f   de
ej                     de
e   d	e
ej                     d
ee   de	ej                  e
ej                     e
e	ej                        f   fd„Zˆ xZS )ÚEmu3Attentionú=Multi-headed attention from 'Attention Is All You Need' paperrV   Ú	layer_idxc                 ód  •— t         ‰| �  «        || _        || _        t	        |d|j
                  |j                  z  «      | _        |j                  |j                  z  | _	        | j                  dz  | _
        |j                  | _        d| _        t        j                  |j
                  |j                  | j                  z  |j                  ¬«      | _        t        j                  |j
                  |j                  | j                  z  |j                  ¬«      | _        t        j                  |j
                  |j                  | j                  z  |j                  ¬«      | _        t        j                  |j                  | j                  z  |j
                  |j                  ¬«      | _        y )Nr~   ç      à¿TrT   )r*   r+   rV   r›   Úgetattrr3   Únum_attention_headsr~   r|   r‹   r…   Úattention_dropoutÚ	is_causalr,   rX   Úattention_biasÚq_projÚk_projÚv_projÚo_proj©r2   rV   r›   r5   s      €r6   r+   zEmu3Attention.__init__°   sM  ø€ Ü‰ÑÔØˆŒØ"ˆŒÜ ¨
°F×4FÑ4FÈ&×JdÑJdÑ4dÓeˆŒØ$*×$>Ñ$>À&×B\ÑB\Ñ$\ˆÔ!Ø—}‘} dÑ*ˆŒØ!'×!9Ñ!9ˆÔØˆŒä—i‘iØ×Ñ × :Ñ :¸T¿]¹]Ñ JÐQW×QfÑQfô
ˆŒô —i‘iØ×Ñ × :Ñ :¸T¿]¹]Ñ JÐQW×QfÑQfô
ˆŒô —i‘iØ×Ñ × :Ñ :¸T¿]¹]Ñ JÐQW×QfÑQfô
ˆŒô —i‘iØ×&Ñ&¨¯©Ñ6¸×8JÑ8JÐQW×QfÑQfô
ˆ�r7   rB   Úposition_embeddingsr„   Úpast_key_valueÚcache_positionr‘   rw   c                 ó¶  — |j                   d d }g |¢d‘| j                  ‘­}| j                  |«      j                  |«      j	                  dd«      }	| j                  |«      j                  |«      j	                  dd«      }
| j                  |«      j                  |«      j	                  dd«      }|\  }}t        |	|
||«      \  }	}
|�'|||dœ}|j                  |
|| j                  |«      \  }
}t        }| j                  j                  dk7  r^| j                  j                  dk(  r(|j                  dd«      rt        j                  d	«       nt         | j                  j                     } || |	|
||f| j"                  sd
n| j$                  | j&                  dœ|¤Ž\  }} |j(                  g |¢d‘­Ž j+                  «       }| j-                  |«      }||fS )Nr:   r!   r9   )rp   ro   rª   ÚeagerÚsdpaÚoutput_attentionsFúã`torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to eager attention. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.ç        )r†   r…   )rH   r~   r£   Úviewr�   r¤   r¥   ru   Úupdater›   r—   rV   Ú_attn_implementationÚgetÚloggerÚwarning_oncer   rŠ   r    r…   rz   r�   r¦   )r2   rB   r¨   r„   r©   rª   r‘   Úinput_shapeÚhidden_shapeÚquery_statesr’   r“   ro   rp   Úcache_kwargsÚattention_interfacer–   r”   s                     r6   rE   zEmu3Attention.forwardÇ   sá  € ð $×)Ñ)¨#¨2Ð.ˆØ8˜Ð8 bÐ8¨$¯-©-Ñ8ˆà—{‘{ =Ó1×6Ñ6°|ÓD×NÑNÈqÐRSÓTˆØ—[‘[ Ó/×4Ñ4°\ÓB×LÑLÈQÐPQÓRˆ
Ø—{‘{ =Ó1×6Ñ6°|ÓD×NÑNÈqÐRSÓTˆà&‰ˆˆSÜ#7¸ÀjÐRUÐWZÓ#[Ñ ˆ�jàÐ%à#&¨sÀnÑUˆLØ'5×'<Ñ'<¸ZÈÐW[×WeÑWeÐgsÓ'tÑ$ˆJ˜ä(?ÐØ�;‰;×+Ñ+¨wÒ6Ø�{‰{×/Ñ/°6Ò9¸f¿j¹jÐI\Ð^cÔ>dÜ×#Ñ#ðLõô
 '>¸d¿k¹k×>^Ñ>^Ñ&_Ð#á$7ØØØØØð	%
ð  $Ÿ}š}‘C°$×2HÑ2HØ—L‘Lñ	%
ð ñ	%
Ñ!ˆ�\ð *�k×)Ñ)Ð;¨;Ð;¸Ò;×FÑFÓHˆØ—k‘k +Ó.ˆØ˜LÐ(Ð(r7   ©NN)rL   rM   rN   Ú__doc__r"   Úintr+   r.   ÚTensorr   r   r   Ú
LongTensorr   r   rE   rO   rP   s   @r6   r™   r™   ­   sÅ   ø„ ÙGð
˜zð 
°cõ 
ð8 +/Ø59ñ/)à—|‘|ð/)ð # 5§<¡<°·±Ð#=Ñ>ð/)ð ! §¡Ñ.ð	/)ð
 ! ™ð/)ð ! ×!1Ñ!1Ñ2ð/)ð Ð-Ñ.ð/)ð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷/)r7   r™   c                   óf  ‡ — e Zd Zdedefˆ fd„Z	 	 	 	 	 	 	 ddej                  deej                     deej                     dee
   dee   d	ee   d
eej                     deeej                  ej                  f      deej                  eeej                  ej                  f      f   fd„Zˆ xZS )ÚEmu3DecoderLayerrV   r›   c                 óh  •— t         ‰| �  «        |j                  | _        t        ||¬«      | _        t        |«      | _        t        |j                  |j                  ¬«      | _	        t        |j                  |j                  ¬«      | _
        t        j                  |j                  «      | _        y )N)rV   r›   ©r4   )r*   r+   r3   r™   Ú	self_attnrR   Úmlpr(   Úrms_norm_epsÚinput_layernormÚpost_attention_layernormr,   ÚDropoutr    r†   r§   s      €r6   r+   zEmu3DecoderLayer.__init__ú   s�   ø€ Ü‰ÑÔØ!×-Ñ-ˆÔä&¨fÀ	ÔJˆŒä˜6“?ˆŒÜ*¨6×+=Ñ+=À6×CVÑCVÔWˆÔÜ(3°F×4FÑ4FÈF×L_ÑL_Ô(`ˆÔ%Ü—z‘z &×":Ñ":Ó;ˆ�r7   rB   r„   rq   r©   r®   Ú	use_cacherª   r¨   rw   c	                 ó  — |}
| j                  |«      } | j                  d||||||||dœ|	¤Ž\  }}|
| j                  |«      z   }|}
| j                  |«      }| j	                  |«      }|
| j                  |«      z   }|f}|r||fz  }|S )a  
        Args:
            hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
            attention_mask (`torch.FloatTensor`, *optional*):
                attention mask of size `(batch_size, sequence_length)` if flash attention is used or `(batch_size, 1,
                query_sequence_length, key_sequence_length)` if default attention is used.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            use_cache (`bool`, *optional*):
                If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
                (see `past_key_values`).
            past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
            cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
                Indices depicting the position of the input sequence tokens in the sequence
            kwargs (`dict`, *optional*):
                Arbitrary kwargs to be ignored, used for FSDP and other methods that injects code
                into the model
        )rB   r„   rq   r©   r®   rË   rª   r¨   © )rÈ   rÅ   r†   rÉ   rÆ   )r2   rB   r„   rq   r©   r®   rË   rª   r¨   r‘   ÚresidualÚself_attn_weightsÚoutputss                r6   rE   zEmu3DecoderLayer.forward  sÃ   € ð> !ˆà×,Ñ,¨]Ó;ˆð ,:¨4¯>©>ð 
,
Ø'Ø)Ø%Ø)Ø/ØØ)Ø 3ñ
,
ð ñ
,
Ñ(ˆÐ(ð ! 4§<¡<°Ó#>Ñ>ˆð !ˆØ×5Ñ5°mÓDˆØŸ™ Ó/ˆØ  4§<¡<°Ó#>Ñ>ˆà Ð"ˆáØÐ)Ð+Ñ+ˆGàˆr7   )NNNFFNN)rL   rM   rN   r"   r¾   r+   r.   r¿   r   rÀ   r   Úboolr   ÚFloatTensorrE   rO   rP   s   @r6   rÂ   rÂ   ù   sû   ø„ ð	<˜zð 	<°cõ 	<ð 26Ø37Ø*.Ø,1Ø$)Ø59ØKOñ<à—|‘|ð<ð ! §¡Ñ.ð<ð ˜u×/Ñ/Ñ0ð	<ð
 ! ™ð<ð $ D™>ð<ð ˜D‘>ð<ð ! ×!1Ñ!1Ñ2ð<ð & e¨E¯L©L¸%¿,¹,Ð,FÑ&GÑHð<ð 
ˆu× Ñ  (¨5°×1BÑ1BÀE×DUÑDUÐ1UÑ+VÑ"WÐWÑ	X÷<r7   rÂ   c                   óH   ‡ — e Zd ZdZdefˆ fd„Zdej                  fd„Zˆ xZ	S )ÚEmu3VQVAEVectorQuantizeraâ  
    A module for vector quantization using learned embedding vectors.

    This module implements the quantization process similar to te one described in
    the VQ-VAE (Vector Quantized Variational AutoEncoder) paper. It quantizes continuous
    input vectors into discrete codebook vectors, which are learned during training.
    Current implementation improves over previous ones by avoiding costly matrix multiplications
    and allowing for post-hoc remapping of indices.
    rV   c                 ó  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        | j                  j                  j                  j                  d|j                  z  d|j                  z  «       y )Ng      ð¿g      ð?)
r*   r+   r,   Ú	EmbeddingÚcodebook_sizeÚ	embed_dimÚ	embeddingr0   ÚdataÚuniform_r_   s     €r6   r+   z!Emu3VQVAEVectorQuantizer.__init__O  sb   ø€ Ü‰ÑÔÜŸ™ f×&:Ñ&:¸F×<LÑ<LÓMˆŒØ�‰×Ñ×"Ñ"×+Ñ+¨D°6×3GÑ3GÑ,GÈÈv×OcÑOcÑIcÕdr7   Úhidden_statec                 ó  — |j                   \  }}}}}|j                  ddddd«      j                  «       }|j                  d|«      }t	        j
                  |dz  dd¬«      }t	        j
                  | j                  j                  dz  d¬	«      }	dt	        j                  || j                  j                  j                  dd«      «      z  }
||	z   |
z
  }
t	        j                  |
d¬	«      }|j                  ||||«      }|S )
Nr   r!   r
   é   r9   r:   T)rf   r;   re   )rH   Úpermuter�   r±   r.   ÚsumrÙ   r0   rŒ   r�   Úargmin)r2   rÜ   Ú
batch_sizeÚtemporalÚchannelsÚheightÚwidthÚhidden_state_flattenedÚhidden_state_sumÚembedding_sumÚ	distancesÚmin_encoding_indicess               r6   rE   z Emu3VQVAEVectorQuantizer.forwardT  sõ   € Ø8D×8JÑ8JÑ5ˆ
�H˜h¨°Ø#×+Ñ+¨A¨q°!°Q¸Ó:×EÑEÓGˆØ!-×!2Ñ!2°2°xÓ!@Ðô !Ÿ9™9Ð%;¸QÑ%>ÀAÈtÔTÐÜŸ	™	 $§.¡.×"7Ñ"7¸Ñ":ÀÔBˆð œŸ™Ð%;¸T¿^¹^×=RÑ=R×=\Ñ=\Ð]^Ð`aÓ=bÓcÑcˆ	Ø$ }Ñ4°yÑ@ˆ	ä$Ÿ|™|¨I¸1Ô=ÐØ3×8Ñ8¸ÀXÈvÐW\Ó]ÐØ#Ð#r7   )
rL   rM   rN   r½   r$   r+   r.   r¿   rE   rO   rP   s   @r6   rÔ   rÔ   D  s&   ø„ ñðe˜õ eð
$ E§L¡L÷ $r7   rÔ   c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚEmu3VQVAEEncoderConvDownsamplec                 ó`   •— t         ‰| �  «        t        j                  ||ddd¬«      | _        y )Nr
   r9   r   ©Úkernel_sizeÚstrideÚpadding©r*   r+   r,   ÚConv2dÚconv©r2   Úin_channelsr5   s     €r6   r+   z'Emu3VQVAEEncoderConvDownsample.__init__g  ó'   ø€ Ü‰ÑÔÜ—I‘I˜k¨;ÀAÈaÐYZÔ[ˆ�	r7   c                 óZ   — t        j                  |ddd¬«      }| j                  |«      }|S )N)r   r!   r   r!   Úconstantr   )ÚpadÚmoderƒ   )ÚFrû   rõ   ©r2   rB   s     r6   rE   z&Emu3VQVAEEncoderConvDownsample.forwardk  s+   € äŸ™˜m°ÀJÐVWÔXˆØŸ	™	 -Ó0ˆØÐr7   rc   rP   s   @r6   rí   rí   f  s   ø„ ô\ör7   rí   c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚEmu3VQVAEEncoderConvUpsamplec                 ó`   •— t         ‰| �  «        t        j                  ||ddd¬«      | _        y )Nr
   r!   rï   ró   rö   s     €r6   r+   z%Emu3VQVAEEncoderConvUpsample.__init__s  rø   r7   c                 óX   — t        j                  |dd¬«      }| j                  |«      }|S )Nç       @Únearest©Úscale_factorrü   )rý   Úinterpolaterõ   rþ   s     r6   rE   z$Emu3VQVAEEncoderConvUpsample.forwardw  s(   € ÜŸ™ mÀ#ÈIÔVˆØŸ	™	 -Ó0ˆØÐr7   rc   rP   s   @r6   r   r   r  s   ø„ ô\ör7   r   c            	       ó\   ‡ — e Zd Zdededee   dee   fˆ fd„Zdej                  fd„Zˆ xZ	S )ÚEmu3VQVAEConv3dÚ
in_channelÚout_channelrð   rñ   c                 óP  •— t         ‰	| �  «        t        |dd  |dd  «      D ��cg c]
  \  }}||z
  ‘Œ }}}d| _        |d d d…   D ]%  }| xj                  |dz  |dz  z   |dz  fz  c_        Œ' | xj                  dz  c_        t	        j
                  ||||¬«      | _        y c c}}w )Nr!   rÍ   r:   r9   )r9   r   )rñ   )r*   r+   Úziprò   r,   ÚConv3drõ   )
r2   r
  r  rð   rñ   Ú
one_kernelÚ
one_strideÚpadding_sizesÚpad_sizer5   s
            €r6   r+   zEmu3VQVAEConv3d.__init__~  s½   ø€ ô 	‰ÑÔäORÐS^Ð_`Ð_aÐSbÐdjÐklÐkmÐdnÓOo×pÑ5K°ZÀ˜ jÓ0ÐpˆÑpØˆŒØ%¡d¨ dÑ+ò 	JˆHØ�LŠL˜X¨™]¨X¸©\Ñ9¸8Àq¹=ÐIÑIŽLð	Jà�Š˜Ñ�ä—I‘IØØØØô	
ˆ�	ùó qs   ¥B"rB   c                 óh   — t        j                  || j                  «      }| j                  |«      }|S ra   )rý   rû   rò   rõ   rþ   s     r6   rE   zEmu3VQVAEConv3d.forward”  s*   € ÜŸ™˜m¨T¯\©\Ó:ˆØŸ	™	 -Ó0ˆØÐr7   )
rL   rM   rN   r¾   r   r+   r.   r¿   rE   rO   rP   s   @r6   r	  r	  }  sF   ø„ ð
àð
ð ð
ð ˜3‘Zð	
ð
 �c‘
õ
ð, U§\¡\÷ r7   r	  c                   ó`   ‡ — e Zd Zdedefˆ fd„Zdej                  dej                  fd„Zˆ xZS )ÚEmu3VQVAESpatialNormr÷   Úout_channelsc                 óÚ   •— t         ‰| �  «        t        j                  |ddd¬«      | _        t        j
                  ||ddd¬«      | _        t        j
                  ||ddd¬«      | _        y )Né    rK   T©Únum_channelsÚ
num_groupsr4   Úaffiner!   r   rï   )r*   r+   r,   Ú	GroupNormÚ
norm_layerrô   Úconv_yÚconv_b©r2   r÷   r  r5   s      €r6   r+   zEmu3VQVAESpatialNorm.__init__›  sn   ø€ ô
 	‰ÑÔÜŸ,™,Ø%ØØØô	
ˆŒô —i‘iØØØØØô
ˆŒô —i‘iØØØØØô
ˆ�r7   rB   Úquant_statesc                 ó¾   — t        j                  ||j                  dd  d¬«      }| j                  |«      }|| j	                  |«      z  | j                  |«      z   }|S )Nrˆ   r  )Úsizerü   )rý   r  rH   r  r  r   )r2   rB   r"  s      r6   rE   zEmu3VQVAESpatialNorm.forward·  sX   € Ü—}‘} \¸×8KÑ8KÈBÈCÐ8PÐW`ÔaˆØŸ™¨Ó6ˆØ%¨¯©°LÓ(AÑAÀDÇKÁKÐP\ÓD]Ñ]ˆØÐr7   ©	rL   rM   rN   r¾   r+   r.   r¿   rE   rO   rP   s   @r6   r  r  š  s5   ø„ ð
àð
ð õ
ð8 U§\¡\ð ÀÇÁ÷ r7   r  c                   óH   ‡ — e Zd Zdedefˆ fd„Zdej                  fd„Zˆ xZS )ÚEmu3VQVAETemporalUpsampler
  r  c                 óJ   •— t         ‰| �  «        t        ||dd¬«      | _        y )N©r
   r
   r
   ©r!   r!   r!   ©rð   rñ   ©r*   r+   r	  rõ   ©r2   r
  r  r5   s      €r6   r+   z"Emu3VQVAETemporalUpsample.__init__¿  ó(   ø€ ô
 	‰ÑÔÜ#ØØØ!Øô	
ˆ�	r7   rB   c                 óP  — |j                   \  }}}}}|j                  ddddd«      j                  «       j                  |d|«      }t	        j
                  |dd¬	«      }|j                  ||||d«      j                  ddddd«      j                  «       }| j                  |«      }|S )
Nr   r!   r
   rÞ   r9   r:   r  r  r  )rH   rß   r�   r±   rý   r  rõ   )r2   rB   râ   rä   rã   rå   ræ   s          r6   rE   z!Emu3VQVAETemporalUpsample.forwardÌ  sª   € Ø8E×8KÑ8KÑ5ˆ
�H˜h¨°Ø%×-Ñ-¨a°°A°q¸!Ó<×GÑGÓI×NÑNÈzÐ[]Ð_gÓhˆÜŸ™ mÀ#ÈIÔVˆØ%×*Ñ*¨:°xÀÈÐPRÓS×[Ñ[Ð\]Ð_`ÐbcÐefÐhiÓj×uÑuÓwˆØŸ	™	 -Ó0ˆØÐr7   r%  rP   s   @r6   r'  r'  ¾  s*   ø„ ð
àð
ð õ
ð U§\¡\÷ r7   r'  c                   óH   ‡ — e Zd Zdedefˆ fd„Zdej                  fd„Zˆ xZS )ÚEmu3VQVAETemporalDownsampler
  r  c                 óJ   •— t         ‰| �  «        t        ||dd¬«      | _        y )N)rÞ   r
   r
   )r9   r!   r!   r+  r,  r-  s      €r6   r+   z$Emu3VQVAETemporalDownsample.__init__Ö  r.  r7   rB   c                 ó(   — | j                  |«      }|S ra   )rõ   rþ   s     r6   rE   z#Emu3VQVAETemporalDownsample.forwardã  s   € ØŸ	™	 -Ó0ˆØÐr7   r%  rP   s   @r6   r1  r1  Õ  s*   ø„ ð
àð
ð õ
ð U§\¡\÷ r7   r1  c                   ó(   ‡ — e Zd Z	 dˆ fd„	Zd„ Zˆ xZS )ÚEmu3VQVAETemporalResnetBlockc                 óp  •— t         ‰| �  «        || _        |€|n|| _        t	        j
                  |«      | _        t        ||dd¬«      | _        t	        j
                  |«      | _	        t        ||dd¬«      | _
        | j                  | j                  k7  r t	        j                  ||ddd¬«      | _        y y )Nr)  r*  r+  r!   r   rï   )r*   r+   r÷   r  r,   ÚBatchNorm3dÚnorm1r	  Úconv1Únorm2Úconv2r  Únin_shortcutr!  s      €r6   r+   z%Emu3VQVAETemporalResnetBlock.__init__é  s´   ø€ ô
 	‰ÑÔØ&ˆÔØ+7Ð+?™KÀ\ˆÔä—^‘^ KÓ0ˆŒ
Ü$ØØØ!Øô	
ˆŒ
ô —^‘^ LÓ1ˆŒ
Ü$ØØØ!Øô	
ˆŒ
ð ×Ñ˜t×0Ñ0Ò0Ü "§	¡	ØØØØØô!ˆDÕð 1r7   c                 óL  — |}| j                  |«      }|t        j                  |«      z  }| j                  |«      }| j	                  |«      }|t        j                  |«      z  }| j                  |«      }| j                  | j                  k7  r| j                  |«      }||z   S ra   )	r8  r.   Úsigmoidr9  r:  r;  r÷   r  r<  )r2   rB   rÎ   s      r6   rE   z$Emu3VQVAETemporalResnetBlock.forward	  s”   € Ø ˆØŸ
™
 =Ó1ˆØœŸ™ }Ó5Ñ5ˆØŸ
™
 =Ó1ˆàŸ
™
 =Ó1ˆØœŸ™ }Ó5Ñ5ˆØŸ
™
 =Ó1ˆà×Ñ˜t×0Ñ0Ò0Ø×(Ñ(¨Ó2ˆHà˜-Ñ'Ð'r7   ra   rc   rP   s   @r6   r5  r5  è  s   ø„ ð õö@(r7   r5  c                   ó~   ‡ — e Zd Z	 	 ddedee   dee   fˆ fd„Zddej                  deej                     fd„Zˆ xZ	S )	ÚEmu3VQVAEResnetBlockr÷   r  Úquant_channelsc                 ó  •— t         ‰| �  «        || _        |€|n|}|| _        || _        |€=t        j                  |ddd¬«      | _        t        j                  |ddd¬«      | _        n"t        ||«      | _        t        ||«      | _        t        j                  ||ddd¬«      | _        t        j                  ||ddd¬«      | _        | j                  | j                  k7  r t        j                  ||ddd¬«      | _        y y )	Nr  rK   Tr  r
   r!   rï   r   )r*   r+   r÷   r  rA  r,   r  r8  r:  r  rô   r9  r;  r<  )r2   r÷   r  rA  r5   s       €r6   r+   zEmu3VQVAEResnetBlock.__init__  s  ø€ ô 	‰ÑÔØ&ˆÔØ&2Ð&:‘{ÀˆØ(ˆÔØ,ˆÔàÐ!ÜŸ™°;È2ÐSWÐ`dÔeˆDŒJÜŸ™°<ÈBÐTXÐaeÔfˆD�Jä-¨n¸kÓJˆDŒJÜ-¨n¸lÓKˆDŒJä—Y‘YØØØØØô
ˆŒ
ô —Y‘YØØØØØô
ˆŒ
ð ×Ñ˜t×0Ñ0Ò0Ü "§	¡	ØØØØØô!ˆDÕð 1r7   rB   c                 óv  — | j                   €dn|f}|} | j                  |g|¢­Ž }|t        j                  |«      z  }| j	                  |«      } | j
                  |g|¢­Ž }|t        j                  |«      z  }| j                  |«      }| j                  | j                  k7  r| j                  |«      }||z   S ©NrÍ   )
rA  r8  r.   r>  r9  r:  r;  r÷   r  r<  )r2   rB   rA  Ú	norm_argsrÎ   s        r6   rE   zEmu3VQVAEResnetBlock.forwardF  s·   € Ø×-Ñ-Ð5‘B¸NÐ;Lˆ	à ˆØ"˜Ÿ
™
 =Ð=°9Ò=ˆØœŸ™ }Ó5Ñ5ˆØŸ
™
 =Ó1ˆà"˜Ÿ
™
 =Ð=°9Ò=ˆØœŸ™ }Ó5Ñ5ˆØŸ
™
 =Ó1ˆà×Ñ˜t×0Ñ0Ò0Ø×(Ñ(¨Ó2ˆHà˜-Ñ'Ð'r7   r¼   ra   )
rL   rM   rN   r¾   r   r+   r.   r¿   rE   rO   rP   s   @r6   r@  r@    sU   ø„ ð '+Ø(,ñ	*àð*ð ˜s‘mð*ð ! ™õ	*ñX( U§\¡\ð (À8ÈEÏLÉLÑCY÷ (r7   r@  c                   ó²   ‡ — e Zd ZdZdefˆ fd„Z	 	 d	dej                  deej                     dee	   de
ej                  eej                     f   fd„Zˆ xZS )
ÚEmu3VQVAEAttentionBlockrš   rV   c                 ó&  •— t         ‰| �  «        || _        |j                  | _        |j
                  | _        | j                  | j                  z  | _        | j                  | j                  z  | j                  k7  r&t        d| j                  › d| j                  › d�«      ‚| j                  dz  | _	        |j                  | _        d| _        t        j                  | j                  | j                  «      | _        t        j                  | j                  | j                  «      | _        t        j                  | j                  | j                  «      | _        t        j                  | j                  | j                  «      | _        d| _        y )Nz;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).r�   Fr!   )r*   r+   rV   r3   rØ   rŸ   Ú	num_headsr~   Ú
ValueErrorÚscaler    r†   r¡   r,   rX   r¤   r¥   r£   Úout_projr‹   r_   s     €r6   r+   z Emu3VQVAEAttentionBlock.__init__[  s$  ø€ Ü‰ÑÔØˆŒØ×+Ñ+ˆŒØ×3Ñ3ˆŒØŸ™¨$¯.©.Ñ8ˆŒØ�=‰=˜4Ÿ>™>Ñ)¨T¯^©^Ò;ÜØMÈdÏnÉnÐM]ð ^Ø—N‘NÐ# 2ð'óð ð —]‘] DÑ(ˆŒ
Ø×/Ñ/ˆŒØˆŒä—i‘i §¡°·±Ó?ˆŒÜ—i‘i §¡°·±Ó?ˆŒÜ—i‘i §¡°·±Ó?ˆŒÜŸ	™	 $§.¡.°$·.±.ÓAˆŒð %&ˆÕ!r7   rB   r„   r®   rw   c           
      ó¤  — |j                   \  }}}| j                  |«      }| j                  |«      }| j                  |«      }	|j	                  ||| j
                  | j                  «      j                  dd«      }|j	                  ||| j
                  | j                  «      j                  dd«      }|	j	                  ||| j
                  | j                  «      j                  dd«      }	t        }
| j                  j                  dk7  rN| j                  j                  dk(  r|rt        j                  d«       nt        | j                  j                     }
 |
| |||	|| j                  | j                  | j                   sdn| j"                  ¬«      \  }}|j%                  |||«      j'                  «       }| j)                  |«      }|sd}||fS )	z#Input shape: Batch x Time x Channelr!   r9   r¬   r­   r¯   r°   )r¡   r…   r†   N)rH   r£   r¤   r¥   r±   rI  r~   r�   r—   rV   r³   rµ   r¶   r   r¡   rK  rŠ   r†   rz   r�   rL  )r2   rB   r„   r®   râ   Ú
seq_lengthrØ   ÚqueriesÚkeysÚvaluesr»   r–   r”   s                r6   rE   zEmu3VQVAEAttentionBlock.forwardr  s”  € ð -:×,?Ñ,?Ñ)ˆ
�J 	à—+‘+˜mÓ,ˆØ�{‰{˜=Ó)ˆØ—‘˜]Ó+ˆà—,‘,˜z¨:°t·~±~ÀtÇ}Á}ÓU×_Ñ_Ð`aÐcdÓeˆØ�y‰y˜ Z°·±ÀÇÁÓO×YÑYÐZ[Ð]^Ó_ˆØ—‘˜Z¨°T·^±^ÀTÇ]Á]ÓS×]Ñ]Ð^_ÐabÓcˆä(?ÐØ�;‰;×+Ñ+¨wÒ6Ø�{‰{×/Ñ/°6Ò9Ñ>OÜ×#Ñ#ðLõô
 '>¸d¿k¹k×>^Ñ>^Ñ&_Ð#á$7ØØØØØØ—n‘nØ—J‘JØ#Ÿ}š}‘C°$·,±,ô	%
Ñ!ˆ�\ð "×)Ñ)¨*°jÀ)ÓL×WÑWÓYˆØ—m‘m KÓ0ˆá ØˆLà˜LÐ(Ð(r7   )NF)rL   rM   rN   r½   r$   r+   r.   r¿   r   rÑ   r   rE   rO   rP   s   @r6   rG  rG  X  sm   ø„ ÙGð&˜õ &ð4 26Ø,1ñ	-)à—|‘|ð-)ð ! §¡Ñ.ð-)ð $ D™>ð	-)ð
 
ˆu�|‰|˜X e§l¡lÑ3Ð3Ñ	4÷-)r7   rG  c                   ó*   ‡ — e Zd ZdZˆ fd„Zdd„Zˆ xZS )ÚEmu3VQVAEGroupNormzá
    Same as the torch GroupNorm with the only difference that this ones accepts
    an optional kwarg `quant_states` which is not used. This class makes it easier to
    use SpatialNorm or GroupNorm without conditionals
    c                 ó$   •— t        ‰| �  di |¤Ž y rD  )r*   r+   )r2   r‘   r5   s     €r6   r+   zEmu3VQVAEGroupNorm.__init__©  s   ø€ Ü‰ÑÑ"˜6Ó"r7   c                 ó„   — t        j                  || j                  | j                  | j                  | j
                  «      S ra   )rý   Ú
group_normr  r0   rU   r4   )r2   Úinputr"  s      r6   rE   zEmu3VQVAEGroupNorm.forward¬  s)   € Ü�|‰|˜E 4§?¡?°D·K±KÀÇÁÈDÏHÉHÓUÐUr7   ra   )rL   rM   rN   r½   r+   rE   rO   rP   s   @r6   rS  rS  ¢  s   ø„ ñô#÷Vr7   rS  c                   ó`   ‡ — e Zd Zdˆ fd„	Zddej
                  deej
                     fd„Zˆ xZS )ÚEmu3VQVAEMiddleBlockc                 óÞ   •— t         ‰| �  «        t        |||¬«      | _        t	        |«      | _        |€t        |ddd¬«      | _        nt        ||«      | _        t        |||¬«      | _	        y )N©r÷   r  rA  r  rK   Tr  )
r*   r+   r@  Úblock_1rG  Úattn_1rS  Ú	attn_normr  Úblock_2)r2   rV   r÷   rA  r5   s       €r6   r+   zEmu3VQVAEMiddleBlock.__init__±  so   ø€ Ü‰ÑÔä+Ø#Ø$Ø)ô
ˆŒô
 .¨fÓ5ˆŒØÐ!Ü/¸[ÐUWÐ]aÐjnÔoˆD�Nä1°.À+ÓNˆDŒNä+Ø#Ø$Ø)ô
ˆ�r7   rB   r"  c                 ób  — | j                  ||«      }|}| j                  ||«      }|j                  \  }}}}|j                  ||||z  «      j	                  dd«      }| j                  |«      d   }|j                  ||||«      j                  dddd«      }||z   }| j                  ||«      }|S )Nr!   r9   r   r
   )	r\  r^  rH   r±   r�   r]  rz   rß   r_  )r2   rB   r"  rÎ   râ   rä   rå   ræ   s           r6   rE   zEmu3VQVAEMiddleBlock.forwardÅ  sÀ   € ØŸ™ ]°LÓAˆØ ˆØŸ™ }°lÓCˆØ.;×.AÑ.AÑ+ˆ
�H˜f eØ%×*Ñ*¨:°xÀÈ%ÁÓP×ZÑZÐ[\Ð^_Ó`ˆØŸ™ MÓ2°1Ñ5ˆØ%×-Ñ-¨j¸&À%ÈÓR×ZÑZÐ[\Ð^_ÐabÐdeÓfˆØ  =Ñ0ˆØŸ™ ]°LÓAˆØÐr7   ra   )	rL   rM   rN   r+   r.   rÒ   r   rE   rO   rP   s   @r6   rY  rY  °  s,   ø„ õ
ñ(
 U×%6Ñ%6ð 
ÀhÈu×O`ÑO`ÑFa÷ 
r7   rY  c                   ó>   ‡ — e Zd Zˆ fd„Zdej
                  fd„Zˆ xZS )ÚEmu3VQVAEDownBlockc           
      óÌ  •— t         ‰| �  «        t        |j                  «      | _        |j
                  | _        |j                  }|j                  }dt        |«      z   }|| _        t        j                  «       | _        t        | j                  «      D �]K  }t        j                  «       }t        j                  «       }t        j                  «       }|||   z  }	|||   z  }
t        | j
                  «      D ]~  }|j                  t        |	|
¬«      «       |
}	|j                  €Œ.||j                  v sŒ=|j                  t!        |«      «       |j                  t        j"                  |	ddd¬«      «       Œ€ t        j$                  «       }||_        ||_        ||_        || j                  dz
  k7  rt-        |	«      |_        | j                  j                  |«       �ŒN y )N)r!   ©r÷   r  r  rK   Tr  r!   )r*   r+   ÚlenÚchannel_multiplierÚnum_resolutionsÚnum_res_blocksÚbase_channelsrG   Úin_channel_multiplierr,   Ú
ModuleListÚdownÚrangeÚappendr@  Úattn_resolutionsrG  r  ÚModuleÚblockÚattnÚ
attn_normsrí   Ú
downsample)r2   rV   ri  rf  rj  Úi_levelrq  rr  rs  Úblock_inÚ	block_outÚi_blockrl  r5   s                €r6   r+   zEmu3VQVAEDownBlock.__init__Ó  s¢  ø€ Ü‰ÑÔä" 6×#<Ñ#<Ó=ˆÔØ$×3Ñ3ˆÔØ×,Ñ,ˆØ#×6Ñ6Ðà $¤uÐ-?Ó'@Ñ @ÐØ%:ˆÔ"Ü—M‘M“OˆŒ	Ü˜T×1Ñ1Ó2ó 	#ˆGÜ—M‘M“OˆEÜ—=‘=“?ˆDÜŸ™›ˆJØ$Ð'<¸WÑ'EÑEˆHØ%Ð(:¸7Ñ(CÑCˆIÜ  ×!4Ñ!4Ó5ò 
q�Ø—‘Ü(Ø$,Ø%.ôôð %�Ø×*Ñ*Ñ6¸7Àf×F]ÑF]Ò;]Ø—K‘KÔ 7¸Ó ?Ô@Ø×%Ñ%¤b§l¡lÀÐUWÐ]aÐjnÔ&oÕpð
qô —9‘9“;ˆDØˆDŒJØˆDŒIØ(ˆDŒOØ˜$×.Ñ.°Ñ2Ò2Ü"@ÀÓ"J�”Ø�I‰I×Ñ˜TÖ"ñ1	#r7   rB   c                 ó>  — t        | j                  «      D �]  \  }}t        | j                  «      D ]Á  } |j                  |   |«      }t        |j                  «      dkD  sŒ1|} |j                  |   |«      }|j                  \  }}}}	|j                  ||||	z  «      j                  dd«      } |j                  |   |«      d   }|j                  |||	|«      j                  dddd«      }||z   }ŒÃ || j                  dz
  k7  sŒó|j                  |«      }�Œ |S )Nr   r!   r9   r
   )Ú	enumeraterl  rm  rh  rq  re  rr  rs  rH   r±   r�   rz   rß   rg  rt  )
r2   rB   ru  Úblocksrx  rÎ   râ   rä   rå   ræ   s
             r6   rE   zEmu3VQVAEDownBlock.forwardø  s5  € Ü(¨¯©Ó3ó 	A‰OˆG�VÜ  ×!4Ñ!4Ó5ò =�Ø 5 §¡¨WÑ 5°mÓ D�Ü�v—{‘{Ó# aÓ'Ø,�HØ$> F×$5Ñ$5°gÑ$>¸}Ó$M�Mà:G×:MÑ:MÑ7�J ¨&°%Ø$1×$6Ñ$6°zÀ8ÈVÐV[É^Ó$\×$fÑ$fÐghÐjkÓ$l�MØ$8 F§K¡K°Ñ$8¸Ó$GÈÑ$J�Mà$1×$9Ñ$9¸*ÀfÈeÐU]Ó$^×$fÑ$fÐghÐjkÐmnÐpqÓ$r�MØ$,¨}Ñ$<‘Mð=ð ˜$×.Ñ.°Ñ2Ó2Ø &× 1Ñ 1°-Ó @’ð	Að" Ðr7   ©rL   rM   rN   r+   r.   rÒ   rE   rO   rP   s   @r6   rb  rb  Ò  s   ø„ ô##ðJ U×%6Ñ%6÷ r7   rb  c                   óV   ‡ — e Zd Zˆ fd„Zdej
                  dej
                  fd„Zˆ xZS )ÚEmu3VQVAEUpBlockc           	      ó¨  •— t         ‰| �  «        t        |j                  «      | _        |j
                  | _        |j                  }|j                  |j                  d   z  }t        j                  «       | _
        t        t        | j                  «      «      D �]5  }t        j                  «       }t        j                  «       }t        j                  «       }|j                  |j                  |   z  }t        | j
                  dz   «      D ]e  }	|j                  t        |||¬«      «       |}||j                  v sŒ1|j                  t!        |«      «       |j                  t#        ||«      «       Œg t        j$                  «       }
||
_        ||
_        ||
_        |dk7  rt-        |«      |
_        | j                  j1                  d|
«       �Œ8 y )Nr:   r!   r[  r   )r*   r+   re  rf  rg  rh  rØ   ri  r,   rk  ÚupÚreversedrm  rn  r@  ro  rG  r  rp  rq  rr  rs  r   ÚupsampleÚinsert)r2   rV   rA  rv  ru  rq  rr  rs  rw  rx  r€  r5   s              €r6   r+   zEmu3VQVAEUpBlock.__init__  s  ø€ Ü‰ÑÔä" 6×#<Ñ#<Ó=ˆÔØ$×3Ñ3ˆÔà×)Ñ)ˆØ×'Ñ'¨&×*CÑ*CÀBÑ*GÑGˆä—-‘-“/ˆŒÜ¤ d×&:Ñ&:Ó ;Ó<ó 	"ˆGÜ—M‘M“OˆEÜ—=‘=“?ˆDÜŸ™›ˆJØ×,Ñ,¨v×/HÑ/HÈÑ/QÑQˆIÜ  ×!4Ñ!4°qÑ!8Ó9ò V�Ø—‘Ü(Ø$,Ø%.Ø'5ôôð %�Ø˜f×5Ñ5Ò5Ø—K‘KÔ 7¸Ó ?Ô@Ø×%Ñ%Ô&:¸>È8Ó&TÕUðVô —‘“ˆBØˆBŒHØˆBŒGØ&ˆBŒMØ˜!Š|Ü:¸8ÓD�”à�G‰G�N‰N˜1˜bÖ!ñ3	"r7   rB   r"  c                 óh  — t        | j                  d d d…   «      D �]  \  }}t        | j                  dz   «      D ]Ã  } |j                  |   ||«      }t        |j                  «      dkD  sŒ2|} |j                  |   ||«      }|j                  \  }}}	}
|j                  |||	|
z  «      j                  dd«      } |j                  |   |«      d   }|j                  ||	|
|«      j                  dddd«      }||z   }ŒÅ |t        | j                  «      dz
  k7  s�Œ|j                  |«      }�Œ |S )Nr:   r!   r   r9   r
   )rz  r€  rm  rh  rq  re  rr  rs  rH   r±   r�   rz   rß   r‚  )r2   rB   r"  ru  r{  rx  rÎ   râ   rä   rå   ræ   s              r6   rE   zEmu3VQVAEUpBlock.forward3  sD  € Ü(¨¯©±°2°©Ó7ó 	?‰OˆG�VÜ  ×!4Ñ!4°qÑ!8Ó9ò =�Ø 5 §¡¨WÑ 5°mÀ\Ó R�Ü�v—{‘{Ó# aÓ'Ø,�HØ$> F×$5Ñ$5°gÑ$>¸}ÈlÓ$[�Mà:G×:MÑ:MÑ7�J ¨&°%Ø$1×$6Ñ$6°zÀ8ÈVÐV[É^Ó$\×$fÑ$fÐghÐjkÓ$l�MØ$8 F§K¡K°Ñ$8¸Ó$GÈÑ$J�Mà$1×$9Ñ$9¸*ÀfÈeÐU]Ó$^×$fÑ$fÐghÐjkÐmnÐpqÓ$r�MØ$,¨}Ñ$<‘Mð=ð œ#˜dŸg™g›,¨Ñ*Ô*Ø &§¡°Ó >’ð	?ð  Ðr7   r|  rP   s   @r6   r~  r~    s(   ø„ ô#"ðJ U×%6Ñ%6ð Àe×FWÑFW÷ r7   r~  c                   ó>   ‡ — e Zd Zˆ fd„Zdej
                  fd„Zˆ xZS )ÚEmu3VQVAEEncoderc                 ó˜  •— t         ‰| �  «        |j                  }|j                  }|j                  }|j
                  }|j                  }|rd|z  n|}||d   z  }t        j                  j                  ||ddd¬«      | _
        t        |«      | _        t        ||«      | _        t        j                  j                  d|dd¬	«      | _        t        j                  j                  ||ddd¬«      | _        t%        t'        j(                  |j*                  «      «      }	t        j,                  «       | _        t        j,                  «       | _        t3        |	«      D ])  }
t5        ||«      }| j.                  j7                  |«       Œ+ t3        |j8                  «      D ]*  }t;        ||¬
«      }| j0                  j7                  |«       Œ, y )Nr9   r:   r
   r!   rï   r  rK   T)r  r  r4   r  rd  )r*   r+   ri  r÷   Údouble_latentÚlatent_channelsrf  r.   r,   rô   Úconv_inrb  Ú
down_blockrY  Úmiddle_blockr  Únorm_outÚconv_outr¾   ÚmathÚlog2Útemporal_downsample_factorrk  Ú	time_convÚtime_res_stackrm  r1  rn  rh  r5  )r2   rV   ri  r÷   rˆ  r‰  rf  r  rv  Útemporal_down_blocksÚirõ   Ú_Útime_res_convr5   s                 €r6   r+   zEmu3VQVAEEncoder.__init__H  s”  ø€ Ü‰ÑÔà×,Ñ,ˆØ×(Ñ(ˆØ×,Ñ,ˆØ ×0Ñ0ˆØ#×6Ñ6ÐÙ.;�q˜?Ò*ÀˆØ Ð#5°bÑ#9Ñ9ˆä—x‘x—‘ {°MÈqÐYZÐde�ÓfˆŒÜ,¨VÓ4ˆŒÜ0°¸ÓBˆÔäŸ™×*Ñ*°bÀxÐUYÐbfÐ*ÓgˆŒÜŸ™Ÿ™ØØØØØð (ó 
ˆŒô  #¤4§9¡9¨V×-NÑ-NÓ#OÓPÐÜŸ™›ˆŒÜ Ÿm™m›oˆÔäÐ+Ó,ò 	(ˆAÜ.¨|¸\ÓJˆDØ�N‰N×!Ñ! $Õ'ð	(ô �v×,Ñ,Ó-ò 	6ˆAÜ8Ø(Ø)ôˆMð ×Ñ×&Ñ& }Õ5ñ	6r7   Úpixel_valuesc                 óh  — |j                   d   } |j                  dg|j                   dd  ¢­Ž }| j                  |«      }| j                  |«      }| j	                  |«      }| j                  |«      }|t        j                  |«      z  }| j                  |«      } |j                  d|g|j                   dd  ¢­Ž }|j                  ddddd«      }| j                  D ]"  } ||«      }|t        j                  |«      z  }Œ$ | j                  D ]
  } ||«      }Œ |j                  ddddd«      }|S )Nr!   r:   r9   r   r
   rÞ   )rH   rz   rŠ  r‹  rŒ  r�  r.   r>  rŽ  rß   r’  r“  )r2   r˜  Útemporal_dimrB   rõ   Úlayers         r6   rE   zEmu3VQVAEEncoder.forwardo  sH  € Ø#×)Ñ)¨!Ñ,ˆØ+�|×+Ñ+¨BÐH°×1CÑ1CÀAÀBÐ1GÒHˆð Ÿ™ \Ó2ˆØŸ™¨Ó6ˆØ×)Ñ)¨-Ó8ˆð Ÿ™ mÓ4ˆØœŸ™ }Ó5Ñ5ˆØŸ™ mÓ4ˆà-˜×-Ñ-¨b°,ÐYÀ×ATÑATÐUVÐUWÐAXÒYˆØ%×-Ñ-¨a°°A°q¸!Ó<ˆð —N‘Nò 	:ˆDÙ  Ó/ˆMØœUŸ]™]¨=Ó9Ñ9‰Mð	:ð ×(Ñ(ò 	1ˆEÙ! -Ó0‰Mð	1ð &×-Ñ-¨a°°A°q¸!Ó<ˆàÐr7   )rL   rM   rN   r+   r.   rÀ   rE   rO   rP   s   @r6   r†  r†  G  s   ø„ ô%6ðN E×$4Ñ$4÷ r7   r†  c                   ó\   ‡ — e Zd Zdefˆ fd„Zdej                  dej                  fd„Zˆ xZS )ÚEmu3VQVAEDecoderrV   c                 ó¬  •— t         ‰	| �  «        |j                  }|j                  |j                  d   z  }t        j                  «       | _        t        |j                  «      D ]>  }t        |j                  |j                  ¬«      }| j                  j                  |«       Œ@ t        t        j                  |j                   «      «      }t        j                  «       | _        t        |«      D ]=  }t%        |j                  |j                  «      }| j"                  j                  |«       Œ? t        j&                  |j                  |ddd¬«      | _        t+        |||¬«      | _        t/        |«      | _        |j                  |j                  d   z  }t3        ||«      | _        t        j&                  ||j6                  ddd¬«      | _        y )Nr:   rd  r
   r!   rï   )rA  r   )r*   r+   rØ   ri  rf  r,   rk  r“  rm  rh  r5  r‰  rn  r¾   r�  r�  r‘  r’  r'  rô   rŠ  rY  rŒ  r~  Úup_blockr  r�  r  rŽ  )
r2   rV   rA  rv  r–  r—  Útemp_upsample_block_numr•  rõ   r5   s
            €r6   r+   zEmu3VQVAEDecoder.__init__Ž  sŠ  ø€ Ü‰ÑÔà×)Ñ)ˆØ×'Ñ'¨&×*CÑ*CÀBÑ*GÑGˆÜ Ÿm™m›oˆÔÜ�v×,Ñ,Ó-ò 	6ˆAÜ8Ø"×2Ñ2À×AWÑAWôˆMð ×Ñ×&Ñ& }Õ5ð		6ô #&¤d§i¡i°×0QÑ0QÓ&RÓ"SÐÜŸ™›ˆŒÜÐ.Ó/ò 	(ˆAÜ,¨V×-CÑ-CÀV×E[ÑE[Ó\ˆDØ�N‰N×!Ñ! $Õ'ð	(ô —y‘yØ×"Ñ"ØØØØô
ˆŒô 1°¸ÐR`ÔaˆÔÜ(¨Ó0ˆŒà×'Ñ'¨&×*CÑ*CÀAÑ*FÑFˆÜ,¨^¸XÓFˆŒÜŸ	™	ØØ×ÑØØØô
ˆ�r7   rB   r"  c                 ó¶  — t        j                  ||fd¬«      }|j                  ddddd«      }| j                  D ]
  } ||«      }Œ | j                  D ]"  } ||«      }|t        j
                  |«      z  }Œ$ |j                  ddddd«      }t        j                  |dd¬«      \  }} |j                  dg|j                  dd  ¢­Ž } |j                  dg|j                  dd  ¢­Ž }| j                  |«      }| j                  ||«      }| j                  ||«      }| j                  ||«      }|t        j
                  |«      z  }| j                  |«      }|S )Nr   re   r9   r!   r
   rÞ   r:   )r.   rg   rß   r“  r’  r>  Úchunkrz   rH   rŠ  rŒ  rŸ  r�  rŽ  )r2   rB   r"  Úhidden_quant_statesr›  s        r6   rE   zEmu3VQVAEDecoder.forwardµ  sp  € Ü#Ÿi™i¨¸Ð(EÈ1ÔMÐØ1×9Ñ9¸!¸QÀÀ1ÀaÓHÐð ×(Ñ(ò 	=ˆEÙ"'Ð(;Ó"<Ñð	=ð —^‘^ò 	FˆEÙ"'Ð(;Ó"<ÐØ¤5§=¡=Ð1DÓ#EÑEÑð	Fð 2×9Ñ9¸!¸QÀÀ1ÀaÓHÐÜ&+§k¡kÐ2EÀqÈaÔ&PÑ#ˆ�|Ø-˜×-Ñ-¨bÐK°=×3FÑ3FÀqÀrÐ3JÒKˆØ+�|×+Ñ+¨BÐH°×1CÑ1CÀAÀBÐ1GÒHˆàŸ™ ]Ó3ˆð ×)Ñ)¨-¸ÓFˆØŸ™ m°\ÓBˆàŸ™ m°\ÓBˆØœŸ™ }Ó5Ñ5ˆØŸ™ mÓ4ˆàÐr7   )	rL   rM   rN   r$   r+   r.   r¿   rE   rO   rP   s   @r6   r�  r�  �  s+   ø„ ð%
˜õ %
ðN U§\¡\ð ÀÇÁ÷ r7   r�  aN  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

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

    Parameters:
        config ([`Emu3VQVAEConfig`]):
            Model configuration class with all the parameters of the model. Initializing with a config file does not
            load the weights associated with the model, only the configuration. Check out the
            [`~PreTrainedModel.from_pretrained`] method to load the model weights.
aA  The VQ-VAE model used in Emu3 for encoding/decoding images into discrete tokens.
    This model follows the "Make-a-scene: Scene-based text-to-image generation with human priors" paper from
    [ Oran Gafni, Adam Polyak, Oron Ashual, Shelly Sheynin, Devi Parikh, and Yaniv Taigman](https://arxiv.org/abs/2203.13131).
    c                   ó¢   ‡ — e Zd ZeZdZdZdZdZdZ	g d¢Z
d„ Zdefˆ fd„Zdej                  dej                  fd	„Zd
ej                  fd„Zˆ xZS )Ú	Emu3VQVAEÚ
emuvideovqr˜  T)r5  rG  r@  rÔ   c                 óˆ  — t        |t        j                  t        j                  f«      r-t        j                  j                  |j                  dd¬«       y t        |t        j                  «      rÃt        j                  j                  |j                  t        j                  d«      ¬«       |j                  �xt        j                  j                  |j                  «      \  }}|dkD  rdt        j                  |«      z  nd}t        j                  j                  |j                  | |«       y y t        |t        j                  t        j                  t        j                   f«      rUt        j                  j#                  |j                  d«       t        j                  j#                  |j                  d«       y y )NÚfan_outÚrelu)rü   Únonlinearityé   )Úar   r!   )Ú
isinstancer,   rô   r  ÚinitÚkaiming_normal_r0   rX   Úkaiming_uniform_r�  ÚsqrtrU   Ú_calculate_fan_in_and_fan_outrÛ   ÚBatchNorm2dr7  r  Ú	constant_)r2   r€   Úfan_inr–  Úbounds        r6   Ú_init_weightszEmu3VQVAE._init_weightsù  s  € Ü�fœrŸy™y¬"¯)©)Ð4Ô5Ü�G‰G×#Ñ# F§M¡M¸	ÐPVÐ#ÕWÜ˜¤§	¡	Ô*Ü�G‰G×$Ñ$ V§]¡]´d·i±iÀ³lÐ$ÔCØ�{‰{Ð&ÜŸG™G×AÑAÀ&Ç-Á-ÓP‘	�˜Ø17¸!²˜œDŸI™I fÓ-Ò-À�Ü—‘× Ñ  §¡¨u¨f°eÕ<ð 'ô ˜¤§¡´·±ÄÇÁÐ NÔOÜ�G‰G×Ñ˜fŸm™m¨QÔ/Ü�G‰G×Ñ˜fŸk™k¨1Õ-ð Pr7   rV   c                 óò  •— t         ‰| �  |«       || _        t        |«      | _        t        |«      | _        t        |«      | _        dt        |j                  «      dz
  z  | _        t        |j                  |j                  dd¬«      | _        t        |j                  |j                  dd¬«      | _        dt        |j                  «      dz
  z  | _        | j%                  «        | j'                  «        y )Nr9   r!   )r
   r!   r!   r*  r+  )r*   r+   rV   r†  Úencoderr�  ÚdecoderrÔ   Úquantizere  rf  Úvision_spatial_factorr	  r‰  rØ   Ú
quant_convÚpost_quant_convÚspatial_scale_factorÚevalÚ	post_initr_   s     €r6   r+   zEmu3VQVAE.__init__  sÑ   ø€ Ü‰Ñ˜Ô àˆŒä'¨Ó/ˆŒÜ'¨Ó/ˆŒÜ0°Ó8ˆŒØ%&¬3¨v×/HÑ/HÓ+IÈAÑ+MÑ%NˆÔ"ä)Ø×"Ñ" F×$4Ñ$4À)ÐT]ô
ˆŒô  /Ø×Ñ˜f×4Ñ4À)ÐT]ô 
ˆÔð %&¬#¨f×.GÑ.GÓ*HÈ1Ñ*LÑ$MˆÔ!Ø�	‰	Œà�‰Õr7   Úimage_sizesc                 ó†  — |j                   dk(  }|rL| j                  j                  }|j                  \  }}}}|j	                  d«      j                  d|ddd«      }n|j                  \  }}}}}| j                  |«      }	|	j                  ddddd«      }	| j                  |	«      }	|	j                  ddddd«      }	| j                  |	«      }
|r|
j                  d«      n|
}t        ||«      D ��cg c]B  \  }}|d t        |d   | j                  z  «      …d t        |d   | j                  z  «      …f   ‘ŒD }}}|S c c}}w )NrÞ   r!   r   r9   r
   )ÚndimrV   r‘  rH   rl   Úrepeatr¹  rß   r½  r»  Úsqueezer  r¾   r¼  )r2   r˜  rÂ  Úis_imagerã   râ   rä   rå   ræ   rB   ÚcodesÚimage_tokensÚsingle_imager$  s                 r6   ÚencodezEmu3VQVAE.encode  sX  € Ø×$Ñ$¨Ñ)ˆÙØ—{‘{×=Ñ=ˆHØ2>×2DÑ2DÑ/ˆJ˜ &¨%Ø'×1Ñ1°!Ó4×;Ñ;¸A¸xÈÈAÈqÓQ‰Là<H×<NÑ<NÑ9ˆJ˜ (¨F°EàŸ™ \Ó2ˆð &×-Ñ-¨a°°A°q¸!Ó<ˆØŸ™¨Ó6ˆð &×-Ñ-¨a°°A°q¸!Ó<ˆØ—‘˜mÓ,ˆá+3�u—}‘} QÔ'¸ˆô '*¨,¸Ó&D÷
á"�˜dð ÐDœ3˜t A™w¨×)CÑ)CÑCÓDÐDÐFqÌÈDÐQRÉGÐVZ×VpÑVpÑLpÓHqÐFqÐqÓrð
ˆñ 
ð
 Ðùó
s   Ã1AD=rB   c                 ó¬  — |j                   dk(  }|r|j                  d«      }|j                  \  }}}}| j                  j	                  |j                  «       «      }|j                  d   }|j                  |||||«      j                  ddddd«      j                  «       }| j                  |«      }	|j                  ddddd«      }|	j                  ddddd«      }	| j                  |	|«      }
|
j                  ||| j                  j                  z  | j                  j                  || j                  z  || j                  z  «      }
|r	|
d d …df   S |
S )Nr
   r!   r:   r   rÞ   r9   )rÄ  rl   rH   r»  rÙ   Úflattenr±   rß   r�   r¾  rº  rz   rV   r‘  r  r¿  )r2   rB   rÇ  râ   rã   rå   ræ   Úquanträ   Ú
post_quantÚvideos              r6   ÚdecodezEmu3VQVAE.decode7  sK  € Ø ×%Ñ%¨Ñ*ˆÙØ)×3Ñ3°AÓ6ˆMà.;×.AÑ.AÑ+ˆ
�H˜f eØ—‘×'Ñ'¨×(=Ñ(=Ó(?Ó@ˆà—;‘;˜r‘?ˆØ—
‘
˜: x°¸ÀÓI×QÑQÐRSÐUVÐXYÐ[\Ð^_Ó`×kÑkÓmˆØ×)Ñ)¨%Ó0ˆ
à—‘˜a  A q¨!Ó,ˆØ×'Ñ'¨¨1¨a°°AÓ6ˆ
à—‘˜Z¨Ó/ˆØ—‘ØØ�t—{‘{×=Ñ=Ñ=Ø�K‰K×$Ñ$Ø�T×.Ñ.Ñ.Ø�D×-Ñ-Ñ-ó
ˆñ 'ˆu’Q˜�T‰{Ð1¨EÐ1r7   )rL   rM   rN   r$   Úconfig_classÚbase_model_prefixÚmain_input_nameÚ_supports_sdpaÚ_supports_flash_attn_2Ú_supports_flex_attnÚ_no_split_modulesr·  r+   r.   r¿   rË  rÑ  rO   rP   s   @r6   r¥  r¥  ä  sj   ø„ ð #€LØ$ÐØ$€OØ€NØ!ÐØÐòÐò.ð˜õ ð* 5§<¡<ð ¸e¿l¹ló ð82 E§L¡L÷ 2r7   r¥  c                   óì   — e Zd ZdZd„ Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	ed„ «       Z
ed„ «       Zd	eej                     d
ej                  fd„Zd	ej                  d
ej                  fd„Zy)ÚEmu3ImageVocabularyMappingzM
    A class for mapping discrete image tokens from VQGAN to BPE tokens.
    c                 ój   — || _         |j                  d«      | _        |j                  d«      | _        y )Nz<|extra_200|>z<image>)Ú	vocab_mapr´   Úeol_token_idÚimage_token_id)r2   rÜ  s     r6   r+   z#Emu3ImageVocabularyMapping.__init__V  s+   € Ø"ˆŒØ%ŸM™M¨/Ó:ˆÔØ'Ÿm™m¨IÓ6ˆÕr7   c           	      óž   — t        | j                  j                  «       D ��cg c]  \  }}|j                  d«      sŒ|‘Œ c}}«      S c c}}w ©Nz<|visual token©ÚsortedrÜ  ÚitemsÚ
startswith©r2   ÚnameÚvals      r6   rÉ  z'Emu3ImageVocabularyMapping.image_tokens[  s8   € ä¨D¯N©N×,@Ñ,@Ó,B×h™y˜t SÀdÇoÁoÐVfÕFg’sÓhÓiÐiùÓhó
   £A	
½A	
c           	      óž   — t        | j                  j                  «       D ��cg c]  \  }}|j                  d«      sŒ|‘Œ c}}«      S c c}}w rà  rá  rå  s      r6   Úimage_tokens_strz+Emu3ImageVocabularyMapping.image_tokens_str_  s8   € ä¨T¯^©^×-AÑ-AÓ-C×i¡	  cÀtÇÁÐWgÕGh’tÓiÓjÐjùÓirè  c                 ót   — | j                   D �ci c]  }t        |dd «      | j                  |   “Œ  c}S c c}w )Niøÿÿÿrˆ   )rê  r¾   rÜ  )r2   Útokens     r6   Úimg2bpez"Emu3ImageVocabularyMapping.img2bpec  s5   € àFJ×F[ÑF[Ö\¸U”�E˜"˜R�LÓ! 4§>¡>°%Ñ#8Ñ8Ò\Ð\ùÒ\s   �#5c                 ój   — | j                   j                  «       D ��ci c]  \  }}||“Œ
 c}}S c c}}w ra   )rí  rã  )r2   rn   Úvs      r6   Úbpe2imgz"Emu3ImageVocabularyMapping.bpe2imgg  s+   € à!%§¡×!3Ñ!3Ó!5×6™˜˜A��1‘Ó6Ð6ùÓ6s   ž/c                 óæ   — t        j                  t        | j                  j	                  «       «      dz   t         j
                  ¬«      }| j                  j                  «       D ]
  \  }}|||<   Œ |S ©Nr!   ©r<   )r.   ÚzerosÚmaxrð  rP  r¾   rã  ©r2   Úmappingrn   rï  s       r6   Úbpe2img_mapping_tensorz1Emu3ImageVocabularyMapping.bpe2img_mapping_tensork  ó[   € ä—+‘+œc $§,¡,×"3Ñ"3Ó"5Ó6¸Ñ:Ä%Ç)Á)ÔLˆØ—L‘L×&Ñ&Ó(ò 	‰DˆAˆqØˆG�AŠJð	àˆr7   c                 óæ   — t        j                  t        | j                  j	                  «       «      dz   t         j
                  ¬«      }| j                  j                  «       D ]
  \  }}|||<   Œ |S rò  )r.   rô  rõ  rí  rP  r¾   rã  rö  s       r6   Úimg2bpe_mapping_tensorz1Emu3ImageVocabularyMapping.img2bpe_mapping_tensorr  rù  r7   Ú	img_batchrw   c                 ó,  — |j                   }t        j                  |j                  d   dft        j                  ¬«      | j
                  z  }| j                  |j                  d«         }t        j                  ||gd¬«      }|j                  |«      S )Nr   r!   ró  Úcpur:   re   )	Údevicer.   r/   rH   r¾   rÝ  rû  r=   rg   )r2   rü  rÿ  Úeol_rowÚ
img_tokenss        r6   Úconvert_img2bpez*Emu3ImageVocabularyMapping.convert_img2bpey  sw   € Ø×!Ñ!ˆÜ—*‘*˜iŸo™o¨aÑ0°!Ð4¼E¿I¹IÔFÈ×IZÑIZÑZˆØ×0Ñ0°·±¸eÓ1DÑEˆ
Ü—Y‘Y 
¨GÐ4¸"Ô=ˆ
Ø�}‰}˜VÓ$Ð$r7   c                 óŠ   — |j                   }|dd d…f   }| j                  |j                  d«         }|j                  |«      S )N.r:   rþ  )rÿ  rø  r=   )r2   rü  rÿ  r  s       r6   Úconvert_bpe2imgz*Emu3ImageVocabularyMapping.convert_bpe2img€  sG   € Ø×!Ñ!ˆØ˜c 3 B 3˜hÑ'ˆ	Ø×0Ñ0°·±¸eÓ1DÑEˆ
Ø�}‰}˜VÓ$Ð$r7   N)rL   rM   rN   r½   r+   r   rÉ  rê  rí  rð  rø  rû  r   r.   r¿   r  r  rÍ   r7   r6   rÚ  rÚ  Q  sÅ   „ ñò7ð
 ñjó ðjð ñkó ðkð ñ]ó ð]ð ñ7ó ð7ð ñó ðð ñó ðð%¨¨e¯l©lÑ);ð %ÀÇÁó %ð%¨¯©ð %¸%¿,¹,ô %r7   rÚ  aI  
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

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

    Parameters:
        config ([`Emu3Config`]):
            Model configuration class with all the parameters of the model. Initializing with a config file does not
            load the weights associated with the model, only the configuration. Check out the
            [`~PreTrainedModel.from_pretrained`] method to load the model weights.
zRThe bare emu3 Model outputting raw hidden-states without any specific head on top.c                   óH   — e Zd ZeZdZdZdgZddgZdZ	dZ
dZdZdZdZdZd„ Zy)	ÚEmu3PreTrainedModelÚmodelTrÂ   Úpast_key_valuesr•   Fc                 óª  — | j                   j                  «       j                  }t        |t        «      r|j                  |j                  «       y t        |t        j                  t        j                  f«      rY|j                  j                  j                  d|¬«       |j                  �%|j                  j                  j                  «        y y t        |t        j                  «      rf|j                  j                  j                  d|¬«       |j                   �2|j                  j                  |j                      j                  «        y y y )Nr°   )r@   Ústd)rV   Úget_text_configÚinitializer_ranger­  r¥  Úapplyr·  r,   rX   rô   r0   rÚ   Únormal_rU   Úzero_rÖ   Úpadding_idx)r2   r€   r
  s      r6   r·  z!Emu3PreTrainedModel._init_weights¬  sñ   € Ø�k‰k×)Ñ)Ó+×=Ñ=ˆÜ�fœiÔ(Ø�L‰L˜×-Ñ-Õ.Ü˜¤§¡¬B¯I©IÐ 6Ô7Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ð .r7   N)rL   rM   rN   r"   rÒ  rÓ  Úsupports_gradient_checkpointingrØ  Ú_skip_keys_device_placementrÖ  rÕ  Ú_supports_quantized_cacheÚ_supports_cache_classÚ_supports_static_cacheÚ!_supports_param_buffer_assignmentr×  r·  rÍ   r7   r6   r  r  ˜  s[   „ ð
 €LØÐØ&*Ð#àðÐð $5°mÐ"DÐØ!ÐØ€NØ $ÐØ ÐØ!ÐØ(-Ð%ØÐó?r7   r  c                   ó^   ‡ — e Zd Zddefˆ fd„Z ej                  «       ed„ «       «       Zˆ xZ	S )ÚEmu3RotaryEmbeddingrV   c                 óê  •— t         ‰| �  «        t        |d«      rG|j                  �;|j                  j	                  d|j                  j	                  d«      «      | _        nd| _        |j                  | _        |j                  | _        || _	        t        | j
                     | _        | j                  | j                  |«      \  }| _        | j                  d|d¬«       | j                  | _        y )NÚrope_scalingÚ	rope_typeÚtypeÚdefaultÚinv_freqF)Ú
persistent)r*   r+   Úhasattrr  r´   r  Úmax_position_embeddingsÚmax_seq_len_cachedÚoriginal_max_seq_lenrV   r   Úrope_init_fnÚattention_scalingÚregister_bufferr  Úoriginal_inv_freq)r2   rV   rÿ  r  r5   s       €r6   r+   zEmu3RotaryEmbedding.__init__»  sÉ   ø€ Ü‰ÑÔä�6˜>Ô*¨v×/BÑ/BÐ/NØ#×0Ñ0×4Ñ4°[À&×BUÑBU×BYÑBYÐZ`ÓBaÓbˆD�Nà&ˆDŒNØ"(×"@Ñ"@ˆÔØ$*×$BÑ$BˆÔ!àˆŒÜ/°·±Ñ?ˆÔà+/×+<Ñ+<¸T¿[¹[È&Ó+QÑ(ˆ�$Ô(Ø×Ñ˜Z¨¸eÐÔDØ!%§¡ˆÕr7   c                 ób  — | j                   d d d …d f   j                  «       j                  |j                  d   dd«      j	                  |j
                  «      }|d d …d d d …f   j                  «       }t        |j
                  j                  t        «      r/|j
                  j                  dk7  r|j
                  j                  nd}t        j                  |d¬«      5  |j                  «       |j                  «       z  j                  dd«      }t        j                  ||fd¬	«      }|j                  «       | j                  z  }|j                  «       | j                  z  }	d d d «       j	                  |j                   ¬
«      	j	                  |j                   ¬
«      fS # 1 sw Y   ŒAxY w)Nr   r:   r!   Úmpsrþ  F)Údevice_typeÚenabledr9   re   ró  )r  Úfloatry   rH   r=   rÿ  r­  r  Ústrr.   Úautocastr�   rg   ro   r%  rp   r<   )
r2   rb   rq   Úinv_freq_expandedÚposition_ids_expandedr*  ÚfreqsÚembro   rp   s
             r6   rE   zEmu3RotaryEmbedding.forwardÌ  sV  € ð !ŸM™M¨$²°4¨-Ñ8×>Ñ>Ó@×GÑGÈ×HZÑHZÐ[\ÑH]Ð_aÐcdÓe×hÑhÐij×iqÑiqÓrÐØ ,ªQ°²a¨ZÑ 8× >Ñ >Ó @Ðä'1°!·(±(·-±-ÄÔ'EÈ!Ï(É(Ï-É-Ð[`ÒJ`�a—h‘h—m’mÐfkˆÜ�^‰^¨¸UÔCñ 	5Ø&×,Ñ,Ó.Ð1F×1LÑ1LÓ1NÑN×YÑYÐZ[Ð]^Ó_ˆEÜ—)‘)˜U E˜N°Ô3ˆCØ—'‘'“)˜d×4Ñ4Ñ4ˆCØ—'‘'“)˜d×4Ñ4Ñ4ˆC÷		5ð �v‰v˜AŸG™GˆvÓ$ c§f¡f°1·7±7 fÓ&;Ð;Ð;÷	5ð 	5ús   Ã BF%Æ%F.ra   )
rL   rM   rN   r"   r+   r.   Úno_gradr   rE   rO   rP   s   @r6   r  r  º  s3   ø„ ñ/˜zõ /ð" €U‡]�]ƒ_Øñ<ó ó ô<r7   r  aÖ  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
            it.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

            [What are attention masks?](../glossary#attention-mask)

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
            `past_key_values`).

            If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
            and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
            information on the default strategy.

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.
        position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.n_positions - 1]`.

            [What are position IDs?](../glossary#position-ids)
        past_key_values (`Cache`, *optional*):
            Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
            blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
            returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.

            Has to be an instance of [`~cache_utils.Cache`] instance, see our
            [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

            The model will output the same cache type that is fed as input. If no `past_key_values` are passed, the
            legacy cache format will be returned.

            If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
            have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
            of shape `(batch_size, sequence_length)`.
        inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
            is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
            model's internal embedding lookup matrix.
        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
            Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
            this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
            the complete sequence length.
zVThe bare Emu3Text Model outputting raw hidden-states without any specific head on top.c                   ó  ‡ — e Zd ZdZdefˆ fd„Zd„ Zd„ Ze e	e
«      	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej                     d	ee   d
eej                      dee   dee   dee   deej                     dee   defd„«       «       Z	 ddej                  dej                  dej                  d	edef
d„Zedej                  dededej2                  dej4                  dej                  defd„«       Zˆ xZS )ÚEmu3TextModelz¡
    Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Emu3TextDecoderLayer`]

    Args:
        config: Emu3TextConfig
    rV   c           	      ó  •— t         ‰| �  |«       |j                  | _        |j                  | _        t        j                  |j                  |j                  | j                  «      | _        t        j                  t        |j                  «      D �cg c]  }t        ||«      ‘Œ c}«      | _        t        |j                  |j                  ¬«      | _        t#        |¬«      | _        d| _        | j)                  «        y c c}w )NrÄ   )rV   F)r*   r+   Úpad_token_idr  Ú
vocab_sizer,   rÖ   r3   Úembed_tokensrk  rm  Únum_hidden_layersrÂ   Úlayersr(   rÇ   Únormr  Ú
rotary_embÚgradient_checkpointingrÁ  r§   s      €r6   r+   zEmu3TextModel.__init__/  sÆ   ø€ Ü‰Ñ˜Ô Ø!×.Ñ.ˆÔØ ×+Ñ+ˆŒäŸL™L¨×):Ñ):¸F×<NÑ<NÐPT×P`ÑP`ÓaˆÔÜ—m‘mÜBGÈ×H`ÑH`ÓBaÖb°YÔ˜f iÕ0Òbó
ˆŒô   × 2Ñ 2¸×8KÑ8KÔLˆŒ	Ü-°VÔ<ˆŒØ&+ˆÔ#ð 	�‰Õùò cs   ÂDc                 ó   — | j                   S ra   ©r9  rI   s    r6   Úget_input_embeddingsz"Emu3TextModel.get_input_embeddings?  s   € Ø× Ñ Ð r7   c                 ó   — || _         y ra   r@  ©r2   rƒ   s     r6   Úset_input_embeddingsz"Emu3TextModel.set_input_embeddingsB  s
   € Ø!ˆÕr7   Ú	input_idsr„   rq   r  Úinputs_embedsrË   r®   Úoutput_hidden_statesrª   Úflash_attn_kwargsrw   c
                 ó^  — |�|n| j                   j                  }|�|n| j                   j                  }|�|n| j                   j                  }|d u |d uz  rt	        d«      ‚| j
                  r%| j                  r|rt        j                  d«       d}t        |t        d «      t        f«      st	        d«      ‚|€| j                  |«      }|r|€
t        «       }|	€F|�|j                  «       nd}t        j                   |||j"                  d   z   |j$                  ¬«      }	|€|	j'                  d«      }| j)                  |||	||«      }|}| j+                  ||«      }|rdnd }|rdnd }| j,                  d | j                   j.                   D ]r  }|r||fz  }| j
                  r:| j                  r.| j1                  t3        |j4                  fi |
¤Ž|||||||	|«	      }n ||f||||||	|d	œ|
¤Ž}|d   }|sŒj||d   fz  }Œt | j7                  |«      }|r||fz  }t9        ||r|nd ||¬
«      S )Nz:You must specify exactly one of input_ids or inputs_embedszX`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`.FzBThe `past_key_values` should be either a `Cache` object or `None`.r   r!   ©rÿ  rÍ   )r„   rq   r©   r®   rË   rª   r¨   )Úlast_hidden_stater  rB   Ú
attentions)rV   r®   rG  rË   rJ  r>  rŠ   rµ   r¶   r­  r  r   r9  r   Úget_seq_lengthr.   ÚarangerH   rÿ  rl   Ú_update_causal_maskr=  r;  r:  Ú_gradient_checkpointing_funcr   Ú__call__r<  r   )r2   rE  r„   rq   r  rF  rË   r®   rG  rª   rH  Úpast_seen_tokensr•   rB   r¨   Úall_hidden_statesÚall_self_attnsÚdecoder_layerÚlayer_outputss                      r6   rE   zEmu3TextModel.forwardE  s£  € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	à˜Ð -°tÐ";Ò<ÜÐYÓZÐZà×&Ò&¨4¯=ª=¹YÜ×ÑØjôð ˆIô ˜/¬D°«J¼Ð+>Ô?ÜÐaÓbÐbàÐ Ø ×-Ñ-¨iÓ8ˆMá˜Ð0Ü*›nˆOàÐ!ØCRÐC^˜×=Ñ=Ô?ÐdeÐÜ"Ÿ\™\Ø Ð"2°]×5HÑ5HÈÑ5KÑ"KÐTa×ThÑThôˆNð ÐØ)×3Ñ3°AÓ6ˆLà×.Ñ.Ø˜M¨>¸?ÐL]ó
ˆð &ˆð #Ÿo™o¨m¸\ÓJÐñ #7™B¸DÐÙ0™°dˆà!Ÿ[™[Ð)H¨4¯;©;×+HÑ+HÐIò  	6ˆMÙ#Ø! mÐ%5Ñ5Ð!à×*Ò*¨t¯}ª}Ø $× AÑ AÜ˜M×2Ñ2ÑHÐ6GÑHØ!ØØ Ø#Ø%ØØ"Ø'ó
!‘ñ !.Ø!ð
!à#.Ø!-Ø#2Ø&7Ø'Ø#1Ø(;ñ
!ð (ñ
!�ð *¨!Ñ,ˆMâ Ø =°Ñ#3Ð"5Ñ5‘ðA 	6ðD Ÿ	™	 -Ó0ˆñ  Ø -Ð!1Ñ1Ðä&Ø+Ù/8™O¸dØ+Ø%ô	
ð 	
r7   Úinput_tensorc           
      óÆ  — | j                   j                  dk(  r|�|dk(  j                  «       r|S y | j                   j                  dk(  r7t        |t        j
                  «      rt        |«      }t        |t        «      r|S |�|j                  «       nd}t        |t        «      }| j                   j                  dk(  r(|s&|s$t        j                  |||| j                  ¬«      ry |j                  |j                  }	}|j                  d   }
|r|j!                  «       }n1t        |t        j
                  «      r|j                  d   n||
z   dz   }| j#                  ||
|||	||j                  d   ¬	«      }| j                   j                  dk(  rQ|�O|j                  j$                  d
v r7|s5t	        j&                  |«      j(                  }t        j*                  ||«      }|S )NÚflash_attention_2r°   Úflex_attentionr   r­   )rF  Úpast_key_values_lengthÚis_trainingr!   r:   )Úsequence_lengthÚtarget_lengthr<   rÿ  rª   râ   )ÚcudaÚxpu)rV   r³   Úanyr­  r.   r¿   r&   r%   rM  r   r   Ú_ignore_causal_mask_sdparŠ   r<   rÿ  rH   Úget_max_cache_shapeÚ5_prepare_4d_causal_attention_mask_with_cache_positionr  ÚfinfoÚminÚ_unmask_unattended)r2   r„   rW  rª   r  r®   rR  Úusing_static_cacher<   rÿ  r]  r^  r•   Ú	min_dtypes                 r6   rO  z!Emu3TextModel._update_causal_mask²  sÖ  € ð �;‰;×+Ñ+Ð/BÒBØÐ)¨~ÀÑ/D×.IÑ.IÔ.KØ%Ð%ØØ�;‰;×+Ñ+Ð/?Ò?Ü˜.¬%¯,©,Ô7Ü!<¸^Ó!L�Ü˜.¬)Ô4Ø%Ð%ð
 @OÐ?Z˜?×9Ñ9Ô;Ð`aÐÜ'¨¼ÓEÐð �;‰;×+Ñ+¨vÒ5Ñ>PÑYjÜ%×>Ñ>ØØ*Ø'7Ø ŸM™Mõ	ð à$×*Ñ*¨L×,?Ñ,?ˆvˆØ&×,Ñ,¨QÑ/ˆÙØ+×?Ñ?ÓA‰Mô ˜n¬e¯l©lÔ;ð ×$Ñ$ RÒ(à%¨Ñ7¸!Ñ;ð ð ×PÑPØØ+Ø'ØØØ)Ø#×)Ñ)¨!Ñ,ð Qó 
ˆð �K‰K×,Ñ,°Ò6ØÐ*Ø×%Ñ%×*Ñ*¨oÑ=Ù%ô
 Ÿ™ EÓ*×.Ñ.ˆIÜ0×CÑCÀKÐQZÓ[ˆKàÐr7   r]  r^  r<   rÿ  râ   c                 ó˜  — | �| j                  «       dk(  r| }|S t        j                  |«      j                  }	t        j                  ||f|	||¬«      }|dk7  rt        j
                  |d¬«      }|t        j                  ||¬«      |j                  dd«      kD  z  }|dddd…dd…f   j                  |ddd«      }| �Œ|j                  «       }| j                  d   }
|dd…dd…dd…d|
…f   | dd…dddd…f   j                  |j                  «      z   }|dk(  }|dd…dd…dd…d|
…f   j                  ||	«      |dd…dd…dd…d|
…f<   |S )	a°  
        Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
        `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.

        Args:
            attention_mask (`torch.Tensor`):
                A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape
                `(batch_size, 1, query_length, key_value_length)`.
            sequence_length (`int`):
                The sequence length being processed.
            target_length (`int`):
                The target length: when generating with static cache, the mask should be as long as the static cache,
                to account for the 0 padding, the part of the cache that is not filled yet.
            dtype (`torch.dtype`):
                The dtype to use for the 4D attention mask.
            device (`torch.device`):
                The device to place the 4D attention mask on.
            cache_position (`torch.Tensor`):
                Indices depicting the position of the input sequence tokens in the sequence.
            batch_size (`torch.Tensor`):
                Batch size.
        NrÞ   )Ú
fill_valuer<   rÿ  r!   )ÚdiagonalrJ  r:   r   )rf   r.   re  rf  ÚfullÚtriurN  rz   ry   ÚclonerH   r=   rÿ  Úmasked_fill)r„   r]  r^  r<   rÿ  rª   râ   r‘   r•   ri  Úmask_lengthÚpadding_masks               r6   rd  zCEmu3TextModel._prepare_4d_causal_attention_mask_with_cache_positionø  sy  € ðB Ð%¨.×*<Ñ*<Ó*>À!Ò*Cà(ˆKð* Ðô' Ÿ™ EÓ*×.Ñ.ˆIÜŸ*™*Ø  -Ð0¸YÈeÐ\bôˆKð  !Ò#Ü#Ÿj™j¨¸qÔA�Øœ5Ÿ<™<¨¸fÔEÈ×H^ÑH^Ð_aÐcdÓHeÑeÑeˆKØ% d¨D²!²QÐ&6Ñ7×>Ñ>¸zÈ1ÈbÐRTÓUˆKØÐ)Ø)×/Ñ/Ó1�Ø,×2Ñ2°2Ñ6�Ø*ª1ªa²°L°[°LÐ+@ÑAÀNÒSTÐVZÐ\`ÒbcÐScÑDd×DgÑDgØ×&Ñ&óEñ  �ð  ,¨qÑ0�Ø5@ÂÂAÂqÈ,È;È,ÐAVÑ5W×5cÑ5cØ  )ó6�šAšq¢! \ k \Ð1Ñ2ð Ðr7   )	NNNNNNNNN)F)rL   rM   rN   r½   r"   r+   rA  rD  r   r   ÚEMU3_TEXT_INPUTS_DOCSTRINGr   r.   rÀ   r¿   r   rÒ   rÑ   r   r   r   rE   rO  Ústaticmethodr¾   r<   rÿ  rd  rO   rP   s   @r6   r5  r5  #  sÖ  ø„ ñ
ð˜zõ ò !ò"ð Ù*Ð+EÓFð 15Ø15Ø37Ø+/Ø59Ø$(Ø,0Ø/3Ø59ñi
à˜E×,Ñ,Ñ-ði
ð ! §¡Ñ.ði
ð ˜u×/Ñ/Ñ0ð	i
ð
 " %™ði
ð   × 1Ñ 1Ñ2ði
ð ˜D‘>ði
ð $ D™>ði
ð ' t™nði
ð ! ×!1Ñ!1Ñ2ði
ð $Ð$8Ñ9ði
ð 
!òi
ó Gó ði
ðb #(ñDàŸ™ðDð —l‘lðDð Ÿ™ð	Dð
 ðDð  óDðL ð7ØŸ™ð7àð7ð ð7ð �{‰{ð	7ð
 —‘ð7ð Ÿ™ð7ð ò7ó ô7r7   r5  c                   ó   — e Zd Zy)ÚKwargsForCausalLMN)rL   rM   rN   rÍ   r7   r6   rv  rv  3  s   … r7   rv  c                   óæ  ‡ — e Zd ZdgZddiZddgdgfiZeZˆ fd„Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Ze eddd¬«       ee«       eed¬«      	 	 	 	 	 	 	 	 	 	 	 d deej.                     deej0                     deej.                     dee   deej4                     deej.                     dee   dee   dee   deej.                     deeej0                  f   dee   defd„«       «       «       «       Z ˆ xZ!S )!ÚEmu3ForCausalLMzlm_head.weightÚlm_headÚcolwise_reprB   Úlogitsc                 óè   •— t         ‰| �  |«       t        |«      | _        |j                  | _        t        j                  |j                  |j                  d¬«      | _        | j                  «        y )NFrT   )
r*   r+   r5  r  r8  r,   rX   r3   ry  rÁ  r_   s     €r6   r+   zEmu3ForCausalLM.__init__<  sU   ø€ Ü‰Ñ˜Ô Ü" 6Ó*ˆŒ
Ø ×+Ñ+ˆŒÜ—y‘y ×!3Ñ!3°V×5FÑ5FÈUÔSˆŒð 	�‰Õr7   c                 ó.   — | j                   j                  S ra   ©r  r9  rI   s    r6   rA  z$Emu3ForCausalLM.get_input_embeddingsE  s   € Ø�z‰z×&Ñ&Ð&r7   c                 ó&   — || j                   _        y ra   r~  rC  s     r6   rD  z$Emu3ForCausalLM.set_input_embeddingsH  s   € Ø"'ˆ�
‰
Õr7   c                 ó   — | j                   S ra   ©ry  rI   s    r6   Úget_output_embeddingsz%Emu3ForCausalLM.get_output_embeddingsK  s   € Ø�|‰|Ðr7   c                 ó   — || _         y ra   r�  )r2   Únew_embeddingss     r6   Úset_output_embeddingsz%Emu3ForCausalLM.set_output_embeddingsN  s	   € Ø%ˆ�r7   c                 ó   — || _         y ra   ©r  )r2   rº  s     r6   Úset_decoderzEmu3ForCausalLM.set_decoderQ  s	   € Øˆ�
r7   c                 ó   — | j                   S ra   r‡  rI   s    r6   Úget_decoderzEmu3ForCausalLM.get_decoderT  s   € Ø�z‰zÐr7   Únum_logits_to_keepz4.50Úlogits_to_keep)ÚversionÚnew_namer#   ©Úoutput_typerÒ  rE  r„   rq   r  rF  ÚlabelsrË   r®   rG  rª   r‘   rw   c                 óæ  — |�|n| j                   j                  }|	�|	n| j                   j                  }	 | j                  d||||||||	|
dœ	|¤Ž}|j                  }t        |t        «      rt        | d«      n|}| j                  |dd…|dd…f   «      }d}|�* | j                  d||| j                   j                  dœ|¤Ž}t        |||j                  |j                  |j                  ¬«      S )a  
            labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
                config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
                (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.

            logits_to_keep (`int` or `torch.Tensor`, *optional*):
                If an `int`, compute logits for the last `logits_to_keep` tokens. If `0`, calculate logits for all
                `input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
                token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
                If a `torch.Tensor`, must be 1D corresponding to the indices to keep in the sequence length dimension.
                This is useful when using packed tensor format (single dimension for batch and sequence length).

        Returns:

        Example:

        ```python
        >>> from transformers import Emu3Processor, Emu3ForConditionalGeneration
        >>> import torch
        >>> import requests
        >>> from PIL import Image

        >>> model = Emu3ForCausalLM.from_pretrained("BAAI/Emu3-Chat-hf", torch_dtype=torch.bfloat16)
        >>> processor = Emu3Processor.from_pretrained("BAAI/Emu3-Chat-hf")

        >>> inputs = processor(text=["Can you write me a poem about winter."], return_tensors="pt").to(model.device)

        >>> generated_ids = model.generate(**inputs, max_new_tokens=100, do_sample=False)
        >>> processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
        ```N)	rE  r„   rq   r  rF  rË   r®   rG  rª   )r{  r‘  r8  )Úlossr{  r  rB   rL  rÍ   )rV   r®   rG  r  rK  r­  r¾   Úslicery  Úloss_functionr8  r   r  rB   rL  )r2   rE  r„   rq   r  rF  r‘  rË   r®   rG  rª   rŒ  r‘   rÐ   rB   Úslice_indicesr{  r“  s                     r6   rE   zEmu3ForCausalLM.forwardW  s  € ðd 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð
 ,6¨4¯:©:ð ,
ØØ)Ø%Ø+Ø'ØØ/Ø!5Ø)ñ,
ð ñ,
ˆð  ×1Ñ1ˆä8BÀ>ÔSVÔ8Wœ˜~˜o¨tÔ4Ð]kˆØ—‘˜mªA¨}ºaÐ,?Ñ@ÓAˆàˆØÐØ%�4×%Ñ%Ðp¨V¸FÈtÏ{É{×OeÑOeÑpÐioÑpˆDä%ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r7   )NNNNNNNNNNr   )"rL   rM   rN   Ú_tied_weights_keysÚ_tp_planÚ_pp_planr#   rÒ  r+   rA  rD  r‚  r…  rˆ  rŠ  r   r    r   rs  r   r   r   r.   rÀ   r¿   r   rÒ   rÑ   r	   r¾   r   rv  rE   rO   rP   s   @r6   rx  rx  6  s±  ø„ Ø*Ð+ÐØ˜=Ð)€HØ˜_Ð-°¨zÐ:Ð;€HØ!€Lôò'ò(òò&òòð ÙÐ)°6ÐDTÔUÙ*Ð+EÓFÙÐ+AÐP`Ôað 15Ø15Ø37Ø+/Ø59Ø-1Ø$(Ø,0Ø/3Ø59Ø34ñP
à˜E×,Ñ,Ñ-ðP
ð ! §¡Ñ.ðP
ð ˜u×/Ñ/Ñ0ð	P
ð
 " %™ðP
ð   × 1Ñ 1Ñ2ðP
ð ˜×)Ñ)Ñ*ðP
ð ˜D‘>ðP
ð $ D™>ðP
ð ' t™nðP
ð ! ×!1Ñ!1Ñ2ðP
ð ˜c 5§<¡<Ð/Ñ0ðP
ð Ð*Ñ+ðP
ð 
 òP
ó bó Gó Vó ôP
r7   rx  aò  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
            it.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        pixel_values (`torch.FloatTensor` of shape `(batch_size, max_num_images, max_num_tiles, channels, image_size, image_size)):
            The tensors corresponding to the input images. Pixel values can be obtained using
            [`AutoImageProcessor`]. See [`Emu3ImageProcessor.__call__`] for details ([]`Emu3Processor`] uses
            [`Emu3ImageProcessor`] for processing images).
        image_sizes (`torch.LongTensor` of shape `(batch_size, 2)`):
                The sizes of the images in the batch, being (height, width) for each image. Image sizes can be obtained using
            [`AutoImageProcessor`]. See [`Emu3ImageProcessor.__call__`] for details ([]`Emu3Processor`] uses
            [`Emu3ImageProcessor`] for processing images).
        attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
            Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

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

            [What are attention masks?](../glossary#attention-mask)

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
            `past_key_values`).

            If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
            and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
            information on the default strategy.

            - 1 indicates the head is **not masked**,
            - 0 indicates the head is **masked**.
        position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
            Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
            config.n_positions - 1]`.

            [What are position IDs?](../glossary#position-ids)
        past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
            Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
            blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
            returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.

            Has to be an instance of [`~cache_utils.Cache`] instance, see our
            [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

            The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
            legacy cache format will be returned.

            If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
            have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
            of shape `(batch_size, sequence_length)`.
        inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
            Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
            is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
            model's internal embedding lookup matrix.
        use_cache (`bool`, *optional*):
            If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
            `past_key_values`).
        output_attentions (`bool`, *optional*):
            Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
            tensors for more detail.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
        cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
            Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
            this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
            the complete sequence length.
c                    óh  ‡ — e Zd ZdgZdZˆ fd„Zd„ Zd„ Zdej                  dej                  fd„Zej                  d	ej                  d
edefd„«       Ze ee«       eee¬«      	 	 	 	 	 	 	 	 	 	 	 	 	 ddeej                     deej                     deej,                     deej,                     deej                     dee   deej                     dee   dee   dee   deej                     deej                     deeej,                  f   defd„«       «       «       Z	 	 	 	 	 	 	 dˆ fd„	Zˆ xZS )ÚEmu3ForConditionalGenerationztext_model.lm_head.weightFc                 óô   •— t         ‰| �  |«       t        j                  |j                  «      | _        t        |j                  «      | _        t        |j                  «      | _        | j                  «        y ra   )r*   r+   rx  Ú_from_configÚtext_configÚ
text_modelr¥  Ú	vq_configÚvqmodelrÚ  Úvocabulary_mapÚvocabulary_mappingrÁ  r_   s     €r6   r+   z%Emu3ForConditionalGeneration.__init__  sY   ø€ Ü‰Ñ˜Ô Ü)×6Ñ6°v×7IÑ7IÓJˆŒÜ  ×!1Ñ!1Ó2ˆŒÜ"<¸V×=RÑ=RÓ"SˆÔð 	�‰Õr7   c                 ó6   — | j                   j                  «       S ra   )rŸ  rA  rI   s    r6   rA  z1Emu3ForConditionalGeneration.get_input_embeddings
  s   € Ø�‰×3Ñ3Ó5Ð5r7   c                 ó:   — | j                   j                  |«       y ra   )rŸ  rD  rC  s     r6   rD  z1Emu3ForConditionalGeneration.set_input_embeddings  s   € Ø�‰×,Ñ,¨UÕ3r7   r˜  rÂ  c                 óÞ   — | j                   j                  ||«      }|D �cg c]+  }| j                  j                  |«      j	                  «       ‘Œ- }}t        j                  |«      }|S c c}w )a  
        Tokenizes images into discrete tokens with VQGAN module. Converts
        obtained image tokens into BPE tokens and wraps with "boi" and "eoi"
        special tokens.

        Args:
            pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
                The tensors corresponding to the input images.
            image_sizes (`torch.LongTensor` of shape `(batch_size, 2)`):
                The sizes of the images in the batch, being (height, width) for each image.
        )r¡  rË  r£  r  rÍ  r.   rg   )r2   r˜  rÂ  Úimage_tokens_listÚtokensÚbpe_tokens_listÚ
bpe_tokenss          r6   Úget_image_tokensz-Emu3ForConditionalGeneration.get_image_tokens  sc   € ð !ŸL™L×/Ñ/°¸kÓJÐØctÖuÐY_˜4×2Ñ2×BÑBÀ6ÓJ×RÑRÕTÐuˆÐuÜ—Y‘Y˜Ó/ˆ
ØÐùò vs   ¡0A*rÉ  rå   ræ   c                 ó°   — |dd…dd…f   j                  d||dz   «      }| j                  j                  |«      }| j                  j	                  |«      }|S )aå  
        Decodes generated image tokens from language model to continuous pixel values
        with VQGAN module via upsampling.

        Args:
            image_tokens (`torch.LongTensor` of shape `(batch_size, num_of_tokens)`):
                The tensors corresponding to the input images.
            height (`int`):
                Height of the generated image before upsampling.
            width (`int`):
                Width of the generated image before upsampling.
        Néýÿÿÿr:   r!   )r±   r£  r  r¡  rÑ  )r2   rÉ  rå   ræ   Ú	sequencesÚimages         r6   Údecode_image_tokensz0Emu3ForConditionalGeneration.decode_image_tokens!  sX   € ð !¢ C R C Ñ(×-Ñ-¨b°&¸%À!¹)ÓDˆ	Ø×.Ñ.×>Ñ>¸yÓIˆØ—‘×#Ñ# LÓ1ˆØˆr7   r�  rE  r„   rq   r  rF  rË   r®   rG  rª   r‘  rŒ  rw   c                 ó°  — |	�|	n| j                   j                  }	|
�|
n| j                   j                  }
|du |duz  rt        d«      ‚|�|�t        d«      ‚|�c| j	                  ||«      }|| j
                  j                  k(  }|j                  |j                  |j                  «      }|j                  ||«      }| j                  |||||||	|
||¬«
      S )aÃ	  
            labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
                Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
                config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
                (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.

            logits_to_keep (`int` or `torch.Tensor`, *optional*):
                If an `int`, compute logits for the last `logits_to_keep` tokens. If `0`, calculate logits for all
                `input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
                token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
                If a `torch.Tensor`, must be 1D corresponding to the indices to keep in the sequence length dimension.
                This is useful when using packed tensor format (single dimension for batch and sequence length).

        Returns:

        Example:

        ```python
        >>> from transformers import Emu3Processor, Emu3ForConditionalGeneration
        >>> import torch
        >>> import requests
        >>> from PIL import Image

        >>> model = Emu3ForConditionalGeneration.from_pretrained("BAAI/Emu3-Chat-hf", torch_dtype=torch.bfloat16)
        >>> processor = Emu3Processor.from_pretrained("BAAI/Emu3-Chat-hf")

        >>> conversation = [
        ...     {
        ...     "role": "system",
        ...     "content": [
        ...         {"type": "text", "text": "You are a helpful assistant."},
        ...         ],
        ...     },
        ...     {
        ...     "role": "user",
        ...     "content": [
        ...         {"type": "image"},
        ...         {"type": "text", "text": "Please describe the image."},
        ...         ],
        ...     },
        ... ]

        >>> prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
        >>> image = Image.open(requests.get("https://www.ilankelman.org/stopsigns/australia.jpg", stream=True).raw)

        >>> inputs = processor(images=[image], text=[prompt], return_tensors="pt").to(model.device, torch.bfloat16)

        >>> generated_ids = model.generate(**inputs, max_new_tokens=100, do_sample=False)
        >>> processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
        ```NzaYou cannot specify both input_ids and inputs_embeds at the same time, and must specify either onezdYou cannot specify both pixel_values and inputs_embeds at the same time, and must specify either one)
rE  r„   rq   r  rF  rË   r®   rG  rª   rŒ  )rV   r®   rG  rJ  r«  r£  rÞ  r=   rÿ  r<   Úmasked_scatterrŸ  )r2   rE  r˜  rÂ  r„   rq   r  rF  rË   r®   rG  rª   r‘  rŒ  rÉ  Úspecial_image_masks                   r6   rE   z$Emu3ForConditionalGeneration.forward4  s  € ðJ 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð ˜Ð -°tÐ";Ò<ÜØsóð ð Ð#¨Ð(AÜØvóð ð Ð#Ø×0Ñ0°¸{ÓKˆLØ!*¨d×.EÑ.E×.TÑ.TÑ!TÐØ'Ÿ?™?¨9×+;Ñ+;¸Y¿_¹_ÓMˆLØ!×0Ñ0Ð1CÀ\ÓRˆIð �‰ØØ)Ø%Ø+Ø'ØØ/Ø!5Ø)Ø)ð ó 
ð 	
r7   c	                 óR   •— t        ‰| �  |f|||||||dœ|	¤Ž}
|d   dk7  rd |
d<   |
S )N)r  r„   rF  rª   rq   r˜  rË   r   r˜  )r*   Úprepare_inputs_for_generation)r2   rE  r  r„   rF  rª   rq   rË   r˜  r‘   Úmodel_inputsr5   s              €r6   rµ  z:Emu3ForConditionalGeneration.prepare_inputs_for_generationœ  sZ   ø€ ô ‘wÑ<Øð

à+Ø)Ø'Ø)Ø%Ø%Øñ

ð ñ

ˆð ˜!Ñ Ò!Ø+/ˆL˜Ñ(àÐr7   )NNNNNNNNNNNNr   )NNNNNTN)rL   rM   rN   r—  r  r+   rA  rD  r.   rÒ   rÀ   r«  r3  r¾   r°  r   r   ÚEMU3_INPUTS_DOCSTRINGr   r   Ú_CONFIG_FOR_DOCr   r¿   r   rÑ   r	   rE   rµ  rO   rP   s   @r6   r›  r›  ý  s   ø„ Ø5Ð6ÐØ"Ðôò6ò4ð¨U×->Ñ->ð ÈU×M]ÑM]ó ð" ‡]�]ð°×0@Ñ0@ð È#ð ÐVYò ó ðð$ Ù*Ð+@ÓAÙÐ+AÐP_Ô`ð 15Ø48Ø.2Ø15Ø37Ø+/Ø59Ø$(Ø,0Ø/3Ø59Ø-1Ø34ñc
à˜E×,Ñ,Ñ-ðc
ð ˜u×0Ñ0Ñ1ðc
ð ˜eŸl™lÑ+ð	c
ð
 ! §¡Ñ.ðc
ð ˜u×/Ñ/Ñ0ðc
ð " %™ðc
ð   × 1Ñ 1Ñ2ðc
ð ˜D‘>ðc
ð $ D™>ðc
ð ' t™nðc
ð ! ×!1Ñ!1Ñ2ðc
ð ˜×)Ñ)Ñ*ðc
ð ˜c 5§<¡<Ð/Ñ0ðc
ð 
 òc
ó aó Bó ðc
ðP ØØØØØØ÷ñ r7   r›  )r›  rx  r5  r  r¥  )Nr!   )r°   )gr�  Ú	functoolsr   r   Útypingr   r   r   r   r	   r.   Útorch.nnr,   Útorch.nn.functionalrŽ   rý   Úactivationsr   Úcache_utilsr   r   r   Ú
generationr   Úmodeling_attn_mask_utilsr   Úmodeling_flash_attention_utilsr   Úmodeling_outputsr   r   Úmodeling_rope_utilsr   r   Úmodeling_utilsr   r   Úprocessing_utilsr   Úutilsr   r   r   r   r   r   r   Úutils.deprecationr    Úconfiguration_emu3r"   r#   r$   Ú!torch.nn.attention.flex_attentionr%   Úintegrations.flex_attentionr&   Ú
get_loggerrL   rµ   r¸  rp  r(   rR   rj   ru   r¿   r¾   r   r,  r—   r™   rÂ   rÔ   rí   r   r	  r  r'  r1  r5  r@  rG  r  rS  rY  rb  r~  r†  r�  ÚEMU3_VQ_START_DOCSTRINGr¥  rÚ  ÚEMU3_START_DOCSTRINGr  r  rs  r5  rv  rx  r·  r›  Ú__all__rÍ   r7   r6   ú<module>rÏ     sg  ðó. ß .ß 9Õ 9ã Ý ß Ð å !ß ;Ñ ;Ý )Ý >Ý Bß Oß Kß FÝ &÷÷ ñ õ 1ß KÑ Kñ  Ô!Ý;åJð 
ˆ×	Ñ	˜HÓ	%€ð €ôJ�"—)‘)ô Jô(ˆb�i‰iô ò (óð6	U˜UŸ\™\ð 	U°#ð 	U¸%¿,¹,ó 	Uð& ñ%Ø�I‰Ið%à�<‰<ð%ð 
�‰ð%ð �<‰<ð	%ð
 ˜UŸ\™\Ñ*ð%ð ð%ð ó%ô4I)�B—I‘Iô I)ôXH�r—y‘yô HôV$˜rŸy™yô $ôD	 R§Y¡Yô 	ô 2§9¡9ô ô�b—i‘iô ô:!˜2Ÿ9™9ô !ôH §	¡	ô ô. "§)¡)ô ô&.( 2§9¡9ô .(ôb<(˜2Ÿ9™9ô <(ô~G)˜bŸi™iô G)ôTV˜Ÿ™ô Vô˜2Ÿ9™9ô ôD8˜Ÿ™ô 8ôv7�r—y‘yô 7ôtC�r—y‘yô CôLC�r—y‘yô CðLÐ ñ" ðð óôc2�ó c2óðc2÷L3%ñ 3%ðlÐ ñ" ØXØóô?˜/ó ?ó	ð?ô<<˜"Ÿ)™)ô <ðDDÐ ñN Ø\ØóôIÐ'ó Ió	ðIôX ?Ð,¨jÔ >ôu
Ð)¨?ô u
ðpLÐ ô^|Ð#6¸ô |ò~ s�r7   