Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac M1 Tensorflow Set Up #1514

Closed
mgebhard opened this issue Jan 18, 2021 · 39 comments
Closed

Mac M1 Tensorflow Set Up #1514

mgebhard opened this issue Jan 18, 2021 · 39 comments
Assignees
Labels
platform:apple silicon apple silicon chip type:build/install For Build and Installation issues

Comments

@mgebhard
Copy link

"ERROR: While resolving toolchains for target @org_tensorflow//tensorflow/tools/git:gen_git_source: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See bazelbuild/bazel#10134 for details and migration instructions.
ERROR: Analysis of target '//mediapipe/examples/ios/facedetectioncpu:facedetectioncpu' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See bazelbuild/bazel#10134 for details and migration instructions."

I am trying to follow instructions here to set up tensorflow using the new mac m1 chip: https://github.com/apple/tensorflow_macos

However, I am still having no luck with initial set up for media pipe.

Have I written custom code: No
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Mac OS 11.0.1
Bazel version:nbazel 3.7.2-homebrew
Xcode & Tulsi version (if issue is related to building in mobile dev enviroment): 12.3 Tusli 0.20210106.88
Exact steps to reproduce: ./build_ios_examples.sh -d out_dir --nostrip

@jiuqiant
Copy link
Contributor

jiuqiant commented Jan 19, 2021

MediaPipe with its TensorFlow dependence needs Bazel to build everything from scratch. I don't think bazel already supports M1 yet: bazelbuild/bazel#11628.

https://github.com/apple/tensorflow_macos requires the users to use https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha1/tensorflow_macos-0.1alpha1.tar.gz, which is not the "official" version of tensorflow.

@jiuqiant jiuqiant added the platform:apple silicon apple silicon chip label Jan 19, 2021
@mgebhard
Copy link
Author

It looks like the tensorflow team has added M1 support. tensorflow/tensorflow#46178

Is there a workaround to not have to wait for bazel compatibility?

@jiuqiant jiuqiant reopened this Jan 20, 2021
@jiuqiant
Copy link
Contributor

I took a look at tensorflow/tensorflow@e687cab. My conclusion is the mediapipe repo needs some config changes for supporting Apple Silicon. For example, the repo needs to add a config for "macos_arm64" config_setting like the one it has for macos_x86_64. Also, it needs to point to the latest TF version that supports Apple Silicon.

@mgebhard
Copy link
Author

Do you have an ETA when the repo will be updated with the config changes? This blocks any integration from the m1 chip

@hadon hadon added the type:build/install For Build and Installation issues label Feb 5, 2021
@mgebhard
Copy link
Author

mgebhard commented Feb 9, 2021

Any update on M1 support?

@miholeus
Copy link

miholeus commented Jun 6, 2021

also have an error on m1

@ROBYER1
Copy link

ROBYER1 commented Oct 27, 2021

Feels like barely anyone else has an M1 mac, has anyone got a fix for this?

@rcoenen
Copy link

rcoenen commented Oct 28, 2021

I am on M1 and its failing to build still

@gkiernozek
Copy link

gkiernozek commented Oct 31, 2021

Yea, not yet I suppose, I cannot install nuget too as it requires x86_64 architecture, I just use windows for now and my friend works on intel macbook

@homuler
Copy link

homuler commented Nov 18, 2021

I confirmed that hand_tracking_cpu works on Mac mini (M1, 2020) (macOS Big Sur 11.6) with the following patch applied.

diff --git a/.bazelrc b/.bazelrc
index 37a0bc1..7d7e159 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -87,6 +87,11 @@ build:darwin_x86_64 --apple_platform_type=macos
 build:darwin_x86_64 --macos_minimum_os=10.12
 build:darwin_x86_64 --cpu=darwin_x86_64
 
+# May not be necessary
+build:darwin_arm64 --apple_platform_type=macos
+build:darwin_arm64 --macos_minimum_os=10.16
+build:darwin_arm64 --cpu=darwin_arm64
+
 # This bazelrc file is meant to be written by a setup script.
 try-import %workspace%/.configure.bazelrc
 
diff --git a/.bazelversion b/.bazelversion
index 0b2eb36..fae6e3d 100644
--- a/.bazelversion
+++ b/.bazelversion
@@ -1 +1 @@
-3.7.2
+4.2.1
diff --git a/WORKSPACE b/WORKSPACE
index c2aaca6..30afd92 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -200,7 +200,7 @@ new_local_repository(
 new_local_repository(
     name = "macos_opencv",
     build_file = "@//third_party:opencv_macos.BUILD",
-    path = "/usr/local/opt/opencv@3",
+    path = "/opt/homebrew/opt/opencv@3",
 )
 
 new_local_repository(
diff --git a/mediapipe/BUILD b/mediapipe/BUILD
index 1171ea6..72e4208 100644
--- a/mediapipe/BUILD
+++ b/mediapipe/BUILD
@@ -74,6 +74,7 @@ alias(
     name = "macos",
     actual = select({
         ":macos_i386": ":macos_i386",
+        ":macos_arm64": ":macos_arm64",
         ":macos_x86_64": ":macos_x86_64",
         "//conditions:default": ":macos_i386",  # Arbitrarily chosen from above.
     }),
@@ -110,6 +111,15 @@ config_setting(
     visibility = ["//visibility:public"],
 )
 
+config_setting(
+    name = "macos_arm64",
+    values = {
+        "apple_platform_type": "macos",
+        "cpu": "darwin_arm64",
+    },
+    visibility = ["//visibility:public"],
+)
+
 config_setting(
     name = "macos_x86_64",
     values = {

The exact command can be found here.

It seems that a similar patch is already submitted as a PR.
#2591

@Snipeye
Copy link

Snipeye commented Dec 12, 2021

@homuler Thank you for the recommendations; I've made those changes and I'm still having issues. Additionally, the PR you linked has issues: It still references bazel 3.7.2. Additionally in your changes, I had to also change the reference to ffmpeg in WORKSPACE.

I installed the latest bazel (4.2.2) through brew, then updated .bazelversion to reflect that, but when I tried to run the helloworld, I ended up with:

"dyld[70906]: symbol not found in flat namespace '_CFRelease'"

Any further advice?

@mgebhard
Copy link
Author

It has been almost a year does anyone have a solution to this?

I followed the changes in https://github.com/google/mediapipe/pull/2591/files with slight differences in OpenCV and FFMPEG versions and still got build errors.

In file included from mediapipe/framework/formats/image_frame_opencv.cc:15:
In file included from ./mediapipe/framework/formats/image_frame_opencv.h:20:
./mediapipe/framework/port/opencv_core_inc.h:18:10: fatal error: 'opencv2/core/version.hpp' file not found
#include <opencv2/core/version.hpp>

I would prefer not to use a unity plugin.

@daviddavid
Copy link

This doesn't solve the issue of running mediapipe on M1 metal, but you can get mediapipe to run on your M1 hardware by using rosetta, as described in this comment. (Read the rest of the comments before diving in. To solve the homebrew permissions problem in /usr/local you can refer to this SO answer)

@binpan0423
Copy link

@homuler Thank you for the recommendations; I've made those changes and I'm still having issues. Additionally, the PR you linked has issues: It still references bazel 3.7.2. Additionally in your changes, I had to also change the reference to ffmpeg in WORKSPACE.

I installed the latest bazel (4.2.2) through brew, then updated .bazelversion to reflect that, but when I tried to run the helloworld, I ended up with:

"dyld[70906]: symbol not found in flat namespace '_CFRelease'"

Any further advice?

same problem here。 any solutions?

@matanox
Copy link

matanox commented Mar 18, 2022

I wonder why they don't reflect any of this limitation on the installation page at the TensorFlow website. They just say this:

macOS 10.12.6 (Sierra) or later (no GPU support)

Which seems to contradict the actual status if I'm following. What do you think?

@justin-f-perez
Copy link

related: #3277 (community M1 wheels)

@sureshdagooglecom
Copy link

Hi @mgebhard ,
Apple M1 supports in latest release , could you check, verify and close this issue.

@google-ml-butler
Copy link

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

@The-Real-Thisas
Copy link

Hi @sureshdagooglecom just so you know what I mentioned is just a workaround and is not a pull request or anything to fix it mainline. I don't think this issue is resolved.

@google-ml-butler
Copy link

Closing as stale. Please reopen if you'd like to work on this further.

@google-ml-butler
Copy link

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

@kuaashish kuaashish removed stat:awaiting response Waiting for user response stale labels Sep 6, 2022
@kuaashish kuaashish reopened this Sep 8, 2022
@sureshdagooglecom sureshdagooglecom added the stat:awaiting googler Waiting for Google Engineer's Response label Sep 14, 2022
@davidcavazos
Copy link

I was able to install tensorflow-macos (not tensorflow) following Apple's instructions here: https://developer.apple.com/metal/tensorflow-plugin/

However, when I try to pip install other packages requiring grpcio like google-cloud-aiplatform, I get errors while trying to compile grpcio. This has been rather frustrating, and I would expect TensorFlow working with Vertex AI running from my M1 MacBook Pro.

@kuaashish kuaashish assigned kuaashish and unassigned hadon Apr 19, 2023
@kuaashish kuaashish removed the stat:awaiting googler Waiting for Google Engineer's Response label Apr 19, 2023
@kuaashish
Copy link
Collaborator

kuaashish commented Apr 19, 2023

Hello @mgebhard,
We have released Universal Wheels with version 0.9.3.0 as guided here in the release page with python version >=3.8.
Please try out to build mediapipe using pip let us know if still an issue from your end. Thank you

@kuaashish kuaashish added the stat:awaiting response Waiting for user response label Apr 19, 2023
@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.

@github-actions
Copy link

github-actions bot commented May 4, 2023

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale label May 4, 2023
@github-actions
Copy link

This issue was closed due to lack of activity after being marked stale for past 7 days.

@google-ml-butler
Copy link

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

@kuaashish kuaashish removed stat:awaiting response Waiting for user response stale stalled labels May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:apple silicon apple silicon chip type:build/install For Build and Installation issues
Projects
None yet
Development

No branches or pull requests