U
    DAf                     @   sF   d dl Z d dlZd dlZd dlmZ eeZde	e
ddddZdS )    N)loggingF)seeddeterministic_cudnnreturnc              
   C   s   t |  tj |  t| tjd< z:ddl}||  |j	|  |r\d|j
j_d|j
j_W n4 ttfk
r } ztjd|d W 5 d}~X Y nX dS )a  
    Setting multiple seeds to make runs reproducible.

    Important: Enabling `deterministic_cudnn` gives you full reproducibility with CUDA,
    but might slow down your training (see https://pytorch.org/docs/stable/notes/randomness.html#cudnn) !

    :param seed:number to use as seed
    :param deterministic_cudnn: Enable for full reproducibility when using CUDA. Caution: might slow down training.
    ZPYTHONHASHSEEDr   NTFzQCould not set PyTorch seed because torch is not installed. Exception: {exception})	exception)randomr   npstrosenvirontorchZmanual_seedZcudaZmanual_seed_allbackendsZcudnnZdeterministicZ	benchmarkImportErrorModuleNotFoundErrorloggerinfo)r   r   r   exc r   ?/tmp/pip-unpacked-wheel-z752163x/haystack/testing/test_utils.pyset_all_seeds   s    



r   )F)r
   r   Znumpyr   Zhaystackr   	getLogger__name__r   intboolr   r   r   r   r   <module>   s
   
