
    Z j                     h   S SK rS SKJr  SSKJr  SSKJr  SSKJ	r	  SSK
JrJrJr  SS	KJr  SS
KJr  SSKJrJrJr  SSKJr  SSKJr  \" SS9\ " S S\5      5       5       r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r!/ S Qr"g)!    N)strict   )PreTrainedConfig)auto_docstring)VideoMetadata   )CONFIG_MAPPING
AutoConfig	AutoModel)Glm4vImageProcessor)Glm4vImageProcessorPil)Glm4vForConditionalGeneration
Glm4vModelGlm4vPreTrainedModel)Glm4vProcessor)Glm4vVideoProcessorzzai-org/GLM-4.1V-9B-Thinking)
checkpointc                      ^  \ rS rSr% SrSr\\S.rS/rSr	\
\-  S-  \S'   Sr\
\-  S-  \S'   S	r\\S
'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\\S'   Sr\\S'   U 4S jrSrU =r$ )Glm46VConfig   aX  
image_start_token_id (`int`, *optional*, defaults to 151339):
    The image start token index to encode the start of image.
image_end_token_id (`int`, *optional*, defaults to 151340):
    The image end token index to encode the end of image.
video_start_token_id (`int`, *optional*, defaults to 151361):
    The video start token index to encode the start of video.
video_end_token_id (`int`, *optional*, defaults to 151362):
    The video end token index to encode the end of video.

```python
>>> from transformers import Glm46VForConditionalGeneration, Glm46VConfig

>>> # Initializing a GLM-4.6V style configuration
>>> configuration = Glm46VConfig()

>>> # Initializing a model from the GLM-4.6V style configuration
>>> model = Glm4vForConditionalGeneration(configuration)

>>> # Accessing the model configuration
>>> configuration = model.config
```glm46v)text_configvision_configpast_key_valuesNr   r   i/O image_token_idi0O video_token_idi+O image_start_token_idi,O image_end_token_idiAO video_start_token_idiBO video_end_token_idFtie_word_embeddingsc                 v  > [        U R                  [        5      (       aU  U R                  R                  SS5      U R                  S'   [        U R                  S      " S0 U R                  D6U l        O U R                  c  [        S   " 5       U l        [        U R
                  [        5      (       aU  U R
                  R                  SS5      U R
                  S'   [        U R
                  S      " S0 U R
                  D6U l        O U R
                  c  [        S   " 5       U l        [        TU ]  " S0 UD6  g )N
model_typeglm4v_vision
glm4v_text )
isinstancer   dictgetr	   r   super__post_init__)selfkwargs	__class__s     z/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/models/glm46v/modular_glm46v.pyr+   Glm46VConfig.__post_init__F   s   d(($///3/A/A/E/ElTb/cD|,!/0B0B<0P!Q!gTXTfTf!gD'!/!?!ADd&&---1-=-=-A-A,P\-]D\*-d.>.>|.LMaPTP`P`aD%-l;=D''    )__name__
__module____qualname____firstlineno____doc__r#   r
   sub_configskeys_to_ignore_at_inferencer   r(   r   __annotations__r   r   intr   r   r   r   r    r!   boolr+   __static_attributes____classcell__r.   s   @r/   r   r      s    . J",zJK#4"526K((4/648M4**T18 NC  NC  &#&$$ &#&$$ %%( (r1   r   c                   "    \ rS rSrSrSrS rSrg)Glm46VPreTrainedModelV   Nc                     [        S5      e)Nz
Not needed)AttributeError)r,   modules     r/   _init_weights#Glm46VPreTrainedModel._init_weightsZ   s    \**r1   r&   )r2   r3   r4   r5   _can_record_outputs_no_split_modulesrE   r<   r&   r1   r/   r@   r@   V   s    +r1   r@   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )Glm46VModel^   Nc                    > [         TU ]  U5        [        R                  " UR                  5      U l        [        R                  " UR                  5      U l        g N)r*   __init__r   from_configr   visualr   language_model)r,   configr.   s     r/   rN   Glm46VModel.__init__a   sA     ++F,@,@A'33F4F4FGr1   )rQ   rP   )r2   r3   r4   r5   rH   rN   r<   r=   r>   s   @r/   rJ   rJ   ^   s    H Hr1   rJ   c                       \ rS rSrSrg)Glm46VForConditionalGenerationg   r&   Nr2   r3   r4   r5   r<   r&   r1   r/   rU   rU   g       r1   rU   c                       \ rS rSrS rSrg)Glm46VProcessork   c                 *    SU R                    SUS S3$ )Nz<|begin_of_image|>z<|end_of_image|>z.1fz seconds)image_token)r,   timestamp_secs     r/   replace_frame_token_id&Glm46VProcessor.replace_frame_token_idl   s$    #D$4$4#55EmTWEXX`aar1   r&   N)r2   r3   r4   r5   r_   r<   r&   r1   r/   rZ   rZ   k   s    br1   rZ   c                       \ rS rSrSrg)Glm46VImageProcessorPilp   r&   NrW   r&   r1   r/   rb   rb   p   rX   r1   rb   c                       \ rS rSrSrg)Glm46VImageProcessort   r&   NrW   r&   r1   r/   re   re   t   rX   r1   re   c                   8    \ rS rSr SS\S\\-  S-  4S jjrSrg)Glm46VVideoProcessorx   Nmetadatafpsc                    Ub  [        USS 5      c  [        S5      eUR                  nUS-
  nUR                  =(       d    [	        XQR
                  -  5      S-   nSSSS.nSnSn	[        Xi5      n
U
S	::  a  US	   nOU
S
::  a  US
   nOUS   n[        X-  U R                  -  5      n[        X5      nSUR
                  -  n[        U5       Vs/ s H  oU-  PM	     nn[        U5      nXL:  a-  [        R                  " SUS-
  U[        S9R                  5       nOQ/ nSnSU R                  U-  -  n[        U5       H,  nUU   U:  d  M  UU-  nUR                  U5        UU:  d  M,    O   [        U5      U:  aU  [        U5      S:X  a  S[        US-
  S5      nnO
US   US   nn[        R                  " UUU[        S9R                  5       nO;[        U5      U:  a,  [        R                  " SUS-
  U[        S9R                  5       n[!        5       / nnU H-  nUU;  d  M  UR#                  U5        UR                  U5        M/     [        U5      S-  (       a  UR                  US   5        [        R$                  " U5      $ s  snf )Nrk   zAsked to sample frames per second but no video metadata was provided which is required when sampling in Glm46V. Please pass in `VideoMetadata` object or set `do_sample_frames=False`   r   g      ?)r   ,  `	  i  ro   r   rn   r   )dtype)getattr
ValueErrortotal_num_framesdurationroundrk   minr:   temporal_patch_sizerangenplinspacetolistappendlenmaxsetaddarray)r,   rj   rk   r-   total_framesmax_frame_idxru   DYNAMIC_FPS_THRESMAX_FRAME_COUNT_DYNAMICMAX_DURATIONeffective_duration
target_fps	extract_tduration_per_framei
timestamps
max_secondframe_indicescurrent_secondinv_fpsframe_indexstartendseenuniqidxs                             r/   sample_frames"Glm46VVideoProcessor.sample_framesy   s    wx=EX 
  00$q($$Omll.J(Ka(O!"#6"% 8#*2.J3&*3/J*40J*7$:R:RRS		;	-6;L6IJ6I,,6I
J]
#KK<!+;YcRYY[MMN433j@AG$\2k*n<"g-N!((5%3  3 }	)=!Q&L1$4a 8ss*1-}R/@sKKsISIPPRM)+KK<!+;YcRYY[MUBd C$C  !
 t9q=KKR!xx~E Ks   Jr&   rM   )	r2   r3   r4   r5   r   r:   floatr   r<   r&   r1   r/   rh   rh   x   s0     #'@@ 5[4@ @r1   rh   )r   rJ   r@   rU   rZ   re   rb   rh   )#numpyrz   huggingface_hub.dataclassesr   configuration_utilsr   utilsr   video_utilsr   autor	   r
   r   glm4v.image_processing_glm4vr    glm4v.image_processing_pil_glm4vr   glm4v.modeling_glm4vr   r   r   glm4v.processing_glm4vr   glm4v.video_processing_glm4vr   r   r@   rJ   rU   rZ   rb   re   rh   __all__r&   r1   r/   <module>r      s      . 3 # ( 8 8 > E b b 3 > 9:3(# 3(  ;3(l+0 +H* H	%B 	bn b
	4 		. 	A. AH	r1   