
    ii                     l   d dl Z d dlmZ d dl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 ddlmZmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ddl m!Z!m"Z" ddl#m$Z$m%Z% ddl&m'Z' ddl(m)Z)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/ ddl0m1Z1  ed       G d dejd                               Z3 G d dejd                        Z4 G d dejd                        Z5d Z6 ed      d:d       Z7d ejp                  d!e9d"ejp                  fd#Z:	 d;d$ejd                  d%ejp                  d&ejp                  d'ejp                  d(ejp                  dz  d)e;d*e;d+e'e)   fd,Z<d<d-Z=d=d.Z> G d/ d0ejd                        Z? G d1 d2e      Z@e* G d3 d4e%             ZAe* G d5 d6eA             ZBe* G d7 d8eAe             ZCg d9ZDy)>    N)Callable)Optional)nn   )initialization)ACT2FN)CacheDynamicCache)GenerationMixin)use_kernel_forward_from_hubuse_kernel_func_from_hub)create_causal_mask)FlashAttentionKwargs)GradientCheckpointingLayer)BaseModelOutputWithPastCausalLMOutputWithPast)ROPE_INIT_FUNCTIONSdynamic_rope_update)ALL_ATTENTION_FUNCTIONSPreTrainedModel)Unpack)TransformersKwargsauto_docstringcan_return_tuple)check_model_inputsis_flash_attention_requestedmaybe_autocast   )YoutuConfigRMSNormc                   ,     e Zd Zd fd	Zd Zd Z xZS )YoutuRMSNormc                     t         |           t        j                  t	        j
                  |            | _        || _        y)z;
        YoutuRMSNorm is equivalent to T5LayerNorm
        N)super__init__r   	Parametertorchonesweightvariance_epsilon)selfhidden_sizeeps	__class__s      r/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/transformers/models/youtu/modeling_youtu.pyr%   zYoutuRMSNorm.__init__5   s1     	ll5::k#:; #    c                 "   |j                   }|j                  t        j                        }|j	                  d      j                  dd      }|t        j                  || j                  z         z  }| j                  |j                  |      z  S )N   T)keepdim)	dtypetor'   float32powmeanrsqrtr*   r)   )r+   hidden_statesinput_dtypevariances       r/   forwardzYoutuRMSNorm.forward=   sy    #))%((7 $$Q',,R,>%Ht?T?T4T(UU{{]--k:::r0   c                 ^    t        | j                  j                         d| j                   S )Nz, eps=)tupler)   shaper*   )r+   s    r/   
extra_reprzYoutuRMSNorm.extra_reprD   s*    ))*+6$2G2G1HIIr0   )gư>)__name__
__module____qualname__r%   r>   rB   __classcell__r.   s   @r/   r"   r"   3   s    $;Jr0   r"   c                        e Zd ZU ej                  ed<   ddef fdZe	 	 	 ddedz  de	d   de
dz  ded	ef   fd
       Z ej                         ed               Z xZS )YoutuRotaryEmbeddinginv_freqNconfigc                    t         |           |j                  | _        |j                  | _        || _        | j
                  j                  d   | _        | j                  }| j                  dk7  rt        | j                     } || j
                  |      \  }| _
        | j                  d|d       | j                  d|j                         d       y )N	rope_typedefaultrJ   F)
persistentoriginal_inv_freq)r$   r%   max_position_embeddingsmax_seq_len_cachedoriginal_max_seq_lenrK   rope_parametersrM   compute_default_rope_parametersr   attention_scalingregister_bufferclone)r+   rK   devicerope_init_fnrJ   r.   s        r/   r%   zYoutuRotaryEmbedding.__init__K   s    "("@"@$*$B$B!44[A!%!E!E>>Y&.t~~>L+7V+L($(ZeD0(..2BuUr0   rY   ztorch.deviceseq_lenreturnztorch.Tensorc                    | j                   d   }t        | dd      xs | j                  | j                  z  }d}d|t	        j
                  d|dt        j                        j                  |t        j                        |z  z  z  }||fS )	a  
        Computes the inverse frequencies according to the original RoPE implementation
        Args:
            config ([`~transformers.PreTrainedConfig`]):
                The model configuration.
            device (`torch.device`):
                The device to use for initialization of the inverse frequencies.
            seq_len (`int`, *optional*):
                The current sequence length. Unused for this type of RoPE.
        Returns:
            Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
            post-processing scaling factor applied to the computed cos/sin (unused in this type of RoPE).
        
rope_thetahead_dimN      ?r   r2   r5   )rY   r5   )	rT   getattrr,   num_attention_headsr'   arangeint64r6   float)rK   rY   r[   basedimattention_factorrJ   s          r/   rU   z4YoutuRotaryEmbedding.compute_default_rope_parameters[   s    & %%l3fj$/c63E3EIcIc3c U\\!S!5;;?BB&X]XcXcBdgjjk
 )))r0   c                 N   | 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        |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   r3   r   mpscpuF)device_typeenabledr2   rh   ra   )rJ   rf   expandrA   r6   rY   
isinstancetypestrr   	transposer'   catcosrV   sinr5   )
r+   xposition_idsinv_freq_expandedposition_ids_expandedrm   freqsembrv   rw   s
             r/   r>   zYoutuRotaryEmbedding.forwardy   sR    !MM$4-8>>@GGHZHZ[\H]_acdehhijiqiqr ,QaZ 8 > > @'1!((--'E!((--[`J`ahhmmfkUC 	5&,,.1F1L1L1NNYYZ[]^_E))UEN3C'')d444C'')d444C		5 vvAGGv$cff177f&;;;	5 	5s   BFF$N)NNN)rC   rD   rE   r'   Tensor__annotations__r   r%   staticmethodr   intr@   rf   rU   no_gradr   r>   rF   rG   s   @r/   rI   rI   H   s    llV{ V  %)+/"*d"*(* t* 
~u$	%	* *: U]]_<  <r0   rI   c                   $     e Zd Z fdZd Z xZS )YoutuMLPc                    t         |           || _        |j                  | _        |j                  | _        t        j                  | j                  | j                  d      | _        t        j                  | j                  | j                  d      | _        t        j                  | j                  | j                  d      | _	        t        |j                     | _        y NFbias)r$   r%   rK   r,   intermediate_sizer   Linear	gate_projup_proj	down_projr   
hidden_actact_fnr+   rK   r.   s     r/   r%   zYoutuMLP.__init__   s    !--!'!9!94#3#3T5K5KRWXyy!1!143I3IPUV4#9#94;K;KRWXV../r0   c                     | j                  | j                  | j                  |            | j                  |      z        }|S r~   )r   r   r   r   )r+   rx   r   s      r/   r>   zYoutuMLP.forward   s6    NN4;;t~~a/@#ADLLQRO#ST	r0   )rC   rD   rE   r%   r>   rF   rG   s   @r/   r   r      s    0r0   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..Nr3   r2   ro   )rA   r'   ru   )rx   x1x2s      r/   rotate_halfr      sZ    	
3"!''"+"""	#B	
3q ""	#B99rc2YB''r0   rotary_pos_embc                     |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.
        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krv   rw   unsqueeze_dimq_embedk_embeds          r/   apply_rotary_pos_embr      sY    & --
&C
--
&C3w;q>C/0G3w;q>C/0GGr0   r;   n_repr\   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)rA   rp   reshape)r;   r   batchnum_key_value_headsslenr_   s         r/   	repeat_kvr      so    
 2?1D1D.Ehz!!Qa"23::5BUW\^bdlmM  (;e(CT8TTr0   modulequerykeyvalueattention_maskscalingdropoutkwargsc                 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 )Nr2   r   r3   )rh   r5   )ptrainingr   )r   num_key_value_groupsr'   matmulrt   rA   r   
functionalsoftmaxr7   r6   r5   r   r   
contiguous)r   r   r   r   r   r   r   r   
key_statesvalue_statesattn_weightscausal_maskattn_outputs                r/   eager_attention_forwardr      s    3 ; ;<JUF$?$?@L<<z';';Aq'ABWLL!$Q1.D
0@0@0D.D%DE#k1==((2U]](SVVW\WbWbcL==((6??([L,,|\:K''1-88:K$$r0   c                    |j                  |      }|j                  |      }| j                  \  }}}}	| j                  ||||	dz  d      j                  dd      j	                  ||||	      } |j                  \  }}}}	|j                  ||||	dz  d      j                  dd      j	                  ||||	      }| |z  t        |       |z  z   }
||z  t        |      |z  z   }|
|fS )a  
    TODO let's just use the original freqcis computation to not have the view
    transpose + reshape! This is not optimized!
    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`):
            The position indices of the tokens corresponding to the query and key tensors. For example, this can be
            used to pass offsetted position ids when working with a KV-cache.
        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.
    r2      r   )r   rA   viewrt   r   r   )r   r   rv   rw   ry   r   bhsdr   r   s               r/   apply_rotary_pos_emb_interleaver      s    0 --
&C
--
&CJAq!Q	q!QQ",,Q2::1aAFAJAq!Q	q!QQ",,Q2::1aAFA3w;q>C/0G3w;q>C/0GGr0   c                 J    | dk  ryd|z  t        j                  |       z  dz   S )Nr   r`   g?)mathlog)scalemscales     r/   yarn_get_mscaler     s(    z<$((5/)C//r0   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j                  dz  d	e
dz  d
ej                  dz  dee   de	ej                  ej                  dz  e	ej                     dz  f   fdZ xZS )YoutuAttentionz=Multi-headed attention from 'Attention Is All You Need' paperrK   	layer_idxc                    t         |           || _        || _        |j                  |j
                  z  | _        |j                  | _        |j                  | _        |j                  | _	        |j                  | _
        |j                  | _        |j                  | _        |j                  | _        |j                  | _        d| _        | j                  ?t!        j"                  |j$                  | j                  | j                  z  d      | _        nt!        j"                  |j$                  |j                  |j(                        | _        t-        |j                        | _        t!        j"                  |j                  | j                  | j                  z  d      | _        t!        j"                  |j$                  | j                  | j                  z   |j(                        | _        t-        | j                        | _        t!        j"                  | j                  | j                  | j                  | j                  z   z  d      | _        t!        j"                  | j                  | j                  z  |j$                  |j(                        | _        | j                  dz  | _        | j                  j<                  j?                  dd      dk7  rf| j                  j<                  j?                  dd      }| j                  j<                  d	   }|r$tA        ||      }| j:                  |z  |z  | _        y y y )
NTFr   g      rM   rN   mscale_all_dimr   factor)!r$   r%   rK   r   rc   r   r   attention_dropout	num_headsq_lora_rankqk_rope_head_dimkv_lora_rank
v_head_dimqk_nope_head_dimqk_head_dim	is_causalr   r   r,   q_projattention_biasq_a_projr"   q_a_layernormq_b_projkv_a_proj_with_mqakv_a_layernorm	kv_b_projo_projr   rT   getr   )r+   rK   r   r   scaling_factorr   r.   s         r/   r%   zYoutuAttention.__init__  s   "$*$>$>&B\B\$\!!'!9!933!-- & 7 7"// ++ & 7 7!--#))F$6$6IYIY8Y`efDKIIf&8&8&:L:LSYShShiDM!-f.@.@!ADIIf&8&8$..4K[K[:[bghDM"$)) 5 55&&#

 +4+<+<=NNd33dooEF
 iiNNT__,&&
 ''D1;;&&**;	BiO![[88<<=MqQN![[88BN(H#||f4v=  Pr0   Nr;   position_embeddingsr   past_key_valuescache_positionr   r\   c                 P   |j                   d d \  }}||d| j                  f}	||d| j                  | j                  z   f}
| j                  | j                  |      }n/| j                  | j                  | j                  |                  }|j                  |	      j                  dd      }t        j                  || j                  | j                  gd      \  }}| j                  |      }t        j                  || j                  | j                  gd      \  }}| j!                  | j#                  |            j                  |
      j                  dd      }t        j                  || j                  | j                  gd      \  }}|j                  |d|| j                        }|\  }}| j$                  j&                  rt)        ||||      \  }}nt+        ||||      \  }} |j,                  g |j                   d d d }t        j.                  ||fd      }t        j.                  ||fd      }|'|||d}|j1                  ||| j2                  |      \  }}t5        | j$                        rH| j                  | j                  k7  r/t7        j8                  |d| j                  | j                  z
  g      }t;        j<                  | j$                  j>                  t@              } || ||||f| jB                  sdn| jD                  | jF                  d|\  }}t5        | j$                        r4| j                  | j                  k7  r|d d d d d d d | j                  f   }|jI                  ||d      jK                         }| jM                  |      }||fS )	Nr3   r   r2   ro   )rw   rv   r   r           )r   r   )'rA   r   r   r   r   r   r   r   r   r   rt   r'   splitr   r   r   r   r   rK   rope_interleaver   r   rp   ru   updater   r   Fpadr   get_interface_attn_implementationr   r   r   r   r   r   r   )r+   r;   r   r   r   r   r   
batch_size
seq_lengthquery_shape	key_shapeq_statesq_passq_rotcompressed_kvk_passk_rotr   rv   rw   query_statesr   cache_kwargsattention_interfacer   r   s                             r/   r>   zYoutuAttention.forward@  sR    "/!4!4Sb!9
J!:r43C3CDR1F1F1XY	#{{=1H}}T%7%7m8T%UVH==-771=Ht/D/DdF[F[.\bde//>MD4E4EtG\G\3]cef 3 3F ;<AA)LVVWXZ[\${{6D4I4I4??3[acd

:q*d6K6KL&S;;&&:5%cRLE5/uc3GLE54fll3B/44yy&%b9YYB7
&#&snUL'6'='=j,X\XfXfht'u$J'49I9IT__9\5543C3Cdoo3U/VWL(?(M(MKK,,.E)
 %8	%
  $}}C$2H2HLL	%
 	%
!\ (49I9IT__9\%aA/@/@&@AK!))*j"EPPRkk+.L((r0   )NN)rC   rD   rE   __doc__r   r   r%   r'   r   r@   r	   
LongTensorr   r   r>   rF   rG   s   @r/   r   r     s    G/>{ />s />l )-26B)||B) #5<<#=>B) t+	B)
 B) ((4/B) -.B) 
u||U\\D0%2E2LL	MB)r0   r   c                   "    e Zd Zdedef fdZ	 	 	 	 	 	 ddej                  dej                  dz  dej                  dz  de	dz  d	e
dz  d
ej                  dz  deej                  ej                  f   dz  dee   dej                  fdZ xZS )YoutuDecoderLayerrK   r   c                     t         |           |j                  | _        t        ||      | _        t        |      | _        t        |j                  |j                        | _	        t        |j                  |j                        | _
        y )N)rK   r   r-   )r$   r%   r,   r   	self_attnr   mlpr"   rms_norm_epsinput_layernormpost_attention_layernormr+   rK   r   r.   s      r/   r%   zYoutuDecoderLayer.__init__  sl    !--'vKF#+F,>,>FDWDWX(4V5G5GVM`M`(a%r0   Nr;   r   ry   r   	use_cacher   r   r   r\   c                     |}	| j                  |      } | j                  d|||||||d|\  }}
|	|z   }|}	| j                  |      }| j                  |      }|	|z   }|S )N)r;   r   ry   r   r  r   r    )r  r  r	  r  )r+   r;   r   ry   r   r  r   r   r   residual_s              r/   r>   zYoutuDecoderLayer.forward  s     !,,];)4>> 	
')%+) 3	
 	
q !=0 !55mD/ =0r0   )NNNFNN)rC   rD   rE   r   r   r%   r'   r   r   r	   boolr@   r   r   r>   rF   rG   s   @r/   r  r    s    b{ bs b /304(,!&26HL|| t+ &&-	
  $; ((4/ #5<<#=>E +, 
r0   r  c                        e Zd ZU eed<   dZdZdgZdgZdZ	dZ
dZdZdZeedZ ej$                          fd       Z xZS )YoutuPreTrainedModelrK   modelTr  r   )r;   
attentionsc                    t         |   |       t        | j                  dd      }t        | j                  dd|z        }t	        |t
        j                        rft        j                  |j                  d|       |j                  7t        j                  |j                  j                  |j                            y y y )Ninitializer_rangeg{Gz?embedding_initializer_ranger2   r   )r9   std)r$   _init_weightsrb   rK   rq   r   	Embeddinginitnormal_r)   padding_idxzeros_data)r+   r   r  	embed_stdr.   s       r/   r  z"YoutuPreTrainedModel._init_weights  s    f%dkk#6=DKK)FCP	fbll+LLSi@!!-FMM..v/A/ABC . ,r0   )rC   rD   rE   r   r   base_model_prefixsupports_gradient_checkpointing_no_split_modules_skip_keys_device_placement_supports_flash_attn_supports_sdpa_supports_flex_attn_can_compile_fullgraph_supports_attention_backendr  r   _can_record_outputsr'   r   r  rF   rG   s   @r/   r  r    sp    &*#,-#4"5N!"&*$
 U]]_D Dr0   r  c                       e Zd Zdef fdZee	 	 	 	 	 	 	 ddej                  dz  dej                  dz  dej                  dz  de
dz  dej                  dz  d	ej                  dz  d
edz  dee   defd              Z xZS )
YoutuModelrK   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  rK   F)r$   r%   pad_token_idr  
vocab_sizer   r  r,   embed_tokens
ModuleListrangenum_hidden_layersr  layersr"   r  normrI   
rotary_embgradient_checkpointing	post_initr
  s      r/   r%   zYoutuModel.__init__  s     !.. ++LL):):F<N<NPTP`P`ammCHIaIaCbcivy1c
 !!3!39L9LM	.f=&+# 	 ds   DN	input_idsr   ry   r   inputs_embedsr   r  r   r\   c                 D   |d u |d uz  rt        d      || j                  |      }|r|t        | j                        }|E||j	                         nd}	t        j                  |j                  d   |j                        |	z   }||j                  d      }t        | j                  |||||      }
|}| j                  ||      }| j                  d | j                  j                   D ]  } ||f|
|||||d|} | j                  |      }t        ||	      S )
Nz:You must specify exactly one of input_ids or inputs_embedsr.  r   r   )rY   )rK   input_embedsr   r   r   ry   )ry   )r   r   ry   r   r  r   )last_hidden_stater   )
ValueErrorr1  r
   rK   get_seq_lengthr'   rd   rA   rY   r   r   r7  r5  r4  r6  r   )r+   r:  r   ry   r   r;  r   r  r   past_seen_tokensr   r;   r   decoder_layers                 r/   r>   zYoutuModel.forward  s]    -t";<YZZ *.*;*;I*FM0*$++>O!CRC^==?de]003M<P<PQTdd  )33A6L(;;&))+%
 &"oom,oW![[)H4;;+H+HI 
	M)	*$7) /#-	 	M
	 		-0&++
 	
r0   )NNNNNNN)rC   rD   rE   r   r%   r   r   r'   r   r   r	   FloatTensorr  r   r   r   r>   rF   rG   s   @r/   r,  r,    s    {    .2.204(,2626!%9
##d*9
 t+9
 &&-	9

 9
 ((4/9
 ((4/9
 $;9
 +,9
 
!9
  9
r0   r,  c                   b    e Zd ZddiZddiZddgdgfiZ fdZee	 	 	 	 	 	 	 	 	 dd	e	j                  dz  d
e	j                  dz  de	j                  dz  dedz  de	j                  dz  de	j                  dz  dedz  de	j                  dz  dee	j                  z  dee   defd              Z xZS )YoutuForCausalLMzlm_head.weightzmodel.embed_tokens.weightlm_headcolwise_gather_outputr;   logitsc                     t         |   |       t        |      | _        |j                  | _        t        j                  |j                  |j                  d      | _        | j                          y r   )
r$   r%   r,  r  r0  r   r   r,   rF  r9  r   s     r/   r%   zYoutuForCausalLM.__init__%  sU     '
 ++yy!3!3V5F5FUS 	r0   Nr:  r   ry   r   r;  labelsr  r   logits_to_keepr   r\   c
                 z    | j                   d|||||||d|
}|j                  }t        |	t              rt	        |	 d      n|	}| j                  |dd|ddf         }d}|* | j                  d||| j                  j                  d|
}t        |||j                  |j                  |j                        S )a  
        Example:

        ```python
        >>> from transformers import AutoTokenizer, YoutuForCausalLM

        >>> model = YoutuForCausalLM.from_pretrained("meta-youtu/Youtu-2-7b-hf")
        >>> tokenizer = AutoTokenizer.from_pretrained("meta-youtu/Youtu-2-7b-hf")

        >>> 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."
        ```)r:  r   ry   r   r;  r  r   N)rH  rJ  r0  )lossrH  r   r;   r  r  )r  r>  rq   r   slicerF  loss_functionrK   r0  r   r   r;   r  )r+   r:  r   ry   r   r;  rJ  r  r   rK  r   outputsr;   slice_indicesrH  rM  s                   r/   r>   zYoutuForCausalLM.forward.  s    @ ,64:: 	,
)%+')	,
 	,
  118B>SV8W~ot4]kmA}a,?@A%4%%pVFt{{OeOepiopD%#33!//))
 	
r0   )	NNNNNNNNr   )rC   rD   rE   _tied_weights_keys_tp_plan_pp_planr%   r   r   r'   r   r   r	   rC  r  r   r   r   r   r>   rF   rG   s   @r/   rE  rE    s/   *,GH23H_-z:;H  .2.204(,26*.!%26-.8
##d*8
 t+8
 &&-	8

 8
 ((4/8
   4'8
 $;8
 ((4/8
 ell*8
 +,8
 
 8
  8
r0   rE  )r  r,  rE  )r   )r   )Nr   )r   r   )Er   collections.abcr   typingr   r'   torch.nn.functionalr   r   r    r   r  activationsr   cache_utilsr	   r
   
generationr   integrationsr   r   masking_utilsr   modeling_flash_attention_utilsr   modeling_layersr   modeling_outputsr   r   modeling_rope_utilsr   r   modeling_utilsr   r   processing_utilsr   utilsr   r   r   utils.genericr   r   r   configuration_youtur   Moduler"   rI   r   r   r   r   r   r   rf   r   r   r   r   r  r  r,  rE  __all__r  r0   r/   <module>ri     s  4  $      & ! . ) Q / B 9 O K F & I I ] ] , Y'J299 J (J(><299 ><Bryy  ( *+ ,2	UU\\ 	U# 	U%,, 	U& %II%<<% 
% <<	%
 LL4'% % % '(%4#L0v)RYY v)r*2 *Z D? D D8 L
% L
 L
^ H
+_ H
 H
V Er0   