o
    پi                     @   s@   d dl mZmZ d dlmZ d dlmZmZ G dd deZdS )    )ListUnion)Sarashina2VisionForCausalLM)BaseMultimodalProcessorMultimodalSpecialTokensc                       s<   e Zd ZegZ fddZdeeee	f  fddZ
  ZS )Sarashina2VisionProcessorc                    s   t  j|||g|R i | d| _t|dd| _t|dd| _t|dd| _t| j| jd|| _	t
|d	rNt
|jd
rP|jj  fdd}||j_d S d S d S )Nz<|file|>image_token_index   start_image_token_indexi end_image_token_indexi )image_tokenimage_token_idimage_processor_preprocessc                     s,   h d  fdd|  D }| i |S )N>
   resample	do_resize	image_std
do_rescale
image_meandata_formatdo_normalizedo_convert_rgbrescale_factorinput_data_formatc                    s   i | ]\}}| v r||qS  r   ).0kvallowed_paramsr   f/home/ubuntu/.local/lib/python3.10/site-packages/sglang/srt/multimodal/processors/sarashina2_vision.py
<dictcomp>0   s    zRSarashina2VisionProcessor.__init__.<locals>.patched_preprocess.<locals>.<dictcomp>)items)argskwargsfiltered_kwargsoriginal_preprocessr   r    patched_preprocess!   s
   
z>Sarashina2VisionProcessor.__init__.<locals>.patched_preprocess)super__init__IMAGE_TOKENgetattrIM_TOKEN_IDIM_START_ID	IM_END_IDr   build	mm_tokenshasattrr   r   )self	hf_configserver_args
_processorr#   r$   r(   	__class__r&   r    r*      s$   z"Sarashina2VisionProcessor.__init__
image_datac           
         sF   | j ||| jd}| j|| jd\}}}	|| | jj| j| jdS )zLProcess image data for Sarashina2Vision model using standard SGLang pattern.)promptr9   multimodal_tokens)base_outputr1   )mm_items	input_idsim_token_idim_start_id	im_end_id)load_mm_datar1   process_and_combine_mm_datatolistr   r.   r/   )
r3   r9   
input_textrequest_objr#   r$   r<   r=   r>   retr   r   r    process_mm_data_async7   s    	z/Sarashina2VisionProcessor.process_mm_data_async)__name__
__module____qualname__r   modelsr*   r   r   strbytesrH   __classcell__r   r   r7   r    r   
   s    *r   N)	typingr   r   #sglang.srt.models.sarashina2_visionr   /sglang.srt.multimodal.processors.base_processorr   r   r   r   r   r   r    <module>   s    