o
    ei                     @   s   d dl m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 dd	lmZ dd
lmZ ddlmZ erNd dlmZ d dlmZ g dZG dd deZdS )    )Sequence)getattr_static)AnyTYPE_CHECKING	TypeGuard)Source
SDPAParams)Proxy   )create_call_function)unimplemented)
AttrSource   )VariableTracker)	PyCodegen)InstructionTranslator)querykeyvalue	attn_maskdropout	is_causal
enable_gqac                	       s   e Zd ZdZedddededefddZd	e	d
e
e deddf fddZdddZde	fddZdddedefddZededed fddZ  ZS )SDPAParamsVariablezeRepresents the c++ params struct for scaled dot product attention.
    This is a read-only container.txr   r   sourcereturnc                    s4   ddl m}  fddtD }|t|i S )Nr   )TorchInGraphFunctionVariablec              	      s&   g | ]}t t|t |qS  )r   buildgetattrr   ).0pr   r   r   r   f/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/_dynamo/variables/sdpa.py
<listcomp>(   s    z-SDPAParamsVariable.create.<locals>.<listcomp>)torchr   PARAM_NAMESr	   call_function)r   r   r   r   paramsr   r$   r%   create"   s
   zSDPAParamsVariable.createproxy
param_varskwargsNc                    s"   || _ || _t jdi | d S )Nr   )r,   r-   super__init__)selfr,   r-   r.   	__class__r   r%   r0   .   s   zSDPAParamsVariable.__init__codegenr   c                    sT   | j d u sJ | jd usJ   fdd  | j  tt| jd d S )Nc                      s     ddS )Nztorch._C_SDPAParams)load_import_fromr   r4   r   r%   <lambda>9   s    z0SDPAParamsVariable.reconstruct.<locals>.<lambda>F)r   r-   add_push_nullforeachextend_outputr   len)r1   r4   r   r7   r%   reconstruct5   s   
zSDPAParamsVariable.reconstructc                 C   s   | j S N)r,   )r1   r   r   r%   as_proxy>   s   zSDPAParamsVariable.as_proxynamec              	   C   s   dd l }ddlm} ddlm} z	t|jj| W n$ ty=   dd l	m
  m} tdd| d| dg |jd	 Y nw ||  |}| jd urV|||t| j|d
S |||dS )Nr   r   )wrap_fx_proxy)GetAttrVariablez*unsupported torch._C._SDPAParams attributezname: zUnable to fetch attribute z from torch._C._SDPAParams.)gb_typecontextexplanationhints)r   r,   r   )r   r,   )torch._CbuilderrA   miscrB   r   _Cr5   AttributeErrortorch._dynamo.graph_break_hints_dynamograph_break_hintsr   
USER_ERRORcreate_getattr_proxyr?   r   r   )r1   r   r@   r'   rA   rB   rN   r,   r   r   r%   var_getattrA   s,   


zSDPAParamsVariable.var_getattrr	   c                 C   s   | t u S r>   r   )r   r   r   r%   is_sdpa_params]   s   z!SDPAParamsVariable.is_sdpa_params)r4   r   r   N)__name__
__module____qualname____doc__staticmethodr   r   r   r+   r
   r   r0   r=   r?   strrQ   r   rR   __classcell__r   r   r2   r%   r      s4    
	 r   N)collections.abcr   inspectr   typingr   r   r   torch._guardsr   torch.backends.cudar	   torch.fx.proxyr
   bytecode_transformationr   excr   r   r   baser   torch._dynamo.codegenr   torch._dynamo.symbolic_convertr   r(   r   r   r   r   r%   <module>   s    