
    ^ji                        d dl mZ d dlmZ d dlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZmZmZmZ dd
lmZmZ ddlmZmZ ddlmZ ddlmZmZmZmZ 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*  e       r
d dl+Z+d dl+m,Z,  G d de,jZ                        Z.d Z/de+j`                  de1de+j`                  fdZ2	 d?de,jZ                  de+j`                  de+j`                  d e+j`                  d!e+j`                  dz  d"e3d#e3d$ee   fd%Z4d@d&Z5 G d' d(e,jZ                        Z6 G d) d*e,jZ                        Z7 G d+ d,e      Z8e G d- d.e             Z9 G d/ d0e9      Z: G d1 d2e,jZ                        Z;e G d3 d4e             Z< ed56       G d7 d8e9             Z= ed96      e G d: d;e                    Z> ed56       G d< d=e9e             Z?g d>Z@y)A    )Callable)	dataclass)Optional   )ACT2FN)Cache)GenerationMixin)GradientCheckpointingLayer)BaseModelOutputWithPastBaseModelOutputWithPoolingCausalLMOutputWithPastModelOutput)ROPE_INIT_FUNCTIONSdynamic_rope_update)ALL_ATTENTION_FUNCTIONSPreTrainedModel)Unpack)TransformersKwargsauto_docstringis_torch_availabletorch_compilable_check)can_return_tuplemaybe_autocastmerge_with_config_defaults)capture_outputs   )	AutoModel   )GlmAsrConfigGlmAsrEncoderConfigN)nnc                        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 )GlmAsrRotaryEmbedding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defaultr$   F)
persistentoriginal_inv_freq)super__init__max_position_embeddingsmax_seq_len_cachedoriginal_max_seq_lenr%   rope_parametersr'   compute_default_rope_parametersr   attention_scalingregister_bufferclone)selfr%   devicerope_init_fnr$   	__class__s        u/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/glmasr/modeling_glmasr.pyr,   zGlmAsrRotaryEmbedding.__init__5   s    "("@"@$*$B$B!44[A!%!E!E>>Y&.t~~>L+7V+L($(ZeD0(..2BuU    r6   ztorch.deviceseq_lenreturnztorch.Tensorc                 n   | j                   d   }| j                   j                  dd      }t        | dd      xs | j                  | j                  z  }t        ||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partial_rotary_factorg      ?head_dimNr   r   dtype)r6   rB   )r0   getgetattrhidden_sizenum_attention_headsinttorcharangeint64tofloat)	r%   r6   r;   baser?   r@   dimattention_factorr$   s	            r9   r1   z5GlmAsrRotaryEmbedding.compute_default_rope_parametersE   s    & %%l3 & 6 6 : :;RTW X6:t4h8J8JfNhNh8h(223 U\\!S!5;;?BB&X]XcXcBdgjjk
 )))r:   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   r   mpscpuF)device_typeenabledr   rN   rA   )r$   rL   expandshaperK   r6   
isinstancetypestrr   	transposerH   catcosr2   sinrB   )
r5   xposition_idsinv_freq_expandedposition_ids_expandedrT   freqsembr^   r_   s
             r9   forwardzGlmAsrRotaryEmbedding.forwarde   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)__name__
__module____qualname__rH   Tensor__annotations__r   r,   staticmethodr   rG   tuplerL   r1   no_gradr   rf   __classcell__r8   s   @r9   r#   r#   2   s    llV| V  &*+/"*t#*(* t* 
~u$	%	* *> 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..NrQ   r   rV   )rX   rH   r]   )r`   x1x2s      r9   rotate_halfru   u   sZ    	
3"!''"+"""	#B	
3q ""	#B99rc2YB''r:   hidden_states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)rX   rW   reshape)rv   rw   batchnum_key_value_headsslenr@   s         r9   	repeat_kvr}   |   so    
 2?1D1D.Ehz!!Qa"23::5BUW\^bdlmM  (;e(CT8TTr:   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 )Nr   r   rQ   )rN   rB   )ptrainingr   )r}   num_key_value_groupsrH   matmulr\   r!   
functionalsoftmaxfloat32rK   rB   r   r   
contiguous)r~   r   r   r   r   r   r   r   
key_statesvalue_statesattn_weightsattn_outputs               r9   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$$r:   c                 h   |j                  |      }|j                  |      }|j                  d   }| dd |f   | d|d f   }}|dd |f   |d|d f   }
}	||z  t        |      |z  z   }|	|z  t        |	      |z  z   }t        j                  ||gd      }t        j                  ||
gd      }||fS )NrQ   .rV   )	unsqueezerX   ru   rH   r]   )qkr^   r_   ra   unsqueeze_dim
rotary_dimq_rotq_passk_rotk_passq_embedk_embeds                r9   apply_rotary_pos_embr      s    
--
&C
--
&C2Jc;J;&'3
+;)<6Ec;J;&'3
+;)<6E s{{51C78Gs{{51C78G ii&)r2Gii&)r2GGr:   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z  de
e   d	e	ej                  ej                  f   fd
Z xZS )GlmAsrAttentionz=Multi-headed attention from 'Attention Is All You Need' paperr%   	layer_idxc                    t         |           || _        || _        t	        |d|j
                  |j                  z        | _        |j                  |j                  z  | _	        | j                  dz  | _
        |j                  | _        d| _        t        j                  |j
                  |j                  | j                  z  d      | _        t        j                  |j
                  |j                  | j                  z  d      | _        t        j                  |j
                  |j                  | j                  z  d      | _        t        j                  |j                  | j                  z  |j
                  d      | _        y )Nr@   g      FTbias)r+   r,   r%   r   rD   rE   rF   r@   r{   r   r   attention_dropout	is_causalr!   Linearq_projk_projv_projo_projr5   r%   r   r8   s      r9   r,   zGlmAsrAttention.__init__   s,   "
F4F4F&JdJd4de$*$>$>&B\B\$\!}}d*!'!9!9ii 2 2F4N4NQUQ^Q^4^eijii 2 2F4N4NQUQ^Q^4^ejkii 2 2F4N4NQUQ^Q^4^eijii : :T]] JFL^L^eijr:   Nrv   position_embeddingsr   r<   c                    |j                   d d }g |d| j                  }| j                  |      j                  |      j	                  dd      }| j                  |      j                  |      j	                  dd      }| j                  |      j                  |      j	                  dd      }|\  }	}
t        |||	|
      \  }}t        j                  | j                  j                  t              } || |||fd | j                  sdn| j                  | j                  d|\  }} |j                   g |d j#                         }| j%                  |      }||fS )NrQ   r   r           )r   r   r   )rX   r@   r   viewr\   r   r   r   r   get_interfacer%   _attn_implementationr   r   r   r   ry   r   r   )r5   rv   r   r   input_shapehidden_shapequery_statesr   r   r^   r_   attention_interfacer   r   s                 r9   rf   zGlmAsrAttention.forward   sk    $))#2.88b8$--8{{=166|DNNqRST[[/44\BLLQPQR
{{=166|DNNqRST&S#7jRUWZ#[ j(?(M(MKK,,.E)
 %8		%

  #}}C$2H2HLL	%
 	%
!\ *k));;;;FFHkk+.L((r:   rg   )rh   ri   rj   __doc__r   rG   r,   rH   rk   rn   r   r   rf   rp   rq   s   @r9   r   r      s    Gk| k k" IM!)||!) #5<<#=>E!) +,	!)
 
u||U\\)	*!)r:   r   c                   >     e Zd Z fdZdej
                  fdZ xZS )	GlmAsrMLPc                    t         |           t        j                  |j                  |j
                        | _        t        j                  |j
                  |j                        | _        t        |j                     | _
        y rg   )r+   r,   r!   r   rE   intermediate_sizefc1fc2r   
hidden_actact_fnr5   r%   r8   s     r9   r,   zGlmAsrMLP.__init__   s\    99V//1I1IJ99V55v7I7IJV../r:   rv   c                 l    | j                  |      }| j                  |      }| j                  |      }|S rg   )r   r   r   )r5   rv   s     r9   rf   zGlmAsrMLP.forward   s2    /M2/r:   )rh   ri   rj   r,   rH   rk   rf   rp   rq   s   @r9   r   r      s    0U\\ r:   r   c            	            e Zd Zdedef fdZ	 d
dej                  deej                  ej                  f   dz  de	e
   dej                  fd	Z xZS )GlmAsrEncoderLayerr%   r   c                    t         |           |j                  | _        t        ||      | _        t        |      | _        t        j                  |j                        | _	        t        j                  |j                        | _
        y )N)r%   r   )r+   r,   rE   r   	self_attnr   mlpr!   	LayerNorminput_layernormpost_attention_layernormr   s      r9   r,   zGlmAsrEncoderLayer.__init__   sd    !--()LV$!||F,>,>?(*V5G5G(H%r:   Nrv   r   r   r<   c                     |}| j                  |      } | j                  d||d|\  }}||z   }|}| j                  |      }| j                  |      }||z   }|S )N)rv   r    )r   r   r   r   )r5   rv   r   r   residual_s         r9   rf   zGlmAsrEncoderLayer.forward  s     !,,];)4>> 
' 3
 
q
 !=0 !55mD/ =0r:   rg   )rh   ri   rj   r   rG   r,   rH   rk   rn   r   r   rf   rp   rq   s   @r9   r   r      sp    I| I I IM|| #5<<#=>E +,	
 
r:   r   c                   <    e Zd ZU eed<   dZdZdZdgZdgZ	dZ
dZdZy)GlmAsrPreTrainedModelr%   model)audiotextTr   past_key_valuesN)rh   ri   rj   r   rl   base_model_prefixinput_modalitiessupports_gradient_checkpointing_no_split_modules_skip_keys_device_placement_supports_flash_attn_supports_sdpa_supports_attention_backendr   r:   r9   r   r     s=    (&*#*+#4"5N"&r:   r   c                   x     e Zd ZU eed<   dZdZdgZee	dZ
def fdZeeedee   fd                     Z xZS )	GlmAsrEncoderr%   input_featuresr   r   )rv   
attentionsc           	         t         |   |       t        j                  |j                  |j
                  dd      | _        t        j                  |j
                  |j
                  ddd      | _        t        j                  t        |j                        D cg c]  }t        ||       c}      | _        t        j                  |j
                        | _        t        |      | _        d| _        | j%                          y c c}w )Nr   r   )kernel_sizepaddingr   )r   strider   )r%   F)r+   r,   r!   Conv1dnum_mel_binsrE   conv1conv2
ModuleListrangenum_hidden_layersr   layersr   normr#   
rotary_embgradient_checkpointing	post_initr   s      r9   r,   zGlmAsrEncoder.__init__1  s     YYv22F4F4FTU_`a
YYv1163E3EST]^hij
mmDI&JbJbDcdy	2d
 LL!3!34	/v>&+# es   Dr   c                    t         j                  j                  | j                  |            }t         j                  j                  | j	                  |            }|j                  dd      }|}| j                  |t        j                  |j                  d   |j                        d d d f         }| j                  D ]  } ||fd|i|} | j                  |      }t        |      S )Nr   r   r6   )ra   r   )last_hidden_state)r!   r   gelur   r   r\   r   rH   rI   rX   r6   r   r   r   )r5   r   r   inputs_embedsrv   r   encoder_layers          r9   rf   zGlmAsrEncoder.forward>  s     **4::n+EF**4::m+DE%//15%"oo]5H5H5KTaThTh(ijnpqjq(r . 
 "[[ 	lM)-kM`kdjkM	l 		-0)MJJr:   )rh   ri   rj   r    rl   main_input_namer   r   r   r   _can_record_outputsr,   r   r   r   r   r   rf   rp   rq   s   @r9   r   r   '  sl    &O-.+%
2   K7I0J K    Kr:   r   c                   .     e Zd ZdZdef fdZd Z xZS )GlmAsrMultiModalProjectorz
    Audio adaptor (small MLP) that projects GlmAsrEncoder features
    to the LLM embedding space so they can replace `<sound>` tokens.
    r%   c                 j   t         |           t        j                  |j                  j
                  |j                  j                  dz        | _        t        |j                     | _        t        j                  |j                  j                  dz  |j                  j                        | _        y )Nr   )r+   r,   r!   r   audio_configr   text_configrE   linear_1r   projector_hidden_actactlinear_2r   s     r9   r,   z"GlmAsrMultiModalProjector.__init__X  s    		&"5"5"G"GI[I[IgIgjkIkl&556		&"4"4"@"@1"DfFXFXFdFder:   c                 l    | j                  |      }| j                  |      }| j                  |      }|S rg   )r   r  r  )r5   audio_featuresrv   s      r9   rf   z!GlmAsrMultiModalProjector.forward^  s2    n5/m4r:   )rh   ri   rj   r   r   r,   rf   rp   rq   s   @r9   r   r   R  s    
f| fr:   r   c                   :    e Zd ZU dZdZej                  dz  ed<   y)GlmAsrModelOutputWithPastzg
    audio_hidden_states (`torch.FloatTensor`, *optional*):
        Projected audio hidden states.
    Naudio_hidden_states)rh   ri   rj   r   r  rH   FloatTensorrl   r   r:   r9   r  r  e  s    
 59**T18r:   r  z~
    The GlmAsr model which consists of a fine-tuned Whisper encoder, a multi-modal projector and a Llama language model.
    custom_introc                       e Zd ZdZdZdZ fdZe ed      de	j                  de	j                  dee   deez  fd	              Zd
e	j"                  de	j                  de	j                  fdZee	 	 	 	 	 	 	 	 dd
e	j"                  dz  de	j                  dz  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ez  fd              Z xZS )GlmAsrModelNc                     t         |   |       t        j                  |j                        | _        t        j                  |j                        | _        t        |      | _	        | j                          y rg   )r+   r,   r   from_configr   audio_towerr   language_modelr   multi_modal_projectorr   r   s     r9   r,   zGlmAsrModel.__init__y  sY     $001D1DE'33F4F4FG%>v%F"r:   zgCompute audio embeddings from log-mel input features using the audio encoder and multi-modal projector.r	  r   input_features_maskr   r<   c                 *    | j                   |fddi|}|j                  }|j                  |j                  d   d| j                  j
                  j                        }| j                  |      }|j                  d      }dD ]  \  }}	}
|d|z  z   |	dz
  z
  dz
  |
z  dz   } d}||z
  |z  dz   }t        j                  |j                  d   |j                  	      d
d
d
f   |d
d
d
f   k  }||j                  |j                           |_        |S )a1  
        input_features (`torch.FloatTensor`):
            Float values of mel features extracted from the raw speech waveform.
        input_features_mask (`torch.Tensor` of shape `(batch_size, feature_sequence_length)`):
            Mask to avoid performing attention on padded feature indices.
        return_dictTr   rQ   ))r   r   r   )r   r   r   r   r      r   N)r  r   ry   rX   r%   r   r   r  sumrH   rI   r6   rK   pooler_output)r5   r   r  r   audio_outputsr  audio_embedsaudio_lengthsr   r   r   merge_factorpost_lengths
valid_masks                 r9   get_audio_featureszGlmAsrModel.get_audio_features  s<     )((TTTVT+==199  #R)A)A)S)S
 112EF+//3,B 	`(G[&*Q[8K!OLqPU[[^__M	`%4EI\\,"4"4Q"7@S@STUY[\U\]`lmnptmt`uu
&2:==ATAT3U&V#r:   	input_idsr   r  c                 .   |m| | j                         t        j                  | j                  j                  t        j
                  |j                              k(  }|j                  d      }n|| j                  j                  k(  }|j                         }|j                  d   }|j                  d      j                  |      j                  |j                        }t        ||   j                         |j                         k(  d| d|        |S )z
        Obtains multimodal placeholder mask from `input_ids` or `inputs_embeds`, and checks that the placeholder token count is
        equal to the length of multimodal features. If the lengths are different, an error is raised.
        )rB   r6   rQ   r   z6Audio features and audio tokens do not match, tokens: z, features: )get_input_embeddingsrH   tensorr%   audio_token_idlongr6   allr  rX   r   	expand_asrK   r   numel)r5   r  r   r  special_audio_maskn_audio_tokensn_audio_featuress          r9   get_placeholder_maskz GlmAsrModel.get_placeholder_mask  s    !.2M$2K2K2MT[[77uzzR_RfRfg3 " "4!7!7!;!*dkk.H.H!H+//1)//2/99"=GGVYYZgZnZno,-3359M9M9OOD^DTT`aq`rs	
 "!r:   r   ra   r   	use_cachec	           	         | | j                         |      }d}
|_|]| j                  ||d      j                  }
| j                  |||
      }|j	                  ||
j                  |j                              } | j                  d|||||d|	}t        |j                  |j                  |j                  |j                  |
      S )z
        input_features_mask (`torch.Tensor` of shape `(batch_size, feature_sequence_length)`):
            Mask to avoid performing attention on padding feature indices.
        NT)r  )r   r  )r   r   ra   r   r,  )r   r   rv   r   r  r   )r!  r  r  r+  masked_scatterrK   r6   r  r  r   r   rv   r   )r5   r  r   r  r   ra   r   r   r,  r   r  r(  outputss                r9   rf   zGlmAsrModel.forward  s    $  7D557	BM%)*?22>CVdh2iwwL "&!:!:| "; " *889K\__]j]q]qMrsM%$%% 
')%+
 
 )%77#33!//)) ,
 	
r:   )NNNNNNNN)rh   ri   rj   _tp_plan_pp_plan_keep_in_fp32_modules_strictr,   r   r   rH   r  rk   r   r   rn   r   r  
LongTensorr+  r   boolr  rf   rp   rq   s   @r9   r  r  o  s    HH#'  ~)) #\\ +,	
 
+	+ <"))":?:K:K"]b]n]n"0  .23737.204(,26!%,
##d*,
 ))D0,
 #\\D0	,

 t+,
 &&-,
 ,
 ((4/,
 $;,
 +,,
 
*	*,
  ,
r:   r  zR
    Base class for GlmAsr causal language model (or autoregressive) outputs.
    c                       e Zd ZU dZdZej                  dz  ed<   dZej                  dz  ed<   dZ	e
dz  ed<   dZeej                     dz  ed<   dZeej                     dz  ed<   dZej                  dz  ed<   y)	GlmAsrCausalLMOutputWithPastaV  
    loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
        Language modeling loss (for next-token prediction).
    logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
        Prediction scores of the language modeling head.
    past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
        It is a [`~cache_utils.Cache`] instance.
    audio_hidden_states (`torch.FloatTensor`, *optional*):
        Hidden states of the audio encoder after projection.
    Nlosslogitsr   rv   r   r  )rh   ri   rj   r   r7  rH   r  rl   r8  r   r   rv   rn   r   r  r   r:   r9   r6  r6    s    	 &*D%

d
")'+FE$+$(OUT\(59M5**+d2926Je''(4/648**T18r:   r6  c                       e Zd ZdgZddiZ fdZd Zee	 	 	 	 	 	 	 	 	 	 dde	j                  dz  de	j                  dz  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dddef fdZ xZS )GlmAsrForConditionalGenerationembed_positionszlm_head.weightz(model.language_model.embed_tokens.weightc                     t         |   |       t        |      | _        t	        j
                  |j                  j                  |j                  j                  d      | _	        | j                          y )NFr   )r+   r,   r  r   r!   r   r   rE   
vocab_sizelm_headr   r   s     r9   r,   z'GlmAsrForConditionalGeneration.__init__  sS      (
yy!3!3!?!?ASASA^A^ejkr:   c                 >     | j                   j                  ||fi |S rg   )r   r  )r5   r   r  r   s       r9   r  z1GlmAsrForConditionalGeneration.get_audio_features  s"    ,tzz,,^=P[TZ[[r:   Nr  r   r  r   ra   r   r   labelsr,  logits_to_keepr   r<   c                     | j                   d||||||||	d|}|j                  }t        |
t              rt	        |
 d      n|
}| j                  |dd|ddf         }d}|4 | j                  d||| j                  j                  j                  d|}t        |||j                  |j                  |j                  |j                        S )a  
        input_features_mask (`torch.Tensor` of shape `(batch_size, feature_sequence_length)`):
            Mask to avoid performing attention on padding feature indices. Mask values selected in `[0, 1]`:

            - 1 for tokens that are **not masked**,
            - 0 for tokens that are **masked**.
        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]`.

        Example:

        ```python
        >>> from transformers import GlmAsrForConditionalGeneration, AutoProcessor

        >>> model_id = "zai-org/GLM-ASR-Nano-2512"
        >>> processor = AutoProcessor.from_pretrained(model_id)
        >>> model = GlmAsrForConditionalGeneration.from_pretrained(model_id, dtype="auto", device_map="auto")
        >>> inputs = processor.apply_transcription_request("https://huggingface.co/datasets/hf-internal-testing/dummy-audio-samples/resolve/main/bcn_weather.mp3")

        >>> inputs = inputs.to(model.device, dtype=model.dtype)

        >>> outputs = model.generate(**inputs, do_sample=False, max_new_tokens=500)

        >>> decoded_outputs = processor.batch_decode(outputs[:, inputs.input_ids.shape[1] :], skip_special_tokens=True)
        >>> print(decoded_outputs)
        ```)r  r   r  r   ra   r   r   r,  N)r8  r@  r=  )r7  r8  r   rv   r   r  r   )r   r   rY   rG   slicer>  loss_functionr%   r   r=  r6  r   rv   r   r  )r5   r  r   r  r   ra   r   r   r@  r,  rA  r   r/  rv   slice_indicesr8  r7  s                    r9   rf   z&GlmAsrForConditionalGeneration.forward  s    X $** 

) 3)%+'

 

  118B>SV8W~ot4]kmA}a,?@A%4%% f9P9P9[9[_eD ,#33!//)) ' ; ;
 	
r:   F)is_first_iterationrF  c                    |j                  dd       }|j                  dd       }t        |   |i |}|s|j                  dd      s|||d<   |||d<   |S )Nr   r  r,  F)popr+   prepare_inputs_for_generationrC   )r5   rF  argsr   r   r  model_inputsr8   s          r9   rI  z<GlmAsrForConditionalGeneration.prepare_inputs_for_generationb  st    $4d;$jj)>Ew<dMfM\%5%5k5%I)1?-.".6I23r:   )
NNNNNNNNNr   )rh   ri   rj   r2  _tied_weights_keysr,   r  r   r   rH   r3  r  rk   r   r4  rG   r   r   r   rf   rI  rp   rq   s   @r9   r:  r:    s^    %6#6 *,VW\  .23737.204(,26*.!%-.G
##d*G
 ))D0G
 #\\D0	G

 t+G
 &&-G
 G
 ((4/G
   4'G
 $;G
 ell*G
 +,G
 
 G
  G
R OT t  r:   r:  )r   r:  r  r   )r   )Nr   )Acollections.abcr   dataclassesr   typingr   activationsr   cache_utilsr   
generationr	   modeling_layersr
   modeling_outputsr   r   r   r   modeling_rope_utilsr   r   modeling_utilsr   r   processing_utilsr   utilsr   r   r   r   utils.genericr   r   r   utils.output_capturingr   autor   configuration_glmasrr   r    rH   r!   Moduler#   ru   rk   rG   r}   rL   r   r   r   r   r   r   r   r   r  r  r6  r:  __all__r   r:   r9   <module>r_     s   * % !  !   ) 9  L F & c c Y Y 5  C @<BII @<F(	UU\\ 	U# 	U%,, 	U& %II%<<% 
% <<	%
 LL4'% % % '(%2$2)bii 2)j		  3  F 	'O 	' 	'(K) (KV		 & 9 7 9 9 
t
' t

t
n 
 9; 9 9( 
d%:O d
dN fr:   