tensorflow.jstfjs-node

Node - tfjs (tensorflowjs in node) error: zsh: illegal hardware instruction node app.js


I am working with tensorflowjs in node. when i run the code, "const tf = require('@tensorflow/tfjs-node');" it throw an error "zsh: illegal hardware instruction node app.js".

i am using macbook air M1 chip.


Solution

  • Official @tensorflow/tfjs-node does not support Apple's M1 CPU just yet

    There are unofficial ways to make it work (by using M1 build of tensorflow.so and rebuilding NodeJS bindings), but that is anything but trivial

    UPDATE: as requested, a bit more info

    there is Apple's port of Tensorflow that works on M1, but Apple stopped developing it and last update is from ~2 years: https://github.com/apple/tensorflow_macos

    and there are several 3rd party ports, for example https://towardsdatascience.com/installing-tensorflow-on-the-m1-mac-410bb36b776

    also, suggest going through TF's GitHub for M1 issues: https://github.com/tensorflow/tensorflow/issues?q=M1

    in either case, once you have tensorflow, you still need to manually rebuild @tensorflow/tfjs-node so it binds to it which is non-trivial.