
    i>g                     x   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 ddl2m3Z3  ed       G d dejh                               Z5 G d dejh                        Z6 G d dejh                        Z7d Z8 ed      d;d        Z9d!ejt                  d"e;d#ejt                  fd$Z<	 d<d%ejh                  d&ejt                  d'ejt                  d(ejt                  d)ejt                  dz  d*e=d+e=d,e'e)   fd-Z>d=d.Z?d>d/Z@ G d0 d1ejh                        ZA G d2 d3e      ZBe* G d4 d5e%             ZCe* G d6 d7eC             ZDe* G d8 d9eCe             ZEg d:ZFy)?    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)is_flash_attention_requestedmaybe_autocastmerge_with_config_defaults)capture_outputs   )YoutuConfigRMSNormc                   h     e Zd Zddeddf fdZdej                  dej                  fdZd Z xZ	S )	YoutuRMSNormepsreturnNc                     t         |           t        j                  t	        j
                  |            | _        || _        y)z;
        YoutuRMSNorm is equivalent to T5LayerNorm
        N)super__init__r   	Parametertorchonesweightvariance_epsilon)selfhidden_sizer$   	__class__s      y/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/transformers/models/youtu/modeling_youtu.pyr(   zYoutuRMSNorm.__init__7   s1     	ll5::k#:; #    hidden_statesc                 "   |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.   r3   input_dtypevariances       r1   forwardzYoutuRMSNorm.forward?   sy    #))%((7 $$Q',,R,>%Ht?T?T4T(UU{{]--k:::r2   c                 ^    t        | j                  j                         d| j                   S )Nz, eps=)tupler,   shaper-   )r.   s    r1   
extra_reprzYoutuRMSNorm.extra_reprF   s*    ))*+6$2G2G1HIIr2   )gư>)
__name__
__module____qualname__floatr(   r*   Tensorr@   rD   __classcell__r0   s   @r1   r#   r#   5   s7    $ $$ $;U\\ ;ell ;Jr2   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defaultrN   F)
persistentoriginal_inv_freq)r'   r(   max_position_embeddingsmax_seq_len_cachedoriginal_max_seq_lenrO   rope_parametersrQ   compute_default_rope_parametersr   attention_scalingregister_bufferclone)r.   rO   devicerope_init_fnrN   r0   s        r1   r(   zYoutuRotaryEmbedding.__init__M   s    "("@"@$*$B$B!44[A!%!E!E>>Y&.t~~>L+7V+L($(ZeD0(..2BuUr2   r]   ztorch.deviceseq_lenr%   z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   r5   r8   )r]   r8   )	rX   getattrr/   num_attention_headsr*   arangeint64r9   rH   )rO   r]   r_   basedimattention_factorrN   s          r1   rY   z4YoutuRotaryEmbedding.compute_default_rope_parameters]   s    & %%l3fj$/c63E3EIcIc3c U\\!S!5;;?BB&X]XcXcBdgjjk
 )))r2   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   r6   r   mpscpuF)device_typeenabledr5   rj   rd   )rN   rH   expandrC   r9   r]   
isinstancetypestrr   	transposer*   catcosrZ   sinr8   )
r.   xposition_idsinv_freq_expandedposition_ids_expandedro   freqsembrx   ry   s
             r1   r@   zYoutuRotaryEmbedding.forward{   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)rE   rF   rG   r*   rI   __annotations__r    r(   staticmethodr   intrB   rH   rY   no_gradr   r@   rJ   rK   s   @r1   rM   rM   J   s    llV{ V  %)+/"*d"*(* t* 
~u$	%	* *: U]]_<  <r2   rM   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(   rO   r/   intermediate_sizer   Linear	gate_projup_proj	down_projr   
hidden_actact_fnr.   rO   r0   s     r1   r(   zYoutuMLP.__init__   s    !--!'!9!94#3#3T5K5KRWXyy!1!143I3IPUV4#9#94;K;KRWXV../r2   c                     | j                  | j                  | j                  |            | j                  |      z        }|S r   )r   r   r   r   )r.   rz   r   s      r1   r@   zYoutuMLP.forward   s6    NN4;;t~~a/@#ADLLQRO#ST	r2   )rE   rF   rG   r(   r@   rJ   rK   s   @r1   r   r      s    0r2   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..Nr6   r5   rq   )rC   r*   rw   )rz   x1x2s      r1   rotate_halfr      sZ    	
3"!''"+"""	#B	
3q ""	#B99rc2YB''r2   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krx   ry   unsqueeze_dimq_embedk_embeds          r1   apply_rotary_pos_embr      sY    & --
&C
--
&C3w;q>C/0G3w;q>C/0GGr2   r3   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)rC   rr   reshape)r3   r   batchnum_key_value_headsslenrb   s         r1   	repeat_kvr      so    
 2?1D1D.Ehz!!Qa"23::5BUW\^bdlmM  (;e(CT8TTr2   modulequerykeyvalueattention_maskscalingdropoutkwargsc                    t        || j                        }t        || j                        }	t        j                  ||j	                  dd            |z  }
||
|z   }
t
        j                  j                  |
dt        j                        j                  |j                        }
t
        j                  j                  |
|| j                        }
t        j                  |
|	      }|j	                  dd      j                         }||
fS )Nr5   r   r6   )rj   r8   )ptrainingr   )r   num_key_value_groupsr*   matmulrv   r   
functionalsoftmaxr:   r9   r8   r   r   
contiguous)r   r   r   r   r   r   r   r   
key_statesvalue_statesattn_weightsattn_outputs               r1   eager_attention_forwardr      s     3 ; ;<JUF$?$?@L<<z';';Aq'ABWLL!#n4==((2U]](SVVW\WbWbcL==((6??([L,,|\:K''1-88:K$$r2   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.
    r5      r   )r   rC   viewrv   r   r   )r   r   rx   ry   r{   r   bhsdr   r   s               r1   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r2   c                 J    | dk  ryd|z  t        j                  |       z  dz   S )Nr   rc   g?)mathlog)scalemscales     r1   yarn_get_mscaler     s(    z<$((5/)C//r2   c                       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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' paperrO   	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      rQ   rR   mscale_all_dimr   factor)!r'   r(   rO   r   rf   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   rX   getr   )r.   rO   r   r   scaling_factorr   r0   s         r1   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r2   Nr3   position_embeddingsr   past_key_valuesr   r%   c                 B   |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      }| |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 )Nr6   r   r5   rq   r           )r   r   )'rC   r   r   r   r   r   r   r   r   r   rv   r*   splitr   r   r   r   r   rO   rope_interleaver   r   rr   rw   updater   r   Fpadr   get_interface_attn_implementationr   r   r   r   r   r   r   )r.   r3   r   r   r   r   
batch_size
seq_lengthquery_shape	key_shapeq_statesq_passq_rotcompressed_kvk_passk_rotr   rx   ry   query_statesr   attention_interfacer   r   s                           r1   r@   zYoutuAttention.forwardA  sC    "/!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
&'6'='=j,X\XfXf'g$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((r2   r   )rE   rF   rG   __doc__r    r   r(   r*   rI   rB   r	   r   r   r@   rJ   rK   s   @r1   r   r     s    G/>{ />s />l )-?)||?) #5<<#=>?) t+	?)
 ?) -.?) 
u||U\\D0%2E2LL	M?)r2   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ej                  ej                  f   dz  dee   dej                  fdZ xZS )YoutuDecoderLayerrO   r   c                     t         |           |j                  | _        t        ||      | _        t        |      | _        t        |j                  |j                        | _	        t        |j                  |j                        | _
        y )N)rO   r   r$   )r'   r(   r/   r   	self_attnr   mlpr#   rms_norm_epsinput_layernormpost_attention_layernormr.   rO   r   r0   s      r1   r(   zYoutuDecoderLayer.__init__  sl    !--'vKF#+F,>,>FDWDWX(4V5G5GVM`M`(a%r2   Nr3   r   r{   r   	use_cacher   r   r%   c           
          |}| j                  |      } | j                  d||||||d|\  }}	||z   }|}| j                  |      }| j                  |      }||z   }|S )N)r3   r   r{   r   r  r    )r  r  r  r  )
r.   r3   r   r{   r   r  r   r   residual_s
             r1   r@   zYoutuDecoderLayer.forward  s     !,,];)4>> 
')%+ 3
 
q !=0 !55mD/ =0r2   )NNNFN)rE   rF   rG   r    r   r(   r*   rI   
LongTensorr	   boolrB   r   r   r@   rJ   rK   s   @r1   r   r     s    b{ bs b /304(,!&HL|| t+ &&-	
  $; #5<<#=>E +, 
r2   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 )YoutuPreTrainedModelrO   modelTr   r   )r3   
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_ranger5   r   )r<   std)r'   _init_weightsre   rO   rs   r   	Embeddinginitnormal_r,   padding_idxzeros_data)r.   r   r  	embed_stdr0   s       r1   r  z"YoutuPreTrainedModel._init_weights  s    f%dkk#6=DKK)FCP	fbll+LLSi@!!-FMM..v/A/ABC . ,r2   )rE   rF   rG   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  rJ   rK   s   @r1   r  r    sp    &*#,-#4"5N!"&*$
 U]]_D Dr2   r  c                        e Zd Zdef fdZe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dz  d
ee   defd                     Z xZS )
YoutuModelrO   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   rO   F)r'   r(   pad_token_idr  
vocab_sizer   r  r/   embed_tokens
ModuleListrangenum_hidden_layersr   layersr#   r  normrM   
rotary_embgradient_checkpointing	post_initr  s      r1   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   r{   r   inputs_embedsr  r   r%   c           
      <   |d u |d uz  rt        d      || j                  |      }|r|t        | j                        }|V||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   )r]   )rO   r8  r   r   r{   )r{   )r   r   r{   r   r  )last_hidden_stater   )
ValueErrorr.  r
   rO   get_seq_lengthr*   rg   rC   r]   r   r   r4  r2  r1  r3  r   )r.   r7  r   r{   r   r8  r  r   past_seen_tokenscausal_maskr3   r   decoder_layers                r1   r@   zYoutuModel.forward  sL    -t";<YZZ *.*;*;I*FM0*$++>OCRC^==?de <<(;(;A(>}G[G[\_ooL'11!4L(;;')+%
 &"oom,oW![[)H4;;+H+HI 		M)*$7) /# M		 		-0&++
 	
r2   )NNNNNN)rE   rF   rG   r    r(   r   r   r   r*   r  rI   r	   FloatTensorr  r   r   r   r@   rJ   rK   s   @r1   r)  r)    s    {     .2.204(,26!%2
##d*2
 t+2
 &&-	2

 2
 ((4/2
 $;2
 +,2
 
!2
    2
r2   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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_outputr3   logitsc                     t         |   |       t        |      | _        |j                  | _        t        j                  |j                  |j                  d      | _        | j                          y r   )
r'   r(   r)  r  r-  r   r   r/   rC  r6  r   s     r1   r(   zYoutuForCausalLM.__init__  sU     '
 ++yy!3!3V5F5FUS 	r2   Nr7  r   r{   r   r8  labelsr  logits_to_keepr   r%   c	           
      x    | 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."
        ```)r7  r   r{   r   r8  r  N)rE  rG  r-  )lossrE  r   r3   r  r	  )r  r:  rs   r   slicerC  loss_functionrO   r-  r   r   r3   r  )r.   r7  r   r{   r   r8  rG  r  rH  r   outputsr3   slice_indicesrE  rJ  s                  r1   r@   zYoutuForCausalLM.forward$  s    > ,64:: ,
)%+',
 ,
  118B>SV8W~ot4]kmA}a,?@A%4%%pVFt{{OeOepiopD%#33!//))
 	
r2   )NNNNNNNr   )rE   rF   rG   _tied_weights_keys_tp_plan_pp_planr(   r   r   r*   r  rI   r	   r@  r  r   r   r   r   r@   rJ   rK   s   @r1   rB  rB    s   *,GH23H_-z:;H  .2.204(,26*.!%-.6
##d*6
 t+6
 &&-	6

 6
 ((4/6
   4'6
 $;6
 ell*6
 +,6
 
 6
  6
r2   rB  )r  r)  rB  )r   )r   )Nr   )r   r   )Gr   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   utils.output_capturingr   configuration_youtur    Moduler#   rM   r   r   r   rI   r   r   rH   r   r   r   r   r   r  r)  rB  __all__r	  r2   r1   <module>rg     s  6  $      & ! . ) Q / B 9 O K F & I I e e 5 , Y'J299 J (J(><299 ><Bryy  ( *+ ,2	UU\\ 	U# 	U%,, 	U& %II%<<% 
% <<	%
 LL4'% % % '(%2#L0s)RYY s)l(2 (V D? D D8 F
% F
 F
R F
+_ F
 F
R Er2   