U
    d                     @   s   d dl mZmZ d dlmZmZmZmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlZddgZdZG d	d
 d
eZeej dG dd deZG dd deZedkre  dS )    )core	workspace)build_conv_model!build_resnet50_dataparallel_modelrun_resnet50_epochExecutorTestBaseexecutor_test_settingsexecutor_test_model_names)TestCase)givenNparallelasync_scheduling   c                   @   sF   e Zd Zeeeee edgedgdedd Z	dS )ExecutorCPUConvNetTestr      )executor
model_name
batch_sizenum_workersc                    s8   t | |  _ fdd}| j d||d d S )Nc                     s"   t } dkrd} t j|  d S )NZMLPr   )
ITERATIONSr   RunNetnet)Z
iterationsmodelr    D/tmp/pip-unpacked-wheel-ua33x9lu/caffe2/python/test/executor_test.py	run_model$   s    z7ExecutorCPUConvNetTest.test_executor.<locals>.run_modelsimpleZref_executortest_executorZmodel_run_func)r   Protor   compare_executors)selfr   r   r   r   r   r   r   r   r      s    

z$ExecutorCPUConvNetTest.test_executorN)
__name__
__module____qualname__r   stsampled_from	EXECUTORSr	   r   r   r   r   r   r   r      s   



r   zno gpuc                   @   s2   e Zd Zeeeedgdedd ZdS )ExecutorGPUResNetTestr   )r   r   c                    s>   t t ddd |  _ fdd}| j d||d d S )Nr   )Znum_gpusr   
epoch_sizec                      s   t  ddd d S )Nr   )r   r*   )r   r   r   r   r   r   <   s    z6ExecutorGPUResNetTest.test_executor.<locals>.run_modelr   r   )r   r   ZNumGpuDevicesr    r   r!   )r"   r   r   r   r   r+   r   r   4   s      
z#ExecutorGPUResNetTest.test_executorN)	r#   r$   r%   r   r&   r'   r(   r   r   r   r   r   r   r)   2   s
   

r)   c                   @   s   e Zd Zdd ZdS )ExecutorFailingOpTestc              	   C   s   dd }t   |dd}t | | t t | W 5 Q R X | t t j|dd W 5 Q R X t   |dd}t | | t t | W 5 Q R X t j|dd}| | d S )Nc                 S   s6   t d}| r|g g  n|g g  d| _|S )NZfailing_netr   )r   ZNetZThrowExceptionZFailr    type)throw_exceptionr   r   r   r   create_failing_netI   s    

zAExecutorFailingOpTest.test_failing_op.<locals>.create_failing_netT)r.   )Z
allow_failF)r   ZResetWorkspaceZ	CreateNetassertRaisesRuntimeErrorr   ZassertFalse)r"   r/   r   resr   r   r   test_failing_opH   s    	



z%ExecutorFailingOpTest.test_failing_opN)r#   r$   r%   r3   r   r   r   r   r,   G   s   r,   __main__)Zcaffe2.pythonr   r   Z%caffe2.python.test.executor_test_utilr   r   r   r   r   r	   Zcaffe2.python.test_utilr
   Z
hypothesisr   Zhypothesis.strategiesZ
strategiesr&   Zunittestr(   r   r   ZskipIfZhas_gpu_supportr)   r,   r#   mainr   r   r   r   <module>   s    