Ë
    T^(h±Ã  ã                   óÔ  — d Z ddlZddlmZmZmZmZ ddlZddlZddl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mZ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&m'Z' ddl(m)Z)  e#«       rddl*m+Z+ ddl,m-Z-  e$j\                  e/«      Z0dZ1dZ2 G d„ de	jf                  «      Z4d„ Z5d/d„Z6 G d„ de	jf                  «      Z7 G d„ de	jf                  «      Z8 G d„ de	jf                  «      Z9dZ: e d e:«       G d!„ d"e«      «       Z;d#Z< e d e:«       G d$„ d%e;«      «       Z= G d&„ d'e;e«      Z> e d(e:«       G d)„ d*e;«      «       Z? e d+e:«       G d,„ d-e;«      «       Z@g d.¢ZAy)0zPyTorch Persimmon model.é    N)ÚListÚOptionalÚTupleÚUnion)Únné   )ÚACT2FN)ÚCacheÚDynamicCacheÚStaticCache)ÚGenerationMixin)ÚAttentionMaskConverter)ÚBaseModelOutputWithPastÚCausalLMOutputWithPastÚ SequenceClassifierOutputWithPastÚTokenClassifierOutput)ÚROPE_INIT_FUNCTIONSÚdynamic_rope_update)ÚPreTrainedModel)Úadd_code_sample_docstringsÚadd_start_docstringsÚ%add_start_docstrings_to_model_forwardÚcan_return_tupleÚis_torch_flex_attn_availableÚloggingÚreplace_return_docstrings)Údeprecate_kwargé   )ÚPersimmonConfig)Ú	BlockMask)Úmake_flex_block_causal_maskzadept/persimmon-8b-baser   c                   ó^   ‡ — e Zd Zddefˆ fd„Z ej                  «       ed„ «       «       Zˆ xZ	S )ÚPersimmonRotaryEmbeddingÚconfigc                 óê  •— 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)ÚsuperÚ__init__Úhasattrr&   Úgetr'   Úmax_position_embeddingsÚmax_seq_len_cachedÚoriginal_max_seq_lenr$   r   Úrope_init_fnÚattention_scalingÚregister_bufferr*   Úoriginal_inv_freq)Úselfr$   Údevicer*   Ú	__class__s       €ún/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/persimmon/modeling_persimmon.pyr-   z!PersimmonRotaryEmbedding.__init__D   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Ø!%§¡ˆÕó    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   ÚmpsÚcpuF)Údevice_typeÚenabledé   ©Údim)Údtype)r*   ÚfloatÚexpandÚshapeÚtor8   Ú
isinstancer(   ÚstrÚtorchÚautocastÚ	transposeÚcatÚcosr4   ÚsinrE   )
r7   ÚxÚposition_idsÚinv_freq_expandedÚposition_ids_expandedr@   ÚfreqsÚembrP   rQ   s
             r:   Úforwardz PersimmonRotaryEmbedding.forwardU   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.©N)
Ú__name__Ú
__module__Ú__qualname__r   r-   rL   Úno_gradr   rX   Ú__classcell__©r9   s   @r:   r#   r#   C   s3   ø„ ñ/˜õ /ð" €U‡]�]ƒ_Øñ<ó ó ô<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=   rB   rC   )rH   rL   rO   )rR   Úx1Úx2s      r:   Úrotate_halfrc   f   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.
    )Ú	unsqueezerc   )ÚqÚkrP   rQ   rS   Úunsqueeze_dimÚq_embedÚk_embeds           r:   Úapply_rotary_pos_embrk   n   sY   € ð( �-‰-˜Ó
&€CØ
�-‰-˜Ó
&€CØ�3‰wœ; q›>¨CÑ/Ñ0€GØ�3‰wœ; q›>¨CÑ/Ñ0€GØ�GÐÐr;   c                   ó$   ‡ — e Zd Zˆ fd„Zd„ Zˆ xZS )ÚPersimmonMLPc                 ó  •— t         ‰| �  «        t        j                  |j                  |j
                  «      | _        t        j                  |j
                  |j                  «      | _        t        |j                     | _
        y rY   )r,   r-   r   ÚLinearÚhidden_sizeÚintermediate_sizeÚdense_h_to_4hÚdense_4h_to_hr	   Ú
hidden_actÚact©r7   r$   r9   s     €r:   r-   zPersimmonMLP.__init__‹   s^   ø€ Ü‰ÑÔÜŸY™Y v×'9Ñ'9¸6×;SÑ;SÓTˆÔÜŸY™Y v×'?Ñ'?À×ASÑASÓTˆÔÜ˜&×+Ñ+Ñ,ˆ�r;   c                 ól   — | j                  |«      }| j                  |«      }| j                  |«      }|S rY   )rr   ru   rs   )r7   Úhidden_statess     r:   rX   zPersimmonMLP.forward‘   s6   € Ø×*Ñ*¨=Ó9ˆØŸ™ Ó/ˆØ×*Ñ*¨=Ó9ˆØÐr;   )rZ   r[   r\   r-   rX   r^   r_   s   @r:   rm   rm   Š   s   ø„ ô-ör;   rm   c                   óÖ  ‡ — e Zd ZdZddedee   fˆ fd„Zdej                  de
ej                  ej                  ej                  f   fd„Z	 	 	 	 	 	 	 ddej                  d	eej                     d
eej                     dee   dededeej                     dee
ej                  ej                  f      de
ej                  eej                     ee
ej                        f   fd„Zˆ xZS )ÚPersimmonAttentionz=Multi-headed attention from 'Attention Is All You Need' paperr$   Ú	layer_idxc                 óÆ  •— t         ‰| �  «        || _        || _        |€-t        j                  d| j                  j                  › d�«       |j                  | _        |j                  | _
        | j                  | j                  z  | _        |j                  | _        t        | j                  |j                  z  «      | _        d| _        | j                  | j                  z  | j                  k7  r&t#        d| j                  › d| j                  › d�«      ‚t%        j&                  | j                  d| j                  z  d¬«      | _        t%        j&                  | j                  | j                  z  | j                  d¬«      | _        |j,                  | _        | j,                  r|t%        j.                  |j                  | j                  z  |j0                  d¬	«      | _        t%        j.                  |j                  | j                  z  |j0                  d¬	«      | _        t%        j6                  |j8                  «      | _        t;        | j                  ¬
«      | _        y )NzInstantiating z¹ without passing a `layer_idx` is not recommended and will lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` when creating this class.Tz?hidden_size must be divisible by num_heads (got `hidden_size`: z and `num_heads`: z).r   ©Úbias)ÚepsÚelementwise_affine©r$   )r,   r-   r$   r{   ÚloggerÚwarning_oncer9   rZ   rp   Únum_attention_headsÚ	num_headsÚhead_dimÚ
rope_thetaÚintÚpartial_rotary_factorÚrotary_ndimsÚ	is_causalÚ
ValueErrorr   ro   Úquery_key_valueÚdenseÚqk_layernormÚ	LayerNormÚlayer_norm_epsÚq_layernormÚk_layernormÚDropoutÚattention_dropoutr#   Ú
rotary_emb©r7   r$   r{   r9   s      €r:   r-   zPersimmonAttention.__init__›   sè  ø€ Ü‰ÑÔØˆŒØ"ˆŒØÐÜ×ÑØ  §¡×!8Ñ!8Ð 9ð :,ð ,ôð "×-Ñ-ˆÔØ×3Ñ3ˆŒØ×(Ñ(¨D¯N©NÑ:ˆŒØ ×+Ñ+ˆŒÜ §¡°×0LÑ0LÑ LÓMˆÔØˆŒà�M‰M˜DŸN™NÑ*¨t×/?Ñ/?Ò?ÜØQÐRV×RbÑRbÐQcØ$ T§^¡^Ð$4°Bð8óð ô  "Ÿy™y¨×)9Ñ)9¸1¸t×?OÑ?OÑ;OÐVZÔ[ˆÔÜ—Y‘Y˜tŸ~™~°·±Ñ=¸t×?OÑ?OÐVZÔ[ˆŒ
Ø"×/Ñ/ˆÔà×ÒÜ!Ÿ|™|Ø×"Ñ" d§n¡nÑ4¸&×:OÑ:OÐdhô ˆDÔô  "Ÿ|™|Ø×"Ñ" d§n¡nÑ4¸&×:OÑ:OÐdhô ˆDÔô "$§¡¨F×,DÑ,DÓ!EˆÔÜ2¸$¿+¹+ÔFˆ�r;   Ú	fused_qkvÚreturnc                 ó®   — |j                   \  }}}|j                  ||| j                  d| j                  «      }|dddd…f   |dddd…f   |dddd…f   fS )aÊ  
        Split the last dimension into (num_heads, head_dim) without making any copies, results share same memory
        storage as `fused_qkv`

        Args:
            fused_qkv (`torch.tensor`): [batch_size, seq_length, num_heads * 3 * head_dim]

        Returns:
            query: [batch_size, seq_length, num_heads, head_dim] key: [batch_size, seq_length, num_heads, head_dim]
            value: [batch_size, seq_length, num_heads, head_dim]
        r   .r   Nr   rB   )rH   Úviewr…   r†   )r7   r˜   Ú
batch_sizeÚ
seq_lengthÚthree_times_hidden_sizes        r:   Ú_split_headszPersimmonAttention._split_headsÀ   sb   € ð ;D¿/¹/Ñ7ˆ
�JÐ 7Ø—N‘N :¨z¸4¿>¹>È1ÈdÏmÉmÓ\ˆ	Ø˜˜a¢˜Ñ# Y¨s°A²q¨yÑ%9¸9ÀSÈ!ÊQÀYÑ;OÐOÐOr;   rx   Úattention_maskrS   Úpast_key_valueÚoutput_attentionsÚ	use_cacheÚcache_positionÚposition_embeddingsc	                 óö  — |j                  «       \  }	}
}| j                  |«      }| j                  |«      \  }}}| j                  r"| j	                  |«      }| j                  |«      }|j                  dd«      }|j                  dd«      }|j                  dd«      }|\  }}|dd | j                  …f   |d| j                  d …f   }}|dd | j                  …f   |d| j                  d …f   }}t        ||||«      \  }}t        j                  ||fd¬«      }t        j                  ||fd¬«      }|�2||| j                  |dœ}|j                  ||| j                  |«      \  }}t        j                  ||j                  dd«      «      t        j                  | j                   «      z  }|�#|d d …d d …d d …d |j"                  d   …f   }||z   }t$        j&                  j)                  |t        j*                  d¬	«      j-                  |j.                  «      }| j1                  |«      }t        j                  ||«      }|j                  «       |	| j2                  |
| j                   fk7  r7t5        d
|	| j2                  |
| j                   f› d|j                  «       › �«      ‚|j                  dd«      j7                  «       }|j9                  |	|
| j:                  «      }| j=                  |«      }|sd }|||fS )Nr   rB   .r=   rC   )rQ   rP   Úpartial_rotation_sizer¤   r   éþÿÿÿ)rE   rD   z `attn_output` should be of size z	, but is )Úsizer�   rŸ   r�   r’   r“   rN   rŠ   rk   rL   rO   Úupdater{   ÚmatmulÚmathÚsqrtr†   rH   r   Ú
functionalÚsoftmaxÚfloat32rI   rE   r•   r…   rŒ   Ú
contiguousÚreshaperp   rŽ   )r7   rx   r    rS   r¡   r¢   r£   r¤   r¥   ÚbszÚq_lenÚ_r˜   Úquery_statesÚ
key_statesÚvalue_statesrP   rQ   Ú	query_rotÚ
query_passÚkey_rotÚkey_passÚcache_kwargsÚattn_weightsÚcausal_maskÚattn_outputs                             r:   rX   zPersimmonAttention.forwardÐ   s"  € ð &×*Ñ*Ó,‰ˆˆU�Að ×(Ñ(¨Ó7ˆ	ð 48×3DÑ3DÀYÓ3OÑ0ˆ�z <à×ÒØ×+Ñ+¨LÓ9ˆLØ×)Ñ)¨*Ó5ˆJð $×-Ñ-¨a°Ó3ˆØ#×-Ñ-¨a°Ó3ˆØ×)Ñ)¨!¨QÓ/ˆ
à&‰ˆˆSð ˜Ð1 × 1Ñ 1Ð1Ð1Ñ2Ø˜˜d×/Ñ/Ñ1Ð1Ñ2ð ˆ	ð
 �sÐ/˜d×/Ñ/Ð/Ð/Ñ0Ø�s˜D×-Ñ-Ñ/Ð/Ñ0ð ˆô
 2°)¸WÀcÈ3ÓOÑˆ	�7ô —y‘y )¨ZÐ!8¸bÔAˆÜ—Y‘Y ¨Ð2¸Ô;ˆ
àÐ%ð ØØ)-×):Ñ):Ø"0ñ	ˆLð (6×'<Ñ'<¸ZÈÐW[×WeÑWeÐgsÓ'tÑ$ˆJ˜ä—|‘| L°*×2FÑ2FÀqÈ!Ó2LÓMÔPT×PYÑPYÐZ^×ZgÑZgÓPhÑhˆàÐ%Ø(ªªAªqÐ2H°J×4DÑ4DÀRÑ4HÐ2HÐ)HÑIˆKØ'¨+Ñ5ˆLô —}‘}×,Ñ,¨\ÄÇÁÐTVÐ,ÓW×ZÑZÐ[g×[mÑ[mÓnˆØ×-Ñ-¨lÓ;ˆä—l‘l <°Ó>ˆà×ÑÓ # t§~¡~°u¸d¿m¹mÐ!LÒLÜØ2°C¸¿¹ÈÐPT×P]ÑP]Ð3^Ð2_ð `Ø×$Ñ$Ó&Ð'ð)óð ð
 "×+Ñ+¨A¨qÓ1×<Ñ<Ó>ˆØ!×)Ñ)¨#¨u°d×6FÑ6FÓGˆà—j‘j Ó-ˆá ØˆLà˜L¨.Ð8Ð8r;   rY   ©NNNFFNN)rZ   r[   r\   Ú__doc__r   r   rˆ   r-   rL   ÚTensorr   rŸ   Ú
LongTensorr
   ÚboolrX   r^   r_   s   @r:   rz   rz   ˜   s9  ø„ ÙGñ#G˜ð #G¸8ÀC¹=õ #GðJP e§l¡lð P°u¸U¿\¹\È5Ï<É<ÐY^×YeÑYeÐ=eÑ7fó Pð& 26Ø37Ø*.Ø"'ØØ59ØKOñR9à—|‘|ðR9ð ! §¡Ñ.ðR9ð ˜u×/Ñ/Ñ0ð	R9ð
 ! ™ðR9ð  ðR9ð ðR9ð ! ×!1Ñ!1Ñ2ðR9ð & e¨E¯L©L¸%¿,¹,Ð,FÑ&GÑHðR9ð 
ˆu�|‰|˜X e§l¡lÑ3°X¸eÀEÇLÁLÑ>QÑ5RÐRÑ	S÷R9r;   rz   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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 )ÚPersimmonDecoderLayerr$   r{   c                 ó�  •— t         ‰| �  «        |j                  | _        t        ||¬«      | _        t        |«      | _        t        j                  |j                  |j                  ¬«      | _
        t        j                  |j                  |j                  ¬«      | _        t        j                  |j                  «      | _        y )N)r$   r{   ©r   )r,   r-   rp   rz   Ú	self_attnrm   Úmlpr   r�   r‘   Úinput_layernormÚpost_attention_layernormr”   Úhidden_dropoutÚdropoutr—   s      €r:   r-   zPersimmonDecoderLayer.__init__&  sŠ   ø€ Ü‰ÑÔØ!×-Ñ-ˆÔÜ+°6ÀYÔOˆŒÜ Ó'ˆŒÜ!Ÿ|™|¨F×,>Ñ,>ÀF×DYÑDYÔZˆÔÜ(*¯©°V×5GÑ5GÈV×MbÑMbÔ(cˆÔ%Ü—z‘z &×"7Ñ"7Ó8ˆ�r;   rx   r    rS   r¡   r¢   r£   r¤   r¥   r™   c	           
      ó
  — |}	| j                  |«      }| j                  ||||||||¬«      \  }}
}|	|z   }|}	| j                  |«      }| 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, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
            position_ids (`torch.LongTensor` of shape `({0})`, *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_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.
            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
            position_embeddings (`Tuple[torch.FloatTensor, torch.FloatTensor]`, *optional*):
                Tuple containing the cosine and sine positional embeddings of shape `(batch_size, seq_len, head_dim)`,
                with `head_dim` being the embedding dimension of each attention head.
        )rx   r    rS   r¡   r¢   r£   r¤   r¥   )rÌ   rÊ   rÍ   rË   rÏ   )r7   rx   r    rS   r¡   r¢   r£   r¤   r¥   ÚresidualÚself_attn_weightsÚpresent_key_valueÚoutputss                r:   rX   zPersimmonDecoderLayer.forward/  sÊ   € ðF !ˆà×,Ñ,¨]Ó;ˆð ?C¿n¹nØ'Ø)Ø%Ø)Ø/ØØ)Ø 3ð ?Mó 	?
Ñ;ˆÐ(Ð*;ð ! =Ñ0ˆð !ˆØ×5Ñ5°mÓDˆØŸ™ Ó/ˆàŸ™ ]Ó3ˆØ%¨Ñ0ˆà Ð"ˆáØÐ)Ð+Ñ+ˆGáØÐ)Ð+Ñ+ˆGàˆr;   rÁ   )rZ   r[   r\   r   rˆ   r-   rL   rÃ   r   rÄ   r   rÅ   ÚFloatTensorrX   r^   r_   s   @r:   rÇ   rÇ   %  s  ø„ ð9˜ð 9¸3õ 9ð 26Ø37Ø8<Ø,1Ø$)Ø59ØKOñDà—|‘|ðDð ! §¡Ñ.ðDð ˜u×/Ñ/Ñ0ð	Dð
 !  u§|¡|Ñ!4Ñ5ðDð $ D™>ðDð ˜D‘>ðDð ! ×!1Ñ!1Ñ2ðDð & e¨E¯L©L¸%¿,¹,Ð,FÑ&GÑHðDð 
ˆu× Ñ  (¨5°×1BÑ1BÀE×DUÑDUÐ1UÑ+VÑ"WÐWÑ	X÷Dr;   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 ([`PersimmonConfig`]):
            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.
zWThe bare Persimmon Model outputting raw hidden-states without any specific head on top.c                   ó4   — e Zd ZeZdZdZdgZdZdZ	dZ
dZd„ Zy)ÚPersimmonPreTrainedModelÚmodelTrÇ   Úpast_key_valuesc                 ó  — | 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 )Nç        )ÚmeanÚstd)r$   Úinitializer_rangerJ   r   ro   ÚweightÚdataÚnormal_r~   Úzero_Ú	EmbeddingÚpadding_idx)r7   ÚmodulerÝ   s      r:   Ú_init_weightsz&PersimmonPreTrainedModel._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)rZ   r[   r\   r   Úconfig_classÚbase_model_prefixÚsupports_gradient_checkpointingÚ_no_split_modulesÚ_skip_keys_device_placementÚ_supports_cache_classÚ_supports_quantized_cacheÚ_supports_static_cacheræ   © r;   r:   r×   r×   ‡  s;   „ ð
 #€LØÐØ&*Ð#Ø0Ð1ÐØ"3ÐØ ÐØ $ÐØ!Ðó	?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 `decoder_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`.

            Two formats are allowed:
            - a [`~cache_utils.Cache`] instance, see our
            [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache);
            - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
            shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
            cache format.

            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                   ó&  ‡ — 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j                     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j0                  dej2                  dej                  defd„«       Zˆ xZS )ÚPersimmonModelz£
    Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`PersimmonDecoderLayer`]

    Args:
        config: PersimmonConfig
    r$   c           	      ó   •— t         ‰| �  |«       |j                  | _        |j                  | _        t        j                  |j                  |j                  | j                  «      | _        t        j                  t        |j                  «      D �cg c]  }t        ||«      ‘Œ c}«      | _        t        j                  |j                  |j                  ¬«      | _        t#        |¬«      | _        d| _        | j)                  «        y c c}w )NrÉ   r�   F)r,   r-   Úpad_token_idrä   Ú
vocab_sizer   rã   rp   Úembed_tokensÚ
ModuleListÚrangeÚnum_hidden_layersrÇ   Úlayersr�   r‘   Úfinal_layernormr#   r–   Úgradient_checkpointingÚ	post_initr—   s      €r:   r-   zPersimmonModel.__init__ø  sÉ   ø€ Ü‰Ñ˜Ô Ø!×.Ñ.ˆÔØ ×+Ñ+ˆŒäŸL™L¨×):Ñ):¸F×<NÑ<NÐPT×P`ÑP`ÓaˆÔÜ—m‘mÜGLÈV×MeÑMeÓGfÖg¸)Ô" 6¨9Õ5Ògó
ˆŒô  "Ÿ|™|¨F×,>Ñ,>ÀF×DYÑDYÔZˆÔä2¸&ÔAˆŒà&+ˆÔ#à�‰Õùò hs   ÂDc                 ó   — | j                   S rY   ©rõ   ©r7   s    r:   Úget_input_embeddingsz#PersimmonModel.get_input_embeddings	  s   € Ø× Ñ Ð r;   c                 ó   — || _         y rY   rþ   ©r7   Úvalues     r:   Úset_input_embeddingsz#PersimmonModel.set_input_embeddings  s
   € Ø!ˆÕr;   Ú	input_idsr    rS   rÙ   Úinputs_embedsr£   r¢   Úoutput_hidden_statesr¤   r™   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}d}
|rIt        |t        «      s9d}
|€t        «       }n*t        j                  |«      }t        j                  d«       |€| j                  |«      }|	€F|�|j                  «       nd}t        j                   |||j"                  d   z   |j$                  ¬«      }	|€|	j'                  d«      }| j)                  |||	||«      }|}| j+                  ||«      }|rd	nd }|rd	nd }d }| j,                  D ]r  }|r||fz  }| j
                  r0| j                  r$| j/                  |j0                  |||||||	|«	      }n ||||||||	|¬
«      }|d   }|r	||rdnd   }|sŒj||d   fz  }Œt | j3                  |«      }|r||fz  }|r|nd }|
r|j5                  «       }t7        ||||¬«      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`...FTzÿWe detected that you are passing `past_key_values` as a tuple of tuples. This is deprecated and will be removed in v4.47. Please convert your cache or use an appropriate `Cache` class (https://huggingface.co/docs/transformers/kv_cache#legacy-cache-format)r   r   ©r8   rï   )r    rS   r¡   r¢   r£   r¤   r¥   rB   )Úlast_hidden_staterÙ   rx   Ú
attentions)r$   r¢   r  r£   rŒ   rû   Útrainingr‚   rƒ   rJ   r
   r   Úfrom_legacy_cacherõ   Úget_seq_lengthrL   ÚarangerH   r8   re   Ú_update_causal_maskr–   rù   Ú_gradient_checkpointing_funcÚ__call__rú   Úto_legacy_cacher   )r7   r  r    rS   rÙ   r  r£   r¢   r  r¤   Úreturn_legacy_cacheÚpast_seen_tokensr¿   rx   r¥   Úall_hidden_statesÚall_self_attnsÚnext_decoder_cacheÚdecoder_layerÚlayer_outputsÚ
next_caches                        r:   rX   zPersimmonModel.forward  sÇ  € ð 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð "+Ð!6‘I¸D¿K¹K×<QÑ<Qˆ	à˜Ð -°tÐ";Ò<ÜÐYÓZÐZà×&Ò&¨4¯=ª=ÙÜ×#Ñ#Øpôð "�	ð $ÐÙœZ¨¼Ô?Ø"&ÐØÐ&Ü".£.‘ä".×"@Ñ"@ÀÓ"Q�Ü×#Ñ#ð^ôð Ð Ø ×-Ñ-¨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ˆMÙ#Ø! mÐ%5Ñ5Ð!à×*Ò*¨t¯}ª}Ø $× AÑ AØ!×*Ñ*Ø!ØØ Ø#Ø%ØØ"Ø'ó
!‘ñ !.Ø!Ø#.Ø!-Ø#2Ø&7Ø'Ø#1Ø(;ô	!�ð *¨!Ñ,ˆMáØ%2Ñ8I±1ÈqÑ%QÐ"â Ø =°Ñ#3Ð"5Ñ5‘ðE"	6ðH ×,Ñ,¨]Ó;ˆñ  Ø -Ð!1Ñ1Ðá+4Ñ'¸$ˆ
ÙØ#×3Ñ3Ó5ˆJä&Ø+Ø&Ø+Ø%ô	
ð 	
r;   Ú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   Úsdpa)r  Úpast_key_values_lengthÚis_trainingr   r=   )Úsequence_lengthÚtarget_lengthrE   r8   r¤   rœ   )ÚcudaÚxpu)r$   Ú_attn_implementationÚanyrJ   rL   rÃ   r!   r    r  r   r   Ú_ignore_causal_mask_sdpar  rE   r8   rH   Úget_max_cache_shapeÚ5_prepare_4d_causal_attention_mask_with_cache_positionr(   ÚfinfoÚminÚ_unmask_unattended)r7   r    r  r¤   rÙ   r¢   r  Úusing_static_cacherE   r8   r#  r$  r¿   Ú	min_dtypes                 r:   r  z"PersimmonModel._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àÐr;   r#  r$  rE   r8   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.
        Né   )Ú
fill_valuerE   r8   r   )Údiagonalr	  r=   r   )rD   rL   r,  r-  ÚfullÚtriur  r²   rG   ÚclonerH   rI   r8   Úmasked_fill)r    r#  r$  rE   r8   r¤   rœ   Úkwargsr¿   r0  Úmask_lengthÚpadding_masks               r:   r+  zDPersimmonModel._prepare_4d_causal_attention_mask_with_cache_positionÐ  sy  € ðD Ð%¨.×*<Ñ*<Ó*>À!Ò*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ð Ðr;   ©	NNNNNNNNN)F)rZ   r[   r\   rÂ   r   r-   r   r  r   r   ÚPERSIMMON_INPUTS_DOCSTRINGr   rL   rÄ   rÃ   r   rÕ   rÅ   r   rX   r
   r  Ústaticmethodrˆ   rE   r8   r+  r^   r_   s   @r:   rñ   rñ   ì  sÑ  ø„ ñ
ð˜õ ò"!ò"ð Ù*Ð+EÓFð 15Ø15Ø37Ø=AØ59Ø$(Ø,0Ø/3Ø59ñv
à˜E×,Ñ,Ñ-ðv
ð ! §¡Ñ.ðv
ð ˜u×/Ñ/Ñ0ð	v
ð
 " $ u×'8Ñ'8Ñ"9Ñ:ðv
ð   × 1Ñ 1Ñ2ðv
ð ˜D‘>ðv
ð $ D™>ðv
ð ' t™nðv
ð ! ×!1Ñ!1Ñ2ðv
ð 
!òv
ó Gó ðv
ð~ #(ñDàŸ™ðDð —l‘lðDð Ÿ™ð	Dð
 ðDð  óDðL ð7ØŸ™ð7àð7ð ð7ð �{‰{ð	7ð
 —‘ð7ð Ÿ™ð7ð ò7ó ô7r;   rñ   c                   óÚ  ‡ — e Zd Zdg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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*                  f   defd„«       «       «       «       Zˆ xZS )ÚPersimmonForCausalLMzlm_head.weightc                 óè   •— t         ‰| �  |«       t        |«      | _        |j                  | _        t        j                  |j                  |j                  d¬«      | _        | j                  «        y ©NFr}   )
r,   r-   rñ   rØ   rô   r   ro   rp   Úlm_headrü   rv   s     €r:   r-   zPersimmonForCausalLM.__init__  sU   ø€ Ü‰Ñ˜Ô Ü# FÓ+ˆŒ
Ø ×+Ñ+ˆŒÜ—y‘y ×!3Ñ!3°V×5FÑ5FÈUÔSˆŒð 	�‰Õr;   c                 ó.   — | j                   j                  S rY   ©rØ   rõ   rÿ   s    r:   r   z)PersimmonForCausalLM.get_input_embeddings  ó   € Ø�z‰z×&Ñ&Ð&r;   c                 ó&   — || j                   _        y rY   rE  r  s     r:   r  z)PersimmonForCausalLM.set_input_embeddings  ó   € Ø"'ˆ�
‰
Õr;   c                 ó   — | j                   S rY   ©rC  rÿ   s    r:   Úget_output_embeddingsz*PersimmonForCausalLM.get_output_embeddings"  s   € Ø�|‰|Ðr;   c                 ó   — || _         y rY   rJ  )r7   Únew_embeddingss     r:   Úset_output_embeddingsz*PersimmonForCausalLM.set_output_embeddings&  s	   € Ø%ˆ�r;   c                 ó   — || _         y rY   ©rØ   )r7   Údecoders     r:   Úset_decoderz PersimmonForCausalLM.set_decoder*  s	   € Øˆ�
r;   c                 ó   — | j                   S rY   rP  rÿ   s    r:   Úget_decoderz PersimmonForCausalLM.get_decoder.  s   € Ø�z‰zÐr;   Únum_logits_to_keepz4.50Úlogits_to_keep)ÚversionÚnew_name)Úoutput_typerç   r  r    rS   rÙ   r  Úlabelsr£   r¢   r  r¤   r™   c                 óâ  — |�|n| j                   j                  }|	�|	n| j                   j                  }	| j                  ||||||||	|
¬«	      }|j                  }t        |t        «      rt        | d«      n|}| j                  |dd…|dd…f   «      }d}|�* | j                  ||fd| j                   j                  i|¤Ž}t        |||j                  |j                  |j                  ¬«      S )u!  
            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, PersimmonForCausalLM

        >>> model = PersimmonForCausalLM.from_pretrained("adept/persimmon-8b-base")
        >>> tokenizer = AutoTokenizer.from_pretrained("adept/persimmon-8b-base")

        >>> prompt = "human: Hey, what should I eat for dinner?"
        >>> 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]
        'human: Hey, what should I eat for dinner?\n\ncat: ðŸ�±\n\nhuman: ðŸ˜�\n\n'
        ```N)	r  r    rS   rÙ   r  r£   r¢   r  r¤   rô   ©ÚlossÚlogitsrÙ   rx   r  )r$   r¢   r  rØ   r
  rJ   rˆ   ÚslicerC  Úloss_functionrô   r   rÙ   rx   r  )r7   r  r    rS   rÙ   r  rZ  r£   r¢   r  r¤   rV  r9  rÔ   rx   Úslice_indicesr^  r]  s                     r:   rX   zPersimmonForCausalLM.forward1  s  € ðf 2CÐ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ð$DÑ È$Ï+É+×JjÑJjð 	ð
 ,0¯:©:ØØ)Ø%Ø+Ø'ØØ/Ø!5Ø)ð ,6ó 
,
ˆð  ×1Ñ1ˆä8BÀ>ÔSVÔ8Wœ˜~˜o¨tÔ4Ð]kˆØ—‘˜mªA¨}ºaÐ,?Ñ@ÓAˆàˆØÐØ%�4×%Ñ%ØØñð  Ÿ;™;×1Ñ1ðð ñ	ˆDô &ØØØ#×3Ñ3Ø!×/Ñ/Ø×)Ñ)ô
ð 	
r;   )NNNNNNNNNNr   )rZ   r[   r\   Ú_tied_weights_keysr-   r   r  rK  rN  rR  rT  r   r   r   r=  r   r   Ú_CONFIG_FOR_DOCr   rL   rÄ   rÃ   r   rÕ   rÅ   r   rˆ   rX   r^   r_   s   @r:   r@  r@    s‰  ø„ Ø*Ð+Ðôò'ò(òò&òòð ÙÐ)°6ÐDTÔUÙ*Ð+EÓFÙÐ+AÐP_Ô`ð 15Ø15Ø37Ø=AØ59Ø-1Ø$(Ø,0Ø/3Ø59Ø34ñU
à˜E×,Ñ,Ñ-ðU
ð ! §¡Ñ.ðU
ð ˜u×/Ñ/Ñ0ð	U
ð
 " $ u×'8Ñ'8Ñ"9Ñ:ðU
ð   × 1Ñ 1Ñ2ðU
ð ˜×)Ñ)Ñ*ðU
ð ˜D‘>ðU
ð $ D™>ðU
ð ' t™nðU
ð ! ×!1Ñ!1Ñ2ðU
ð ˜c 5§<¡<Ð/Ñ0ðU
ð 
 òU
ó aó Gó Vó ôU
r;   r@  aØ  
    The Persimmon transformer with a sequence classification head on top (linear layer).

    [`PersimmonForSequenceClassification`] 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 )Ú"PersimmonForSequenceClassificationc                 óè   •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        j                  |j                  | j                  d¬«      | _        | j                  «        y rB  )
r,   r-   Ú
num_labelsrñ   rØ   r   ro   rp   Úscorerü   rv   s     €r:   r-   z+PersimmonForSequenceClassification.__init__ž  sS   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒÜ# FÓ+ˆŒ
Ü—Y‘Y˜v×1Ñ1°4·?±?ÈÔOˆŒ
ð 	�‰Õr;   c                 ó.   — | j                   j                  S rY   rE  rÿ   s    r:   r   z7PersimmonForSequenceClassification.get_input_embeddings§  rF  r;   c                 ó&   — || j                   _        y rY   rE  r  s     r:   r  z7PersimmonForSequenceClassification.set_input_embeddingsª  rH  r;   r  r    rS   rÙ   r  rZ  r£   r¢   r  r™   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    rS   rÙ   r  r£   r¢   r  Nr   r   z=Cannot handle batch sizes > 1 if no padding token is defined.r=   )r8   rE   zŠ will not detect padding tokens in `inputs_embeds`. Results may be unexpected if using padding tokens in conjunction with `inputs_embeds.`r	  )r^  rZ  Úpooled_logitsr$   r\  )rØ   r
  rh  rH   r$   ró   rŒ   rI   r8   rL   Úint32r  Úargmaxr‚   rƒ   r9   rZ   r`  r   rÙ   rx   r  )r7   r  r    rS   rÙ   r  rZ  r£   r¢   r  Útransformer_outputsrx   r^  rœ   Úlast_non_pad_tokenÚnon_pad_maskÚtoken_indicesrn  r]  s                      r:   rX   z*PersimmonForSequenceClassification.forward­  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;   r<  )rZ   r[   r\   r-   r   r  r   r   r=  r   rL   rÄ   rÃ   r
   rÕ   rÅ   r   rX   r^   r_   s   @r:   re  re  �  s  ø„ ô"ò'ò(ð Ù*Ð+EÓFð 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
ó Gó ôA
r;   re  z¸
    The Persimmon 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 )ÚPersimmonForTokenClassificationc                 ó„  •— t         ‰| �  |«       |j                  | _        t        |«      | _        t        |dd «      �|j                  }nt        |dd «      �|j                  }nd}t        j                  |«      | _
        t        j                  |j                  |j                  «      | _        | j                  «        y )NÚclassifier_dropoutrÎ   gš™™™™™¹?)r,   r-   rg  rñ   rØ   Úgetattrrx  rÎ   r   r”   rÏ   ro   rp   rh  rü   )r7   r$   rx  r9   s      €r:   r-   z(PersimmonForTokenClassification.__init__ü  s¢   ø€ Ü‰Ñ˜Ô Ø ×+Ñ+ˆŒÜ# FÓ+ˆŒ
Ü�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 rY   rE  rÿ   s    r:   r   z4PersimmonForTokenClassification.get_input_embeddings  rF  r;   c                 ó&   — || j                   _        y rY   rE  r  s     r:   r  z4PersimmonForTokenClassification.set_input_embeddings  rH  r;   )Ú
checkpointrY  rç   r  r    rS   rÙ   r  rZ  r£   r¢   r  r™   c
           
      ó  — | j                  ||||||||	¬«      }
|
j                  }| j                  |«      }| j                  |«      }d}|�| j	                  ||| j
                  «      }t        |||
j                  |
j                  ¬«      S )rl  rm  N)r]  r^  rx   r  )	rØ   r
  rÏ   rh  r`  r$   r   rx   r  )r7   r  r    rS   rÙ   r  rZ  r£   r¢   r  rÔ   Úsequence_outputr^  r]  s                 r:   rX   z'PersimmonForTokenClassification.forward  s    € ð4 ,0¯:©:ØØ)Ø%Ø+Ø'ØØ/Ø!5ð ,6ó 	,
ˆð "×3Ñ3ˆØŸ,™, Ó7ˆØ—‘˜OÓ,ˆàˆØÐØ×%Ñ% f¨f°d·k±kÓBˆDä$ØØØ!×/Ñ/Ø×)Ñ)ô	
ð 	
r;   r<  )rZ   r[   r\   r-   r   r  r   r   r=  r   Ú_CHECKPOINT_FOR_DOCr   rc  r   rL   rÄ   rÃ   r
   rÕ   rÅ   rX   r^   r_   s   @r:   rv  rv  ó  s  ø„ ôò 'ò(ð Ù*Ð+EÓFÙØ&Ø)Ø$ôð 15Ø15Ø37Ø+/Ø59Ø-1Ø$(Ø,0Ø/3ñ*
à˜E×,Ñ,Ñ-ð*
ð ! §¡Ñ.ð*
ð ˜u×/Ñ/Ñ0ð	*
ð
 " %™ð*
ð   × 1Ñ 1Ñ2ð*
ð ˜×)Ñ)Ñ*ð*
ð ˜D‘>ð*
ð $ D™>ð*
ð ' t™nð*
ð 
ò*
óó Gó ô*
r;   rv  )r@  rñ   r×   re  rv  )Nr   )BrÂ   r¬   Útypingr   r   r   r   rL   Útorch.utils.checkpointr   Úactivationsr	   Úcache_utilsr
   r   r   Ú
generationr   Úmodeling_attn_mask_utilsr   Úmodeling_outputsr   r   r   r   Úmodeling_rope_utilsr   r   Úmodeling_utilsr   Úutilsr   r   r   r   r   r   r   Úutils.deprecationr   Úconfiguration_persimmonr   Ú!torch.nn.attention.flex_attentionr    Úintegrations.flex_attentionr!   Ú
get_loggerrZ   r‚   r  rc  ÚModuler#   rc   rk   rm   rz   rÇ   ÚPERSIMMON_START_DOCSTRINGr×   r=  rñ   r@  re  rv  Ú__all__rï   r;   r:   ú<module>r’     s­  ðñ( ã ß /Ó /ã Û Ý å !ß ;Ñ ;Ý )Ý >÷ó ÷ LÝ -÷÷ ñ õ 1Ý 4ñ  Ô!Ý;åJð 
ˆ×	Ñ	˜HÓ	%€à/Ð Ø#€ô<˜rŸy™yô <òF(óô8�2—9‘9ô ôJ9˜Ÿ™ô J9ôZN˜BŸI™Iô NðbÐ ñ" Ø]Øóô?˜ó ?ó	ð?ð,HÐ ñV Ø]ØóôYÐ-ó Yó	ðYôx~
Ð3°_ô ~
ñB ðð óô S
Ð)Aó S
ó!ð S
ñl ðð óôH
Ð&>ó H
óðH
òV�r;   