0

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.

1 Answers1

1

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.

Vladimir Mandic
  • 813
  • 5
  • 11
  • Thanks for the response. Can you explain the one you mentioned, or can you share any links. – Sarath Soman May 23 '22 at 12:10
  • I find it funny that I get this error trying to run the node.js version of the examples of https://github.com/justadudewhohacks/face-api.js, but, the browser examples run smoothly and don't have any kind of errors... any hint of why this different behaviour? This makes me think its not a M1 related issue... or is it? – Yala Yala Herzlin Aug 07 '22 at 23:19
  • when you're running in browser, you're running JS compiled to pseudo-code interpreted and executed by browser (and in case of WebGL backend, GLSL code compiled to WebGL), never native instructions. so its normal that you see issue with `tfjs-node` which tries to run native CPU instructions and not in browser. – Vladimir Mandic Aug 09 '22 at 14:05
  • thanks for clarifying. i've hit a wall, do you recommend any of the ports above to be able to run it server side? – Yala Yala Herzlin Aug 18 '22 at 03:54