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

"cpu backend was already registered" during import/require tfjs + tfjs-node-gpu #708

Closed
vmarkovtsev opened this issue Sep 19, 2018 · 30 comments

Comments

@vmarkovtsev
Copy link
Contributor

vmarkovtsev commented Sep 19, 2018

TensorFlow.js version

0.13.0
tfjs-node-gpu 0.1.17

Browser version

N/A - Node 10.10

Describe the problem or feature request

require('@tensorflow/tfjs');
require('@tensorflow/tfjs-node-gpu');

or

require('@tensorflow/tfjs-node-gpu');
require('@tensorflow/tfjs');

print the warning:

cpu backend was already registered. Reusing existing backend

It's very minor ofc but damn annoys much.

@nkreeger
Copy link
Contributor

Any chance you are double-importing @tensorflow/tfjs?

https://github.com/tensorflow/tfjs-examples/blob/master/mnist-node/main.js#L18

If you perform any operations on tfjs before importing tfjsn-node you might hit this problem.

@vmarkovtsev
Copy link
Contributor Author

@nkreeger nope, I run exactly those two lines in Node. Nothing else.

@nkreeger
Copy link
Contributor

Can you post the entire output from node? I wonder if the GPU bindings are failing to load.

@nkreeger
Copy link
Contributor

Also can you provide more details - which OS / device / etc?

@vmarkovtsev
Copy link
Contributor Author

vmarkovtsev commented Sep 19, 2018

GPU bindings load successfully. My device is described in #709 (output from nvidia-smi). Logs are also taken from #709:

cpu backend was already registered. Reusing existing backend
2018-09-19 11:08:28.536520: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-09-19 11:08:29.784106: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:897] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-09-19 11:08:29.785414: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1405] Found device 0 with properties: 
name: GeForce GTX 1070 major: 6 minor: 1 memoryClockRate(GHz): 1.7845
pciBusID: 0000:06:00.0
totalMemory: 7.93GiB freeMemory: 7.83GiB
2018-09-19 11:08:29.785425: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1484] Adding visible gpu devices: 0
2018-09-19 11:08:30.394301: I tensorflow/core/common_runtime/gpu/gpu_device.cc:965] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-09-19 11:08:30.394325: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971]      0 
2018-09-19 11:08:30.394330: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] 0:   N 
2018-09-19 11:08:30.394547: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1097] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7560 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:06:00.0, compute capability: 6.1)

System:

$ node --version
v10.10.0
$ uname -a
Linux vadim-XPS-13-9360 4.15.0-34-generic #37-Ubuntu SMP Mon Aug 27 15:21:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -d
Description:	Ubuntu 18.04.1 LTS

@obenjiro
Copy link

Any news on this one? Need any help? Have exactly same problem on Mac

@nkreeger
Copy link
Contributor

We need to update docs - we changed @tensorflow/tfjs from a peer dependency to a strict one. Please only include @tensorflow/tfjs-node since it ships @tensorflow/tfjs as well in your package.json.

@vmarkovtsev
Copy link
Contributor Author

@nkreeger How to get tfjs from require('@tensorflow/tfjs-node-gpu');?

@nkreeger
Copy link
Contributor

Just

require('@tensorflow/tfjs')

The GPU package includes tfjs as well.

@obenjiro
Copy link

obenjiro commented Oct 3, 2018

Changing package.json to this: (excluding @tensorflow/tfjs)

"dependencies": {
    "@tensorflow/tfjs-node": "^0.1.17"
}

Running npm install and using

import * as tf from "@tensorflow/tfjs";
import "@tensorflow/tfjs-node";

fixes the issue for me

@nkreeger
Copy link
Contributor

nkreeger commented Oct 3, 2018

@AiBoy Yep - sorry for the confusion. We found it was easier to ship the union tfjs package instead of chasing tfjs-core updates all the time.

@nkreeger nkreeger closed this as completed Oct 3, 2018
@vmarkovtsev
Copy link
Contributor Author

@nkreeger I tried with the most recent versions of the packages and it still does not work for me.

If I don't do require('@tensorflow/tfjs-node-gpu'); then there is no CUDA acceleration. If I do it, I get the error message which I described. Could you please reopen this issue because there seems to be some misunderstanding and also different use cases mixed with @AiBoy who doesn't use CUDA.

@vmarkovtsev
Copy link
Contributor Author

vmarkovtsev commented Nov 7, 2018

Again:

only require('@tensorflow/tfjs'); -> no CUDA
only require('@tensorflow/tfjs-node-gpu'); -> CUDA loads but I hit #708 (comment)

@vmarkovtsev
Copy link
Contributor Author

vmarkovtsev commented Nov 7, 2018

If I do

npm install @tensorflow/tfjs-node-gpu

then require('@tensorflow/tfjs') fails with Error: Cannot find module '@tensorflow/tfjs'.

Then I do

npm install @tensorflow/tfjs

and tf.getBackend() returns cpu instead of tensorflow. So then I do require('@tensorflow/tfjs-node-gpu'); and then tf.getBackend() returns tensorflow. That require prints the warning. I really think that I am misunderstood here.

@signoriello
Copy link

Hi!
Maybe the following helps: In package.json under dependencies I removed the entry for tfjs-node, for me it was "@tensorflow/tfjs-node": "^0.1.20". Of course there is still the line concerning tfjs-node-gpu, i.e., for me "@tensorflow/tfjs-node-gpu": "^0.1.20". After that I did
npm install
Now it works.

@vmarkovtsev
Copy link
Contributor Author

@signoriello How do you import/require? FWIW this issue is not about not working - it works perfectly, just the warning is printed.

@signoriello
Copy link

Currently I am just testing the mnist-node example. In order to require, I use at it was set in the main file
const tf = require('@tensorflow/tfjs'); require('@tensorflow/tfjs-node-gpu');
In my case, before the change that I mentioned, I got information about my GTX 1060 like in one of your prior comments and I also saw in the task manager that memory got allocated for the GPU. However, it did not start updating the net weights, but kind of just froze and did nothing. For me now everything works for the first time.

@nkreeger
Copy link
Contributor

@vmarkovtsev Try deleting your local node_modules/ directory and re-running npm install or yarn.

@ericscottmarquez
Copy link

Same problem gettind it to work on ubuntu 18.04 -
Here's the error:

node index.js
cpu backend was already registered. Reusing existing backend
Registration of backend tensorflow failed
Error: libcublas.so.9.0: cannot open shared object file: No such file or directory
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:718:18)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at bindings (/home/eric/Desktop/MLKits/knn-tf/node_modules/bindings/bindings.js:81:44)
    at /home/eric/Desktop/MLKits/knn-tf/node_modules/@tensorflow/tfjs-node-gpu/dist/index.js:46:60
    at Environment.registerBackend (/home/eric/Desktop/MLKits/knn-tf/node_modules/@tensorflow/tfjs-node-gpu/node_modules/@tensorflow/tfjs-core/dist/environment.js:234:27)
    at Object.<anonymous> (/home/eric/Desktop/MLKits/knn-tf/node_modules/@tensorflow/tfjs-node-gpu/dist/index.js:45:8)

Package.json is fine, deleted node modules. installed with tfjs-node-gpu only, it gave:

Error: Cannot find module '@tensorflow/tfjs-core'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/home/eric/Desktop/MLKits/knn-tf/node_modules/@tensorflow/tfjs-data/dist/dataset.js:48:10)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

It is only working with regular tfjs:

require ('@tensorflow/tfjs-node');

Using Dell XPS 15 9570 with gtx 1050ti, nvidia drivers work on this machine in ubuntu 18.04, they are up to date. Just trying to take advantage of gpu for ML.

Thanks for all your work!

@nsthorat
Copy link
Contributor

This could be an issue with double importing of tfjs.

Can you show what your package.json dependencies look like? You don't need to import @tensorflow/tfjs directly, @tensorflow/tfjs-node will do that for you.

@ericscottmarquez
Copy link

Tensorflow js is only imported once.

const tf = require ('@tensorflow/tfjs-node-gpu');

import * as tf from '@tensorflow/tfjs-node'; is not valid for node servers, my project is not a create-react-app type client-app.

  "dependencies": {
    "@tensorflow/tfjs-node-gpu": "^0.3.2",
    "lodash": "^4.17.11",
    "shuffle-seed": "^1.1.6"
  }
}

returns
Error: Cannot find module '@tensorflow/tfjs-core'


This is what I get when I just do this, with a working calculation in the file. It stilln runs the calculation, but it seems to still be using the CPU not the GPU:

const tf = require('@tensorflow/tfjs-node-gpu');
Registration of backend tensorflow failed
Error: libcublas.so.9.0: cannot open shared object file: No such file or directory
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:718:18)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at bindings (/home/eric/Desktop/MLKits/knn-tf/node_modules/bindings/bindings.js:81:44)
    at /home/eric/Desktop/MLKits/knn-tf/node_modules/@tensorflow/tfjs-node-gpu/dist/index.js:46:60
    at Environment.registerBackend (/home/eric/Desktop/MLKits/knn-tf/node_modules/@tensorflow/tfjs-core/dist/environment.js:234:27)
    at Object.<anonymous> (/home/eric/Desktop/MLKits/knn-tf/node_modules/@tensorflow/tfjs-node-gpu/dist/index.js:45:8)
TensorFlow.js deprecation warnings have been disabled.

============================
Hi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things 
up dramatically, install our node backend, which binds to TensorFlow C++, by 
running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if 
you have CUDA. Then call require('@tensorflow/tfjs-node'); 
(-gpu suffix for CUDA) at the start of your program. 
Visit https://github.com/tensorflow/tfjs-node for more details.
============================

also tested all running as root to no avail.

@ericscottmarquez
Copy link

ericscottmarquez commented Mar 13, 2019

Oh, and CUDA Drivers are installed as well as up to date nvidia drivers ( Ubuntu 18.04 )

@dsmilkov dsmilkov reopened this Mar 13, 2019
@dsmilkov
Copy link
Contributor

Reopening this due to the recent reports from our users.

@nkreeger
Copy link
Contributor

nkreeger commented Mar 13, 2019

@ericscottmarquez which version of CUDA do you have. We ship TensorFlow 1.12 (soon 1.13.1) and that only supports 9.x. CUDA 10 is not currently supported.

@ericscottmarquez
Copy link

Using 9x

nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

@ericscottmarquez
Copy link

Is there an error dump or something that I could pull from somewhere to send you guys that could help?

@nkreeger
Copy link
Contributor

tensorflow/tensorflow#15604

You need CUDA 9.0 right now - sorry for the confusion.

@anujdutt9
Copy link

Hi @dsmilkov I am seeing the same warnings in the console. Although this doesn't affects the functionality but still these are some warnings that appear.

@nsthorat nsthorat added this to To do in Product Excellence Fixit via automation Mar 24, 2019
@dsmilkov
Copy link
Contributor

dsmilkov commented Apr 11, 2019

To summarize:

  • If you want to use CPU (no Cuda):
const tf = require('@tensorflow/tfjs-node');
tf.square(3).print();
  • To use GPU (need exactly CUDA 9.0, 9.1 won't work with the latest version):
const tf = require('@tensorflow/tfjs-node-gpu');
tf.square(3).print();

No need to import @tensorflow/tfjs, or @tensorflow/tfjs-core. They are indirectly installed/imported.

If you get Error: libcublas.so.9.0: cannot open shared object file, make sure you have Cuda 9.0 installed. See this table for which Cuda version goes with which TF version.

Let me know if these instructions are helpful. We can make sure they surface in the README. Thanks everyone for the feedback <3

@rthadur rthadur assigned kangyizhang and unassigned nkreeger Sep 11, 2019
@kangyizhang
Copy link
Contributor

This issue should be ok to close.

Product Excellence Fixit automation moved this from To do to Done Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

9 participants