I try to build tensorflow v1.13 with MKL. The build is performed successfully, the pip package is correctly created, but when I test the package, MKL is clearly not used in the end, i.e. when I run in Python 3.6.8:
import tensorflow
print("Is MKL enabled?{}".format(tensorflow.pywrap_tensorflow.IsMklEnabled()))
It returns "False"
I am operating on CentOS 7 in the following conda environment:
# Name Version Build Channel
blas 1.0 mkl
ca-certificates 2019.1.23 0
certifi 2018.1.18 py36_2 intel
cloog 0.18.0 0
cython 0.29.6 py36he6710b0_0
gcc 4.8.5 7
gmp 6.1.2 h6c8ec71_1
icc_rt 2019.3 intel_199 intel
intel-openmp 2019.3 intel_199 intel
intelpython 2019.3 0 intel
isl 0.12.2 0
keras-applications 1.0.7 pypi_0 pypi
keras-preprocessing 1.0.9 pypi_0 pypi
libedit 3.1.20181209 hc058e9b_0
libffi 3.2.1 hd88cf55_4
libgcc-ng 8.2.0 hdf63c60_1
libgfortran-ng 7.3.0 hdf63c60_0
libstdcxx-ng 8.2.0 hdf63c60_1
mkl 2019.3 intel_199 intel
mkl-dnn 0.14 2 intel
mkl_fft 1.0.11 py36h7b7c402_0 intel
mkl_random 1.0.2 py36h7b7c402_4 intel
mock 2.0.0 py36_0
mpc 1.0.3 hec55b23_5
mpfr 3.1.5 h11a74b3_2
ncurses 6.1 he6710b0_1
numpy 1.16.2 py36h7e9f1db_0
numpy-base 1.16.2 py36hde5b4d6_0
openmp 2018.0.3 intel_0 intel
openssl 1.1.1b h7b6447c_1
pbr 5.1.3 py_0
pip 19.0.3 py36_0
python 3.6.8 h0371630_0
readline 7.0 h7b6447c_5
setuptools 40.8.0 py36_0
six 1.12.0 py36_0
sqlite 3.27.2 h7b6447c_0
tbb 2019.4 intel_199 intel
tk 8.6.8 hbc83047_0
wheel 0.33.1 py36_0
xz 5.2.4 h14c3975_4
zlib 1.2.11 h7b6447c_3
Bazel is in version 0.23.0
GCC is in version 7.3.1 (see below)
I use the following command lines to build the tensorflow package:
scl enable devtoolset-7 bash
bazel build --config=mkl --config=opt --copt=-march=x86-64 --copt=-mavx --copt=-msse4.1 --copt=-msse4.2 --copt=-O2 --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" //tensorflow/tools/pip_package:build_pip_package
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
Obviously, many warnings occur, but none of them is related to MKL. Noteworthy, I am using GCC7 here. I tried GCC4 and GCC5. I am using
That didn't change the problem. Does someone have a clue about why MKL is not linked?
As tensorflow version==1.13 is the latest release ,it might not be stable(https://www.tensorflow.org/versions/)
It worked fine installing with tensorflow version==1.11 using the below steps.
git clone https://github.com/tensorflow/tensorflow
cd tensorflow
git checkout r1.11
conda create -n <conda_environment_name> python=3.6
source activate <conda_environment_name>
conda install numpy bazel
conda install -c intel mkl-dnn
conda install -c conda-forge keras-preprocessing
Configure your system build by running the following at the root of your TensorFlow source tree:
$./configure
bazel build command for Support for the Intel® MKL-DNN.
bazel build --config=mkl -c opt //tensorflow/tools/pip_package:build_pip_package
create a directory tfwheels to place the wheel files and run the below commands
mkdir tfwheels
bazel-bin/tensorflow/tools/pip_package/build_pip_package /home/<your_path>/tfwheels/tensorflow_pkg
pip install /home/<your_path>/tfweels/tensorflow_pkg/tensorflow-<version>-cp36-cp36m-linux_x86_64.whl
for tensorflow version==1.12(similar steps)
refer
https://software.intel.com/en-us/articles/intel-optimization-for-tensorflow-installation-guide
Hope this helps.
Related
I am facing 4 problems when I tried to install TensorFlow on Apple M1:
Conda has supported M1 since 2022.05.06 but most of articles I googled talk about using Miniforge, e.g. So I feel they are all kind of outdated.
How To Install TensorFlow on M1 Mac (The Easy Way)
AI - Apple Silicon Mac M1 natively supports TensorFlow 2.8 GPU acceleration
How to Setup TensorFlow on Apple M1 Pro and M1 Max (works for M1 too)
How To Install TensorFlow 2.7 on MacBook Pro M1 Pro With Ease
I used the latest conda 4.13 to setup my python environment(3.8, 3.9 and 3.10) successfully but when I tried to install tensorflow I got the error "No matching distribution found for tensorflow" (all failed).
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
The answers in Could not find a version that satisfies the requirement tensorflow didn't help. I can't find useful information on https://www.tensorflow.org/ too, actually https://www.tensorflow.org/install just said pip install tensorflow.
I tried to run pip install tensorflow-macos and it succeeded.
I read from the above "works for M1 too" article mentioned "Apple's fork of TensorFlow is called tensorflow-macos" although I can't find much information about that. For example, https://www.tensorflow.org/ does not mention that. I also found from https://developer.apple.com/forums/thread/686926 that someone hit that "ERROR: No matching distribution found for tensorflow-macos" (but I didn't).
All the articles I googled, including above 4 articles and this Tensorflow on macOS Apple M1, all say I also need to run the following 2 commands
conda install -c apple tensorflow-deps
pip install tensorflow-metal
But do I really need to that? I can't find this information from https://www.tensorflow.org/.
What are these 2 packages tensorflow-deps and tensorflow-metal ?
Distilling the official directions from Apple (as of 13 July 2022), one would create an environment using the following YAML:
tf-metal-arm64.yaml
name: tf-metal
channels:
- apple
- conda-forge
dependencies:
- python=3.9 ## specify desired version
- pip
- tensorflow-deps
## uncomment for use with Jupyter
## - ipykernel
## PyPI packages
- pip:
- tensorflow-macos
- tensorflow-metal ## optional, but recommended
Edit to include additional packages.
Creating environment
Before creating the environment we need to know what the base architecture is. Check this with conda config --show subdir.
Native (osx-arm64) base
If you have installed a native osx-arm64 Miniforge variant (I recommend Mambaforge), then you can create with:
mamba env create -n my_tf_env -f tf-metal-arm64.yaml
Note: If you don't have Mamba, then substitute conda for mamba; or install it for much faster solving: conda install -n base mamba.
Emulated (osx-64) base
If you do not have a native base, then you will need to override the subdir setting:
## create env
CONDA_SUBDIR=osx-arm64 mamba env create -n my_tf_env -f tf-metal-arm64.yaml
## activate
mamba activate my_tf_env
## permanently set the subdir
conda config --env --set subdir osx-arm64
Be sure to always activate the environment before installing or updating packages.
I battled with this for hours. The current instructions at https://developer.apple.com/metal/tensorflow-plugin/ specify using Miniconda and can be summarized as:
conda create -y --name cv python
conda activate cv
conda install -y -c apple tensorflow-deps
python -m pip install tensorflow-macos tensorflow-metal
As of Jan 2023, these instructions are riddled with issues:
Symptom: you ran conda install -c apple tensorflow-deps expecting to get the current version (2.10.0) , but conda list tensorflow-deps shows tensorflow-deps 2.9.0
Reason: Apple's tensorflow-deps package v2.10.0 depends on numpy >=1.23.2,<1.23.3. There is no such version of numpy in Anaconda (only conda-forge). Anaconda's dependency resolution silently falls back to an older version of tensorflow-deps. This will cause more problems as you continue with the instructions.
Symptom: you ran conda install -c apple tensorflow-deps==2.10.0 and got UnsatisfiableError: The following specifications were found to be incompatible with each other
Reason: Same as above, but at least Anaconda has told you about it. It doesn't mention what the incompatibility is, because that would be helpful.
Symptom: "RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf"
Reason: If you install tensorflow-deps 2.9.0 (or Anaconda installs it for you due to the above) you will get numpy 1.22.3. When you pip install tensorflow-macos tensorflow-metal, you will get tensorflow-macos 2.11.0 and tensorflow-metal 0.7.0, one or both of which is binary-incompatible with numpy 1.22.3.
Symptom: 2023-01-22 15:16:23.209301: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at xla_ops.cc:418 : NOT_FOUND: could not find registered platform with id
Problem: TensorFlow 2.11 has introduced an incompatibility between optimizers and pluggable architectures. You can have TF 2.11, but you'll need to use a legacy optimizer.
Solutions
I have found 3 options for a working GPU-accelerated TF install on Apple Silicon using Anaconda.
It will help your debugging to get a minimal test script like the one from https://developer.apple.com/metal/tensorflow-plugin/ which is:
import tensorflow as tf
cifar = tf.keras.datasets.cifar100
(x_train, y_train), (x_test, y_test) = cifar.load_data()
model = tf.keras.applications.ResNet50(
include_top=True,
weights=None,
input_shape=(32, 32, 3),
classes=100,)
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer="adam", loss=loss_fn, metrics=["accuracy"])
model.fit(x_train, y_train, epochs=5, batch_size=64)
This way you can check GPU usage by running TF_MLC_LOGGING=1 python tf_arch_test.py and watching Activity Monitor. While feeling which side of the laptop is burning your legs can be a helpful indicator of GPU usage, it's not always reliable.
Fix #1: Add conda-forge as a channel, use the legacy optimizer in your code.
conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -y --name cv
conda activate cv
conda install -y -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
python --version
conda list|grep -E '(tensorflow|numpy)'
TF_MLC_LOGGING=1 python tf_arch_test.py
You will get:
Python 3.10.8
numpy 1.23.2 py310h127c7cf_0 conda-forge
tensorflow-deps 2.10.0 0 apple
tensorflow-estimator 2.11.0 pypi_0 pypi
tensorflow-macos 2.11.0 pypi_0 pypi
tensorflow-metal 0.7.0 pypi_0 pypi
You will need to modify your code to use one of the legacy optimizers. e.g.:
model.compile(
optimizer=tf.keras.optimizers.legacy.Adam(learning_rate=1e-3),
loss=loss_fn,
metrics=["accuracy"],
)
Fix #2: Add conda-forge as a channel, pin the version numbers to avoid the pluggable architecture issue.
conda config --add channels conda-forge
conda config --set channel_priority strict
conda create -y --name cv
conda activate cv
conda install -y -c apple tensorflow-deps==2.10.0
python -m pip install tensorflow-macos==2.10.0
python -m pip install tensorflow-metal==0.6.0
python --version
conda list|grep -E '(tensorflow|numpy)'
You will get:
Python 3.10.8
numpy 1.23.2 py310h127c7cf_0 conda-forge
tensorflow-deps 2.10.0 0 apple
tensorflow-estimator 2.10.0 pypi_0 pypi
tensorflow-macos 2.10.0 pypi_0 pypi
tensorflow-metal 0.6.0 pypi_0 pypi
Fix #3: Don't add conda-forge, pin the version numbers way back to the last ones that actually worked:
conda create -y --name cv python
conda activate cv
conda install -y -c apple tensorflow-deps==2.9.0
python -m pip install tensorflow-macos==2.9.2
python -m pip install tensorflow-metal==0.5.1
python --version
conda list|grep -E '(tensorflow|numpy)'
You will get:
Python 3.10.9
numpy 1.22.3 py310hdb36b11_0
numpy-base 1.22.3 py310h5e3e9f0_0
tensorflow-deps 2.9.0 0 apple
tensorflow-estimator 2.9.0 pypi_0 pypi
tensorflow-macos 2.9.2 pypi_0 pypi
tensorflow-metal 0.5.1 pypi_0 pypi
Download and install Conda env:
https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
Install the TensorFlow dependencies:
conda install -c apple tensorflow-deps
Install base TensorFlow:
python -m pip install tensorflow-macos
Install base TensorFlow-metal:
python -m pip install tensorflow-metal
Create Conda Environment:
conda create -n tensorflow-env tensorflow
conda activate tensorflow-env
First of all, TensorFlow does not support officially the Mac M1. They don't distribute packages precompiled for the Mac M1 (and its specific arm64 arch), hence the tensorflow-macos package, which is maintained by Apple. TensorFlow distributes, as far as I know, official wheels only for x86 (Linux, Windows, Mac), and the Raspberry PI (arm64).
Apple is using a specific plugin in Tensorflow to make the framework compatible with Metal, the graphic stack of MacOS. To put it in a other way, they are leveraging the PluggableDevice API of Tensorflow to write code that translates the TensorFlow operations to code that the GPU of the M1 understands.
Those two packages contain respectively:
tensorflow-deps the dependencies to run Tensorflow on arm64, i.e python, numpy, grpcio and h5py. This is more of a convenience package, I believe.
tensorflow-metal: a plugin to make tensorflow able to run on metal, the shader API of MacOS (comparable to the low level APIs of Vulkan or DirectX12 on other platforms). You can think of it as a replacement of CUDA, if you are used to run TensorFlow on Nvidia GPUs.
Without the tensorflow-metal package, TensorFlow won't be able to leverage the GPU of the M1, but will still be able to run code on the CPU.
The two answers I got have helped better understand how to install TensorFlow on m1. But I would like share my experience too.
About tensorflow-deps. I do need it, without it pip failed to installed grpcio, and thus actually failed to install tensorflow-macos. When I first asked the question I didn't pay enough attention to output of pip install tensorflow-macos.
About tensorflow-macos package, actually https://blog.tensorflow.org/2020/11/accelerating-tensorflow-performance-on-mac.html has the full information. BTW that article, published 2020-11-18, said "In the near future, we’ll be making updates like this even easier for users to get these performance numbers by integrating the forked version into the TensorFlow master branch." But according to Lescurel's answer it seems they have not.
I didn't know the concept of PluggableDevice (as in Lescurel's), so even when I visited https://github.com/apple/tensorflow_macos I was still confused. Take a look at that article if you do not know that either, basically it will let TensorFlow support new devices.
For 4 articles I listed, "works for M1 too" is the most helpful. It actually explained why I need tensorflow-deps & tensorflow-metal. But part of reasons I did not pay enough attention beforehand were: a) I want to use conda, not miniforge, all these package manager tools scare me a little bit (come from nodejs background, npm, yarn, yarn2, pnmp). The answer from merv also suggested another one mamba, but I think I will pass. b) I don't use homebrew, basically all the articles talking about installing ts on m1 mentioned installing homebrew first. But I use macport, for the reason I mentioned here (again I am bit scared of these these package manager tools)
Using environment.yaml like the one in merv's answer is a reliable way to install tensorflow!
BTW, once I have figured out the whole process of installing tensorflow, install pytorch is a lot easier as pytorch also supports M1 now, check here https://pytorch.org/blog/introducing-accelerated-pytorch-training-on-mac/
Official instructions from Apple are available here.
At the time of writing:
conda create python=3.10.6 --name <NAME>
conda activate <NAME>
conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
I installed a working version of tensorflow 2.9.2 on my M1 Mac with pip. First, install pyenv and python 3.10.6. Next, pip install tensorflow-metal and finally pip install tensorflow-macos. That's it, no need for tensorflow-deps.
If your model complains about the unavailability of cuDNN and runs slowly, try adjusting your script to enable cuDNN as per tensorflow docs
Worked for me using Python 3.10.8 via Homebrew and following the instructions from Apple but using the instructions for "x86: AMD" instead.
Check Python version:
% which python3.10
/opt/homebrew/bin/python3.10
Create venv, activate it (prompt will change), and update pip:
% python3.10 -m venv ~/py310-tf-metal
% source ~/py310-tf-metal/bin/activate
(py310-tf-metal) % which python
~/py310-tf-metal/bin/python
(py310-tf-metal) % python -m pip install -U pip
...
Successfully installed pip-22.3.1
Install tensorflow-macos:
(py310-tf-metal) % python -m pip install tensorflow-macos
...
Successfully installed MarkupSafe-2.1.1 absl-py-1.3.0 astunparse-1.6.3 cachetools-5.2.0 certifi-2022.9.24 charset-normalizer-2.1.1 flatbuffers-22.11.23 gast-0.4.0 google-auth-2.14.1 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.50.0 h5py-3.7.0 idna-3.4 keras-2.10.0 keras-preprocessing-1.1.2 libclang-14.0.6 markdown-3.4.1 numpy-1.23.5 oauthlib-3.2.2 opt-einsum-3.3.0 packaging-21.3 protobuf-3.19.6 pyasn1-0.4.8 pyasn1-modules-0.2.8 pyparsing-3.0.9 requests-2.28.1 requests-oauthlib-1.3.1 rsa-4.9 six-1.16.0 tensorboard-2.10.1 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 tensorflow-estimator-2.10.0 tensorflow-macos-2.10.0 termcolor-2.1.1 typing-extensions-4.4.0 urllib3-1.26.13 werkzeug-2.2.2 wheel-0.38.4 wrapt-1.14.1
Install tensorflow-metal:
(py310-tf-metal) % python -m pip install tensorflow-metal
Collecting tensorflow-metal
Downloading tensorflow_metal-0.6.0-cp310-cp310-macosx_12_0_arm64.whl (1.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.4/1.4 MB 25.5 MB/s eta 0:00:00
Requirement already satisfied: six>=1.15.0 in ./Venvs/py310-tf-metal/lib/python3.10/site-packages (from tensorflow-metal) (1.16.0)
Requirement already satisfied: wheel~=0.35 in ./Venvs/py310-tf-metal/lib/python3.10/site-packages (from tensorflow-metal) (0.38.4)
Installing collected packages: tensorflow-metal
Successfully installed tensorflow-metal-0.6.0
Test using the CIFAR training script at the Apple page:
import tensorflow as tf
cifar = tf.keras.datasets.cifar100
(x_train, y_train), (x_test, y_test) = cifar.load_data()
model = tf.keras.applications.ResNet50(
include_top=True,
weights=None,
input_shape=(32, 32, 3),
classes=100,)
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
model.compile(optimizer="adam", loss=loss_fn, metrics=["accuracy"])
model.fit(x_train, y_train, epochs=5, batch_size=64)
Save above as testcifar.py and run it:
(py310-tf-metal) % python testcifar.py
Downloading data from https://www.cs.toronto.edu/~kriz/cifar-100-python.tar.gz
169001437/169001437 [==============================] - 3s 0us/step
Metal device set to: Apple M1
systemMemory: 16.00 GB
maxCacheSize: 5.33 GB
2022-11-28 07:58:10.715660: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:306] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2022-11-28 07:58:10.715837: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:272] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)
2022-11-28 07:58:14.736843: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz
Epoch 1/5
...
2022-11-28 07:58:21.975675: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:114] Plugin optimizer for device_type GPU is enabled.
...
Epoch 5/5
782/782 [==============================] - 206s 264ms/step - loss: 4.0877 - accuracy: 0.1292
I had to downgrade tensorflow to get it to work on Macbook Pro M2:
pip install tensorflow-macos==2.9
pip install tensorflow-metal==0.5.0
I have been finished install Tensorflow env step by step from "https://developer.apple.com/metal/tensorflow-plugin/"
Tf is working!numpy is working! scipy is working!
but when i import sklearn package, have an error message like this:
ImportError: dlopen(/Users/mecilmeng/miniforge3/envs/tf/lib/python3.9/site-packages/scipy/spatial/qhull.cpython-39-darwin.so, 0x0002): Library not loaded: #rpath/liblapack.3.dylib
Referenced from: /Users/mecilmeng/miniforge3/envs/tf/lib/python3.9/site-packages/scipy/spatial/qhull.cpython-39-darwin.so
Reason: tried: '/Users/mecilmeng/miniforge3/envs/tf/lib/liblapack.3.dylib' (no such file), '/Users/mecilmeng/miniforge3/envs/tf/lib/liblapack.3.dylib' (no such file), '/Users/mecilmeng/miniforge3/envs/tf/lib/python3.9/site-packages/scipy/spatial/../../../../liblapack.3.dylib' (no such file), '/Users/mecilmeng/miniforge3/envs/tf/lib/liblapack.3.dylib' (no such file), '/Users/mecilmeng/miniforge3/envs/tf/lib/liblapack.3.dylib' (no such file), '/Users/mecilmeng/miniforge3/envs/tf/lib/python3.9/site-packages/scipy/spatial/../../../../liblapack.3.dylib' (no such file), '/Users/mecilmeng/miniforge3/envs/tf/bin/../lib/liblapack.3.dylib' (no such file), '/Users/mecilmeng/miniforge3/envs/tf/bin/../lib/liblapack.3.dylib' (no such file), '/usr/local/lib/liblapack.3.dylib' (no such file), '/usr/lib/liblapack.3.dylib' (no such file)
How to fix it?
pip list
Package Version
------------------------ -------------------
absl-py 0.10.0
aiohttp 3.8.1
aiosignal 1.2.0
anyio 3.5.0
appnope 0.1.2
argon2-cffi 20.1.0
astunparse 1.6.3
async-generator 1.10
async-timeout 4.0.1
attrs 21.4.0
Babel 2.9.1
backcall 0.2.0
beniget 0.3.0
bleach 4.1.0
blinker 1.4
Bottleneck 1.3.2
brotlipy 0.7.0
cached-property 1.5.2
cachetools 4.2.2
certifi 2021.10.8
cffi 1.15.0
charset-normalizer 2.0.4
click 8.0.3
cryptography 3.4.7
cycler 0.11.0
Cython 0.29.28
debugpy 1.5.1
decorator 5.1.1
defusedxml 0.7.1
dill 0.3.4
entrypoints 0.3
flatbuffers 2.0
fonttools 4.25.0
frozenlist 1.2.0
gast 0.4.0
google-auth 1.33.0
google-auth-oauthlib 0.4.1
google-pasta 0.2.0
googleapis-common-protos 1.54.0
grpcio 1.42.0
h5py 3.1.0
idna 3.3
importlib-metadata 4.8.2
ipykernel 6.4.1
ipython 7.31.1
ipython-genutils 0.2.0
jedi 0.18.1
Jinja2 3.0.2
joblib 1.1.0
json5 0.9.6
jsonschema 3.2.0
jupyter-client 7.1.2
jupyter-core 4.9.1
jupyter-server 1.13.5
jupyterlab 3.2.1
jupyterlab-pygments 0.1.2
jupyterlab-server 2.10.3
keras 2.8.0
Keras-Preprocessing 1.1.2
kiwisolver 1.3.1
libclang 13.0.0
Markdown 3.3.4
MarkupSafe 2.0.1
matplotlib 3.5.0
matplotlib-inline 0.1.2
mistune 0.8.4
multidict 5.2.0
munkres 1.1.4
nbclassic 0.2.6
nbclient 0.5.3
nbconvert 6.3.0
nbformat 5.1.3
nest-asyncio 1.5.1
networkx 2.6.3
notebook 6.4.6
numexpr 2.8.1
numpy 1.22.2
oauthlib 3.1.1
opencv-python 4.5.5.62
opt-einsum 3.3.0
packaging 21.3
pandas 1.3.5
pandocfilters 1.5.0
parso 0.8.3
pexpect 4.8.0
pickleshare 0.7.5
Pillow 9.0.1
pip 21.2.4
ply 3.11
prometheus-client 0.13.1
promise 2.3
prompt-toolkit 3.0.20
protobuf 3.19.1
ptyprocess 0.7.0
pyasn1 0.4.8
pyasn1-modules 0.2.8
pybind11 2.9.1
pycparser 2.21
Pygments 2.11.2
PyJWT 2.1.0
pyOpenSSL 21.0.0
pyparsing 3.0.4
pyrsistent 0.18.0
PySocks 1.7.1
python-dateutil 2.8.2
pythran 0.9.11
pytz 2021.3
pyzmq 22.3.0
requests 2.27.1
requests-oauthlib 1.3.0
rsa 4.7.2
scikit-learn 1.0.2
scipy 1.7.1
Send2Trash 1.8.0
setuptools 58.0.4
six 1.15.0
sklearn 0.0
sniffio 1.2.0
tensorboard 2.8.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.6.0
tensorflow-datasets 4.5.2
tensorflow-macos 2.8.0
tensorflow-metadata 1.6.0
tensorflow-metal 0.3.0
termcolor 1.1.0
terminado 0.13.1
testpath 0.5.0
tf-estimator-nightly 2.8.0.dev2021122109
threadpoolctl 2.2.0
tornado 6.1
tqdm 4.62.3
traitlets 5.1.1
typing-extensions 3.7.4.3
urllib3 1.26.8
wcwidth 0.2.5
webencodings 0.5.1
websocket-client 0.58.0
Werkzeug 2.0.2
wheel 0.35.1
wrapt 1.12.1
yarl 1.6.3
zipp 3.7.0
You can install using Rosetta2 Mode.
To work in Rosetta Mode:
If Rosetta 2 is not installed by default in your M1 Mac, then open the pre-installed Terminal app and run the following command:
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
Rosetta allows us to use apps built for Mac with intel chip.
Several CLI tools do not have native versions built for the new M1 architecture.
Enabling them on your native M1 Mac terminal can be frustrating.
Follow these steps to enable Rosetta:
Select the app(Terminal) in the Finder.
Right click on the app(Terminal) and select Get Info.
In General, check the Open using Rosetta check-box.
Close the Terminal Info.
Now when you quit the terminal and open it again.
If you haven't installed Rosetta yet, then it would prompt you to install it.
If the popup shows up, then click on Install button, then enter your user name and password to allow installation to proceed.
Close the Terminal and open again.
Now we have a special terminal that can install tools with Rosetta translation.
To verify that you are using a Rosetta terminal, run the following command and it should output i386:
arch
The native terminal without Rosetta would output arm64 for the above command.
Moving forward, all commands we ask you to execute should be done in Rosetta enabled terminal.
Uninstall arm64 brew
If you have installed brew in the past from the native terminal, it is likely that you have an arm64 build of brew. Having two different builds of brew can cause major problems as the packages with different builds will not be compatible with each other.
To avoid this problem you need to uninstall your current installation of arm64 brew.
You can check which build you have by running the following command:
which brew
If your installation of brew is the Intel build, then the command should output /usr/local/bin/brew. If that is the case you can skip installing brew and just update your current installation by running brew update.
If your output is /opt/homebrew then your installation of brew is the arm64 build.
You need to uninstall the arm64 build of brew by running the following command from the native terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"
Install Intel brew
Install Homebrew, which is the package manager:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once done, run the below command to ensure that we make use of the HEAD revision:
git -C $(brew --repository homebrew/core) checkout master
Now verify the installation of the brew command:
which brew
The command should output /usr/local/bin/brew, which is the expected path.
When attempting to install tensorflow on an ARM M1 MacBookPro, I am seeing the following issues:
% pip install tensorflow
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
After searching around, I found a package called tensorflow-macos which produces the following issues:
clang: error: the clang compiler does not support 'faltivec', please use -maltivec and include altivec.h explicitly
error: Command "gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DNPY_INTERNAL_BUILD=1 -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=3 -DHAVE_CBLAS -Ibuild/src.macosx-10.9-universal2-3.9/numpy/core/src/umath -Ibuild/src.macosx-10.9-universal2-3.9/numpy/core/src/npymath -Ibuild/src.macosx-10.9-universal2-3.9/numpy/core/src/common -Inumpy/core/include -Ibuild/src.macosx-10.9-universal2-3.9/numpy/core/include/numpy -Inumpy/core/src/common -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/Users/thing/dev/SOTAMoon/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -Ibuild/src.macosx-10.9-universal2-3.9/numpy/core/src/common -Ibuild/src.macosx-10.9-universal2-3.9/numpy/core/src/npymath -c numpy/core/src/multiarray/descriptor.c -o build/temp.macosx-10.9-universal2-3.9/numpy/core/src/multiarray/descriptor.o -MMD -MF build/temp.macosx-10.9-universal2-3.9/numpy/core/src/multiarray/descriptor.o.d -faltivec -I/System/Library/Frameworks/vecLib.framework/Headers -std=c99" failed with exit status 1
----------------------------------------
ERROR: Failed building wheel for numpy
Failed to build numpy
ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/a7/81/20d5d994c91ed8347efda90d32c396ea28254fd8eb9e071e28ee5700ffd5/h5py-3.1.0.tar.gz#sha256=1e2516f190652beedcb8c7acfa1c6fa92d99b42331cbef5e5c7ec2d65b0fc3c2 (from https://pypi.org/simple/h5py/) (requires-python:>=3.6). Command errored out with exit status 1: /Users/thing/dev/SOTAMoon/venv/bin/python3 /private/var/folders/8k/z291bhgd5gs06tp9b4j6_bb40000gn/T/pip-standalone-pip-8qa87uy0/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /private/var/folders/8k/z291bhgd5gs06tp9b4j6_bb40000gn/T/pip-build-env-bxy_nyoo/normal --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'numpy==1.12; python_version == "3.6"' 'numpy==1.19.3; python_version >= "3.9"' 'numpy==1.14.5; python_version == "3.7"' pkgconfig 'Cython>=0.29; python_version < "3.8"' 'Cython>=0.29.14; python_version >= "3.8"' 'numpy==1.17.5; python_version == "3.8"' Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement h5py~=3.1.0 (from tensorflow-macos) (from versions: 2.2.1, 2.3.0b1, 2.3.0, 2.3.1, 2.4.0b1, 2.4.0, 2.5.0, 2.6.0, 2.7.0rc2, 2.7.0, 2.7.1, 2.8.0rc1, 2.8.0, 2.9.0rc1, 2.9.0, 2.10.0, 3.0.0rc1, 3.0.0, 3.1.0, 3.2.0, 3.2.1, 3.3.0)
ERROR: No matching distribution found for h5py~=3.1.0
Unfortunately I couldn't work out a solution to the 'faltivec' issue. I also found a tensorflow package made by Apple that seems specifically geared for M1's, however going by this tutorial produces the following issues:
% pip install --upgrade --force --no-dependencies https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha3/tensorflow_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl
ERROR: tensorflow_addons_macos-0.1a3-cp38-cp38-macosx_11_0_arm64.whl is not a supported wheel on this platform.
After this, I am a bit stuck. I have upgraded pip to 21.1.3, and my python version is Python 3.9.6.
Tensorflow-macos and Tensorflow-metal Install
Currently, to harness the M1 GPU you need to install Tensorflow-macos and TensorFlow-metal as opposed to Tensorflow, the install steps are detailed here, they can be summarized as follows using mini-forge:
conda create -n tf python=3.8 -y
conda activate tf
conda install -c apple tensorflow-deps -y
# Navigate the issue with conda environments
# built against pre-macOS 11 SDK use (Just in case)
# this solves the Intel / M1 install issues:
SYSTEM_VERSION_COMPAT=0 pip install tensorflow-macos
SYSTEM_VERSION_COMPAT=0 pip install tensorflow-metal
to test all is well we can run:
#!/usr/bin/env bash
PYCMD=$(cat <<EOF
import tensorflow as tf
tf.config.list_physical_devices()
with tf.device('/GPU'):
a = tf.random.normal(shape=(2,), dtype=tf.float32)
b = tf.nn.relu(a)
print(a)
print(b)
EOF
)
python3 -c "$PYCMD" 2>/dev/null
the expected output for my test machine:
>./val.sh
Metal device set to: Apple M1
systemMemory: 16.00 GB
maxCacheSize: 5.33 GB
tf.Tensor([-0.4044231 0.08157467], shape=(2,), dtype=float32)
tf.Tensor([0. 0.08157467], shape=(2,), dtype=float32)
ok, everything is (assumed) to be working...
Side-Note: Package Install Issues:
One thing to note is that that packages that rely on tensorflow will try to install tensorflow as they will likely not have an explicit dependency on tensorflow-macos or tensorflow-metal.
When you install tensorflow dependent packages or code you'll likely have to review the requirements.txt file before running:
python3 pip install -r requirements.txt
The requirements.txt will try to install the tensorflow package, not the tensorflow-macosx or tensorflow-metal packages which will result in a host of issues if you run the requirements.txt file unchanged. That and explicit versions of packages == which can also cause problems.
Hopefully, this points you in the right direction in thinking about the hurdles involved in getting python to work with the Apple-M1 laptops using the TensorFlow metal plugin to harness the M1 GPU features.
Stay safe and well.
try
python3 -m pip install tensorflow-macos
python3 -m pip install tensorflow-metal
you may also need:
brew install hdf5
export HDF5_DIR=$(brew --prefix hdf5)
I've been struggling to install an older version of CUDA in a conda environment. In practice, I need to install TensorFlow 1.14 and CUDA 8.0, with the nvcc compiler.
This is what I've tried:
conda create -n tf114-cuda8 tensorflow-gpu=1.14 cudatoolkit=8.0 python=3.6
source activate tf114-cuda8
At this point, nvcc is not available, because it is not included with default conda installation. Thus, I ran:
conda install -c conda-forge nvcc_linux-64=9.2
..but nothing! Now I have nvcc under the environment directory: ~/venvs/conda/miniconda3/envs/tf114-cuda8/, but it seems it is not the right one? In fact, if I do:
nvcc-version
it returns:
nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2019 NVIDIA
Corporation Built on Sun_Jul_28_19:07:16_PDT_2019 Cuda compilation
tools, release 10.1, V10.1.243
What has gone wrong? Why is the nvcc version the 10.1? how can I install TensorFlow 1.14 with CUDA 8.0 and nvcc included?
I have a conda environment with PyTorch and Tensorflow, which both require CUDA 9.0 (~cudatoolkit 9.0 from conda). After installing pytorch with torchvision and the cudatoolkit (like they provided on their website) I wanted to install Tensorflow, the problem here is that I get this error:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: /
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failed
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- tensorflow==1.12.0 -> python[version='2.7.*|3.6.*']
- tensorflow==1.12.0 -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0']
Your python: python=3.5
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
The following specifications were found to be incompatible with your system:
- feature:/linux-64::__cuda==10.2=0
- feature:|#/linux-64::__cuda==10.2=0
Your installed version is: 10.2
If I run nvcc or nvidia-smi on my host or the activated conda environment, I get that I have installed CUDA 10.2, even though conda list shows me that cudatoolkit 9.0 is installed. Any solution to this?
EDIT:
When running this code sample:
# setting device on GPU if available, else CPU
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Using device:', device)
print()
#Additional Info when using cuda
if device.type == 'cuda':
print(torch.cuda.get_device_name(0))
print('Memory Usage:')
print('Allocated:', round(torch.cuda.memory_allocated(0)/1024**3,1), 'GB')
print('Cached: ', round(torch.cuda.memory_cached(0)/1024**3,1), 'GB')
print(torch.version.cuda)
I get this output:
GeForce GTX 1050
Memory Usage:
Allocated: 0.0 GB
Cached: 0.0 GB
9.0.176
So PyTorch does get the correct CUDA version, I just cant get tensorflow-gpu installed.
If I run nvcc or nvidia-smi on my host or the activated conda environment, I get that I have installed CUDA 10.2, even though conda list shows me that cudatoolkit 9.0 is installed. Any solution to this?
cudatoolkit doesn't ship with compiler (nvcc), thus when you run nvcc you start compiler from system wide installation. That's why it prints 10.2 istead of 9.0, and pytorch sees the local cudatoolkit.
anaconda / packages / cudatoolkit :
This CUDA Toolkit includes GPU-accelerated libraries, and the CUDA runtime for the Conda ecosystem. For the full CUDA Toolkit with a compiler and development tools visit https://developer.nvidia.com/cuda-downloads
From your comment above I understood that you are using python=3.5.6. So, first of all you should search for available tensorflow py35 builds using:
conda search tensorflow | grep py35
I have the following output:
tensorflow 1.9.0 eigen_py35h8c89287_1 pkgs/main
tensorflow 1.9.0 gpu_py35h42d5ad8_1 pkgs/main
tensorflow 1.9.0 gpu_py35h60c0932_1 pkgs/main
tensorflow 1.9.0 gpu_py35hb39db67_1 pkgs/main
tensorflow 1.9.0 mkl_py35h5be851a_1 pkgs/main
tensorflow 1.10.0 eigen_py35h5ed898b_0 pkgs/main
tensorflow 1.10.0 gpu_py35h566a776_0 pkgs/main
tensorflow 1.10.0 gpu_py35ha6119f3_0 pkgs/main
tensorflow 1.10.0 gpu_py35hd9c640d_0 pkgs/main
tensorflow 1.10.0 mkl_py35heddcb22_0 pkgs/main
As you can see there is no tensorflow 1.12.0 builds for py35, and that's why you are getting that error. You can try to inspect other conda channels, for example, conda-forge:
conda search tensorflow -c conda-forge | grep py35
But that wasn't helpful:
tensorflow 0.9.0 py35_0 conda-forge
tensorflow 0.10.0 py35_0 conda-forge
tensorflow 0.11.0rc0 py35_0 conda-forge
tensorflow 0.11.0rc2 py35_0 conda-forge
tensorflow 0.11.0 py35_0 conda-forge
tensorflow 0.12.1 py35_0 conda-forge
tensorflow 0.12.1 py35_1 conda-forge
tensorflow 0.12.1 py35_2 conda-forge
tensorflow 1.0.0 py35_0 conda-forge
tensorflow 1.1.0 py35_0 conda-forge
tensorflow 1.2.0 py35_0 conda-forge
tensorflow 1.2.1 py35_0 conda-forge
tensorflow 1.3.0 py35_0 conda-forge
tensorflow 1.4.0 py35_0 conda-forge
tensorflow 1.5.0 py35_0 conda-forge
tensorflow 1.5.1 py35_0 conda-forge
tensorflow 1.6.0 py35_0 conda-forge
tensorflow 1.8.0 py35_0 conda-forge
tensorflow 1.8.0 py35_1 conda-forge
tensorflow 1.9.0 eigen_py35h8c89287_1 pkgs/main
tensorflow 1.9.0 gpu_py35h42d5ad8_1 pkgs/main
tensorflow 1.9.0 gpu_py35h60c0932_1 pkgs/main
tensorflow 1.9.0 gpu_py35hb39db67_1 pkgs/main
tensorflow 1.9.0 mkl_py35h5be851a_1 pkgs/main
tensorflow 1.9.0 py35_0 conda-forge
tensorflow 1.10.0 eigen_py35h5ed898b_0 pkgs/main
tensorflow 1.10.0 gpu_py35h566a776_0 pkgs/main
tensorflow 1.10.0 gpu_py35ha6119f3_0 pkgs/main
tensorflow 1.10.0 gpu_py35hd9c640d_0 pkgs/main
tensorflow 1.10.0 mkl_py35heddcb22_0 pkgs/main
tensorflow 1.10.0 py35_0 conda-forge
So, the possible solutions are:
Install one of the older available tensorflow 1.10.0 gpu_py35 builds.
Switch to python 3.6.
conda search tensorflow | grep py36
...
tensorflow 1.11.0 gpu_py36h4459f94_0 pkgs/main
tensorflow 1.11.0 gpu_py36h9c9050a_0 pkgs/main
...
tensorflow 1.12.0 gpu_py36he68c306_0 pkgs/main
tensorflow 1.12.0 gpu_py36he74679b_0 pkgs/main
...
Note that versions >=1.13.1 doesn't support CUDA 9.
Use pip install inside conda env to install missing tensorflow build, because pip hosts more build combinations: Tested build configurations
Here is some best practices from Anaconda how to use pip w/ conda: Using Pip in a Conda Environment
The last option is to build your own missing conda package with conda-build
My experience is that even though the detected cuda version is incorrect by conda, what matters is the cudatoolkit version.
The actual problem for me was the incompatible python version.
E.g. You might have Python 3.7/3.8 but this version of tensorflow doesn't support that:
tensorflow==1.12.0 -> python[version='>=2.7,<2.8.0a0|>=3.6,<3.7.0a0']
Try an older conda environment or a newer tensorflow, the latest version before 2.0 is 1.15
If I haven't misunderstood, you installed the packages using the
conda install
from https://pytorch.org/get-started/locally/
I once had problems with the conda installation of PyTorch and Cuda: i solved by removing the packages installed with conda and re-installing it via pip.
If you are afraid to mess up the conda enviroment using pip, I suggest you to create another enviroment in order to test this solution.
Use conda to remove pytorch and cuda. See Removing Packages at Conda Managing packages
Install the cuda toolkit you need. Note that pytorch supports only cuda 9.2, 10.1 and 10.2, as you can see on the Pytorch download page.
If your OS is ubuntu 19, follow the CUDA instructions for ubuntu 18. Also note that not all gpus support the latest version of the toolkit for driver reasons (the 1050 should be recent enough to support them all, up to 10.1 sure because I used it).
Follow the instructions to install pytorch with the appropiate cuda support via pip at Pytorch download page. See Using pip in an enviroment at Conda Managing packages