U
    ©Ê¹jÇ  ã                   @   s|  U d dl mZ d dlmZmZmZmZmZmZ d dl	Z	d dl
mZ d dlmZ dddgZedd	�eeed
œdd„ƒZe	jjjjdddgefe	jjjjdddddddddgefe	jjjjddddddgefe	jjjjdg efe	jjjjdddddddgefe	jjjjddgefiZeeeeee eeegef f f ed< edd	�ej eeef dœdd„ƒZ!edd	�eddœd d„ƒZ"dS )!é    )ÚGraphModule)ÚAnyÚCallableÚDictÚListÚTupleÚTypeN)ÚcompatibilityÚdefault_matchingÚextract_attrs_for_loweringÚlift_lowering_attrs_to_nodesF)Zis_backward_compatible)ÚnameÚtarget_versionÚreturnc                 C   s   | S )zDefault matching method
    © )r   r   r   r   úZ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torch/fx/passes/param_fetch.pyr
      s    é   ÚweightZbiasZkernel_sizeZstrideÚpaddingZdilationÚgroupsZpadding_modeé   Zrunning_meanZrunning_varÚepsZreturn_indicesZ	ceil_modeZinplaceÚmodule_fetch_book)Úmodr   c                 C   s˜   i }t  | ¡|d< t| ƒtkr€tt| ƒ \}}}|| jk r^td|› dt  | ¡› d| j› d�ƒ‚|D ]}t| ||| jƒƒ||< qbntt  | ¡› d�ƒ‚|S )z³If `mod` is in `module_fetch_book`, fetch the mod's attributes that in the `module_fetch_book`
    after checking module's version is compatible with the `module_fetch_book`.
    r   zFetcher version z try to fetch z	 version zl, please upgrade the module_fetch_book, open an issue and @842974287 or report a bug to AIACC team directly.z’ is not in the module_fetch_book yet, please add it to the module_fetch_book, open an issue and @842974287 or report a bug to AIACC team directly.)ÚtorchÚtypenameÚtyper   Ú_versionÚRuntimeErrorÚgetattr)r   Úattrs_for_loweringÚversionZparam_to_fetchZmatching_methodÚattrr   r   r   r   !   s    
$)Ú	fx_moduler   c                 C   sX   t |  ¡ ƒ}| jjD ]>}|jdkrt||j tƒrBt||j ƒ qt	||j ƒ|_
qdS )zoRecursively traverse all `fx_module` nodes and fetch the module's attributes if the node is a leaf module.
    Zcall_moduleN)ÚdictZnamed_modulesÚgraphZnodesÚopÚ
isinstanceÚtargetr   r   r   r    )r#   Z
submodulesÚnoder   r   r   r   7   s    
)#Ztorch.fx.graph_moduler   Útypingr   r   r   r   r   r   r   Ztorch.nnÚnnZtorch.fx._compatibilityr	   Ú__all__ÚstrÚintr
   ÚmodulesZlinearZLinearÚconvZConv2dZ	batchnormZBatchNorm2dZpoolingZAdaptiveAvgPool2dZ	MaxPool2dZ
activationZReLUr   Ú__annotations__ÚModuler   r   r   r   r   r   Ú<module>   s>     
	
 
  ÿ
 
 
  ÿ
 
ö.