Ë
    T^(hÁî  ã                   óà  — d dl mZ d dlmZmZmZmZmZ d dlZd dl	m
c mZ d dlm
Z
 ddlmZ ddlmZ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mZmZmZ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/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5  e0jl                  e7«      Z8dZ9dZ: G d„ de
jv                  «      Z< G d„ de
jv                  «      Z= G d„ de
jv                  «      Z>d„ Z?dFd„Z@dej‚                  deBdej‚                  fd „ZC	 dGd!e
jv                  d"ej‚                  d#ej‚                  d$ej‚                  d%eej‚                     d&eDd'eDfd(„ZE G d)„ d*e
jv                  «      ZF G d+„ d,e
jv                  «      ZG G d-„ d.e
jv                  «      ZHd/ZI e-d0eI«       G d1„ d2e'«      «       ZJd3ZK e-d0eI«       G d4„ d5eJ«      «       ZL G d6„ d7ee+«      ZM	 	 	 dHd8eej‚                  eej‚                     df   d9eeB   d%eej‚                     deej‚                  eBf   fd:„ZN G d;„ d<eJe«      ZO e-d=eI«       G d>„ d?eJ«      «       ZP e-d@eI«       G dA„ dBeJ«      «       ZQ e-dCeI«       G dD„ dEeJ«      «       ZRy)Ié    )Úpartial)ÚCallableÚListÚOptionalÚTupleÚUnionN)Únné   )ÚACT2FN)ÚCacheÚDynamicCacheÚSlidingWindowCacheÚStaticCache)ÚGenerationMixin)ÚAttentionMaskConverter)ÚFlashAttentionKwargs)ÚBaseModelOutputWithPastÚCausalLMOutputWithPastÚMoeCausalLMOutputWithPastÚMoeModelOutputWithPastÚQuestionAnsweringModelOutputÚ SequenceClassifierOutputWithPastÚTokenClassifierOutput)ÚROPE_INIT_FUNCTIONSÚdynamic_rope_update)ÚALL_ATTENTION_FUNCTIONSÚPreTrainedModel)ÚUnpack)Ú
LossKwargsÚadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚcan_return_tupleÚloggingÚreplace_return_docstrings)Údeprecate_kwargé   )ÚMixtralConfigzmistralai/Mixtral-8x7B-v0.1r(   c                   ó*   ‡ — e Zd Zdefˆ fd„Zd„ Zˆ xZS )ÚMixtralBlockSparseTop2MLPÚconfigc                 ó¼  •— t         ‰| �  «        |j                  | _        |j                  | _        t        j                  | j
                  | j                  d¬«      | _        t        j                  | j                  | j
                  d¬«      | _	        t        j                  | j
                  | j                  d¬«      | _
        t        |j                     | _        y ©NF©Úbias)ÚsuperÚ__init__Úintermediate_sizeÚffn_dimÚhidden_sizeÚ
hidden_dimr	   ÚLinearÚw1Úw2Úw3r   Ú
hidden_actÚact_fn©Úselfr+   Ú	__class__s     €új/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/mixtral/modeling_mixtral.pyr1   z"MixtralBlockSparseTop2MLP.__init__G   sŽ   ø€ Ü‰ÑÔØ×/Ñ/ˆŒØ ×,Ñ,ˆŒä—)‘)˜DŸO™O¨T¯\©\ÀÔFˆŒÜ—)‘)˜DŸL™L¨$¯/©/ÀÔFˆŒÜ—)‘)˜DŸO™O¨T¯\©\ÀÔFˆŒä˜V×.Ñ.Ñ/ˆ�ó    c                 óŒ   — | j                  | j                  |«      «      | j                  |«      z  }| j                  |«      }|S ©N)r;   r7   r9   r8   )r=   Úhidden_statesÚcurrent_hidden_statess      r?   Úforwardz!MixtralBlockSparseTop2MLP.forwardR   s>   € Ø $§¡¨D¯G©G°MÓ,BÓ CÀdÇgÁgÈmÓF\Ñ \ÐØ $§¡Ð(=Ó >ÐØ$Ð$r@   )Ú__name__Ú
__module__Ú__qualname__r(   r1   rE   Ú__classcell__©r>   s   @r?   r*   r*   F   s   ø„ ð	0˜}õ 	0ö%r@   r*   c                   óZ   ‡ — e Zd ZdZˆ fd„Zdej                  dej                  fd„Zˆ xZS )ÚMixtralSparseMoeBlockaÈ  
    This implementation is
    strictly equivalent to standard MoE with full capacity (no
    dropped tokens). It's faster since it formulates MoE operations
    in terms of block-sparse operations to accommodate imbalanced
    assignments of tokens to experts, whereas standard MoE either
    (1) drop tokens at the cost of reduced performance or (2) set
    capacity factor to number of experts and thus waste computation
    and memory on padding.
    c                 óÀ  •— t         ‰| �  «        |j                  | _        |j                  | _        |j                  | _        |j                  | _	        t        j                  | j                  | j                  d¬«      | _        t        j                  t        | j                  «      D �cg c]  }t        |«      ‘Œ c}«      | _        |j"                  | _        y c c}w r-   )r0   r1   r4   r5   r2   r3   Únum_local_expertsÚnum_expertsÚnum_experts_per_tokÚtop_kr	   r6   ÚgateÚ
ModuleListÚranger*   ÚexpertsÚrouter_jitter_noiseÚjitter_noise)r=   r+   Ú_r>   s      €r?   r1   zMixtralSparseMoeBlock.__init__d   s§   ø€ Ü‰ÑÔØ ×,Ñ,ˆŒØ×/Ñ/ˆŒØ!×3Ñ3ˆÔØ×/Ñ/ˆŒ
ô —I‘I˜dŸo™o¨t×/?Ñ/?ÀeÔLˆŒ	ä—}‘}ÔQVÐW[×WgÑWgÓQhÖ%iÈAÔ&?ÀÕ&GÒ%iÓjˆŒð #×6Ñ6ˆÕùò &js   Â+CrC   Úreturnc                 óf  — |j                   \  }}}| j                  rQ| j                  dkD  rB|t        j                  |«      j                  d| j                  z
  d| j                  z   «      z  }|j                  d|«      }| j                  |«      }t        j                  |dt        j                  ¬«      }t        j                  || j                  d¬«      \  }}||j                  dd¬«      z  }|j                  |j                  «      }t        j                   ||z  |f|j                  |j"                  ¬	«      }t        j$                  j&                  j)                  || j*                  ¬
«      j-                  ddd«      }	t/        | j*                  «      D ]€  }
| j0                  |
   }t        j2                  |	|
   «      \  }}|d|f   j5                  d|«      } ||«      |||df   z  }|j7                  d||j                  |j                  «      «       Œ‚ |j5                  |||«      }||fS )ú r   g      ð?éÿÿÿÿr'   ©ÚdimÚdtype©r^   T)r^   Úkeepdim)r_   Údevice)Únum_classesé   N)ÚshapeÚtrainingrW   ÚtorchÚ
empty_likeÚuniform_ÚviewrR   ÚFÚsoftmaxÚfloatÚtopkrQ   ÚsumÚtor_   Úzerosrb   r	   Ú
functionalÚone_hotrO   ÚpermuterT   rU   ÚwhereÚreshapeÚ
index_add_)r=   rC   Ú
batch_sizeÚsequence_lengthr5   Úrouter_logitsÚrouting_weightsÚselected_expertsÚfinal_hidden_statesÚexpert_maskÚ
expert_idxÚexpert_layerÚidxÚtop_xÚcurrent_staterD   s                   r?   rE   zMixtralSparseMoeBlock.forwards   s  € à2?×2EÑ2EÑ/ˆ
�O ZØ�=Š=˜T×.Ñ.°Ò2ØœU×-Ñ-¨mÓ<×EÑEÀcÈD×L]ÑL]ÑF]Ð_bÐei×evÑevÑ_vÓwÑwˆMØ%×*Ñ*¨2¨zÓ:ˆàŸ	™	 -Ó0ˆäŸ)™) M°qÄÇÁÔLˆÜ,1¯J©J°ÈÏ
É
ÐXZÔ,[Ñ)ˆÐ)Ø˜?×.Ñ.°2¸tÐ.ÓDÑDˆà)×,Ñ,¨]×-@Ñ-@ÓAˆä#Ÿk™kØ˜/Ñ)¨:Ð6¸m×>QÑ>QÐZg×ZnÑZnô
Ðô —h‘h×)Ñ)×1Ñ1Ð2BÐPT×P`ÑP`Ð1Óa×iÑiÐjkÐmnÐpqÓrˆô   × 0Ñ 0Ó1ò 	dˆJØŸ<™<¨
Ñ3ˆLÜŸ™ [°Ñ%<Ó=‰JˆC�ð
 *¨$°¨+Ñ6×>Ñ>¸rÀ:ÓNˆMÙ$0°Ó$?À/ÐRWÐY\Ð^bÐRbÑBcÑ$cÐ!ð  ×*Ñ*¨1¨eÐ5J×5MÑ5MÈm×NaÑNaÓ5bÕcð	dð 2×9Ñ9¸*ÀoÐWaÓbÐØ" MÐ1Ð1r@   )	rF   rG   rH   Ú__doc__r1   rg   ÚTensorrE   rI   rJ   s   @r?   rL   rL   X   s(   ø„ ñ	ô7ð&2 U§\¡\ð &2°e·l±l÷ &2r@   rL   c                   ó,   ‡ — e Zd Zdˆ fd„	Zd„ Zd„ Zˆ xZS )ÚMixtralRMSNormc                 óŠ   •— t         ‰| �  «        t        j                  t	        j
                  |«      «      | _        || _        y)z=
        MixtralRMSNorm is equivalent to T5LayerNorm
        N)r0   r1   r	   Ú	Parameterrg   ÚonesÚweightÚvariance_epsilon)r=   r4   Úepsr>   s      €r?   r1   zMixtralRMSNorm.__init__�   s1   ø€ ô 	‰ÑÔÜ—l‘l¤5§:¡:¨kÓ#:Ó;ˆŒØ #ˆÕr@   c                 ó"  — |j                   }|j                  t        j                  «      }|j	                  d«      j                  dd¬«      }|t        j                  || j                  z   «      z  }| j                  |j                  |«      z  S )Nrd   r\   T)ra   )	r_   rp   rg   Úfloat32ÚpowÚmeanÚrsqrtrŒ   r‹   )r=   rC   Úinput_dtypeÚvariances       r?   rE   zMixtralRMSNorm.forward¥   sy   € Ø#×)Ñ)ˆØ%×(Ñ(¬¯©Ó7ˆØ ×$Ñ$ QÓ'×,Ñ,¨R¸Ð,Ó>ˆØ%¬¯©°H¸t×?TÑ?TÑ4TÓ(UÑUˆØ�{‰{˜]×-Ñ-¨kÓ:Ñ:Ð:r@   c                 ó^   — t        | j                  j                  «      › d| j                  › �S )Nz, eps=)Útupler‹   re   rŒ   ©r=   s    r?   Ú
extra_reprzMixtralRMSNorm.extra_repr¬   s*   € Ü˜Ÿ™×)Ñ)Ó*Ð+¨6°$×2GÑ2GÐ1HÐIÐIr@   )g�íµ ÷Æ°>)rF   rG   rH   r1   rE   r˜   rI   rJ   s   @r?   r‡   r‡   œ   s   ø„ õ$ò;öJr@   r‡   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\   rd   r`   )re   rg   Úcat)ÚxÚx1Úx2s      r?   Úrotate_halfrž   °   sZ   € à	
ˆ3Ð"�!—'‘'˜"‘+ Ñ"Ð"Ð"Ñ	#€BØ	
ˆ3�—‘˜‘˜qÑ Ñ"Ð"Ñ	#€BÜ�9‰9�r�c˜2�Y BÔ'Ð'r@   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.
    )Ú	unsqueezerž   )ÚqÚkÚcosÚsinÚposition_idsÚunsqueeze_dimÚq_embedÚk_embeds           r?   Úapply_rotary_pos_embr©   ·   sY   € ð( �-‰-˜Ó
&€CØ
�-‰-˜Ó
&€CØ�3‰wœ; q›>¨CÑ/Ñ0€GØ�3‰wœ; q›>¨CÑ/Ñ0€GØ�GÐÐr@   rC   Ún_reprY   c                 óª   — | 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)re   Úexpandrv   )rC   rª   ÚbatchÚnum_key_value_headsÚslenÚhead_dims         r?   Ú	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ÐTr@   Ú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 )Nrd   r
   éþÿÿÿr\   r]   )Úprf   r'   )r±   Únum_key_value_groupsrg   ÚmatmulÚ	transposere   r	   rr   rl   r�   rp   r_   r¸   rf   Ú
contiguous)r²   r³   r´   rµ   r¶   r·   r¸   ÚkwargsÚ
key_statesÚvalue_statesÚattn_weightsÚcausal_maskÚattn_outputs                r?   Ú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à˜Ð$Ð$r@   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 )ÚMixtralAttentionz=Multi-headed attention from 'Attention Is All You Need' paperr+   Ú	layer_idxc                 ó  •— t         ‰| �  «        || _        || _        t	        |d|j
                  |j                  z  «      | _        |j                  |j                  z  | _	        | j                  dz  | _
        |j                  | _        d| _        t        j                  |j
                  |j                  | j                  z  d¬«      | _        t        j                  |j
                  |j                  | j                  z  d¬«      | _        t        j                  |j
                  |j                  | j                  z  d¬«      | _        t        j                  |j                  | j                  z  |j
                  d¬«      | _        y )Nr°   g      à¿TFr.   )r0   r1   r+   rÉ   Úgetattrr4   Únum_attention_headsr°   r®   r¼   r·   Úattention_dropoutÚ	is_causalr	   r6   Úq_projÚk_projÚv_projÚo_proj©r=   r+   rÉ   r>   s      €r?   r1   zMixtralAttention.__init__û   s,  ø€ Ü‰ÑÔØˆŒØ"ˆŒÜ ¨
°F×4FÑ4FÈ&×JdÑJdÑ4dÓeˆŒØ$*×$>Ñ$>À&×B\ÑB\Ñ$\ˆÔ!Ø—}‘} dÑ*ˆŒØ!'×!9Ñ!9ˆÔØˆŒÜ—i‘i × 2Ñ 2°F×4NÑ4NÐQU×Q^ÑQ^Ñ4^ÐejÔkˆŒÜ—i‘i × 2Ñ 2°F×4NÑ4NÐQU×Q^ÑQ^Ñ4^ÐejÔkˆŒÜ—i‘i × 2Ñ 2°F×4NÑ4NÐQU×Q^ÑQ^Ñ4^ÐejÔkˆŒÜ—i‘i × :Ñ :¸T¿]¹]Ñ JÈF×L^ÑL^ÐejÔkˆ�r@   rC   Úposition_embeddingsr¶   Úpast_key_valueÚcache_positionrÀ   rY   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&                  t)        | j                  dd «      dœ|¤Ž\  }} |j*                  g |¢d‘­Ž j-                  «       }| j/                  |«      }||fS )Nr\   r'   rd   )r¤   r£   rÖ   ÚeagerÚsdpaÚoutput_attentionsFzã`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.ç        Úsliding_window)r¸   r·   rÜ   )re   r°   rÏ   rj   r¾   rÐ   rÑ   r©   ÚupdaterÉ   rÆ   r+   Ú_attn_implementationÚgetÚloggerÚwarning_oncer   rf   rÍ   r·   rË   rv   r¿   rÒ   )r=   rC   rÔ   r¶   rÕ   rÖ   rÀ   Úinput_shapeÚhidden_shapeÚquery_statesrÁ   rÂ   r£   r¤   Úcache_kwargsÚattention_interfacerÅ   rÃ   s                     r?   rE   zMixtralAttention.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Ü" 4§;¡;Ð0@À$ÓGñ
%
ð ñ
%
Ñ!ˆ�\ð *�k×)Ñ)Ð;¨;Ð;¸Ò;×FÑFÓHˆØ—k‘k +Ó.ˆØ˜LÐ(Ð(r@   )NN)rF   rG   rH   r„   r(   Úintr1   rg   r…   r   r   r   Ú
LongTensorr   r   rE   rI   rJ   s   @r?   rÈ   rÈ   ø   sÈ   ø„ ÙGðl˜}ð l¸õ lð& +/Ø59ñ0)à—|‘|ð0)ð # 5§<¡<°·±Ð#=Ñ>ð0)ð ! §¡Ñ.ð	0)ð
 ! ™ð0)ð ! ×!1Ñ!1Ñ2ð0)ð Ð-Ñ.ð0)ð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷0)r@   rÈ   c                   ó–  ‡ — 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
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   de
ej                  ee
ej                  ej                  f      f   fd„Zˆ xZS )ÚMixtralDecoderLayerr+   rÉ   c                 ó  •— t         ‰| �  «        |j                  | _        t        ||«      | _        t        |«      | _        t        |j                  |j                  ¬«      | _	        t        |j                  |j                  ¬«      | _
        y )N©r�   )r0   r1   r4   rÈ   Ú	self_attnrL   Úblock_sparse_moer‡   Úrms_norm_epsÚinput_layernormÚpost_attention_layernormrÓ   s      €r?   r1   zMixtralDecoderLayer.__init__=  sm   ø€ Ü‰ÑÔØ!×-Ñ-ˆÔä)¨&°)Ó<ˆŒä 5°fÓ =ˆÔÜ-¨f×.@Ñ.@Àf×FYÑFYÔZˆÔÜ(6°v×7IÑ7IÈv×ObÑObÔ(cˆÕ%r@   rC   r¶   r¥   rÕ   rÚ   Úoutput_router_logitsÚ	use_cacherÖ   rÔ   rÀ   rY   c
                 óð   — |}| j                  |«      } | j                  d||	||||||dœ|
¤Ž\  }}||z   }|}| j                  |«      }| j                  |«      \  }}||z   }|f}|r||fz  }|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, sequence_length)` where padding elements are indicated by 0.
            past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
            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_router_logits (`bool`, *optional*):
                Whether or not to return the logits of all the routers. They are useful for computing the router loss, and
                should not be returned during inference.
            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`).
            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
        )rC   rÔ   r¶   r¥   rÕ   rÚ   ró   rÖ   © )rð   rí   rñ   rî   )r=   rC   r¶   r¥   rÕ   rÚ   rò   ró   rÖ   rÔ   rÀ   ÚresidualÚself_attn_weightsrz   Úoutputss                  r?   rE   zMixtralDecoderLayer.forwardG  sÉ   € ðF !ˆà×,Ñ,¨]Ó;ˆð ,:¨4¯>©>ð 
,
Ø'Ø 3Ø)Ø%Ø)Ø/ØØ)ñ
,
ð ñ
,
Ñ(ˆÐ(ð ! =Ñ0ˆð !ˆØ×5Ñ5°mÓDˆØ'+×'<Ñ'<¸]Ó'KÑ$ˆ�}Ø  =Ñ0ˆà Ð"ˆáØÐ)Ð+Ñ+ˆGáØ˜Ð'Ñ'ˆGàˆr@   )NNNFFFNN)rF   rG   rH   r(   rç   r1   rg   r…   r   rè   r   Úboolr   r   ÚFloatTensorrE   rI   rJ   s   @r?   rê   rê   <  s5  ø„ ðd˜}ð d¸õ dð 26Ø37Ø8<Ø,1Ø/4Ø$)Ø59ØKOñCà—|‘|ðCð ! §¡Ñ.ðCð ˜u×/Ñ/Ñ0ð	Cð
 !  u§|¡|Ñ!4Ñ5ðCð $ D™>ðCð ' t™nðCð ˜D‘>ðCð ! ×!1Ñ!1Ñ2ðCð & e¨E¯L©L¸%¿,¹,Ð,FÑ&GÑHðCð Ð-Ñ.ðCð 
ˆu× Ñ  (¨5°×1BÑ1BÀE×DUÑDUÐ1UÑ+VÑ"WÐWÑ	X÷Cr@   rê   c                   ó^   ‡ — e Zd Zddefˆ fd„Z ej                  «       ed„ «       «       Zˆ xZ	S )ÚMixtralRotaryEmbeddingr+   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)r0   r1   Úhasattrrþ   rß   rÿ   Úmax_position_embeddingsÚmax_seq_len_cachedÚoriginal_max_seq_lenr+   r   Úrope_init_fnÚattention_scalingÚregister_bufferr  Úoriginal_inv_freq)r=   r+   rb   r  r>   s       €r?   r1   zMixtralRotaryEmbedding.__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Ø!%§¡ˆÕr@   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'   ÚmpsÚcpuF)Údevice_typeÚenabledrd   r`   )r_   )r  rm   r¬   re   rp   rb   Ú
isinstancer   Ústrrg   Úautocastr¾   rš   r£   r	  r¤   r_   )
r=   r›   r¥   Úinv_freq_expandedÚposition_ids_expandedr  ÚfreqsÚembr£   r¤   s
             r?   rE   zMixtralRotaryEmbedding.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.rB   )
rF   rG   rH   r(   r1   rg   Úno_gradr   rE   rI   rJ   s   @r?   rü   rü   �  s3   ø„ ñ/˜}õ /ð" €U‡]�]ƒ_Øñ<ó ó ô<r@   rü   aL  
    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 ([`MixtralConfig`]):
            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.
zUThe bare Mixtral Model outputting raw hidden-states without any specific head on top.c                   óF   — e Zd ZeZdZdZdgZdgZdZ	dZ
dZdZdZdZdZd„ Zy)ÚMixtralPreTrainedModelÚmodelTrê   Úpast_key_valuesFc                 ó  — | j                   j                  }t        |t        j                  «      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)r+   Úinitializer_ranger  r	   r6   r‹   ÚdataÚnormal_r/   Úzero_Ú	EmbeddingÚpadding_idx)r=   r²   r  s      r?   Ú_init_weightsz$MixtralPreTrainedModel._init_weightsÒ  sÃ   € Ø�k‰k×+Ñ+ˆÜ�fœbŸi™iÔ(Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø�{‰{Ð&Ø—‘× Ñ ×&Ñ&Õ(ð 'ä˜¤§¡Ô-Ø�M‰M×Ñ×&Ñ&¨C°SÐ&Ô9Ø×!Ñ!Ð-Ø—‘×"Ñ" 6×#5Ñ#5Ñ6×<Ñ<Õ>ð .ð .r@   N)rF   rG   rH   r(   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_skip_keys_device_placementÚ_supports_flash_attn_2Ú_supports_sdpaÚ_supports_flex_attnÚ_supports_cache_classÚ_supports_quantized_cacheÚ_supports_static_cacheÚ_supports_attention_backendr%  rõ   r@   r?   r  r  À  sU   „ ð
 !€LØÐØ&*Ð#Ø.Ð/ÐØ#4Ð"5ÐØ!ÐØ€NØÐØ ÐØ $ÐØ"ÐØ"&Ðó	?r@   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`.

            It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).

            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                   óD  ‡ — 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ej                         d
eej                      dee   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j4                  dej6                  dej                  deded	efd„«       Zˆ xZS )ÚMixtralModelzŸ
    Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`MixtralDecoderLayer`]

    Args:
        config: MixtralConfig
    r+   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ì   )r+   F)r0   r1   Úpad_token_idr$  Ú
vocab_sizer	   r#  r4   Úembed_tokensrS   rT   Únum_hidden_layersrê   Úlayersr‡   rï   Únormrü   Ú
rotary_embÚgradient_checkpointingÚ	post_initrÓ   s      €r?   r1   zMixtralModel.__init__-  sÆ   ø€ Ü‰Ñ˜Ô Ø!×.Ñ.ˆÔØ ×+Ñ+ˆŒäŸL™L¨×):Ñ):¸F×<NÑ<NÐPT×P`ÑP`ÓaˆÔÜ—m‘mÜEJÈ6×KcÑKcÓEdÖe¸	Ô  ¨Õ3Òeó
ˆŒô # 6×#5Ñ#5¸6×;NÑ;NÔOˆŒ	Ü0¸Ô?ˆŒØ&+ˆÔ#ð 	�‰Õùò fs   ÂDc                 ó   — | j                   S rB   ©r7  r—   s    r?   Úget_input_embeddingsz!MixtralModel.get_input_embeddings=  s   € Ø× Ñ Ð r@   c                 ó   — || _         y rB   r?  ©r=   rµ   s     r?   Úset_input_embeddingsz!MixtralModel.set_input_embeddings@  s
   € Ø!ˆÕr@   Ú	input_idsr¶   r¥   r  Úinputs_embedsró   rÚ   Úoutput_hidden_statesrò   rÖ   Úflash_attn_kwargsrY   c                 ó8  — |�|n| j                   j                  }|	�|	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}|r|€
t        «       }|€| j                  |«      }|
€F|�|j                  «       nd}t        j                  |||j                  d   z   |j                   ¬«      }
|€|
j#                  d«      }| j%                  |||
||«      }|}| j'                  ||«      }|rdnd }|rdnd }|	rdnd }| j(                  D ]  }|r||fz  }| j                  r;| j                  r/| j+                  t-        |j.                  fi |¤Ž||||||	||
|«
      }n ||f|||||	||
|dœ|¤Ž}|d   }|r	||d   fz  }|	sŒw||d	   fz  }Œ� | j1                  |«      }|r||fz  }t3        |||||¬
«      S )Nz:You must specify exactly one of input_ids or inputs_embedszZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...Fr   r'   ©rb   rõ   )r¶   r¥   rÕ   rÚ   rò   ró   rÖ   rÔ   r\   )Úlast_hidden_stater  rC   Ú
attentionsrz   )r+   rÚ   rò   rF  ró   Ú
ValueErrorr<  rf   rà   rá   r   r7  Úget_seq_lengthrg   Úarangere   rb   r    Ú_update_causal_maskr;  r9  Ú_gradient_checkpointing_funcr   Ú__call__r:  r   )r=   rD  r¶   r¥   r  rE  ró   rÚ   rF  rò   rÖ   rG  Úpast_seen_tokensrÄ   rC   rÔ   Úall_hidden_statesÚall_self_attnsÚall_router_logitsÚdecoder_layerÚlayer_outputss                        r?   rE   zMixtralModel.forwardC  s²  € ð  2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð %9Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	à˜Ð -°tÐ";Ò<ÜÐYÓZÐZà×&Ò&¨4¯=ª=ÙÜ×#Ñ#Øpôð "�	á˜Ð0Ü*›nˆOàÐ Ø ×-Ñ-¨iÓ8ˆMàÐ!Ø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ˆÙ"6™B¸DÐà!Ÿ[™[ò %	:ˆMÙ#Ø! mÐ%5Ñ5Ð!à×*Ò*¨t¯}ª}Ø $× AÑ AÜ˜M×2Ñ2ÑHÐ6GÑHØ!ØØ Ø#Ø%Ø(ØØ"Ø'ó!‘ñ !.Ø!ð!à#.Ø!-Ø#2Ø&7Ø)=Ø'Ø#1Ø(;ñ!ð (ñ!�ð *¨!Ñ,ˆMá Ø =°Ñ#3Ð"5Ñ5�â#Ø! m°BÑ&7Ð%9Ñ9Ñ!ðK%	:ðN Ÿ	™	 -Ó0ˆñ  Ø -Ð!1Ñ1Ðä%Ø+Ø+Ø+Ø%Ø+ô
ð 	
r@   Úinput_tensorc                 ó  — | j                   j                  dk(  rS|�H|�F|d d …df   j                  «       j                  «       |j	                  «       d   k7  }|rt        d«      ‚|�d|v r|S y |�|j                  «       nd}t        |t        «      }t        |t        «      }	| j                   j                  dk(  r?|s=|	s;|s9t        j                  |||| j                   j                  | j                  ¬«      ry |j                  |j                  }}
t!        j"                  |
«      j$                  }|j&                  d   }|	s|r|j)                  «       }n1t        |t         j*                  «      r|j&                  d   n||z   dz   }| j-                  ||||
|||j&                  d   | j                   |¬	«	      }| j                   j                  dk(  r2|�0|j                  j.                  d
v r|st        j0                  ||«      }|S )NÚflash_attention_2r\   r   zìYou are attempting to perform batched generation with padding_side='right' this may lead to unexpected behaviour for Flash Attention version of Mixtral. Make sure to  call `tokenizer.padding_side  = 'left'` before tokenizing the input. rÛ   rÙ   )rE  Úpast_key_values_lengthrÜ   Úis_trainingr'   )ry   Útarget_lengthr_   rb   rÖ   rx   r+   r  )ÚcudaÚxpu)r+   rÞ   ro   ÚitemÚsizerL  rM  r  r   r   r   Ú_ignore_causal_mask_sdparÜ   rf   r_   rb   rg   ÚfinfoÚminre   Úget_max_cache_shaper…   Ú5_prepare_4d_causal_attention_mask_with_cache_positionr   Ú_unmask_unattended)r=   r¶   rX  rÖ   r  rÚ   Úis_padding_rightrR  Úusing_static_cacheÚusing_sliding_window_cacher_   rb   Ú	min_dtypery   r]  rÄ   s                   r?   rO  z MixtralModel._update_causal_mask·  s  € ð �;‰;×+Ñ+Ð/BÒBØÐ)¨oÐ.IØ#1²!°R°%Ñ#8×#<Ñ#<Ó#>×#CÑ#CÓ#EÈ×IZÑIZÓI\Ð]^ÑI_Ñ#_Ð Ù#Ü$ðaóð ð
 Ð)¨c°^Ñ.CØ%Ð%Øð
 @OÐ?Z˜?×9Ñ9Ô;Ð`aÐÜ'¨¼ÓEÐÜ%/°ÔASÓ%TÐ"ð �K‰K×,Ñ,°Ò6Ù'Ñ+EÙ%ä%×>Ñ>ØØ*Ø'7Ø#Ÿ{™{×9Ñ9Ø ŸM™Mõð à$×*Ñ*¨L×,?Ñ,?ˆvˆÜ—K‘K Ó&×*Ñ*ˆ	Ø&×,Ñ,¨QÑ/ˆá%Ñ);Ø+×?Ñ?ÓA‰Mô
 ˜n¬e¯l©lÔ;ð ×$Ñ$ RÒ(à%¨Ñ7¸!Ñ;ð ð ×PÑPØØ+Ø'ØØØ)Ø#×)Ñ)¨!Ñ,Ø—;‘;Ø+ð Qó 

ˆð �K‰K×,Ñ,°Ò6ØÐ*Ø×%Ñ%×*Ñ*¨oÑ=Ù%ô
 1×CÑCÀKÐQZÓ[ˆKàÐr@   ry   r]  r_   rb   rx   c	                 óp  — | �| j                  «       dk(  r| }	|	S t        j                  |«      j                  }
t        j                  ||f|
||¬«      }	t        j
                  ||¬«      |j                  dd«      kD  }|j                  �]t        |t        «      r||kD  rHt        j
                  ||¬«      |j                  dd«      |j                  z
  k  }|j                  |«       |	|z  }	|	dddd…dd…f   j                  |ddd«      }	| �©|	j                  «       }	| j                  d   |kD  r| dd…d|…f   } | 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 )aV  
        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.
            config (`MixtralConfig`):
                The model's configuration class
            past_key_values (`Cache`):
                The cache class that is being used currently to generate
        Né   )Ú
fill_valuer_   rb   rI  r\   r'   r   )r^   rg   rc  rd  ÚfullrN  rv   rÜ   r  r   Úbitwise_or_r¬   Úclonere   rp   rb   Úmasked_fill)r¶   ry   r]  r_   rb   rÖ   rx   r+   r  rÄ   rk  Údiagonal_attend_maskÚsliding_attend_maskÚmask_lengthÚpadding_masks                  r?   rf  zBMixtralModel._prepare_4d_causal_attention_mask_with_cache_position
  sò  € ðH Ð%¨.×*<Ñ*<Ó*>À!Ò*Cà(ˆKð: Ðô7 Ÿ™ EÓ*×.Ñ.ˆIÜŸ*™*Ø  -Ð0¸YÈeÐ\bôˆKô $)§<¡<°ÀfÔ#MÐP^×PfÑPfÐgiÐklÓPmÑ#mÐ Ø×$Ñ$Ð0ô " /Ô3EÔFÈ/Ð\iÒJiÜ*/¯,©,°}ÈVÔ*TØ&×.Ñ.¨r°1Ó5¸×8MÑ8MÑMñ+Ð'ð )×4Ñ4Ð5HÔIØÐ/Ñ/ˆKØ% d¨D²!²QÐ&6Ñ7×>Ñ>¸zÈ1ÈbÐRTÓUˆKØÐ)Ø)×/Ñ/Ó1�Ø!×'Ñ'¨Ñ+¨mÒ;Ø%3²A°~¸°~Ð4EÑ%F�NØ,×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ð Ðr@   )
NNNNNNNNNN)F)rF   rG   rH   r„   r(   r1   r@  rC  r#   r"   ÚMIXTRAL_INPUTS_DOCSTRINGr   rg   rè   r…   r   rú   rù   r   r   r   rE   r   rO  Ústaticmethodrç   r_   rb   rf  rI   rJ   s   @r?   r3  r3  !  s  ø„ ñ
ð˜}õ ò !ò"ð Ù*Ð+CÓDð 15Ø15Ø37Ø=AØ59Ø$(Ø,0Ø/3Ø/3Ø59ñp
à˜E×,Ñ,Ñ-ðp
ð ! §¡Ñ.ðp
ð ˜u×/Ñ/Ñ0ð	p
ð
 " $ u×'8Ñ'8Ñ"9Ñ:ðp
ð   × 1Ñ 1Ñ2ðp
ð ˜D‘>ðp
ð $ D™>ðp
ð ' t™nðp
ð ' t™nðp
ð ! ×!1Ñ!1Ñ2ðp
ð $Ð$8Ñ9ðp
ð 
 òp
ó Eó ðp
ðp #(ñQàŸ™ðQð —l‘lðQð Ÿ™ð	Qð
 ðQð  óQðf ðBØŸ™ðBàðBð ðBð �{‰{ð	Bð
 —‘ðBð Ÿ™ðBð ðBð ðBð òBó ôBr@   r3  c                   ó   — e Zd Zy)ÚKwargsForCausalLMN)rF   rG   rH   rõ   r@   r?   rz  rz  P  s   … r@   rz  Úgate_logitsrO   c                 ó¾  — | �t        | t        «      syt        | t        «      rC| d   j                  }t        j                  | D �cg c]  }|j                  |«      ‘Œ c}d¬«      }t        j                  j                  j                  d¬«      }t        j                  ||d¬«      \  }}	t        j                  j                  j                  |	|«      }
|€>t        j                  |
j                  «       d¬«      }t        j                  |d¬«      }�n|j                  \  }}|j                  d   ||z  z  }|ddd…dd…ddf   j                  |||||f«      j                  d||«      j                  «      }t        j                   |
j                  «       |z  d¬«      t        j                   |d¬«      z  }|ddd…dd…df   j                  ||||f«      j                  d|«      j                  |«      }t        j                   ||z  d¬«      t        j                   |d¬«      z  }t        j                   ||j#                  d«      z  «      }||z  S c c}w )a¼  
    Computes auxiliary load balancing loss as in Switch Transformer - implemented in Pytorch.

    See Switch Transformer (https://arxiv.org/abs/2101.03961) for more details. This function implements the loss
    function presented in equations (4) - (6) of the paper. It aims at penalizing cases where the routing between
    experts is too unbalanced.

    Args:
        gate_logits:
            Logits from the `gate`, should be a tuple of model.config.num_hidden_layers tensors of
            shape [batch_size X sequence_length, num_experts].
        num_experts:
            Number of experts
        top_k:
            The number of experts to route per-token, can be also interpreted as the `top-k` routing
            parameter.
        attention_mask (`torch.Tensor`, *optional*):
            The attention_mask used in forward function
            shape [batch_size X sequence_length] if not None.

    Returns:
        The auxiliary loss.
    Nr   r`   r\   )r  r–   rb   rg   rš   rp   r	   rr   rl   rn   rs   r‘   rm   re   r¬   rv   ro   r    )r{  rO   rQ   r¶   Úcompute_deviceÚ
layer_gateÚconcatenated_gate_logitsr{   rX   r|   r~   Útokens_per_expertÚrouter_prob_per_expertrx   ry   r8  Úexpert_attention_maskÚ router_per_expert_attention_maskÚoverall_losss                      r?   Úload_balancing_loss_funcr…  S  s9  € ð: Ð¤*¨[¼%Ô"@Øä�+œuÔ%Ø$ Q™×.Ñ.ˆÜ#(§9¡9Ð^iÖ-jÐPZ¨j¯m©m¸NÕ.KÒ-jÐpqÔ#rÐ ä—h‘h×)Ñ)×1Ñ1Ð2JÐPRÐ1ÓS€OäŸ*™* _°eÀÔDÑ€AÐä—(‘(×%Ñ%×-Ñ-Ð.>ÀÓL€KàÐä!ŸJ™J {×'8Ñ'8Ó':ÀÔBÐô "'§¡¨OÀÔ!CÒà&4×&:Ñ&:Ñ#ˆ
�OØ4×:Ñ:¸1Ñ=À*ÈÑB^Ñ_Ðð ˜4¢¢A t¨TÐ1Ñ2ß‰VÐ&¨
°OÀUÈKÐXÓYß‰W�R˜ Ó,ß‰R�Óð	 	ô "ŸI™I k×&7Ñ&7Ó&9Ð<QÑ&QÐWXÔYÔ\a×\eÑ\eØ! qô]
ñ 
Ðð ˜4¢¢A tÐ+Ñ,ß‰VÐ&¨
°OÀ[ÐQÓRß‰W�R˜Ó%ß‰R�Óð	 	)ô "'§¡¨?Ð=]Ñ+]ÐcdÔ!eÔhm×hqÑhqØ,°!ôi
ñ "
Ðô —9‘9Ð.Ð1G×1QÑ1QÐRSÓ1TÑTÓU€LØ˜+Ñ%Ð%ùò[ .ks   ÁIc            !       ó  ‡ — e Zd ZdgZddiZddgdgfi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e¬«      	 	 	 	 	 	 	 	 	 	 	 	 d deej,                     deej.                     deej,                     deeej2                        deej2                     deej,                     dee   dee   dee   dee   deej,                     deeej.                  f   dee   defd„«       «       «       «       Z ˆ xZ!S )!ÚMixtralForCausalLMzlm_head.weightÚlm_headÚcolwise_reprC   Úlogitsc                 óN  •— t         ‰| �  |«       t        |«      | _        |j                  | _        t        j                  |j                  |j                  d¬«      | _        |j                  | _	        |j                  | _        |j                  | _        | j                  «        y r-   )r0   r1   r3  r  r6  r	   r6   r4   rˆ  Úrouter_aux_loss_coefrN   rO   rP   r=  r<   s     €r?   r1   zMixtralForCausalLM.__init__ª  s   ø€ Ü‰Ñ˜Ô Ü! &Ó)ˆŒ
Ø ×+Ñ+ˆŒÜ—y‘y ×!3Ñ!3°V×5FÑ5FÈUÔSˆŒØ$*×$?Ñ$?ˆÔ!Ø!×3Ñ3ˆÔØ#)×#=Ñ#=ˆÔ ð 	�‰Õr@   c                 ó.   — | j                   j                  S rB   ©r  r7  r—   s    r?   r@  z'MixtralForCausalLM.get_input_embeddings¶  ó   € Ø�z‰z×&Ñ&Ð&r@   c                 ó&   — || j                   _        y rB   rŽ  rB  s     r?   rC  z'MixtralForCausalLM.set_input_embeddings¹  ó   € Ø"'ˆ�
‰
Õr@   c                 ó   — | j                   S rB   ©rˆ  r—   s    r?   Úget_output_embeddingsz(MixtralForCausalLM.get_output_embeddings¼  s   € Ø�|‰|Ðr@   c                 ó   — || _         y rB   r“  )r=   Únew_embeddingss     r?   Úset_output_embeddingsz(MixtralForCausalLM.set_output_embeddings¿  s	   € Ø%ˆ�r@   c                 ó   — || _         y rB   ©r  )r=   Údecoders     r?   Úset_decoderzMixtralForCausalLM.set_decoderÂ  s	   € Øˆ�
r@   c                 ó   — | j                   S rB   r™  r—   s    r?   Úget_decoderzMixtralForCausalLM.get_decoderÅ  s   € Ø�z‰zÐr@   Únum_logits_to_keepz4.50Úlogits_to_keep)ÚversionÚnew_name)Úoutput_typer&  rD  r¶   r¥   r  rE  Úlabelsró   rÚ   rF  rò   rÖ   rÀ   rY   c                 óØ  — |�|n| j                   j                  }|
�|
n| j                   j                  }
|	�|	n| j                   j                  }	 | j                  d||||||||	|
|dœ
|¤Ž}|j
                  }t        |t        «      rt        | d«      n|}| j                  |dd…|dd…f   «      }d}|� | j                  ||| j                  fi |¤Ž}d}|
rYt        |j                  | j                  | j                  |«      }|�+|| j                   |j#                  |j$                  «      z  z  }t'        ||||j(                  |j*                  |j,                  |j                  ¬«      S )a4  
            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 AutoTokenizer, MixtralForCausalLM

        >>> model = MixtralForCausalLM.from_pretrained("mistralai/Mixtral-8x7B-v0.1")
        >>> tokenizer = AutoTokenizer.from_pretrained("mistralai/Mixtral-8x7B-v0.1")

        >>> prompt = "Hey, are you conscious? Can you talk to me?"
        >>> inputs = tokenizer(prompt, return_tensors="pt")

        >>> # Generate
        >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
        >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
        "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
        ```N)
rD  r¶   r¥   r  rE  ró   rÚ   rF  rò   rÖ   )ÚlossÚaux_lossrŠ  r  rC   rK  rz   rõ   )r+   rÚ   rò   rF  r  rJ  r  rç   Úslicerˆ  Úloss_functionr6  r…  rz   rO   rP   rŒ  rp   rb   r   r  rC   rK  )r=   rD  r¶   r¥   r  rE  r£  ró   rÚ   rF  rò   rÖ   rŸ  rÀ   rø   rC   Úslice_indicesrŠ  r¥  r¦  s                       r?   rE   zMixtralForCausalLM.forwardÈ  s–  € ðh 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð
 %9Ð$DÑ È$Ï+É+×JjÑJjð 	ð
 +5¨$¯*©*ð +
ØØ)Ø%Ø+Ø'ØØ/Ø!5Ø!5Ø)ñ+
ð ñ+
ˆð  ×1Ñ1ˆä8BÀ>ÔSVÔ8Wœ˜~˜o¨tÔ4Ð]kˆØ—‘˜mªA¨}ºaÐ,?Ñ@ÓAˆàˆØÐØ%�4×%Ñ% f¨f°d·o±oÑPÈÑPˆDàˆÙÜ/Ø×%Ñ%Ø× Ñ Ø×(Ñ(Øó	ˆHð Ð!Ø˜×1Ñ1°H·K±KÀÇÁÓ4LÑLÑL�ä(ØØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)Ø!×/Ñ/ô
ð 	
r@   )NNNNNNNNNNNr   )"rF   rG   rH   Ú_tied_weights_keysÚ_tp_planÚ_pp_planr1   r@  rC  r”  r—  r›  r�  r#   r&   r"   rw  r%   r   Ú_CONFIG_FOR_DOCr   rg   rè   r…   r   rú   rù   r   rç   r   rz  r   rE   rI   rJ   s   @r?   r‡  r‡  ¥  sÊ  ø„ Ø*Ð+ÐØ˜=Ð)€HØ˜_Ð-°¨zÐ:Ð;€Hô
ò'ò(òò&òòð ÙÐ)°6ÐDTÔUÙ*Ð+CÓDÙÐ+AÐP_Ô`ð 15Ø15Ø37Ø=AØ59Ø-1Ø$(Ø,0Ø/3Ø/3Ø59Ø34ñd
à˜E×,Ñ,Ñ-ðd
ð ! §¡Ñ.ðd
ð ˜u×/Ñ/Ñ0ð	d
ð
 " $ u×'8Ñ'8Ñ"9Ñ:ðd
ð   × 1Ñ 1Ñ2ðd
ð ˜×)Ñ)Ñ*ðd
ð ˜D‘>ðd
ð $ D™>ðd
ð ' t™nðd
ð ' t™nðd
ð ! ×!1Ñ!1Ñ2ðd
ð ˜c 5§<¡<Ð/Ñ0ðd
ð Ð*Ñ+ðd
ð 
#òd
ó aó Eó Vó ôd
r@   r‡  aÚ  
    The Mixtral Model transformer with a sequence classification head on top (linear layer).

    [`MixtralForSequenceClassification`] uses the last token in order to do the classification, as other causal models
    (e.g. GPT-2) do.

    Since it does classification on the last token, it requires to know the position of the last token. If a
    `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
    no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
    padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
    each row of the batch).
    c                   ó(  ‡ — e Zd Zˆ 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
j                     d
e	e   de	e   de	e   defd„«       «       Zˆ xZS )Ú MixtralForSequenceClassificationc                 óè   •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        j                  |j                  | j                  d¬«      | _        | j                  «        y r-   )
r0   r1   Ú
num_labelsr3  r  r	   r6   r4   Úscorer=  r<   s     €r?   r1   z)MixtralForSequenceClassification.__init__C  sS   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒÜ! &Ó)ˆŒ
Ü—Y‘Y˜v×1Ñ1°4·?±?ÈÔOˆŒ
ð 	�‰Õr@   c                 ó.   — | j                   j                  S rB   rŽ  r—   s    r?   r@  z5MixtralForSequenceClassification.get_input_embeddingsL  r�  r@   c                 ó&   — || j                   _        y rB   rŽ  rB  s     r?   rC  z5MixtralForSequenceClassification.set_input_embeddingsO  r‘  r@   rD  r¶   r¥   r  rE  r£  ró   rÚ   rF  rY   c
           
      ó¢  — | j                  ||||||||	¬«      }
|
j                  }| j                  |«      }|�|j                  d   }n|j                  d   }| j                  j
                  €|dk7  rt        d«      ‚| j                  j
                  €d}nÃ|�“|| j                  j
                  k7  j                  |j                  t        j                  «      }t        j                  |j                  d   |j                  t        j                  ¬«      }||z  j                  d«      }n.d}t        j                  | j                  j                   › d�«       |t        j                  ||j                  ¬	«      |f   }d}|�| j#                  |||| j                  ¬
«      }t%        |||
j&                  |
j(                  |
j*                  ¬«      S )á�  
        labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
            config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
            `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
        ©r¶   r¥   r  rE  ró   rÚ   rF  Nr   r'   z=Cannot handle batch sizes > 1 if no padding token is defined.r\   )rb   r_   zŠ will not detect padding tokens in `inputs_embeds`. Results may be unexpected if using padding tokens in conjunction with `inputs_embeds.`rI  )rŠ  r£  Úpooled_logitsr+   )r¥  rŠ  r  rC   rK  )r  rJ  r²  re   r+   r5  rL  rp   rb   rg   Úint32rN  Úargmaxrà   rá   r>   rF   r¨  r   r  rC   rK  )r=   rD  r¶   r¥   r  rE  r£  ró   rÚ   rF  Útransformer_outputsrC   rŠ  rx   Úlast_non_pad_tokenÚnon_pad_maskÚtoken_indicesr¸  r¥  s                      r?   rE   z(MixtralForSequenceClassification.forwardR  sÁ  € ð* 8<·z±zØØ)Ø%Ø+Ø'ØØ/Ø!5ð 8Bó 	8
Ðð ,×=Ñ=ˆØ—‘˜MÓ*ˆàÐ Ø"Ÿ™¨Ñ+‰Jà&×,Ñ,¨QÑ/ˆJà�;‰;×#Ñ#Ð+°
¸a²ÜÐ\Ó]Ð]Ø�;‰;×#Ñ#Ð+Ø!#ÑØÐ"à%¨¯©×)AÑ)AÑA×EÑEÀfÇmÁmÔUZ×U`ÑU`ÓaˆLÜ!ŸL™L¨¯©¸Ñ)<ÀVÇ]Á]ÔZ_×ZeÑZeÔfˆMØ"/°,Ñ">×!FÑ!FÀrÓ!JÑà!#ÐÜ×ÑØ—>‘>×*Ñ*Ð+ð ,Zð Zôð
 œuŸ|™|¨J¸v¿}¹}ÔMÐOaÐaÑbˆàˆØÐØ×%Ñ%¨V¸FÐR_Ðhl×hsÑhsÐ%ÓtˆDä/ØØ Ø/×?Ñ?Ø-×;Ñ;Ø*×5Ñ5ô
ð 	
r@   ©	NNNNNNNNN)rF   rG   rH   r1   r@  rC  r#   r"   rw  r   rg   rè   r…   r   rú   rù   r   rE   rI   rJ   s   @r?   r¯  r¯  3  s  ø„ ô ò'ò(ð Ù*Ð+CÓDð 15Ø15Ø37Ø+/Ø59Ø-1Ø$(Ø,0Ø/3ñA
à˜E×,Ñ,Ñ-ðA
ð ! §¡Ñ.ðA
ð ˜u×/Ñ/Ñ0ð	A
ð
 " %™ðA
ð   × 1Ñ 1Ñ2ðA
ð ˜×)Ñ)Ñ*ðA
ð ˜D‘>ðA
ð $ D™>ðA
ð ' t™nðA
ð 
*òA
ó Eó ôA
r@   r¯  z¶
    The Mixtral Model transformer with a token classification head on top (a linear layer on top of the hidden-states
    output) e.g. for Named-Entity-Recognition (NER) tasks.
    c                   óD  ‡ — e Zd Zˆ fd„Zd„ Zd„ Ze ee«       e	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j                     dee   dee   dee   defd„«       «       «       Zˆ xZS )ÚMixtralForTokenClassificationc                 ó„  •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        |dd «      �|j                  }nt        |dd «      �|j                  }nd}t        j                  |«      | _
        t        j                  |j                  |j                  «      | _        | j                  «        y )NÚclassifier_dropoutÚhidden_dropoutgš™™™™™¹?)r0   r1   r±  r3  r  rË   rÃ  rÄ  r	   ÚDropoutr¸   r6   r4   r²  r=  )r=   r+   rÃ  r>   s      €r?   r1   z&MixtralForTokenClassification.__init__   s¢   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒÜ! &Ó)ˆŒ
Ü�6Ð/°Ó6ÐBØ!'×!:Ñ!:ÑÜ�VÐ-¨tÓ4Ð@Ø!'×!6Ñ!6Ñà!$ÐÜ—z‘zÐ"4Ó5ˆŒÜ—Y‘Y˜v×1Ñ1°6×3DÑ3DÓEˆŒ
ð 	�‰Õr@   c                 ó.   — | j                   j                  S rB   rŽ  r—   s    r?   r@  z2MixtralForTokenClassification.get_input_embeddings°  r�  r@   c                 ó&   — || j                   _        y rB   rŽ  rB  s     r?   rC  z2MixtralForTokenClassification.set_input_embeddings³  r‘  r@   )Ú
checkpointr¢  r&  rD  r¶   r¥   r  rE  r£  ró   rÚ   rF  rY   c
           
      ó  — | j                  ||||||||	¬«      }
|
j                  }| j                  |«      }| j                  |«      }d}|�| j	                  ||| j
                  «      }t        |||
j                  |
j                  ¬«      S )r¶  r·  N)r¥  rŠ  rC   rK  )	r  rJ  r¸   r²  r¨  r+   r   rC   rK  )r=   rD  r¶   r¥   r  rE  r£  ró   rÚ   rF  rø   Úsequence_outputrŠ  r¥  s                 r?   rE   z%MixtralForTokenClassification.forward¶  s    € ð4 ,0¯:©:ØØ)Ø%Ø+Ø'ØØ/Ø!5ð ,6ó 	,
ˆð "×3Ñ3ˆØŸ,™, Ó7ˆØ—‘˜OÓ,ˆàˆØÐØ×%Ñ% f¨f°d·k±kÓBˆDä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r@   r¿  )rF   rG   rH   r1   r@  rC  r#   r"   rw  r    Ú_CHECKPOINT_FOR_DOCr   r­  r   rg   rè   r…   r   rú   rù   rE   rI   rJ   s   @r?   rÁ  rÁ  ˜  s  ø„ ôò 'ò(ð Ù*Ð+CÓDÙØ&Ø)Ø$ôð 15Ø15Ø37Ø+/Ø59Ø-1Ø$(Ø,0Ø/3ñ*
à˜E×,Ñ,Ñ-ð*
ð ! §¡Ñ.ð*
ð ˜u×/Ñ/Ñ0ð	*
ð
 " %™ð*
ð   × 1Ñ 1Ñ2ð*
ð ˜×)Ñ)Ñ*ð*
ð ˜D‘>ð*
ð $ D™>ð*
ð ' t™nð*
ð 
ò*
óó Eó ô*
r@   rÁ  zç
The Mixtral Model transformer with a span classification head on top for extractive question-answering tasks like
SQuAD (a linear layer on top of the hidden-states output to compute `span start logits` and `span end logits`).
    c                   ód  ‡ — e Zd ZdZˆ 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eeej                     f      d	e
ej                     d
e
ej                     de
ej                     de
e   de
e   defd„«       «       Zˆ xZS )ÚMixtralForQuestionAnsweringr  c                 ó®   •— t         ‰| �  |«       t        j                  |j                  d«      | _        t        |«      | _        | j                  «        y )Nrd   )	r0   r1   r	   r6   r4   Ú
qa_outputsr3  r  r=  r<   s     €r?   r1   z$MixtralForQuestionAnswering.__init__ô  s@   ø€ Ü‰Ñ˜Ô ÜŸ)™) F×$6Ñ$6¸Ó:ˆŒÜ! &Ó)ˆŒ
ð 	�‰Õr@   c                 ó.   — | j                   j                  S rB   rŽ  r—   s    r?   r@  z0MixtralForQuestionAnswering.get_input_embeddingsü  r�  r@   c                 ó&   — || j                   _        y rB   rŽ  rB  s     r?   rC  z0MixtralForQuestionAnswering.set_input_embeddingsÿ  r‘  r@   rD  r¶   r¥   r  rE  Ústart_positionsÚend_positionsrÚ   rF  rY   c
           	      ó”  — | j                  |||||||	¬«      }|j                  }| j                  |«      }|j                  dd¬«      \  }}|j	                  d«      j                  «       }|j	                  d«      j                  «       }d}|�|� | j                  ||||fi |
¤Ž}t        ||||j                  |j                  ¬«      S )a  
        start_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the start of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        end_positions (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
            Labels for position (index) of the end of the labelled span for computing the token classification loss.
            Positions are clamped to the length of the sequence (`sequence_length`). Position outside of the sequence
            are not taken into account for computing the loss.
        )r¶   r¥   r  rE  rÚ   rF  r'   r\   r`   N)r¥  Ústart_logitsÚ
end_logitsrC   rK  )
r  rJ  rÏ  ÚsplitÚsqueezer¿   r¨  r   rC   rK  )r=   rD  r¶   r¥   r  rE  rÒ  rÓ  rÚ   rF  rÀ   rø   rÊ  rŠ  rÕ  rÖ  r¥  s                    r?   rE   z#MixtralForQuestionAnswering.forward  sç   € ð4 ,0¯:©:ØØ)Ø%Ø+Ø'Ø/Ø!5ð ,6ó ,
ˆð "×3Ñ3ˆà—‘ Ó1ˆØ#)§<¡<°°r <Ó#:Ñ ˆ�jØ#×+Ñ+¨BÓ/×:Ñ:Ó<ˆØ×'Ñ'¨Ó+×6Ñ6Ó8ˆ
àˆØÐ&¨=Ð+DØ%�4×%Ñ% l°JÀÐQ^ÑiÐbhÑiˆDä+ØØ%Ø!Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r@   r¿  )rF   rG   rH   r'  r1   r@  rC  r#   r"   rw  r   rg   rè   rú   r   r   r   rù   r   rE   rI   rJ   s   @r?   rÍ  rÍ  ê  s   ø„ ð  Ðôò'ò(ð Ù*Ð+CÓDð 15Ø6:Ø37ØKOØ59Ø6:Ø48Ø,0Ø/3ñ3
à˜E×,Ñ,Ñ-ð3
ð ! ×!2Ñ!2Ñ3ð3
ð ˜u×/Ñ/Ñ0ð	3
ð
 " %¨¨t°E×4EÑ4EÑ/FÐ(FÑ"GÑHð3
ð   × 1Ñ 1Ñ2ð3
ð " %×"2Ñ"2Ñ3ð3
ð   × 0Ñ 0Ñ1ð3
ð $ D™>ð3
ð ' t™nð3
ð 
&ò3
ó Eó ô3
r@   rÍ  )Nr'   )rÛ   )Nrd   N)SÚ	functoolsr   Útypingr   r   r   r   r   rg   Útorch.nn.functionalr	   rr   rk   Úactivationsr   Úcache_utilsr   r   r   r   Ú
generationr   Úmodeling_attn_mask_utilsr   Úmodeling_flash_attention_utilsr   Úmodeling_outputsr   r   r   r   r   r   r   Úmodeling_rope_utilsr   r   Úmodeling_utilsr   r   Úprocessing_utilsr   Úutilsr   r    r!   r"   r#   r$   r%   Úutils.deprecationr&   Úconfiguration_mixtralr(   Ú
get_loggerrF   rà   rË  r­  ÚModuler*   rL   r‡   rž   r©   r…   rç   r±   rm   rÆ   rÈ   rê   rü   ÚMIXTRAL_START_DOCSTRINGr  rw  r3  rz  r…  r‡  r¯  rÁ  rÍ  rõ   r@   r?   ú<module>rë     sü  ðõ6 ß 9Õ 9ã ß Ð Ý å !ß OÓ OÝ )Ý >Ý B÷÷ ñ ÷ Lß FÝ &÷÷ ñ õ 1Ý 0ð 
ˆ×	Ñ	˜HÓ	%€à3Ð Ø!€ô% §	¡	ô %ô$A2˜BŸI™Iô A2ôHJ�R—Y‘Yô Jò((óð6	U˜UŸ\™\ð 	U°#ð 	U¸%¿,¹,ó 	Uð& ñ%Ø�I‰Ið%à�<‰<ð%ð 
�‰ð%ð �<‰<ð	%ð
 ˜UŸ\™\Ñ*ð%ð ð%ð ó%ô4A)�r—y‘yô A)ôHN˜"Ÿ)™)ô Nôb<˜RŸY™Yô <ðDÐ ñ" Ø[Øóô?˜_ó ?ó	ð?ð4@Ð ñF Ø[ØóôhÐ)ó hó	ðhôV	 ?Ð,¨jÔ >ð
 "&Ø
Ø-1ñ	O&Ø�u—|‘| U¨5¯<©<Ñ%8¸$Ð>Ñ?ðO&à˜#‘ðO&ð ˜UŸ\™\Ñ*ð	O&ð
 ˆ5�<‰<˜ÐÑóO&ôdK
Ð/°ô K
ñ\ ðð óôS
Ð'=ó S
óðS
ñl ðð óôH
Ð$:ó H
óðH
ñV ðð óôF
Ð"8ó F
óñF
r@   