o
    j9:j                     @   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e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   c/home/nk/hobo-godmode/plappi-mvp/.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__c                 C   s   t S Nr   r1   r   r   r%   python_type5   s   zSDPAParamsVariable.python_type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   r7   r   r%   <lambda><   s    z0SDPAParamsVariable.reconstruct.<locals>.<lambda>F)r   r-   add_push_nullforeachextend_outputr   len)r1   r7   r   r:   r%   reconstruct8   s   
zSDPAParamsVariable.reconstructc                 C   s   | j S r4   )r,   r5   r   r   r%   as_proxyA   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builderrC   miscrD   r   _Cr8   AttributeErrortorch._dynamo.graph_break_hints_dynamograph_break_hintsr   
USER_ERRORcreate_getattr_proxyrA   r   r   )r1   r   rB   r'   rC   rD   rP   r,   r   r   r%   var_getattrD   s,   


zSDPAParamsVariable.var_getattrr	   c                 C   s   | t u S r4   r   )r   r   r   r%   is_sdpa_params`   s   z!SDPAParamsVariable.is_sdpa_params)r7   r   r   N)__name__
__module____qualname____doc__staticmethodr   r   r   r+   r
   r   r0   typer6   r@   rA   strrS   r   rT   __classcell__r   r   r2   r%   r      s6    
	 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    