1

Goal : To build a Node.js web server for a training and classification model on the server-side using TensorFlow.js I am trying to do this tutorial to learn TensorFlow.js.

Expected results : Server should run locally on an appropriate port like so.

$ npm run start-server
...
  > Running socket on port: 8001
Epoch 1 / 1
eta=0.0 ========================================================================================================>
2432ms 34741us/step - acc=0.429 loss=1.49

Actual results : Server does not run

@MacBook-Pro baseball % npm run start-server

> tfjs-examples-baseball-node@0.2.0 start-server
> node server.js

zsh: illegal hardware instruction  npm run start-server

My hardware and software configuration :

  • MacBook Pro (13 inches, M1, 2020)
  • Chip : Apple M1
  • macOS Big Sur version 11.4
  • @tensorflow/tfjs-node: ^1.3.2
  • Node.js version : v14.17.5
  • Xcode 12.5.1 / Build version 12E507

What have I tried ? At this stage, I can't remember the number of Github issues and Stackoverflow question I have read to solve this problem without success.

  1. Tried using prior versions of @tensorflow/tfjs-node like 1.2.0 and 1.0.0.
  2. Tried the most recent version of @tensorflow/tfjs-node i.e. 3.8.0
  3. Checked if Python 2.7.16 and 3.9.6 are installed on my Mac. They are.
  4. Deleted node_modules and package-lock.json and ran npm install
  5. Updated Node.js to its most recent version.
  6. Made sure Xcode is installed.

It seems to be a hardware compatibility issue but I can't figure out the solution. Please note that I am trying to use the Javascript implementation of TensorFlow and not Python.

Sujay
  • 570
  • 3
  • 8
  • 24

2 Answers2

0

first, tfjs-node includes binary tensorflow implementation (same on as python), the JS part is just a wrapper (tfjs-node installer actually builds NAPI bindings to the binary)

second, this is M1 CPU which doesn't emulates x86 instruction set - and advanced instructions (e.g. AVX) are simply not supported.

since you've already tried old tfjs-node v1.2 (last one before AVX), only proper solution is to build tfjs-node from scratch on M1 hardware - quite a painful process, but not impossible

you might get lucky if you search on github for someone else's port

UPDATE:

Apple has created a fork of TF that uses Apple's ML libs based on TF 2.4RC (and optionally Metal libs),
but it doesn't seem well maintained - last update is in March 2021.

So first step is to get TF working in Python
then it's a question of rebuilding @tensorflow/tfjs-node package to use that library instead of prebundled one

Vladimir Mandic
  • 813
  • 5
  • 11
  • Hey, I am using `"@tensorflow/tfjs-node": "^3.9.0",` this and just trying to do exactly https://www.tensorflow.org/js/guide/models_and_layers this thing. I face the the same problem. I updated npm, node and everything. How can I fix this? – chichi Oct 02 '21 at 00:33
  • 1
    I've updated the answer - still far from ideal, but could be worth a try – Vladimir Mandic Oct 02 '21 at 11:14
  • I’d decided to learn python lol – chichi Oct 03 '21 at 08:25
0

Okay, if you are using Mac or Linux,

And then try npm start or anything you wish.

This is how my issues are gone. Hope that it'll fix this issues from your sides too. Thanks.