U
    <c                 .   @   s  U d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
mZ d dl	Z	d dlm  mZ d dlmZ d dlmZ d dlmZmZ d d	lmZmZmZmZmZmZmZmZ d d
l m!Z! d dl"m#Z#m$Z$ d dl%m&Z&m'Z'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2 e jj3e j4jj5j3e jj6j3e jj7j3e j4jj7j3gZ8e.e, e9d< e jj:e jj;e jj<e jj7j=e j4jj7j=hZ>e1e0 e9d< e?e
dd e8D  Z@e.e0 e9d< dd e@D Z@i ZAe2e0eBf e9d< e8D ]FZCeCjDD ]8ZEeFeCeEZGeCjHIddIddZJeJ deE eAeG< qԐqeddZKG dd deZ3dd ZLG d d! d!eMZNG d"d# d#eMZOG d$d% d%eMZPd&d' ZQd(d) ZRd*d+ ZSd,d- ZTd.d/ ZUd0d1 ZVd2d3 ZWd4d5 ZXd6d7 ZYd8d9 ZZd:d; Z[d<d= Z\d>d? Z]d@dA Z^dBdC Z_dDdE Z`dFdG ZadHdI ZbdJdK ZcdLdM ZddNdO ZedPdQ ZfdRdS ZgdTdU ZhdVdW ZidXdY ZjdZd[ Zkd\d] Zld^d_ Zmd`da Zndbdc Zoddde Zpe!ejqdfdgeoxe* dhdie!ejqdfdjeoe* dhdie!ejqdfdkeoe* dhdie!ejqdfdkeoe*e jrfdhdlfZsePe jjte)e\e!e(dfe jugdmfdnePe jjve[e!ewdodfdpe!e(dfe jugdmfdqePe jjxdre]e!e(dfe jugdmfdsePe jjydre^e!e(dfe jugdmfdsePe jjzee_dtdudve)dre!edwdxdfdpe!edfdpe j{gdme!e(dfe jugdmfe!ee j{dyidfdpfdzePe jj|ee_d{dudve)dre!edwdxdfdpe!edfdpe j{gdme!e(dfe jugdme!ejqdfdpdhe jugd|fe!ee j{dyidfdpfdzePe jj}ee_d}dudve)dre!ed~dxdfdpe!edfdpe j{gdme!e(dfe jugdme!ejqdfdpfe!ee j{dyidfdpfdzePe jj~ee_dtdudrde)dree je!edwdxdfdpe!edfdpe j{gdme!e(dfe jugdme!ejqdfde jfdde!ejqdfdpe jfdde!ejqdfde jfdde!ejqdfdke jfdde!ejqdfde jfdhde!ejqdfde jfdhde!ejqdfde jfdmf
e!ee j{dyidfdpfdePe jjee_d{dudrde)dre!edwdxdfdpe!edfdpe j{gdme!e(dfe jugdme!ejqdfdpdde!ejqdfdpdhe jugd|fe!ee j{dyidfdpfdzePe jjee_d}dudrde)dre!ed~dxdfdpe!edfdpe j{gdme!e(dfe jugdme!ejqdfdpfe!ee j{dyidfdpfdzePe jje`e!e(dfe jugdmfdqePe jjece!ewdodfdpe!e(dfe jugdmfdqePe jjee_dtdrdve)dre!edwdxdfdpe!edfdpe j{gdme!ee!e(dfe jugdmfe!ee j{dyidfdpfdzePe jjee_d{drdve)dre!e(dfe jugdme!edwdxdfdpe!edfdpe j{gdme!ee!ejqdfdpdhe jugd|fe!ee j{dyidfdpfdzePe jjee_d}drdve)dre!ed~dxdfdpe!edfdpe j{gdme!ee!e(dfe jugdme!ejqdfdpfe!ee j{dyidfdpfdzePe jjee_dtdrdrde)dre!edwdxdfdpe!edfdpe j{gdme!ee!e(dfe jugdmfe!ee j{dyidfdpfdzePe jjee_d{drdrde)dre!edwdxdfdpe!edfdpe j{gdme!ee!e(dfe jugdme!ejqdfdpdde!ejqdfdpdhe jugd|fe!ee j{dyidfdpfdzePe jjee_d}drdrde)dre!ed~dxdfdpe!edfdpe j{gdme!ee!e(dfe jugdme!ejqdfdpfe!ee j{dyidfdpfdzePe jjeQe!e(dfe jugdme!ewdodfdpfdqePe jjeRe!ee j{edydyde juedydydidfdddge!e(dfe jugdme!ewdodfdpfdePe jj=efe!ewdodfdke!ewdodfde!e(dfe jugdmfdqePe jjeSe!ewdodfdpe!e(dfe jugdmfdqePe jjeTe!e(dfe jugdme!ewdodfdpfdqePe jjede!e(dfe jugdmfdqePe jjeee!e(dfe jugdmfdudePe jjdrehe!ewdodfdpe!e(dfe jugdmfdsePe jjeie!ewdodfdpe!e(dfe jugdmfdqePe jjeje!ewdodfdpe!e(dfe jugdmfdqePe jjdrele!ewdodfdpe!e(dfe jugdmfdsePe jjeke!ewdodfdpe!e(dfe jugdmfdqePe jjebe!e(dfe jugdmfdqePe jjeemdrde!e(dfe jugdmfdqePe jjeme!e(dfe jugdmfdqePe jjene!e(dfe jugdmfdqePe jjege!e(dfe jugdmfdqePe jjdreeodrde!e(dfe jugdmfesdePe jjdreeodude!e(dfe jugdmfesdePe jjdrepe!e(dfe jugdmfesdg&Ze.eP e9d< dS )    N)deepcopy)Enum)wrapspartial)chainproduct)make_tensor)
TEST_CUDNN)floating_typesfloating_and_complex_types_and)_TestParametrizer_update_param_kwargstoleranceOverridetolskipCUDAIfCudnnVersionLessThanskipCUDAIfRocmprecisionOverrideskipMeta)DecorateInfo)nllloss_referenceget_reduction)freeze_rng_state#set_single_threaded_if_parallel_tbb	skipIfMpsGRADCHECK_NONDET_TOLTEST_WITH_ROCM)
ModuleType)ListTupleTypeSetDictMODULE_NAMESPACESMODULES_TO_SKIPc                    s    g | ]  fd d j D qS )c                    s   g | ]}t  |qS  )getattr).0module_name	namespacer$   J/tmp/pip-unpacked-wheel-gikjz4vx/torch/testing/_internal/common_modules.py
<listcomp>*   s     z<listcomp>.<listcomp>)__all__)r&   r$   r(   r*   r+   )   s   r+   MODULE_CLASSESc                 C   s   g | ]}|t kr|qS r$   )r#   )r&   clsr$   r$   r*   r+   ,   s      MODULE_CLASS_NAMESztorch. z.modules.TrainEvalMode)
train_only	eval_onlytrain_and_evalc                   @   s0   e Zd ZdZdejfddZdd Zdd ZdS )	moduleszQ PROTOTYPE: Decorator for specifying a list of modules over which to run a test. Nc                 C   s&   || _ |d k	rt|nd | _|| _d S N)module_info_listsetallowed_dtypestrain_eval_mode)selfr8   r:   r;   r$   r$   r*   __init__?   s    zmodules.__init__c                 C   s^   g }| j tjks| j tjkr&|d | j tjks>| j tjkrH|d |jsZ|d d }|S )NTF   )r;   r2   r3   r5   appendr4   train_and_eval_differ)r<   module_infotraining_flagsr$   r$   r*   _get_training_flagsD   s    



zmodules._get_training_flagsc                 #   s,  |d krt d| jD ]}t|j}| jd k	r<|| j}| |}t||D ]\}}|j}	t	|dkr|	d|rvdnd 7 }	d|i}
t
|
d| t
|
d| zHt  fd	d
}||j j|j|D ]}||}q||	|
fV  W qP tk
r" } ztd|	|j |W 5 d }~X Y qPX qPqd S )NzThe @modules decorator is only intended to be used in a device-specific context; use it with instantiate_device_type_tests() instead of instantiate_parametrized_tests()r>   _Z
train_modeZ	eval_moderA   dtypetrainingc                     s
    | |S r7   r$   argskwargstestr$   r*   test_wrappern   s    z/modules._parametrize_test.<locals>.test_wrapperz)Failed to instantiate {0} for module {1}!)RuntimeErrorr8   r9   dtypesr:   intersectionrC   r   formatted_namelenr   r   get_decorators__name__device_type	Exceptionprintformatname)r<   rK   Zgeneric_clsZ
device_clsrA   rN   rB   rF   rE   	test_nameZparam_kwargsrL   	decoratorexr$   rJ   r*   _parametrize_testT   s4    


 
zmodules._parametrize_test)	rS   
__module____qualname____doc__r2   r5   r=   rC   r\   r$   r$   r$   r*   r6   <   s   r6   c                 C   s   t |  S )zN Returns the common name of the module class formatted for use in test names. )r/   )
module_clsr$   r$   r*   get_module_fully_qualified_name}   s    ra   c                   @   s    e Zd ZdZddgZdd ZdS )FunctionInputz: Contains args and kwargs to pass as input to a function. rH   rI   c                 O   s   || _ || _d S r7   rG   )r<   rH   rI   r$   r$   r*   r=      s    zFunctionInput.__init__NrS   r]   r^   r_   	__slots__r=   r$   r$   r$   r*   rb      s   rb   c                   @   s&   e Zd ZdZddddgZd
dd	ZdS )ModuleInputzA Contains args / kwargs for module instantiation + forward pass. constructor_inputforward_inputdescreference_fnNr0   c                    s>   || _ || _|| _ | _ d k	r:t  fdd}|| _d S )Nc                    s,   t |t | }} | t|  f||S r7   )r   list
parameters)mrH   rI   ri   r$   r*   copy_reference_fn   s    z/ModuleInput.__init__.<locals>.copy_reference_fn)rf   rg   rh   ri   r   )r<   rf   rg   rh   ri   rn   r$   rm   r*   r=      s    zModuleInput.__init__)Nr0   Nrc   r$   r$   r$   r*   re      s   re   c                   @   sL   e Zd ZdZdde ddddddd	Zd
d Zedd Zedd Z	dS )
ModuleInfoz+ Module information to be used in testing. r$   NT        F)skips
decoratorsrN   supports_gradgradgradcheck_nondet_tolmodule_memformat_affects_outr@   c          
      C   sH   || _ || _|r|ng |r|ng | _|| _|| _|| _|| _|	| _d S r7   )r`   module_inputs_funcrr   rN   rs   rt   ru   r@   )
r<   r`   rv   rq   rr   rN   rs   rt   ru   r@   r$   r$   r*   r=      s    zModuleInfo.__init__c                 C   sH   t g}| jD ]6}t|tr8|||||rB||j q|| q|S r7   )r   rr   
isinstancer   Z	is_activeextendr?   )r<   Z
test_classrY   devicerE   resultrZ   r$   r$   r*   rR      s    

zModuleInfo.get_decoratorsc                 C   s
   t | jS r7   )ra   r`   r<   r$   r$   r*   rX      s    zModuleInfo.namec                 C   s   | j ddS )Nr1   rD   )rX   replacer{   r$   r$   r*   rP      s    zModuleInfo.formatted_name)
rS   r]   r^   r_   r
   r=   rR   propertyrX   rP   r$   r$   r$   r*   ro      s   

ro   c                 K   s|   t t|||d}ttddt|dddd dttddd	d
t|dddd dttddt|dddd dg}|S )Nry   rE   requires_grad
      )   r   )inputc                 S   s,   t ||d  |d dddd S )Nr   r>   r   r   )torchmmtviewexpand)rl   pr   r$   r$   r*   <lambda>       z/module_inputs_torch_nn_Linear.<locals>.<lambda>rf   rg   ri   Fbiasno_biasc                 S   s   t ||d  S )Nr   )r   r   r   rl   r   ir$   r$   r*   r      r   rf   rg   rh   ri         no_batch_dimc                 S   s*   t |dd|d  d|d  S )Nr>   r   r   )r   r   r   r   r   r$   r$   r*   r      r   r   r   re   rb   rA   ry   rE   r   rF   rI   
make_inputmodule_inputsr$   r$   r*   module_inputs_torch_nn_Linear   s"    



r   c              	      s   t t|||d}ddd ttdddt|d|d	 fd
ddttdddddt|d|d	d fdddttdddt|d|dd fdddg}|S )Nr~   Tc                 S   sj   t d||d |}|rf|jd dkr:|d|d  }n,||d dd|jd |d jd  }|S )Nzbn,anm,bm->bar   r>   r   )r   Zeinsumshaper   r   )rl   r   x1x2r   rz   r$   r$   r*   bilinear_reference_fn   s    ,z>module_inputs_torch_nn_Bilinear.<locals>.bilinear_reference_fn   r   r   )r   r   )r   r   c                    s    | |||S r7   r$   rl   r   r   r   r   r$   r*   r      r   z1module_inputs_torch_nn_Bilinear.<locals>.<lambda>r   Fr   r   c                    s    | |||ddS )NFr   r$   r   r   r$   r*   r      r   r   r   c                    s    | || dd| ddS )Nr>   r   )r   r   r   r$   r*   r      r   )Tr   r   r$   r   r*   module_inputs_torch_nn_Bilinear   s$    




r   c                 K   s   t t|||d}t t||dd}di fdddifdddifd	d	d
ifdd|d ifd|d d
dfd|d ddfg}g }	|D ]^\}
}|fdd}|	ttf |t|djddtjd|d	 
d  |
|d q|	S )Nr~   Fr0   reduction_sum	reductionsumreduction_nonenoneignore_indexr   weightsweightr   Zweights_ignore_index)r   r   Zweights_ignore_index_negr   c                 S   s   t ||f|S r7   )r   )rl   r   r   r   constructor_kwargsr$   r$   r*   ri     s    z4module_inputs_torch_nn_NLLLoss.<locals>.reference_fn)   r   r>   )Zdimr   )ry   r   )r   r   absr?   re   rb   Zlog_softmaxr   emptyZuniform_mulfloorlong)rA   ry   rE   r   rF   rI   r   make_weightcasesr   rh   r   ri   r$   r$   r*   module_inputs_torch_nn_NLLLoss   s.    



r   c              
   K   s   t t|||d}t t||dd}di fdddifdddifd	dd
ifg}g }	|D ]<\}
}|	ttf |t|d|d|d |
td qP|	S )Nr~   Fr0   r   r   r   Zreduction_meanmeanr   r   r   r>   r   )r   r   r?   re   rb   r   no_batch_dim_reference_fn)rA   ry   rE   r   rF   rI   r   make_targetr   r   rh   r   r$   r$   r*   &module_inputs_torch_nn_GaussianNLLLoss"  s(    




	r   c              	      s   fdd}|ddrdnd |dd}|d	d
}|dk	rt |tsHt D ].\}}||krP|dk	rP|| }	||	|< qP fdd|D }
t  | |
 }W 5 Q R X |rt| }|dkr|dS |S )a  Reference function for modules supporting no batch dimensions.

    Unbatched inputs are unsqueezed to form a
    single batch input before passing them to the module.
    The output is squeezed to compare with the
    output of unbatched input to the module.

    Currently it only supports modules which return a single Tensor as output.
    You can bind the following kwargs.
    Kwargs:
        batch_first[bool] : If True, all the Tensors in `args` while be unsqueezed at dim `0` .
                        and output will be squeezed at dim `0` else dim `1` for both.
        kwargs_to_batchify[dict] : Dictionary specifying the name of the argument and dimension to unsqueeze.
                               Useful if there are few arguments whose batch dimension are different
                               from the ones selected by `batch_first`.
        is_criterion[bool] : Specify if the module is a criterion and handle the reduction for output accordingly.
    c                    s"     | |}|  kr |  |S r7   )getpop)keydefaultv)rI   r$   r*   get_and_popM  s    
z.no_batch_dim_reference_fn.<locals>.get_and_popbatch_firstTr   r>   kwargs_to_batchifyNis_criterionFc                    s   g | ]}|  qS r$   	unsqueezer&   r   	batch_dimr$   r*   r+   ^  s     z-no_batch_dim_reference_fn.<locals>.<listcomp>r   )rw   dictAssertionErroritemsr   r   squeezer   )rl   r   rH   rI   r   r   r   kr   Zbdimsingle_batch_input_argsoutputr   r$   )r   rI   r*   r   ;  s$    


r   c              
      s   | ddrdnd d|kr&|d d|krL|d dk	rL|d d|d<  fdd|D }t 4 | ||}|d  |d dfW  5 Q R  S Q R X dS )	a  Reference function for MultiheadAttention supporting no batch dimensions.

    Unbatched inputs are unsqueezed to form a
    single batch input before passing them to the module.
    The output is squeezed to compare with the
    output of unbatched input to the module.
    r   Tr   r>   key_padding_maskNc                    s   g | ]}|  qS r$   r   r   r   r$   r*   r+   v  s     z.no_batch_dim_reference_mha.<locals>.<listcomp>)r   r   r   r   r   )rl   r   rH   rI   r   r   r$   r   r*   no_batch_dim_reference_mhai  s    

r   c           	   
   O   s   t |dkr|\}d}nt |dkr6|\}}|d}|d rBdnd}|d ||}||f}t 4 | ||}|d ||d dfW  5 Q R  S Q R X dS )a  Reference function for RNN and GRU supporting no batch dimensions.

    Unbatched inputs are unsqueezed to form a
    single batch input before passing them to the module.
    The output is squeezed to compare with the
    output of unbatched input to the module.
    r>   Nr   r   r   rQ   r   r   r   r   	rl   r   rH   rI   inphr   r   r   r$   r$   r*   no_batch_dim_reference_rnn_gru|  s    



r   c           	   
   O   s   t |dkr|\}d}n0t |dkrH|\}}|d d|d df}|d rTdnd}|d ||}||f}t J | ||}|d ||d d d|d d dffW  5 Q R  S Q R X dS )a  Reference function for LSTM supporting no batch dimensions.

    Unbatched inputs are unsqueezed to form a
    single batch input before passing them to the module.
    The output is squeezed to compare with the
    output of unbatched input to the module.
    r>   Nr   r   r   r   r   r$   r$   r*   no_batch_dim_reference_lstm  s    


r   c           	   
   O   sn   |\}\}}| d| d| dff}t 4 | ||}|d d|d dfW  5 Q R  S Q R X dS )zReference function for LSTMCell supporting no batch dimensions.

    The module is passed the input and target in batched form with a single item.
    The output is squeezed to compare with the no-batch input.
    r   r>   N)r   r   r   )	rl   r   rH   rI   r   r   cr   r   r$   r$   r*   no_batch_dim_reference_lstmcell  s
    
r   c                    s    fdddD S )Nc              	      s>   g | ]6}t t|d t d dttddd|dqS )r   )r   r   Tr   zno_batch_dim_{}rf   rg   ri   rh   )re   rb   r   r   rW   )r&   r   r   r$   r*   r+     s   
z8generate_regression_criterion_inputs.<locals>.<listcomp>)r   r   r   r$   r   r$   r   r*   $generate_regression_criterion_inputs  s    
r   c                 K   s0   t t|||d}ttddt|ddtdgS )Nr~   r   )kernel_size)r      r   r   r   r   re   rb   r   rA   ry   rE   r   rF   rI   r   r$   r$   r*    module_inputs_torch_nn_AvgPool1d  s    

r   c                 K   s,   t t|||d}ttdt|dddgS )Nr~   r   )r>   r   r   r   Zsinglerf   rg   rh   r   r   r$   r$   r*   (module_inputs_torch_nn_AdaptiveAvgPool2d  s    
r   c                 K   s*   t t|||d}ttdt|ddgS )Nr~   r   )r   r   r   r   rf   rg   r   r   r$   r$   r*   "module_inputs_torch_nn_BatchNorm2d  s
    
r   c                 K   s*   t t|||d}ttdt|ddgS )Nr~   r   )r   r   r   r   r   r   r   r   r$   r$   r*   "module_inputs_torch_nn_BatchNorm3d  s
    
r   c           	         s   |d }| dd| dd}tt|||d|r:i gn
i ddig}d\  ftd	d
 t|D  d  fddtddg|D S )NNlazyF
transposedr~   paddingZsame)r   r   r   c                 s   s   | ]}|d  V  qdS )r   Nr$   )r&   r   r$   r$   r*   	<genexpr>  s     z0module_inputs_torch_nn_ConvNd.<locals>.<genexpr>)r   c                    s^   g | ]V\}}t r tf|nt f|t|r:n|rHd nd|rRdntdqS )r0   r   Nr   )re   rb   r   )r&   Z
with_batchZconv_kwargsZC_inZC_outZinput_batch_shapeZinput_no_batch_shaper   r   r   r$   r*   r+     s   


z1module_inputs_torch_nn_ConvNd.<locals>.<listcomp>T)r   r   r   tuplerange	itertoolsr   )	rA   ry   rE   r   rF   rI   r   r   Zconv_kwargs_listr$   r   r*   module_inputs_torch_nn_ConvNd  s    
r   c                 K   s~   t t|||d}ttddt|ddd dttddt|dd	d
tt t|ddtdttddt|ddd
gS )Nr~          @alphar   r   r   c                 S   s   t |dk|d| d  S Nr   r   r>   r   whereexpr   r$   r$   r*   r      r   z,module_inputs_torch_nn_ELU.<locals>.<lambda>r   r$   scalarr   r   r   r   r   r   r   r   4d_inputr   r   r$   r$   r*   module_inputs_torch_nn_ELU  s&    






r   c                 K   sn   t t|||d}ttddt|ddd dttddt|dd	d d
dttddt|ddtdgS )Nr~   r   r   r   c                 S   s"   t |dk|dd|  d  S )Nr   r         ?r>   r   r   r$   r$   r*   r     r   z-module_inputs_torch_nn_CELU.<locals>.<lambda>r   r$   c                 S   s   t |dk|d| d  S r   r   r   r$   r$   r*   r     r   r   r   r   r   r   r   r   r$   r$   r*   module_inputs_torch_nn_CELU  s     





r   c                 K   sV   t t|||d}tt t|dddtt t|dddtt t|dddgS )	Nr~   r   r   r   r   r   r   r   channels_last_mem_formatr   r   r   r   r   channels_last_3d_mem_formatr   r   r$   r$   r*   module_inputs_torch_nn_ReLU  s    


r  c                 K   s^   t t|||d}tt t|d|ddd dtt t|d|ddd dd	gt| S )
Nr~   r   r   r   c                 S   s$   d|   tdd t||D  S )N      ?c                 s   s"   | ]\}}||    V  qd S r7   )r   r   )r&   abr$   r$   r*   r   4  s   zBmodule_inputs_torch_nn_L1Loss.<locals>.<lambda>.<locals>.<genexpr>)numelr   ziprl   r   r   r   r$   r$   r*   r   4  s   z/module_inputs_torch_nn_L1Loss.<locals>.<lambda>r   r$   c                 S   s   d|   ||    S )Nr  )r
  r   r   r  r$   r$   r*   r   8  r   r   r   )r   r   re   rb   r   r   r$   r$   r*   module_inputs_torch_nn_L1Loss-  s    	r  c                 K   s6  t t|||d}t t|tjdd}t t||dd}dddg}	g }
|	D ]}|
tt|dt|d|dd	d
dt tddd |
tt||ddt|d|dd	d
dt tddd |
tt|ddt|d|dd	d
dt tddd |
tt|d|ddt|d|dd	d
dt tddd qD|
S )Nr~   Fr   r   r   r   )	   r$   r   r  )lowhighTr   r   )r   r   r   )r   label_smoothing)r   r  r   )r   r   r   r   r?   re   rb   r   )rA   ry   rE   r   rF   rI   r   r   r   Z
reductionssamplesr   r$   r$   r*   'module_inputs_torch_nn_CrossEntropyLoss<  sB    





r  c                 K   sB   t t|||d}tt t|dtddtt t|dddgS )Nr~   r   r   r   r   r   r   r   r   r$   r$   r*    module_inputs_torch_nn_Hardswish^  s    

r  c              	   K   sl   t t|||d}ttdddt|dddttdddt|dd	dttdddd
dt|dddgS )Nr~   r   r   r   r   )r>   r>   )r      r  Z3d_inputr   )r>   r   r  r  r   T)return_indicesr  r   r   r$   r$   r*    module_inputs_torch_nn_MaxPool2do  s"    




r  c                 K   s@   t t|||d}tt t|dddtt t|dddgS )Nr~   r  r  r   r  r  r   r   r$   r$   r*   module_inputs_torch_nn_Sigmoid  s    

r  c                 K   s  t t|||d}ttddddt|dddttddd	dtjt|dd
dg}d tjdddg|tjdf}d tjdddg|tjd	df}	t
|	|dD ]\}
}}|ttddd	dd|dt|d|
|dt tdddiddd |ttddd	dd|dt|d|
|dt tdddiddd qdd }|sdD ]>}|ttddd	dd|dt|d||rtdndd qB|S )Nr~   r   r      rp   r  relu_activationr   r   gelu_activationFTry   rE   r  TFd_modelnheaddim_feedforwarddropoutr   
norm_firstr   r   )src_masksrc_key_padding_maskr(  r   r   r   no_batch_dim_batch_firstr   r$  r   r%  r   c                 _   s,   | j r
t| d} | ||}| d} |S )NTF)rF   r   Ztrain)modulerk   rH   rI   r   r$   r$   r*   fast_path_reference_fn  s
    



zNmodule_inputs_torch_nn_TransformerEncoderLayer.<locals>.fast_path_reference_fnZfast_path_norm_firstZ	fast_pathr   r   re   rb   FZgelur   tensorboolr   r   r   r?   r   )rA   ry   rE   r   rF   rI   r   r  key_padding_masks
attn_masksr'  r(  r%  r-  r$   r$   r*   .module_inputs_torch_nn_TransformerEncoderLayer  s    "        r4  c                 K   s`  t t|||d}ttddddt|d|dddttddd	dtjt|d|dd
dg}d tjdddg|tjdf}d tjdddg|tjd	df}	t
|	|dD ]\}
}}|
}|}|ttddd	dd|dt|d|d|
|||dt tddddddd |ttddd	dd|dt|d|d|
|||dt tddddddd q|S )Nr~   r   r   r  rp   r  r  r   r   r  FTr  r  r  r   r&  )tgt_maskmemory_masktgt_key_padding_maskmemory_key_padding_maskr   )r7  r8  r)  r*  r   r+  r   r.  )rA   ry   rE   r   rF   rI   r   r  r2  r3  r5  r7  r%  r6  r8  r$   r$   r*   .module_inputs_torch_nn_TransformerDecoderLayer  s      "          r9  c                 K   s0  t t|||d}g }d tjdddg|tjdf}d tjdddg|tjddf}	t|	|dD ]\}
}}|
fd \}}|fd \}}|t	t
ddd	d
d
dd|dt
|d|d||||dt tddddddd |t	t
ddd	d
d
dd|dt
|d|d||||dt tddddddd q`|S )Nr~   FTr  r  r  r   r   r   r>   rp   )r!  r"  r#  Znum_encoder_layersZnum_decoder_layersr$  r   r%  r&  )r5  r'  r7  r(  r   )r7  r(  r)  r*  r   r   )r   r   r   r0  r1  r   r   r   r?   re   rb   r   )rA   ry   rE   r   rF   rI   r   r  r2  r3  maskr   r%  r'  r5  r(  r7  r$   r$   r*   "module_inputs_torch_nn_Transformer  sp    "              r;  c                 K   sf   t tj|tjdd}ttdddt|ddddttdddt|dd	dd
d	ddgS )NFr~   r   r   )Znum_embeddingsZembedding_dimr   r   r>   i   r  Zdiscontiguousr   )r   r   r   r   re   rb   Zrandom_r   )rA   ry   rE   r   rF   rI   Z
make_emptyr$   r$   r*    module_inputs_torch_nn_Embedding;  s    

r<  c                 K   s  t t|||d}g }d}d tjdddg|tjdf}	d tjdddg|tjddf}
t||||	|
}|D ]\}}}}}|t	t
ddd|||dt
|d	|d	|d	||d
td |t	t
ddd|||dt
|d	|d	|d	||d
t tddd ql|S )Nr~   r  FTr  )r   r   r   r   )Z	embed_dimZ	num_headsr   r   add_bias_kvadd_zero_attnr  )r   	attn_maskr   r   )r   r   r   r0  r1  r   r   r   r?   re   rb   r   )rA   ry   rE   r   rF   rI   r   r  Z	bool_valsr2  r3  Zproductsr   r=  r>  r   r?  r$   r$   r*   )module_inputs_torch_nn_MultiheadAttentionJ  sH    "   	   

rA  c           	   	   K   s   t t|||d}ttddt|d|dtdttddddt|d|dtdg}|dd}|r|ttdddd	d
t|d|dtd |S )Nr~   r   r   r   Tr   is_rnnFrelu)r   nonlinearity)r   r   re   rb   r   r   r?   )	rA   ry   rE   r   rF   rI   r   r  rB  r$   r$   r*   #module_inputs_torch_nn_RNN_GRU_Celli  s,    rE  c                 K   sl   t t|||d}ttddt|d|d|dftdttddddt|d|d|dftdf}|S )Nr~   r   r   r   Tr   )r   r   re   rb   r   )rA   ry   rE   r   rF   rI   r   r  r$   r$   r*   module_inputs_torch_nn_LSTMCell  s    rF  c              
   K   s  t t|||d}|d }d}d}	d}
d}g }|r@t||	|
|}nt|	|
|}|D ]}|rf|\}}}}n
|\}}}ddd|||d}ddd|||d}|r||d< ||d< |ttf |t|d	t t|d
d |ttf |t|d||rdnddft t|d
d qP|S )Nr~   rB  )rC  tanhFTr   )
input_sizehidden_size
num_layersr   r   bidirectionalr   rD  r  r@  r   r   r   r   )r   r   r   r?   re   rb   r   )rA   ry   rE   r   rF   rI   r   rB  rD  r   r   rL  r  prod_genrH   nlr	  b_fbidir	cons_argscons_args_hiddenr$   r$   r*   module_inputs_torch_nn_RNN_GRU  sT    
    


rT  c              
   K   s  t t|||d}d}d}d}	d}
g }t|||	|
}|D ]}|\}}}}d}d|d||||d}d|d||||d}|ttf |t|dt t|dd	 |d
kr|n|}||rdnd|f||rdnd|ff}|ttf |t|d|t t|dd	 q6|S )Nr~   rH  )r   r   r   r   )rI  rJ  rK  	proj_sizer   r   rL  r  r@  r   r   r   rM  )r   r   r   r?   re   rb   r   )rA   ry   rE   r   rF   rI   r   r   r   rL  Z
proj_sizesr  rN  rH   r	  rP  rQ  rU  rJ  rR  rS  Zh_outhxr$   r$   r*   module_inputs_torch_nn_LSTM  sJ        

(
rW  Z
TestModuleZ	test_gradZcuda)	active_ifrT   Ztest_gradgradZtest_non_contiguous_tensors)rX  rN   rT   )rN   )rt   rv   rq   zSkipped!Ztest_memory_format)rv   rq   T)r@   rv   rq   r>   F)r   r   i  )versiong-C6?)rv   rt   ru   rq   rr   r   )rT   rN   r   iE  )r   r   r   Ztest_forwardcpu)rN   rT   Z#test_if_train_and_eval_modes_differZtest_cpu_gpu_parityZtest_multiple_device_transferZtest_pickle)rv   rt   ru   rN   rq   rr   )rT   )ZatolZrtol)rv   rr   rq   )rv   rq   rs   )rB  )r@   rv   rq   rr   	module_db)r   Zunittestcopyr   enumr   	functoolsr   r   r   r   r   Ztorch.nn.functionalnnZ
functionalr/  Ztorch.testingr   Z#torch.testing._internal.common_cudar	   Z$torch.testing._internal.common_dtyper
   r   Z*torch.testing._internal.common_device_typer   r   r   r   r   r   r   r   Z2torch.testing._internal.common_methods_invocationsr   Z!torch.testing._internal.common_nnr   r   Z$torch.testing._internal.common_utilsr   r   r   r   r   typesr   typingr   r   r   r    r!   r6   ZaoZqatZquantizableZ	quantizedr"   __annotations__Module	ContainerZ	NLLLoss2dZ	MaxPool2dr#   rj   r-   r/   strr)   r,   r'   r%   r`   rS   r|   Znamespace_namer2   ra   objectrb   re   ro   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r4  r9  r;  r<  rA  rE  rF  rT  rW  ZexpectedFailurefloatZ#rnn_gru_lstm_module_info_decoratorsZAdaptiveAvgPool2dZfloat64Z	AvgPool1dskipZBatchNorm2dZBatchNorm3dZConv1dZfloat32ZConv2dZConv3dZConvTranspose1dZchalfZConvTranspose2dZConvTranspose3dZELUZL1LossZ
LazyConv1dZ
LazyConv2dZ
LazyConv3dZLazyConvTranspose1dZLazyConvTranspose2dZLazyConvTranspose3dZLinearZBilinearZNLLLossZGaussianNLLLossZCrossEntropyLossZ	HardswishZTransformerEncoderLayerZTransformerDecoderLayerZTransformerZMultiheadAttentionZ	EmbeddingZReLUZRNNCellZGRUCellZLSTMCellZSigmoidZRNNZGRUZLSTMr[  r$   r$   r$   r*   <module>   s   (



	



A	,#.

	"E8+/,  
   
   
     
 
 
   
 
 
 
  
 
  



   