o
    áÙ·im  ã                   @   sZ   d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 ee
ƒZG dd„ deeƒZdS )é    N)Úinit_logger)ÚNPUPlatform)ÚDiffusionAttentionBackendEnum)ÚOmniPlatformÚOmniPlatformEnumc                   @   s  e Zd ZU dZejZdZee	d< e
defdd„ƒZe
defdd„ƒZe
defd	d
„ƒZe
dedB dedefdd„ƒZe
defdd„ƒZe
d"dedB dejfdd„ƒZe
defdd„ƒZe
dedB fdd„ƒZe
d#dd„ƒZe
d"dejdB defdd„ƒZe
d$dedefd d!„ƒZdS )%ÚNPUOmniPlatformz·NPU/Ascend implementation of OmniPlatform.

    Inherits all NPU-specific implementations from vllm-ascend's NPUPlatform,
    and adds Omni-specific interfaces from OmniPlatform.
    ÚhcclÚdist_backendÚreturnc                 C   ó   dS )Nz8vllm_omni.platforms.npu.worker.npu_ar_worker.NPUARWorker© ©Úclsr   r   úT/home/ubuntu/.local/lib/python3.10/site-packages/vllm_omni/platforms/npu/platform.pyÚget_omni_ar_worker_cls   ó   z&NPUOmniPlatform.get_omni_ar_worker_clsc                 C   r   )NzHvllm_omni.platforms.npu.worker.npu_generation_worker.NPUGenerationWorkerr   r   r   r   r   Úget_omni_generation_worker_cls   r   z.NPUOmniPlatform.get_omni_generation_worker_clsc                 C   r   )Nz%vllm_omni/platforms/npu/stage_configsr   r   r   r   r   Úget_default_stage_config_path    r   z-NPUOmniPlatform.get_default_stage_config_pathÚselected_backendNÚ	head_sizec                 C   sh   ddl m} |d ur| ¡ }t| }t d|¡ | ¡ S |dƒr*t d¡ tj ¡ S t d¡ tj ¡ S )Nr   )Ú	find_specz&Using diffusion attention backend '%s'Úmindiesdz4Defaulting to diffusion attention backend FLASH_ATTNz0Falling back to diffusion attention backend SDPA)	Úimportlib.utilr   Úupperr   ÚloggerÚinfoÚget_pathÚ
FLASH_ATTNÚ
TORCH_SDPA)r   r   r   r   Úbackend_upperÚbackendr   r   r   Úget_diffusion_attn_backend_cls$   s   



z.NPUOmniPlatform.get_diffusion_attn_backend_clsc                 C   r   )NFr   r   r   r   r   Úsupports_torch_inductor:   r   z'NPUOmniPlatform.supports_torch_inductorÚ
local_rankc                 C   s   |d u r	t  d¡S t  d|¡S )NÚnpu)ÚtorchÚdevice)r   r#   r   r   r   Úget_torch_device>   s   
z NPUOmniPlatform.get_torch_devicec                 C   s
   t j ¡ S ©N)r%   r$   Údevice_countr   r   r   r   Úget_device_countD   s   
z NPUOmniPlatform.get_device_countc                 C   s   d S r(   r   r   r   r   r   Úget_device_versionH   r   z"NPUOmniPlatform.get_device_versionc                 C   s   t j ¡  d S r(   )r%   r$   Úsynchronizer   r   r   r   r,   L   s   zNPUOmniPlatform.synchronizer&   c                 C   s   t j |¡\}}|S r(   )r%   r$   Úmem_get_info)r   r&   ÚfreeÚ_r   r   r   Úget_free_memoryP   s   zNPUOmniPlatform.get_free_memoryr   Ú	device_idc                 C   s   t j |¡}|jS r(   )r%   r$   Úget_device_propertiesÚtotal_memory)r   r1   Údevice_propsr   r   r   Úget_device_total_memoryU   s   z'NPUOmniPlatform.get_device_total_memoryr(   )r
   N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚNPUÚ
_omni_enumr	   ÚstrÚ__annotations__Úclassmethodr   r   r   Úintr!   Úboolr"   r%   r&   r'   r*   r+   r,   r0   r5   r   r   r   r   r      s@   
 þýür   )r%   Úvllm.loggerr   Úvllm_ascend.platformr   Ú/vllm_omni.diffusion.attention.backends.registryr   Úvllm_omni.platforms.interfacer   r   r6   r   r   r   r   r   r   Ú<module>   s   