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

Installation Issues on Apple M1 device #655

Open
stfnmangini opened this issue Jan 18, 2022 · 4 comments
Open

Installation Issues on Apple M1 device #655

stfnmangini opened this issue Jan 18, 2022 · 4 comments
Assignees
Labels
area/docs Concerns documentation – problems, ideas, requests area/installation Concerns installation of TFQ kind/bug-report Something doesn't seem to work priority/p1 Fix is needed as soon as possible

Comments

@stfnmangini
Copy link

stfnmangini commented Jan 18, 2022

I'm having troubles installing tensorflow-quantum on an Apple M1 device.

Tensorflow installation is fine following Apple's official guide (https://developer.apple.com/metal/tensorflow-plugin/), though I am not able to install tfq, either via pip or building from source:

  • installation via pip requires tensorflow==2.4.1, but Tensorflow for M1 chips comes at least at >v2.5.0;
  • installing from source yields errors due to missing recognized Tensorflow package (configure.sh looks for tensorflow but tensorflow-macos is installed instead), and also due to Bazel, as the required version (3.7.2) is not available for M1 architectures.

Step to reproduce the problem:

First install Tensorflow following Apple's guide, then follow tfq installation procedure https://github.com/tensorflow/quantum/blob/master/docs/install.md

  git clone https://github.com/tensorflow/tensorflow.git
  cd tensorflow
  git checkout v2.7.0 (same version obtained with   python -m pip tensorflow-macos)

  pip install -U pip six numpy wheel setuptools mock 'future>=0.17.1'
  pip install -U keras_applications --no-deps
  pip install -U keras_preprocessing --no-deps
  pip install numpy==1.19.5  (fails to compile wheels, must install with conda install numpy=1.19.5 instead)

  ./configure


WARNING: Package(s) not found: tensorflow
WARNING: Package(s) not found: tf-nightly
WARNING: Package(s) not found: tensorflow-cpu
WARNING: Package(s) not found: tf-nightly-cpu
Installing tensorflow .....\n
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow

If modifying the configure.sh by having it look for tensorflow-macos (instead of tensorflow), then problems occur when building with Bazel (the required distribution 3.7.2 is not available for M1 architecture).
Installing from source also Tensorflow itself comes with its own bag of installation issues (versions incompatibilities, problems with packages like numpy, grpcio, h5f, ...), and doesn't feel like the best way to proceed.

Is there a workaround or fix? How should one proceed?
Thanks!

@lockwo
Copy link
Contributor

lockwo commented Jan 18, 2022

I can't check what works (the only mac I have access to has an i9), but if the problem for pip installing is TF == 2.4.1, could you work with the nightly build? That has TF 2.7. The nightly pip install also break?

@stfnmangini
Copy link
Author

stfnmangini commented Jan 18, 2022

I can't check what works (the only mac I have access to has an i9), but if the problem for pip installing is TF == 2.4.1, could you work with the nightly build? That has TF 2.7. The nightly pip install also break?

Hi Owen, thanks for the suggestion! I've just tried installing tfq-nightly using stadard pip install tfq-nightly in the conda environment with the M1-optimized tensorflow, but it yields the following error

ERROR: Could not find a version that satisfies the requirement tfq-nightly (from versions: none)
ERROR: No matching distribution found for tfq-nightly

Again, this must have something to do with tfq-nightly looking for package tensorflow instead of tensorflow-macos. Also, having a look at the tfq-nightly wheels (https://pypi.org/project/tfq-nightly/#files) they are for x86_64 architecture, and not M1-arm64 one. Though, I know very little about architectures, compilations and builds, so I may be getting something wrong.


However, after digging some more I found a way to install it using the x86_64 architecure! I don't know exactly if it is the minimal (or most efficient) solution, but it worked for me (at least for installation and import, haven't tested it in detail yet).

Solution: Installing tensorflow-quantum with x86_64 architecture on M1 device

  1. Install Rosetta: run on terminal softwareupdate --install-rosetta

  2. Create a Rosetta-Terminal: go to Application folder and duplicate the Terminal (or iTerm) app. Open the "Get info" tab of the duplicate terminal, and check the "Open with Rosetta" option. Rename the duplicate app (like "Rosetta-iTerm") to distinguish it from the original one (M1 arm64-based).

  3. Create Environment: create a python environment using the default python3 distribution (not using conda). Open the just created Rosetta-terminal, and run

python3 -m venv ~/tensorflow-env
source ~/tensorflow-env/bin/activate
python -m pip install -U pip
  1. Install Tensorflow: following How to run tensorflow 2.4.0 on ARM Mac using Rosetta 2 tensorflow#46044 (comment),
    download the wheels for tensorflow v2.4.1 from the provided link, and run pip install /position/of/file/tensorflow-2.4.1-py3-none-any.whl

  2. Install Tensorflow Quantum: just pip install tensorflow-quantum

Note: always use the Rosetta enabled-terminal for activating the environment and using these tensorflow installations, otherwise you receive compatibility errors.

My default version of python3 is Python 3.8.9. Follwing these steps I could install all packages without errors, and import them as well. I still haven't tested in detail the performances and functionalities. Also, it remains to be understood how to set up tfq with the optimized M1 tensorflow distribution.

Hope this works for others as well!

@owenonline
Copy link

owenonline commented Jun 7, 2023

I followed these steps and still get the error:

ERROR: Could not find a version that satisfies the requirement tensorflow-quantum (from versions: none)
ERROR: No matching distribution found for tensorflow-quantum

@kyujin2228
Copy link

I got the same error, too.

@mhucka mhucka added kind/bug-report Something doesn't seem to work area/docs Concerns documentation – problems, ideas, requests area/installation Concerns installation of TFQ labels Dec 1, 2024
@mhucka mhucka added the priority/p1 Fix is needed as soon as possible label Dec 4, 2024
@mhucka mhucka self-assigned this Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs Concerns documentation – problems, ideas, requests area/installation Concerns installation of TFQ kind/bug-report Something doesn't seem to work priority/p1 Fix is needed as soon as possible
Projects
Development

No branches or pull requests

5 participants