o
    ۷i
                     @   st   d Z ddlZddlZddlmZ ddlmZ ddlmZ ee	Z
dedee fdd	Zed
edee fddZdS )a&  
Diffusion attention backend selector.

This module provides the interface for selecting diffusion attention backends.
The actual backend selection logic is delegated to the platform layer
(vllm_omni.platforms), similar to how vLLM handles attention backend selection.

Usage:
    from vllm_omni.diffusion.attention.selector import get_attn_backend

    # Get the appropriate backend for current platform
    backend_cls = get_attn_backend(head_size=64)

    # Or override via environment variable
    # export DIFFUSION_ATTENTION_BACKEND=FLASH_ATTN
    N)cache)init_logger)AttentionBackendcls_pathreturnc              
   C   s   |  dd\}}zt|}t||}|W S  ty+ } z
td| d| d}~w ty@ } z
td| d| d}~ww )zLoad a backend class from its fully qualified path.

    Args:
        cls_path: Fully qualified class path (e.g.,
            "vllm_omni.diffusion.attention.backends.sdpa.SDPABackend")

    Returns:
        The loaded backend class
    .   zFailed to import module z: NzClass z not found in module: )rsplit	importlibimport_modulegetattrImportErrorAttributeError)r   module_path
class_namemodulebackend_classe r   \/home/ubuntu/vllm_env/lib/python3.10/site-packages/vllm_omni/diffusion/attention/selector.py_load_backend_cls!   s   


r   	head_sizec                 C   s.   ddl m} tjd}|j|| d}t|S )a  
    Get attention backend for diffusion models.

    The backend selection is delegated to the current platform
    (vllm_omni.platforms.current_omni_platform), which selects the
    appropriate backend based on:
    1. User override via DIFFUSION_ATTENTION_BACKEND environment variable
    2. Platform-specific defaults and capabilities

    This is similar to how vLLM's get_attn_backend_cls works, where the
    platform layer decides which backend to use based on hardware capabilities.

    Args:
        head_size: Head size for attention computation (may affect backend selection)

    Returns:
        The selected attention backend class
    r   )current_omni_platformDIFFUSION_ATTENTION_BACKEND)selected_backendr   )vllm_omni.platformsr   osenvirongetget_diffusion_attn_backend_clsr   )r   r   r   backend_cls_pathr   r   r   get_attn_backend6   s   r!   )__doc__r
   r   	functoolsr   vllm.loggerr   /vllm_omni.diffusion.attention.backends.abstractr   __name__loggerstrtyper   intr!   r   r   r   r   <module>   s   