Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensorflow 2.0.0 cpu, import error: DLL load failed #36138

Closed
faltinl opened this issue Jan 22, 2020 · 19 comments
Closed

Tensorflow 2.0.0 cpu, import error: DLL load failed #36138

faltinl opened this issue Jan 22, 2020 · 19 comments
Assignees
Labels
stat:awaiting response Status - Awaiting response from author subtype:windows Windows Build/Installation Issues TF 2.0 Issues relating to TensorFlow 2.0 type:build/install Build and install issues

Comments

@faltinl
Copy link

faltinl commented Jan 22, 2020

System information

  • OS Platform and Distribution: x86_64-w64-mingw32/x64 (64-bit) under Win10 x64 (build 18363),
    Bios V1.08
  • Processor: Intel(R) Pentium(R) CPU N3710 @ 1,6GHz, RAM 4GB (DDR), 4 cores, L1 Cache 56kB,
    L2 Cache 1024kB
  • Maker & Model: Acer Notebook TravelMate B117-M Signature Edition
  • TensorFlow installed from (source or binary): binary
    i. under Rstudio 1.2.5033 with R 3.6.2 (20191212) & Miniconda3 4.7.12 (Py 3.7.4-64bit)
    ii. under conda (since i. failed, see below)
  • TensorFlow version: 2.0.0
  • Python version: 3.6.10 (under conda)
  • Installed using virtualenv? pip? conda?: conda=>pip install

Describe the problem
i. Since I used keras (including reticulate & tensorflow) for the last 3 yrs under RStudio, but had various problems with my very old installation, I definitely want to continue with tensorflow + keras under RStudio and tried to install tensorflow 2.0.0. under RStudio:

install.packages("tensorflow", version = "2.0.0.")   
library(tensorflow)
install_tensorflow(method = "conda")

then test sequence - is tensorflow installed?

library(reticulate)
use_condaenv(condaenv = "r-reticulate", required = TRUE)
library(tensorflow)
> reticulate::py_config()
python:         C:/.../Miniconda3/envs/r-reticulate/python.exe
libpython:      C:/.../Miniconda3/envs/r-reticulate/python36.dll
pythonhome:     C:/.../Miniconda3/envs/r-reticulate
version:        3.6.10 |Anaconda, Inc.| (default, Jan  7 2020, 15:18:16) [MSC v.1916 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/.../Miniconda3/envs/r-reticulate/Lib/site-packages/numpy
numpy_version:  1.18.1
tensorflow:     C:\...\MINICO~1\envs\R-RETI~1\lib\site-packages\tensorflow\__init__.p
python versions found: 
 C:/.../Miniconda3/envs/r-reticulate/python.exe
 C:/.../Miniconda3/python.exe
> tensorflow::tf_config()
**Installation of TensorFlow not found.**
Python environments searched for 'tensorflow' package:
 C:\...\Miniconda3\envs\r-reticulate\python.exe
 C:\...Miniconda3\python.exe
**You can install TensorFlow using the install_tensorflow() function.**

Thus, although installation was terminated correctly, tensorflow was not found, i.e. not working.

ii. After forwarding this issue under Installation w/ Miniconda, Reticulate 1.14, Tensorflow 2.0.0 & Keras 2.2.5.0 failing #964 to RStudio/keras, tests were made to get tensorflow 2.0.0 pip installed directly under Miniconda3 (also under Anaconda3 and starting with R3.5.3 and R3.6.1), all with the same result:

conda activate r-reticulate
pip install tensorflow==2.0
python 
import tensorflow as tf

This produced the following error log (sorry, I'm unable to copy text from the python shell window), indicating ImportError: DLL load failed twice:

import_tensorflow_as_tf_20200122-1800

Any other info
Unfortunately, I am an absolute newbie as regards Python - taking that into account, please help...

@skeydan
Copy link

skeydan commented Jan 23, 2020

If I may add: This issue - DLL not found - looks very similar to the recently closed

#35749 and
#35618

which were solved by either

  • reverting from 2.1 to 2.0
  • installing tensorflow-cpu explicitly
  • installing Microsoft Visual C++ Redistributable for Visual Studio

@faltinl tried all of those but none worked. The above screenshot shows the "DLL not found" error using TF 2.0.

@oanush oanush self-assigned this Jan 23, 2020
@oanush oanush added subtype:windows Windows Build/Installation Issues TF 2.0 Issues relating to TensorFlow 2.0 type:build/install Build and install issues labels Jan 23, 2020
@oanush oanush assigned gunan and unassigned oanush Jan 23, 2020
@oanush oanush added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Jan 23, 2020
@mihaimaruseac
Copy link
Collaborator

There are many DLLs that are loaded and depending on which one fails to load the solution is different. It would be great if we have the DLL name listed in the issue.

@skeydan
Copy link

skeydan commented Jan 23, 2020

Yeah! Do you know a good way of getting it, apart from adding a print statement to line 342 of imp.py (which might be a way though; and shouldn't require admin rights I guess [[but not sure as myself I'm not on Windows]])

@gunan
Copy link
Contributor

gunan commented Jan 24, 2020

What is your CPU make and model?
Also I see that you installed through anaconda, adding @jjhelmus to see if there are any known issues there.

@faltinl
Copy link
Author

faltinl commented Jan 24, 2020

What is your CPU make and model? 0> data added to system information

@gunan
Copy link
Contributor

gunan commented Jan 24, 2020 via email

@faltinl
Copy link
Author

faltinl commented Jan 24, 2020

You can build TF from source to use it, however prebuilt binaries will not work for you.

Tnx. That's raising several questions for me:

  • From which TF versions onwards has the AVX instruction set been used? I have used TF 1.8,
    Reticulate 1.10 & Keras 2.1.6 until 2 weeks ago without any (for me) noticable restrictions.
  • Which ones are the 'prebuilt binaries', i.e. in which way does that restrict my future work with NNs?
  • How would I install TF from source? How could I circumvent the semi-automatic installation process
    as it is now used in TF2.0 in connection with Reticulate 1.14 and Keras 2.2.5.0?

@skeydan
Copy link

skeydan commented Jan 24, 2020

thanks @gunan! (I would just be wondering why 1.8 has worked for @faltinl then, since AVX builds should have happened since 1.6)?

@faltinl on the build-from-source page (which also contains the instructions how to build from source on Windows)

https://www.tensorflow.org/install/source

it says

Note: Starting with TensorFlow 1.6, binaries use AVX instructions which may not run on older CPUs.

so in theory, even 1.8 should not have worked? Anyways, since that was a version that you say worked for you, I would suggest reverting to that one:

conda activate r-reticulate
pip install tensorflow==1.8

@faltinl
Copy link
Author

faltinl commented Jan 24, 2020

Tnx for replies, @gunan and @skeydan ! I tried pip install tensorflow==1.8 as suggested, installation went smoothly, but import failed again, though with different error messages:

import_tensorflow1 8 as tf_20200124a
import_tensorflow1 8 as tf_20200124b

Since TF1.8 possibly also required AVX, I tried pip install tensorflow==1.5 too, presumably the last version before AVX has been required. As you can see...

import_tensorflow1 5 as tf_20200124

... a completely different reaction. Again no success message either but 6 "future warnings". I suspect this might be related to my Miniconda3, which didn't yet exist at the time of TF1.5. I still have the version Anaconda3-5.1.0-Windows-x86_64.exe, which I used in spring 2018 for my then working installation. What do you think - should I try to replace my present Miniconda3 with this old version? The configuration would then correspond entirely to what I had in working condition at that time, except for my then R3.5.1. That would then be the very last step...

Regardless of all these attempts, I would still like to know, @gunan, which restrictions I would have to face using tensorflow 2.0.0 installed from source without AVX in my cpu and how exactly I should carry out the installation under these preconditions.

@skeydan
Copy link

skeydan commented Jan 24, 2020

Again no success message either but 6 "future warnings". I

These are just warnings... Can you try running a simple program against that installation?

Although you'd need to make sure you don't use any newer than 1.5 features ...

@faltinl
Copy link
Author

faltinl commented Jan 24, 2020

No, unfortunately not - I even don't come that far. Using the installation sequence I was used to apply earlier (with tensorflow 1.5, reticulate 1.10 and keras 2.1.6 (also 2.2.0), with a restart R for every new attempt), i.e.

library(tensorflow)
#install_tensorflow(method = "conda", conda = "auto", version = "1.5.0") #, envname = "r-tensorflow")
# the attribute envname=... is seen as an "unused argument"
library(reticulate)
use_condaenv("r-reticulate", required = TRUE) 
# result for "r-tensorflow" instead of "r-reticulate": Unable to locate conda environment 'r-tensorflow'.
library(keras) 
#install_keras(method = "conda", conda = "auto") #, tensorflow = "1.5.0")
is_keras_available() # => FALSE

Whichever "install_..." command I actually use, I get the error message

Creating r-tensorflow conda environment for TensorFlow installation...
Collecting package metadata (current_repodata.json): ...working... failed
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/win-64/current_repodata.json>
'https://repo.anaconda.com/pkgs/main/win-64'
Fehler: Error 1 occurred creating conda environment r-tensorflow

Without any of the install_ commands nothing happens at all, except that keras is not available. That's the reason why I suspect Miniconda3 to cause (compatibility) problems. If I run the test programme (you might know it...!), error messages start to rain down right from the first keras-specific commands:

> input <- layer_input(shape = 3)
Fehler: ImportError: cannot import name 'tf_utils'
> dense <- layer_dense(input, units = 32)
Fehler: Python module keras was not found.

Obviously, there is no reticulation between the 3 packages.

@skeydan
Copy link

skeydan commented Jan 24, 2020

Please don't use R in this issue, this one's purpose is just to get your TensorFlow installation working from the Python side. I meant pasting a simple example in Python, just to see if 1.5 is working on your machine.

Honestly though, I don't know how much sense it makes using TF 1.5. (Our current R wrappers might not be compatible with 1.5 either.)

As to compiling 2.0 from source on Windows, I certainly leave all recommendations to @gunan - but given that building from source on a current laptop, on linux, takes hours I don't know...

Perhaps it's worthwhile thinking about working in the cloud somewhere.

@faltinl
Copy link
Author

faltinl commented Jan 24, 2020

Well, I don't have an example in Python - and if I had, I simply wouldn't know how to get it running there. Except for typing in the few commands forwarded in your posts I have never before used Python.

My entry to Keras and all that happened by reading @jjallaire's and @fchollet's book "Deep Learning with R" which had me so excited to start working in that field and learning everything needed while going along, starting with R. It's really extremely disappointing to feel that all that should now come to such a sudden end, simply because I concluded from this article that it could be the right opportunity to update my existing - and working - Keras-setup. If I look at my (at the moment) only available resource, just finding a machine on the market exhibiting the required properties seems already to be a problem.

Important experience for me: In order to avoid the frustrating experience with unexpected requirements like this AVX thing, I have to be much more cautious with my decisions regarding updates.

Sorry about molesting you with all that. You are the one who deserves it the least, taking into account all the positive support I received and appreciated from your side over these years...

@gunan
Copy link
Contributor

gunan commented Jan 24, 2020

One potential difference could be, if you are getting TF binaries through conda/anaconda.
We are not building them, so I am not sure which version started to require AVX. @jjhelmus may know that.

When it comes to pip install tensorflow, looks like 1.5 is where we switched?
https://github.com/tensorflow/tensorflow/releases/tag/v1.5.1
So the reason 1.8 worked for you may be because you got them through a different source, or through anaconda?

To test TF 1.x, here is a simple snippet you can try this example:
https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1_Introduction/helloworld.py

@jjhelmus
Copy link

AFAIK all the conda packages of Tensorflow released by Anaconda, Inc do not require AVX, our target CPU minimum is nocona (x86_64 with SSE3).

@faltinl
Copy link
Author

faltinl commented Jan 25, 2020

to @gunan:

So the reason 1.8 worked for you may be because you got them through a different source, or through anaconda?

No, certainly not (at least not that I noticed it!-), but what might have happened is that I downloaded v1.8, but overlooked that the version was automatically downgraded, e.g. during installation. (I must confess that, for me, Anaconda is a necessary evil - my aim is to work with Keras for R within RStudio).

To test TF 1.x, here is a simple snippet you can try this example:

Yeah, I'm using that snippet for tests already. However, since TF2.0.0 the command import tensorflow as tf never succeded on my notebook - neither using the conda prompt nor the command tf <- import(tensorflow) within RStudio where I prefer to work. Both produce the error messages I reported here earlier.

to @jjhelmus:

Is SSE / SSE3 a feature which is usually offered in addition to AVX or rather as an alternative, i.e. does one replace the other or are they independent features?

@gunan gunan removed their assignment Sep 28, 2020
@kumariko kumariko self-assigned this Oct 21, 2021
@kumariko
Copy link

@faltinl Could you please let us know if you still need help on this ? if it is resolved then please feel free to move this issue to close status ? Thanks!

@kumariko kumariko added the stat:awaiting response Status - Awaiting response from author label Oct 25, 2021
@faltinl
Copy link
Author

faltinl commented Oct 25, 2021

Sorry for keeping that issue open without further need. I am actually using TF2.6.0.9000. And since recently, when initializing my R programs, I get the notice

2021-10-25 17:22:41.359220: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2

So apparently the problem has been solved (or solved itself) by updating Tensorflow regularly...

Thank you all for your continued interest and support!

@faltinl faltinl closed this as completed Oct 25, 2021
@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting response Status - Awaiting response from author subtype:windows Windows Build/Installation Issues TF 2.0 Issues relating to TensorFlow 2.0 type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests

8 participants