Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

How to set "MKL_THREADING_LAYER=GNU" as an environment variable for a python script?

Writer Emily Wong

When I run a py script there is an error like this

RuntimeError: To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environement.

I googled why and in the terminal tried

export MKL_THREADING_LAYER=GNU

and run again, but the problem still exists. I wanted to check whether the environment variable exists or not, so I tried

$ env MKL_THREADING_LAYER=GNU
env: ‘MKL_THREADING_LAYER’: No such file or directory

Does that mean I don't get the environment or what?

Back to the code of the original bug, the problem is this:

File "/home/chen/anaconda2/envs/rllab3/lib/python3.5/site-packages/theano/configdefaults.py", line 1251, in check_mkl_openmp

This is how the code of the library is designed:

def check_mkl_openmp():
if not theano.config.blas.check_openmp: return
import os
if ('MKL_THREADING_LAYER' in os.environ and os.environ['MKL_THREADING_LAYER'] == 'GNU'): return
try: import mkl if '2018' in mkl.get_version_string(): raise RuntimeError('To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environement.')
except ImportError: raise RuntimeError(""" Could not import 'mkl'. Either install mkl-service with conda or set MKL_THREADING_LAYER=GNU in your environment for MKL 2018.
If you have MKL 2017 install and are not in a conda environment you can set the Theano flag blas.check_openmp to False. Be warned that if you set this flag and don't set the appropriate environment or make sure you have the right version you *will* get wrong results.
""")

How can I set this environment variable and make the original code work?

1

4 Answers

I used

conda install mkl=2017

and it worked!

Add this line to your ~/.bashrc file

export MKL_THREADING_LAYER=GNU

then re-open your terminal, it will work

1

I had the same error, and resolved it simply by typing and executing these commands one by one on the terminal.

conda install theano
conda install keras

I think the error meant that there was no theano installed, anyway, it worked.

1

To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environment. This command would solve your problem

conda install mkl=2018

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy