
    ^jn                         d dl mZmZ d dlmZmZmZ d dlmZ  e       rddl	Z	 ej                  e      Z G d ded	      Ze ed
       G d de                    ZdgZy)   )ProcessingKwargsProcessorMixin)auto_docstringis_torch_availablelogging)requires    Nc                       e Zd ZdddiiZy)InklingProcessorKwargsaudio_kwargsload_audio_backend
torchaudioN)__name__
__module____qualname__	_defaults     y/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/inkling/processing_inkling.pyr   r      s     ,
Ir   r   F)total)torch)backendsc                        e Zd ZeZ	 	 	 	 	 	 	 	 	 	 	 d fd	ZddZd Zdede	de
fdZded	e	de
fd
Zedee
   fd       Zedee
   fd       Z xZS )InklingProcessorc                 n   t        |d      r|j                  n|| _        |j                  | j                  d      d   | _        t        |d      r|j                  n|| _        |j                  | j                  d      d   | _        || _        |j                  | j                  d      d   | _        || _        |j                  | j                  d      d   | _	        |	| _
        |
| _        || _        t        j                  |
||	t        j                        | _        t"        | I  ||||       y)	aS  
        image_token (`str`, *optional*, defaults to `"<|unused_200054|>"`):
            Placeholder token for each image soft-token slot (replaced by image features).
        audio_token (`str`, *optional*, defaults to `"<|unused_200053|>"`):
            Placeholder token for each audio soft-token slot (replaced by audio features).
        image_bos_token (`str`, *optional*, defaults to `"<|content_image|>"`):
            Marker token that begins an image span (kept as an ordinary embedded token).
        audio_bos_token (`str`, *optional*, defaults to `"<|content_audio_input|>"`):
            Marker token that begins an audio span (kept as an ordinary embedded token).
        num_dmel_bins (`int`, *optional*, defaults to 16):
            Number of discrete bins each (clamped) log-mel value is quantized into.
        dmel_min_value (`float`, *optional*, defaults to -7.0):
            Lower clamp bound, in log10 space, used for dMel quantization.
        dmel_max_value (`float`, *optional*, defaults to 2.0):
            Upper clamp bound, in log10 space, used for dMel quantization.
        image_tokenF)add_special_tokensr	   audio_token)dtype)chat_templateN)hasattrr   encodeimage_token_idr   audio_token_idimage_bos_tokenimage_bos_token_idaudio_bos_tokenaudio_bos_token_idnum_dmel_binsdmel_min_valuedmel_max_valuer   linspacefloat64bin_centerssuper__init__)selffeature_extractorimage_processor	tokenizerr    r   r   r%   r'   r)   r*   r+   kwargs	__class__s                r   r0   zInklingProcessor.__init__)   s-   > 5<I}4U900[f'..t/?/?TY.Z[\]4;I}4U900[f'..t/?/?TY.Z[\]."+"2"243G3G\a"2"bcd"e."+"2"243G3G\a"2"bcd"e +,, >>..-_d_l_lm*OYVcdr   returnc                 r   | j                   j                  |j                        }|j                  t        j                        j                  | j                  | j                        }|j                  d      |z
  j                         j                  d      j                  t        j                        S )N)minmax)dim)r.   todevicer   r-   clampr*   r+   	unsqueezeabsargminint32)r1   input_featuresr.   mels       r   _extract_dmel_binsz#InklingProcessor._extract_dmel_binsY   s    &&)).*?*?@.449L9LRVReRe4fb!K/446=="=EHHUUr   c                      | j                   |fi |}| j                  |d         |j                  d      d}t        t	        |            D cg c]  }| j                  ||       }}||fS c c}w )NrD   input_features_mask)audio_input_idsaudio_input_ids_mask)	audio_idx)r2   rF   getrangelenreplace_audio_token)r1   audior5   audio_inputsprocessed_audioidxaudio_replacementss          r   _process_audiozInklingProcessor._process_audio^   s    -t--e>v>  $66|DT7UV$0$4$45J$K
 chhklqhrbst[^d66RU6Vtt 222 us   A0image_inputs	image_idxc                 0    |d   |   }| j                   |z  S Nnum_patches)r   )r1   rV   rW   num_soft_tokenss       r   replace_image_tokenz$InklingProcessor.replace_image_tokenh   s"    &}5i@/11r   rQ   rK   c                     |j                  d      }|t        ||   j                               }nt        |d   |   j                  d         }| j                  |z  S )NrJ   rI   )rL   intsumshaper   )r1   rQ   rK   rJ   r[   s        r   rO   z$InklingProcessor.replace_audio_tokenl   se    +//0FG+!"6y"A"E"E"GHO!,/@"A)"L"R"RSU"VWO/11r   c                     dgS rY   r   )r1   s    r   unused_input_namesz#InklingProcessor.unused_input_namesu   s
    r   c                     ddg| j                   j                  | j                  j                  }t        j	                  |      D cg c]  }|| j
                  vs| c}S c c}w )NrI   rJ   )r3   model_input_namesr4   dictfromkeysrc   )r1   namesnames      r   re   z"InklingProcessor.model_input_namesy   sg     "
 !!33
 ^^--	
 "&u!5]TE\E\9\]]]s   A#A#)NNNNz<|unused_200054|>z<|unused_200053|>z<|content_image|>z<|content_audio_input|>   g      g       @)rD   torch.Tensorr7   rk   )r   r   r   r   valid_processor_kwargsr0   rF   rU   rf   r_   strr\   rO   propertylistrc   re   __classcell__)r6   s   @r   r   r   $   s     4 ''+1.e`V
32 2 2 22 2 2 2 DI   ^49 ^ ^r   r   )processing_utilsr   r   utilsr   r   r   utils.import_utilsr   r   
get_loggerr   loggerr   r   __all__r   r   r   <module>rw      s{     A @ @ *  
		H	%-U  	:[^~ [^  [^| 
r   