o
    ٷiA                     @   s   d dl mZmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ eeZdd
dZdd ZeG dd de	ZeG dd deZdS )    )	dataclassfield)AnyN)AsyncEngineArgs
EngineArgs)init_logger)is_gguf)OmniModelConfig)load_omni_general_pluginsreturnc               
   C   sx   zddl m}  ddlm} W n ty' } ztd| W Y d }~d S d }~ww z	| d| W d S  ty;   Y d S w )Nr   )
AutoConfig)Qwen3TTSConfigz<Skipping omni HF config registration due to import error: %s	qwen3_tts)	transformersr   Avllm_omni.model_executor.models.qwen3_tts.configuration_qwen3_ttsr   	Exceptionloggerwarningregister
ValueError)r   r   exc r   N/home/ubuntu/.local/lib/python3.10/site-packages/vllm_omni/engine/arg_utils.py_register_omni_hf_configs   s   r   c               
   C   sh   ddl m}  ddlm} t  |  }| D ]\}\}}}||vr1| |d| d| d|  qd S )Nr   )ModelRegistry)_OMNI_MODELSz vllm_omni.model_executor.models..:)vllm.model_executor.modelsr   (vllm_omni.model_executor.models.registryr   r   get_supported_archsitemsregister_model)r   r   supported_archsarch
mod_foldermod_relnamecls_namer   r   r   register_omni_models_to_vllm!   s   r(   c                          e Zd ZU dZdZeed< dZeed< dZ	eed< dZ
edB ed	< dZedB ed
< dZedB ed< eedZeeef ed< dZeed< dZedB ed< dZedB ed< dZedB ed< d fddZdd ZdefddZ  ZS )OmniEngineArgsa4  Engine arguments for omni models, extending base EngineArgs.
    Adds omni-specific configuration fields for multi-stage pipeline
    processing and output type specification.
    Args:
        stage_id: Identifier for the stage in a multi-stage pipeline (default: 0)
        model_stage: Stage type identifier, e.g., "thinker" or "talker"
            (default: "thinker")
        model_arch: Model architecture name
            (default: "Qwen2_5OmniForConditionalGeneration")
        engine_output_type: Optional output type specification for the engine.
            Used to route outputs to appropriate processors (e.g., "image",
            "audio", "latents"). If None, output type is inferred.
        custom_process_next_stage_input_func: Optional path to a custom function for processing
            inputs from previous stages
            If None, default processing is used.
        stage_connector_spec: Extra configuration for stage connector
        async_chunk: If set to True, perform async chunk
        worker_type: Model Type, e.g., "ar" or "generation"
    r   stage_idthinkermodel_stage#Qwen2_5OmniForConditionalGeneration
model_archNengine_output_typehf_config_name$custom_process_next_stage_input_funcdefault_factorystage_connector_specFasync_chunkomni_kv_configquantization_configworker_typer   c                       t   t   d S Nr
   super__post_init__self	__class__r   r   r>   P      zOmniEngineArgs.__post_init__c                 C      t | drdS t  d| _dS N_omni_models_registeredThasattrr(   rF   r?   r   r   r   _ensure_omni_models_registeredT   
   
z-OmniEngineArgs._ensure_omni_models_registeredc                 C     t | jrd | _| _tjstd| j | 	  t
| di }t
| dd}t
| dd}t
| di }t
| dd}t
| d	d
}t
| dd}t
| dd
}t
| dd}	t
| dd}
t
| dd}t
| dd
}t
| dd}| jdd| jdi  d}| j|d d< tdKi d| jd| jd| jd| jd| jd | jd!| jd"| jd#| jd$| jd%| jd&| jd'| jd(| jd)| jd*| jd+| jd,| jd-| jd.| j d/| j!d0| j"d1| j#d2| j$d3| j%d4| j&d5| j'd6| j(d7| j)d|d|d|d|d|d8| j*d	|d|d|d|	d|
d|d|d9| j+d:| j,d;| j-d<| j.d=| j/d>| j0d?| j1d@| j2d|dA| j3d| jdB| j4dC| j5dD| j6dE| j7dF| j8dG| j9dH| j:dI|dJ| j;}|j<|j=_<|S LzCreate an OmniModelConfig from these engine arguments.
        Returns:
            OmniModelConfig instance with all configuration fields set
        ggufzThe global random seed is set to %d. Since VLLM_ENABLE_V1_MULTIPROCESSING is set to False, this may affect the random state of the Python process that launched vLLM.limit_mm_per_promptenable_mm_embedsFinterleave_mm_stringsmedia_io_kwargsskip_mm_profilingmm_processor_kwargsNmm_processor_cache_gb   mm_processor_cache_typemm_shm_cache_max_object_size_mb   mm_encoder_onlymm_encoder_tp_modeweightsmm_encoder_attn_backendvideo_pruning_rateg        nameSharedMemoryConnectorextra)r^   r`   r+   modelmodel_weightshf_config_pathrunnerconvert	tokenizertokenizer_modetrust_remote_codeallowed_local_media_pathallowed_media_domainsdtypeseedrevisioncode_revisionhf_tokenhf_overridestokenizer_revisionmax_model_lenquantizationallow_deprecated_quantizationenforce_eagerenable_return_routed_expertsmax_logprobslogprobs_modedisable_sliding_windowdisable_cascade_attnskip_tokenizer_initenable_prompt_embedsserved_model_nameconfig_formatpooler_configlogits_processor_patterngeneration_configoverride_generation_configenable_sleep_mode
model_imploverride_attention_dtypelogits_processorsio_processor_pluginr6   r-   r/   r9   r0   r1   r2   stage_connector_configr7   r   >r   ra   rs   load_formatenvsVLLM_ENABLE_V1_MULTIPROCESSINGr   r   rl   rI   getattrr5   getcopyr+   r	   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rm   rn   ro   rp   rq   rr   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r6   r-   r/   r9   r0   r1   r2   r7   architectures	hf_configr@   rN   rO   rP   rQ   rR   rS   rT   rV   rW   rY   rZ   r\   r]   r   omni_configr   r   r   create_model_config[   0  
		
 !"#$%&'()*+,-./012345789:;<=>?@
Bz"OmniEngineArgs.create_model_configr   N__name__
__module____qualname____doc__r+   int__annotations__r-   strr/   r0   r1   r2   r   dictr5   r   r6   boolr7   r8   r9   r>   rI   r	   r   __classcell__r   r   rA   r   r*   .   s    
 r*   c                       r)   )AsyncOmniEngineArgsa_  Async engine arguments for omni models, extending base AsyncEngineArgs.
    Adds omni-specific configuration fields for multi-stage pipeline
    processing and output type specification in async contexts.
    Args:
        stage_id: Identifier for the stage in a multi-stage pipeline (default: 0)
        model_stage: Stage type identifier, e.g., "thinker" or "talker"
            (default: "thinker")
        model_arch: Model architecture name
            (default: "Qwen2_5OmniForConditionalGeneration")
        engine_output_type: Optional output type specification for the engine.
            Used to route outputs to appropriate processors (e.g., "image",
            "audio", "latents"). If None, output type is inferred.
        stage_connector_spec: Extra configuration for stage connector
        worker_type: Model Type, e.g., "ar" or "generation"
    r   r+   r,   r-   r.   r/   Nr0   r1   r2   r3   r5   Fr6   r7   r8   r9   r   c                    r:   r;   r<   r?   rA   r   r   r>      rC   z!AsyncOmniEngineArgs.__post_init__c                 C   rD   rE   rG   r?   r   r   r   rI      rJ   z2AsyncOmniEngineArgs._ensure_omni_models_registeredc                 C   rK   rL   r   r   r   r   r   r      r   z'AsyncOmniEngineArgs.create_model_configr   r   r   r   rA   r   r      s    
 r   r   )dataclassesr   r   typingr   	vllm.envsr   vllm.engine.arg_utilsr   r   vllm.loggerr   "vllm.transformers_utils.gguf_utilsr   vllm_omni.configr	   vllm_omni.pluginsr
   r   r   r   r(   r*   r   r   r   r   r   <module>   s     
 !