o
    )i                     @   s   d dl Z d dlmZ d dlmZ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	e jd
e jde jde jfddZd	e jd
e jde jde jfddZdd Zdd Zdd ZG dd deZdS )    N)auto_functionalized)PatternMatcherPassfwd_onlyregister_replacement)
VllmConfig)init_logger)current_platform   )VllmInductorPassresultresult_silu_mulinputscalec                 C   s:   t tjjjj||d}t tjjjj| |d |d}|d S )N)r   r   r	   r   r   r   )r   torchops_CZsilu_and_muldefaultZstatic_scaled_fp8_quant)r   r   r   r   Zat1Zat2 r   t/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/vllm/compilation/activation_quant_fusion.pysilu_mul_pattern_static   s   r   c                 C   s    t tjjjj| ||d}|d S )Nr   r	   )r   r   r   r   Zsilu_and_mul_quantr   )r   r   r   r   atr   r   r   silu_mul_replacement_static   s   r   c                  O      t j| i |t jddS Ncuda)ZdtypeZdevice)r   emptyZbfloat16argskwargsr   r   r   
empty_bf16)      r    c                  O   s"   t  }tj| i ||ddS r   )r   Z	fp8_dtyper   r   )r   r   Zfp8r   r   r   	empty_fp8-   s   r"   c                  O   r   r   )r   r   Zfloat32r   r   r   r   
empty_fp322   r!   r#   c                       s8   e Zd ZdZdef fddZdejjfddZ	  Z
S )ActivationQuantFusionPassah  
    This pass fuses a pre-defined set of custom ops into fused ops.
    It uses the torch pattern matcher to find the patterns and replace them.

    Because patterns can only be registered once, the pass is a singleton.
    This will be addressed in a future version of PyTorch:
    https://github.com/pytorch/pytorch/pull/139321#issuecomment-2452354980
    configc                    sR   t  | tdd| _tddtddtddtddg}ttt	|t
| j d S )NZactivation_quant_fusion_pass)Z	pass_name      r	   )super__init__r   patternsr"   r    r#   r   r   r   r   )selfr%   Zinputs	__class__r   r   r)   @   s   z"ActivationQuantFusionPass.__init__graphc                 C   sD   |    | |d | j|}td| | |d |   d S )NZbefore_act_quant_fusionz1Replaced %s patterns in ActivationQuantFusionPassZafter_act_quant_fusion)beginZ
dump_graphr*   applyloggerdebugZend_and_log)r+   r.   countr   r   r   __call__P   s   z"ActivationQuantFusionPass.__call__)__name__
__module____qualname____doc__r   r)   r   ZfxZGraphr4   __classcell__r   r   r,   r   r$   6   s    	r$   )r   Z*torch._higher_order_ops.auto_functionalizer   Ztorch._inductor.pattern_matcherr   r   r   Zvllm.configr   Zvllm.loggerr   Zvllm.platformsr   Zvllm_inductor_passr
   r5   r1   ZTensorr   r   r    r"   r#   r$   r   r   r   r   <module>   s4   


