o
    پiP                     @   s@   d Z ddlmZmZ ddlmZ ddlmZ G dd deZdS )aX  
Multimodal processor for lightonai/LightOnOCR-2-1B.

Key difference from Pixtral: LightOnOCR does NOT use image break/end tokens.
The parent PixtralProcessor inserts row-break and image-end tokens between
image patch rows. This processor removes them after the parent processing
to produce a single contiguous range of image tokens per image.
    )ListUnion)"LightOnOCRForConditionalGeneration)PixtralProcessorc                       sD   e Zd ZdZegZ fddZdeee	e
f  f fddZ  ZS )LightOnOCRProcessorzProcessor for LightOnOCR model.c           
         s   t |dst|dd|_t|dd}t |dr'|j}t |dr$|jd u r'||_t |dr/||_t j|||g|R i | t | _dD ]}t||d }	|	d urV| j	|	 qDd	D ]}t||d }	|	d urk| j	|	 qYd S )
Nimage_token_indeximage_token_idigP spatial_merge_size   vision_config
patch_size)image_break_token_idimage_break_id)image_end_token_idimage_end_id)
hasattrgetattrr   r   r	   super__init__set_break_token_idsadd)
self	hf_configserver_args
_processorargskwargsr	   vcattrtid	__class__ _/home/ubuntu/.local/lib/python3.10/site-packages/sglang/srt/multimodal/processors/lightonocr.pyr   #   s,   


zLightOnOCRProcessor.__init__
image_datac                    s   t  j||||d|I d H }|r| js|S |dg }|dg }g }	i  t|D ]\}
}|| jvr@t|	 |
< |	| q,t|	t|krK|S |D ]}|jsSqMt fdd|jD }|rk|d |d fg|_qM|	|d< |S )N)r%   
input_textrequest_obj	input_idsmm_itemsc                 3   s8    | ]\}}t ||d  D ]}| v r | V  qqdS )   N)range).0startendidx
old_to_newr#   r$   	<genexpr>d   s    z<LightOnOCRProcessor.process_mm_data_async.<locals>.<genexpr>r   )	r   process_mm_data_asyncr   get	enumeratelenappendoffsetssorted)r   r%   r&   r'   r   r   resultr(   r)   new_input_idsold_idxtoken_idmm_itemnew_indicesr!   r0   r$   r4   ?   sB   


z)LightOnOCRProcessor.process_mm_data_async)__name__
__module____qualname____doc__r   modelsr   r   r   strbytesr4   __classcell__r#   r#   r!   r$   r      s    r   N)	rD   typingr   r   sglang.srt.models.lightonocrr   (sglang.srt.multimodal.processors.pixtralr   r   r#   r#   r#   r$   <module>   s
   	