o
    :/Êiñ  ã                   @  s–   d Z ddlmZ ddlmZ ddlZzddlmZ W n e	y(   d$dd	„ZY nw d%dd„Z
ed&dd„ƒZd'dd„Zd(dd„Zd)dd „Zd*d"d#„ZdS )+a  Small helper wrappers for external Oink Blackwell custom ops.

vLLM does not depend on the external Oink repository/package. When an external
plugin registers torch.library.custom_op entrypoints under the `oink::`
namespace (e.g. via vLLM's general_plugins mechanism) and
`VLLM_USE_OINK_OPS=1` is set, vLLM can route eligible calls to those ops.

This module provides:
- A single place to probe Oink op availability at module init time
  (outside torch.compile tracing), and
- Thin wrappers around the torch.ops entrypoints for use in CUDA fast paths,
  without introducing graph breaks.

Important:
  Do not call the availability helpers in a compiled region. They may call
  functions decorated with `torch._dynamo.disable` to safely check
  conditions that should not be traced.
é    )Úannotations)ÚCallableN)ÚdisableÚfnr   c                 C  s   | S )N© )r   r   r   ú[/lsinfo/ai/hellotax_ai/llm_service/venv_vllm/lib/python3.10/site-packages/vllm/_oink_ops.pyÚ_dynamo_disable    s   r   Úop_nameÚstrÚreturnÚboolc                 C  s   t tjdƒot tjj| ƒS )z*Check if a specific oink op is registered.Úoink)ÚhasattrÚtorchÚopsr   )r	   r   r   r   Ú_has_oink_op$   s   r   Údevice_indexÚintc                 C  sX   t j ¡ sdS zt j | ¡\}}d| | }|dk rW dS W tdƒS  ty+   Y dS w )aT  Return True if Oink ops are registered and device is SM100+.

    This function is intended to be called during module initialization
    (e.g., in RMSNorm.__init__), not in the forward path.

    External plugins are expected to gate registration on SM100+ and
    VLLM_USE_OINK_OPS=1, so if the ops are present they should be usable.
    Fé
   éd   Úrmsnorm)r   ÚcudaÚis_availableÚget_device_capabilityÚ	Exceptionr   )r   ÚmajorÚminorÚsmr   r   r   Úis_oink_available_for_device)   s   

ÿýÿr   c                   C  s   t dƒS )z3Return True if the in-place fused op is registered.Úfused_add_rms_norm)r   r   r   r   r   Úhas_fused_add_rms_normA   s   r    Úxútorch.TensorÚweightÚepsÚfloatc                 C  s   t jj | ||¡S )z_Call `torch.ops.oink.rmsnorm`.

    This wrapper is safe to call in torch.compile regions.
    )r   r   r   r   )r!   r#   r$   r   r   r   r   F   s   r   ÚresidualÚNonec                 C  s   t jj | |||¡ dS )zBCall `torch.ops.oink.fused_add_rms_norm` (mutates x and residual).N)r   r   r   r   ©r!   r&   r#   r$   r   r   r   Úfused_add_rms_norm_N   s   r)   ú!tuple[torch.Tensor, torch.Tensor]c                 C  s   t | |||ƒ | |fS )zDConvenience wrapper returning (x, residual) after in-place mutation.)r)   r(   r   r   r   r   X   s   r   )r   r   )r	   r
   r   r   )r   r   r   r   )r   r   )r!   r"   r#   r"   r$   r%   r   r"   )
r!   r"   r&   r"   r#   r"   r$   r%   r   r'   )
r!   r"   r&   r"   r#   r"   r$   r%   r   r*   )Ú__doc__Ú
__future__r   Úcollections.abcr   r   Útorch._dynamor   r   r   r   r   r    r   r)   r   r   r   r   r   Ú<module>   s    þ




