
    )`i                     "   d Z ddlmZmZmZmZ ddlmZ ddlm	Z	m
Z
mZmZmZmZmZmZmZmZmZ  G d de          Zdee         d	efd
Zdee         d	efdZdee         d	efdZdee         d	efdZdee         d	efdZd	ee         fdZdS )a3  
Copyright (c) 2025 by FlashInfer team.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    )CallableList
NamedTupleTuple   )Op)FusedProbsMinPSampleOpFusedProbsTopKSampleOpFusedProbsTopKTopPSampleOpFusedProbsTopPSampleOpFusedTemperatureSoftmaxOpMinPOpProbsSampleOpProbsTopKOp	SoftmaxOpTemperatureOpTopPOpc                       e Zd ZU dZeedf         ed<   eee	         ge
f         ed<   eee	         ge	f         ed<   dZeed<   dS )	
FusionRulea  
    Attributes:
        pattern: Tuple of operator types to match (e.g., (TopK, Sampling))
        guard: Function that takes the matched operators and returns True if fusion should apply. It accepts a window of operators parameter which is a subset of the operators in the pipeline and is an exact match of the pattern.
        build: Function that takes the matched operators and returns a fused operator
        prio: Priority for rule application (higher = tried earlier)
    .patternguardbuildr   prioN)__name__
__module____qualname____doc__r   type__annotations__r   r   r   boolr   int     |/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/flashinfer/logits_processor/fusion_rules.pyr   r   #   su           49T"XJ$%%%%T"XJN####D#MMMMMr#   r   windowreturnc                 `    | d         }t          |di                               dd          }|S )z0
    Only fuse when joint_topk_topp is True
    r   default_paramsjoint_topk_toppF)getattrget)r%   topk_opr)   s      r$   !joint_topk_topp_sampleprobs_guardr-   2   s<     QiGg'7<<@@5 O r#   c                 |    | d         }t          |di                               dd           }t          |          S )Nr   r(   
enable_pdl)r/   )r*   r+   r   )r%   
softmax_opr/   s      r$   build_temperature_softmaxr1   =   s>    J%5r::>>|TRRJ$
;;;;r#   c                 |    | d         }t          |di                               dd          }t          |          S Nr   r(   deterministicT)r4   )r*   r+   r
   r%   sampling_opr4   s      r$   build_topk_samplingr7   C   E    )KK)92>>BB M ">>>>r#   c                 |    | d         }t          |di                               dd          }t          |          S r3   )r*   r+   r   r5   s      r$   build_topp_samplingr:   K   r8   r#   c                 |    | d         }t          |di                               dd          }t          |          S r3   )r*   r+   r	   r5   s      r$   build_minp_samplingr<   S   r8   r#   c            
      z   t          t          t          fd t          d          t          t          t
          t          ft          d d          t          t          t          fd t          d          t          t
          t          fd t          d          t          t          t          fd t          d          gS )	Nc                     dS NTr"   r%   s    r$   <lambda>z*get_default_fusion_rules.<locals>.<lambda>_        r#   d   )r   r   r   r   c                     t                      S )N)r   r@   s    r$   rA   z*get_default_fusion_rules.<locals>.<lambda>f   s    !;!=!= r#   c                     dS r?   r"   r@   s    r$   rA   z*get_default_fusion_rules.<locals>.<lambda>k   rB   r#   
   c                     dS r?   r"   r@   s    r$   rA   z*get_default_fusion_rules.<locals>.<lambda>q   rB   r#   c                     dS r?   r"   r@   s    r$   rA   z*get_default_fusion_rules.<locals>.<lambda>w   rB   r#   )r   r   r   r1   r   r   r   r-   r7   r:   r   r<   r"   r#   r$   get_default_fusion_rulesrI   [   s    "I.%%+		
 	
 	
 	 &-83==		
 	
 	
 	 -0%%%		
 	
 	
 	]+%%%		
 	
 	
 	]+%%%		
 	
 	
3 r#   N)r   typingr   r   r   r   opr   	operatorsr	   r
   r   r   r   r   r   r   r   r   r   r   r    r-   r1   r7   r:   r<   rI   r"   r#   r$   <module>rM      s     5 4 4 4 4 4 4 4 4 4 4 4                                      d2h 4    <d2h <2 < < < <?R ?R ? ? ? ??R ?R ? ? ? ??R ?R ? ? ? ? $z"2            r#   