Skip to content

The Recurrent class will not function without a GPU #901

Open
@Vectorrent

Description

@Vectorrent

A GIF or MEME to give some spice of the internet

What is wrong?

I am trying to use the new Recurrent class from inside of a Docker container, which does not have access to a GPU driver. This is the error I receive, when trying to train:

one-test-1  | /one/node_modules/gpu.js/src/gpu.js:185
one-test-1  |         throw new Error(`A requested mode of "${this.mode}" and is not supported`);
one-test-1  |               ^
one-test-1  | 
one-test-1  | Error: A requested mode of "gpu" and is not supported
one-test-1  |     at GPU.chooseKernel (/one/node_modules/gpu.js/src/gpu.js:185:15)
one-test-1  |     at new GPU (/one/node_modules/gpu.js/src/gpu.js:124:10)
one-test-1  |     at makeKernel (/one/node_modules/brain.js/dist/index.js:254:24)
one-test-1  |     at Input.setupKernels (/one/node_modules/brain.js/dist/index.js:2466:33)
one-test-1  |     at Recurrent.initializeLayers (/one/node_modules/brain.js/dist/index.js:3869:19)
one-test-1  |     at Recurrent.initialize (/one/node_modules/brain.js/dist/index.js:5996:14)
one-test-1  |     at Recurrent.verifyIsInitialized (/one/node_modules/brain.js/dist/index.js:3987:18)
one-test-1  |     at Recurrent._prepTraining (/one/node_modules/brain.js/dist/index.js:6075:14)
one-test-1  |     at Recurrent.train (/one/node_modules/brain.js/dist/index.js:6042:56)
one-test-1  |     at file:///one/src/custom.js:33:5
one-test-1  | 
one-test-1  | Node.js v20.3.1
one-test-1  | 
one-test-1 exited with code 0

Where does it happen?

Inside the node:20-alpine Docker image.

How do we replicate the issue?

Try to execute the following code from Node.js, within an environment that has no GPU driver:

import { Recurrent, layer, utilities } from 'brain.js'
const { add, input, multiply, output, random, rnnCell, lstmCell } = layer

const net = new Recurrent({
  inputLayer: () => input({ height: 1 }),
  hiddenLayers: [
    (inputLayer, recurrentInput) =>
      lstmCell({ height: 10 }, inputLayer, recurrentInput),
  ],
  outputLayer: (inputLayer) => output({ height: 1 }, inputLayer),
})

const xor = [
  [[0.001], [0.001], [0.001]],
  [[0.001], [1], [1]],
  [[1], [0.001], [1]],
  [[1], [1], [0.001]],
]


net.train(xor, {
    errorThresh: 0.03,
    iterations: 5000,
    log: (details) => console.log(details),
    logPeriod: 1
})

console.log(net.run([0, 1]))

(I don't think this code actually works as-is, because I can't get it running in the browser, either.)

Expected behavior (i.e. solution)

Brain.js should select 'cpu' mode, and proceed with training. Or, it should throw an error which states that 'cpu' mode is unsupported. It should never request 'gpu' mode in an environment without a GPU.

Version information

Nodejs:

20.3.0

Brain.js:

beta 23

How important is this (1-5)?

3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions