tfjs: Unsupported system error when installing on M1 / Apple Silicon

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS 11.0.1 (20B29)
  • TensorFlow.js installed from (npm or script link): npm
  • TensorFlow.js version: 2.8.3

Describe the problem

Installation fails due to a missing precompiled libtensorflow for darwin / arm64.

Apple has their own fork of TensorFlow supporting their chips-- is there a way to tell the installation script to use their libtensorflow.dylib?

Provide the exact sequence of commands / steps that you executed before running into the problem

npm install @tensorflow/tfjs-node --save

Any other info / logs

npm ERR! code 1
npm ERR! path /Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node
npm ERR! command failed
npm ERR! command sh -c node scripts/install.js
npm ERR! CPU-darwin-2.8.3.tar.gz
npm ERR! * Downloading libtensorflow
npm ERR! /Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node/scripts/install.js:100
npm ERR!     throw new Error(`Unsupported system: ${libType}-${platform}-${os.arch()}`);
npm ERR!           ^
npm ERR! 
npm ERR! Error: Unsupported system: cpu-darwin-arm64
npm ERR!     at getPlatformLibtensorflowUri (/Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node/scripts/install.js:100:11)
npm ERR!     at downloadLibtensorflow (/Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node/scripts/install.js:134:7)
npm ERR!     at async run (/Users/nicklee/Documents/Development/<redacted>/src/<redacted>/node_modules/@tensorflow/tfjs-node/scripts/install.js:197:5)

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/nicklee/.npm/_logs/2021-01-09T02_53_09_673Z-debug.log

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 15
  • Comments: 102 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Need M1 mac support!

We are expecting to release a new version next week. Thanks for the patience.

On Fri, Dec 3, 2021 at 6:12 PM Charlie Fish @.***> wrote:

@pyu10055 https://github.com/pyu10055 Is there any chance we could get an ETA on a release for this tho? Although pointing to the branch directly works fine, I’d love to submit some PRs to some dependencies that use tfjs, and it’s highly unlikely PRs will get approved when pointing to a branch.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/tensorflow/tfjs/issues/4514#issuecomment-985948486, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAA7MTDWNA26H445KS6K6TUPF2HTANCNFSM4V3HOZSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

To use the precompiled libraries from @vodianyk (https://github.com/vodianyk/libtensorflow-cpu-darwin-arm64) just use the last part of my instructions, posted earlier.

Disclaimer: I’m not affiliated nor can vouch for the safety of a binary downloaded from a private Github account! Use at your own risk!

I’m also not sure this combination of tfjs-node@latest and libtensorflow-2.8.0 is the correct pick, but it doesn’t look bad.

mkdir myproject
cd myproject
npm init -y
npm i @tensorflow/tfjs-node@latest --ignore-scripts
npm i node-pre-gyp
mkdir node_modules/@tensorflow/tfjs-node/deps
cd node_modules/@tensorflow/tfjs-node/deps
curl -LO 'https://github.com/vodianyk/libtensorflow-cpu-darwin-arm64/raw/main/libtensorflow-cpu-darwin-arm64-2.8.0.tar.gz'
tar xvf *.tar.gz
rm *.tar.gz
cd ..
npx node-pre-gyp rebuild
cd ../../..

And you’re all set.

Why is this closed? There is a workaround but it makes common development workflows tedious.

Any update on this issue by any chance? Experiencing the exact same dylib error.

Latest release works 😃

Same issue with @GitHelge, would be great if there’s a resolution for docker!

I don’t want to wait any longer!

Any word/ETA on official support?

@pyu10055 Do you have any thoughts about this on Docker?

@fishcharlie I think another solution is for tfjs team to supply a semi-official M1 TF binary. If some can share a working docker file, we can build and release a new version of tfjs-node that using the binary we built. Since we don’t have M1 hardware, would need your help to verify the validity of the build.

I really don’t want to add too much noise here. But @pyu10055 it looks like this issue is assigned to you. Can you please provide us an update on the status of this? Or maybe @rthadur since you have reopened this issue multiple times?

The fact that there hasn’t been any official word regarding the status of this is really disappointing considering how many people are simply asking for a simple status update.

I respect that open source is very community driven, and things get busy. But this project is maintained by Google. Additionally, providing a simple status update or ETA I don’t believe is unreasonable to expect.

I’ve just successfully built and ran my models with tfjs-node 3.5.0 with TensorFlow 2.5.0-rc1 on my M1 Macbook Air. From what I could see, the yet-to-be released TF 2.5.0 is where Apple Silicon is supported, but pre-release 2.5.0-rc1 is already fully usable.

Caveat: I didn’t keep exact track of all the steps, this was written in “hindsight” so I maybe I’m missing something.


# 1) set the build directory at will and clone Tensorflow

export BUILDDIR=~/tf-build
mkdir $BUILDDIR && cd $BUILDDIR
git clone -b v2.5.0-rc1 https://github.com/tensorflow/tensorflow tensorflow
cd tensorflow

# 2) you'll need Bazel 3.7.2 to build TF from source
# I've used bazelisk installed with brew under Rosetta
# note that the binaries are built for ARM64 regardless

arch -x86_64 bash
brew install bazelisk

# 3) the following takes a couple hours aprox on my Macbook air
# set the number of jobs to a higher value to speed up the build
# or lower to have it in the background

USE_BAZEL_VERSION=3.7.2 bazel build --jobs 4 --config=macos_arm64 --config=noaws --config=nogcp --config=nohdfs --config=nonccl //tensorflow:libtensorflow.dylib
USE_BAZEL_VERSION=3.7.2 bazel build --jobs 4 --config=macos_arm64 --config=noaws --config=nogcp --config=nohdfs --config=nonccl //tensorflow:libtensorflow_framework.dylib

# 4) now install/bind JS libs with NPM
# I'm assuming you have NVM to manage Node versions
# brew install nvm if you don't have it yet

exit # <---------- we leave the Rosetta bash prompt here
cd $BUILDDIR
mkdir tfjs-test && cd tfjs-test
nvm install 16  # <---- I've actually built with 15.8.0, but it's working under v16 too
npm init -y
npm i node-pre-gyp
npm i @tensorflow/tfjs-node@latest --ignore-scripts
cd node_modules/@tensorflow/tfjs-node/
mkdir -p deps/lib deps/include/tensorflow
cp -r $BUILDDIR/tensorflow/tensorflow/c deps/include/tensorflow/
cp -r $BUILDDIR/tensorflow/tensorflow/core deps/include/tensorflow/
cp -r $BUILDDIR/tensorflow/bazel-bin/tensorflow/*.dylib deps/lib/
npx node-pre-gyp rebuild

That’s it.

You should be able to import/require the Tensorflow JS modules and train/predict without issues. I’m still testing this, but so far so good. Training speed is ~5x or faster compared my 2015 Intel i7 Macbook Air and 2-3x compared to a 16 core 4GHz Intel Xeon E5 server.

You can install the @tensorflow/tfjs-node directory by copying it around, repeating the steps or just doing this in a global context (-g, not recommended).

Just chiming in - I wasn’t able to get tfjs/node working on my M1. The moment I import ‘@tensorflow/tfjs-node’, node just quits out with no error message.

Are you satisfied with the resolution of your issue? Yes No

for Monterey, tfjs-node is installed, but while running code gives error zsh: illegal hardware instruction node ./index.js

Im running the new version on my M1. Locally it works fine but when using docker, it runs into this issue:

#10 10.74 npm ERR! code 1
#10 10.74 npm ERR! path /app/node_modules/@tensorflow/tfjs-node
#10 10.75 npm ERR! command failed
#10 10.75 npm ERR! command sh -c node scripts/install.js
#10 10.75 npm ERR! CPU-linux-3.12.0.tar.gz
#10 10.75 npm ERR! * Downloading libtensorflow
#10 10.75 npm ERR! /app/node_modules/@tensorflow/tfjs-node/scripts/install.js:106
#10 10.75 npm ERR!     throw new Error(`Unsupported system: ${libType}-${platform}-${os.arch()}`);
#10 10.75 npm ERR!           ^
#10 10.75 npm ERR! 
#10 10.75 npm ERR! Error: Unsupported system: cpu-linux-arm64
#10 10.75 npm ERR!     at getPlatformLibtensorflowUri (/app/node_modules/@tensorflow/tfjs-node/scripts/install.js:106:11)
#10 10.75 npm ERR!     at downloadLibtensorflow (/app/node_modules/@tensorflow/tfjs-node/scripts/install.js:139:15)
#10 10.75 npm ERR!     at async run (/app/node_modules/@tensorflow/tfjs-node/scripts/install.js:208:5)
#10 10.76 
#10 10.76 npm ERR! A complete log of this run can be found in:
#10 10.76 npm ERR!     /root/.npm/_logs/2021-12-29T22_14_19_027Z-debug.log

I think the the PR enabled the function for cpu-darwin-arm64 but not for cpu-linux-arm64. Does anyone know if support for linux/arm64 is planned?

In case it’s helpful, I have a compiled version of tensorflow shared libs for M1: https://github.com/vodianyk/libtensorflow-cpu-darwin-arm64

Hi! Could you guid us how to install it? Thanks

Just use instructions from tensorflow website: https://www.tensorflow.org/install/lang_c

I really don’t want to add too much noise here. But @pyu10055 it looks like this issue is assigned to you. Can you please provide us an update on the status of this? Or maybe @rthadur since you have reopened this issue multiple times?

The fact that there hasn’t been any official word regarding the status of this is really disappointing considering how many people are simply asking for a simple status update.

I respect that open source is very community driven, and things get busy. But this project is maintained by Google. Additionally, providing a simple status update or ETA I don’t believe is unreasonable to expect.

I agree with you on this. We urgently need to be informed about a roadmap or estimated time of resolution.

I regret buying M1 so much

Why is this closed? There is a workaround but it makes common development workflows tedious.

Yeah, hoping this issue can be re-opened. TF.js is the only dependency preventing me from having a native development experience for my projects, so it would be nice to see a proper resolution to this.

I’m currently using a libtensorflow binary compiled under x86/Rosetta 2. I tried compiling for darwin-arm64 but ran into issues with Bazel.

Can this be reopened or someone point us in the direction of where we should go to help? Support for the new M1 macs is essential for any applications running edge TF models.

Nice that https://github.com/tensorflow/tfjs/pull/5899 got merged!

Now we just have to wait for the next release to happen. Or is there some pre-release tag on npm that we can use that have this?

Thank you for verifying, this is an official build from us, will update TFJS-node package to use the TF arm64 binary in our gcp storage.

On Thu, Nov 25, 2021 at 10:37 AM Charlie Fish @.***> wrote:

@pyu10055 https://github.com/pyu10055 One more question. While waiting for an official release, is the build that you linked safe to use? I’m extremely hesitant to use the precompiled libraries linked above. Security is a concern and using precompiled libraries from an untrusted source does raise certain concerns.

Ie. was the build you linked above compiled by yourself, or just a version based on the third party precompiled libraries here: https://github.com/vodianyk/libtensorflow-cpu-darwin-arm64 (or another 3rd party source)?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/tensorflow/tfjs/issues/4514#issuecomment-979417901, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAA7MXLQO4VA2QOP22J7WTUNZ7AJANCNFSM4V3HOZSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Why is this closed? There is a workaround but it makes common development workflows tedious.

Yeah, hoping this issue can be re-opened. TF.js is the only dependency preventing me from having a native development experience for my projects, so it would be nice to see a proper resolution to this. I’m currently using a libtensorflow binary compiled under x86/Rosetta 2. I tried compiling for darwin-arm64 but ran into issues with Bazel.

Agree! I’ve decided to just not dev with TF.js on my mac and just use my windows pc

I third that!

Note that I’ve used a release candidate version. I’d say we still need to wait for TensorFlow 2.5.x to be released, that would be the first GA version to fully support Apple Silicon. Then, yes, we can publish the binary to the storage location and update the install scripts to handle darwin-arm64. As I understand from the Release Notes for 2.5.0-rc1, apparently there aren’t any breaking changes that would affect TFJS.

I’m also not sure about the build flags that should be used, --config=macos_arm64 seems to fold the correct configuration options. Here are some build configs in case they actually enable M1 features that could improve performance to make sure we publish a fully optimized M1 lib.

	--config=mkl         	# Build with MKL support.
	--config=mkl_aarch64 	# Build with oneDNN support for Aarch64.
	--config=monolithic  	# Config for mostly static monolithic build.
	--config=numa        	# Build with NUMA support.
	--config=dynamic_kernels	# (Experimental) Build kernels into separate shared objects.
	--config=v2          	# Build TensorFlow 2.x instead of 1.x.

Source: https://github.com/tensorflow/tensorflow/pull/45404

Perhaps with https://github.com/tensorflow/tensorflow/pull/45404 this is more feasible? Has anyone been able to get tfjs-node to work on an M1 device?

We’re extremely interested in this as well. If anyone has been able to get it working, we would very, very much appreciate some pointers 😃

so far no luck with monterey.

tried . tfjs-node 3.15,3.5 & node 14,16 & build my own tensorflow 2.5 & used posted tensorflow 2.7 builds too. has anyone tried out in monterey ?

But the main reason i am posting is to ask for any idea or even it would be possible to use the instance of Tensorflow on Conda Env. with Metal Plugin (which i already succeded to run GPU based Tensorflow runs) . I think somehow configuring tfjs-node wrapper to use Apple’s supported platform will encourage people to use tfjs-node much much more.

@pyu10055 Awesome!! Let me know if I can assist any further. Can’t wait for this update to be released to npm!

@pyu10055 As far as I can tell, it works great!! Here is the steps I took to test it:

  1. Downloaded the linked file to my downloads directory.
  2. Cloned the microsoft/customvision-tfjs-node repo
  3. Within the customvision-tfjs-node directory, ran npm i ~/Downloads/tensorflow-tfjs-node-0.0.0.tar (path to the downloaded file in step 1)
  4. Created a new empty folder
  5. Ran npm i ~/Downloads/customvision-tfjs-node (path to cloned repo in step 2)

Side note: I feel like at this point either step 3 or 5 would have failed. However, I have received no errors, so far, so I kept going.

  1. I used the code listed here (modified slightly) to test this
  2. It was successful and the prediction score was 99.8%.

Please let me know if there are any further tests you would like me to run. I have only run these tests on an Apple Silicon machine (M1 Max) without Rosetta 2 running 🎉. If you would like me to run on a machine with Rosetta 2 installed, or an Intel machine, please let me know and I have access to both environments, and can run those tests.

@pyu10055 I would be more than happy to help assist in testing an Apple Silicon/M1 build on my hardware. However, one thing to note, my experience with tfjs is limited to customvision-tfjs-node. So that will likely be the extent I’ll be able to do manual tests. It looks like there are automated tests in this repo tho? So I can possibly run those. Might need some guidance about the tests we want to run to verify validity.

Short version: I’d be more than happy to help in whatever capacity I can.

In case it’s helpful, I have a compiled version of tensorflow shared libs for M1: https://github.com/vodianyk/libtensorflow-cpu-darwin-arm64

@rodrigolive Yes, it throws x86_64

Thanks. Now I’ve spotted the problem and I’ve tried a lot of cleans and re-installs, but NVM keeps installing the x86_64 on my node version 😔.

Can’t manage to get the arm64 for some reason. But that issue is not relevant for this channel. I’ll see what I can do to get it build for arm64. Weird cause uname -m on my Terminal throws arm64.

@tensorflow-butler please do not close, it is awaiting 2.5.0 release to be completed, but still important.