Running Tensor flow on MacBook Pro M1 Metal.
https://youtu.be/_1CaUOHhI6U
% conda update --all -y
>> command not found: conda
curl
numpy
matplotlib
jupyter_core
protobuf
sqlite
ipython
jupyterlab
jupyter
notebook
matplotlib
pip
pandas
pillow
scikit-learn
python-3.9
$ conda activate base$ conda update -n base -c defaults conda$ conda update --all -y
cd $REPO // the directory you want as a base of your project (e.g. in GitHub directory)
jupyter-lab
% python --version
Python 3.9.13
$ conda create -n py_39_tf python=3.9 tensorflow -y
$ conda info --envs
% conda info --envs
# conda environments:
#
base * /Users/uki/opt/anaconda3
py_39_tf /Users/uki/opt/anaconda3/envs/py_39_tf
% conda activate py_39_tf
(py_39_tf) uki ~ %
$ python -m ipykernel install --user --name py_36_tf --display-name "Python 3.6 (tensorflow)"
$ ls -alt ~/Library/Jupyter/kernels/
$ rm -r ~/Library/Jupyter/kernels/my_old_kernel_name
uki@uki-p6710f:~$ lspci | grep -i nvidia
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1c82 (rev a1)
01:00.1 Audio device: NVIDIA Corporation Device 0fb9 (rev a1)
uki@uki-p6710f:~$ uname -m && cat /etc/*release
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
uki@uki-p6710f:~$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
uki@uki-p6710f:~$ lspci | grep -i nvidia
01:00.0 VGA compatible controller: NVIDIA Corporation Device 1c82 (rev a1)
01:00.1 Audio device: NVIDIA Corporation Device 0fb9 (rev a1)
uki@uki-p6710f:~$ uname -m && cat /etc/*release
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
NAME="Ubuntu"
VERSION="16.04.1 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.1 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
uki@uki-p6710f:~$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ conda env create --file .../conda_environment.yml
$ conda info --envs
$ source activate py352_tf_gpu
$ python -m ipykernel install --user --name py352_tf_gpu --display-name "conda env py352_tf_gpu"$ jupyter notebook
$ conda env create --file .../conda_environment.yml
$ conda info --envs
$ source activate py352_tf_gpu
$ python -m ipykernel install --user --name py352_tf_gpu --display-name "conda env py352_tf_gpu"$ jupyter notebook
$ echo $DYLD_LIBRARY_PATH/usr/local/cuda/lib:
$ echo $CUDA_HOME/Developer/NVIDIA/CUDA-8.0/
$ sudo easy_install pip
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl
$ echo $TF_BINARY_URL https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl
$ sudo pip3 install --upgrade $TF_BINARY_URL Password:The directory '/Users/ukilucas/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.The directory '/Users/ukilucas/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.Collecting tensorflow-gpu==1.0.0 from https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl Downloading https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl (89.0MB) 100% |████████████████████████████████| 89.0MB 8.8kB/s Requirement already up-to-date: numpy>=1.11.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Requirement already up-to-date: wheel>=0.26 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Requirement already up-to-date: six>=1.10.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Requirement already up-to-date: protobuf>=3.1.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Collecting setuptools (from protobuf>=3.1.0->tensorflow-gpu==1.0.0) Downloading setuptools-34.2.0-py2.py3-none-any.whl (389kB) 100% |████████████████████████████████| 399kB 2.0MB/s Requirement already up-to-date: appdirs>=1.4.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu==1.0.0)Requirement already up-to-date: packaging>=16.8 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu==1.0.0)Requirement already up-to-date: pyparsing in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow-gpu==1.0.0)Installing collected packages: tensorflow-gpu, setuptools Found existing installation: tensorflow-gpu 0.12.1 Uninstalling tensorflow-gpu-0.12.1: Successfully uninstalled tensorflow-gpu-0.12.1 Found existing installation: setuptools 34.1.1 Uninstalling setuptools-34.1.1: Successfully uninstalled setuptools-34.1.1Successfully installed setuptools-34.2.0 tensorflow-gpu-1.0.0(tensorflow_gpu) uki@UkiPEsMcBookPro 192.168.1.24 19:44 dev $
(tensorflow_gpu) $ jupyter notebook
import tensorflow as tf
import time
from tensorflow.python.client import device_lib
def get_available_CPU_GPU():
devices = device_lib.list_local_devices()
#return [x.name for x in devices if x.device_type == 'CPU']
return [x.name for x in devices ]
print(get_available_CPU_GPU())
['/cpu:0', '/gpu:0']
start = timeit.timeit()
print ("starting")with tf.device('/gpu:0'):
# [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print (sess.run(c))
end = timeit.timeit()
print ("elapsed", end - start)starting
[[ 22. 28.]
[ 49. 64.]]
elapsed -0.003607149003073573
$ echo $DYLD_LIBRARY_PATH/usr/local/cuda/lib:
$ echo $CUDA_HOME/Developer/NVIDIA/CUDA-8.0/
$ sudo easy_install pip
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl
$ echo $TF_BINARY_URL https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl
$ sudo pip3 install --upgrade $TF_BINARY_URL Password:The directory '/Users/ukilucas/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.The directory '/Users/ukilucas/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.Collecting tensorflow-gpu==1.0.0 from https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl Downloading https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-1.0.0-py3-none-any.whl (89.0MB) 100% |████████████████████████████████| 89.0MB 8.8kB/s Requirement already up-to-date: numpy>=1.11.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Requirement already up-to-date: wheel>=0.26 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Requirement already up-to-date: six>=1.10.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Requirement already up-to-date: protobuf>=3.1.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from tensorflow-gpu==1.0.0)Collecting setuptools (from protobuf>=3.1.0->tensorflow-gpu==1.0.0) Downloading setuptools-34.2.0-py2.py3-none-any.whl (389kB) 100% |████████████████████████████████| 399kB 2.0MB/s Requirement already up-to-date: appdirs>=1.4.0 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu==1.0.0)Requirement already up-to-date: packaging>=16.8 in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu==1.0.0)Requirement already up-to-date: pyparsing in /Users/ukilucas/anaconda3/envs/tensorflow_gpu/lib/python3.5/site-packages (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow-gpu==1.0.0)Installing collected packages: tensorflow-gpu, setuptools Found existing installation: tensorflow-gpu 0.12.1 Uninstalling tensorflow-gpu-0.12.1: Successfully uninstalled tensorflow-gpu-0.12.1 Found existing installation: setuptools 34.1.1 Uninstalling setuptools-34.1.1: Successfully uninstalled setuptools-34.1.1Successfully installed setuptools-34.2.0 tensorflow-gpu-1.0.0(tensorflow_gpu) uki@UkiPEsMcBookPro 192.168.1.24 19:44 dev $
(tensorflow_gpu) $ jupyter notebook
import tensorflow as tf
import time
from tensorflow.python.client import device_lib
def get_available_CPU_GPU():
devices = device_lib.list_local_devices()
#return [x.name for x in devices if x.device_type == 'CPU']
return [x.name for x in devices ]
print(get_available_CPU_GPU())
['/cpu:0', '/gpu:0']
start = timeit.timeit()
print ("starting")with tf.device('/gpu:0'):
# [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print (sess.run(c))
end = timeit.timeit()
print ("elapsed", end - start)starting
[[ 22. 28.]
[ 49. 64.]]
elapsed -0.003607149003073573
['/cpu:0']
Currently, I can see and execute only on CPU.
MacBook Pro i7 Late 2013Device 0: "GeForce GT 750M" CUDA Driver Version /Runtime Version 8.0 / 8.0 CUDA Capability Major/Minor version number: 3.0Total amount of global memory: 2048 MBytes (2147024896 bytes)( 2) Multiprocessors,(192) CUDA Cores/MP: 384 CUDA Cores GPUMax Clock rate: 926 MHz (0.93 GHz)Memory Clock rate: 2508 Mhz Memory Bus Width: 128-bit L2Cache Size: 262144 bytes
http://osxdaily.com/2017/01/08/disable-gpu-switching-macbook-pro/
Still not working with TensorFlow
start = timeit.timeit()
print ("starting")
with tf.device('/cpu:0'):
# [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print (sess.run(c))
end = timeit.timeit()
print ("elapsed", end - start)
starting [[ 22. 28.] [ 49. 64.]] elapsed -0.0033593010011827573
['/cpu:0']
Currently, I can see and execute only on CPU.
MacBook Pro i7 Late 2013
Device 0: "GeForce GT 750M" CUDA Driver Version /
Runtime Version 8.0 / 8.0 CUDA Capability Major/Minor version number: 3.0
Total amount of global memory: 2048 MBytes (2147024896 bytes)
( 2) Multiprocessors,
(192) CUDA Cores/MP: 384 CUDA Cores GPU
Max Clock rate: 926 MHz (0.93 GHz)
Memory Clock rate: 2508 Mhz Memory Bus Width: 128-bit L2
Cache Size: 262144 bytes
http://osxdaily.com/2017/01/08/disable-gpu-switching-macbook-pro/
Still not working with TensorFlowstart = timeit.timeit()
print ("starting")
with tf.device('/cpu:0'):
# [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
# Creates a session with log_device_placement set to True.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
# Runs the op.
print (sess.run(c))
end = timeit.timeit()
print ("elapsed", end - start)
starting
[[ 22. 28.]
[ 49. 64.]]
elapsed -0.0033593010011827573
bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip install /tmp/tensorflow_pkg/tensorflow-0.6.0-py2-none-any.whl
bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer
bazel build -c opt --config=cuda //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip install /tmp/tensorflow_pkg/tensorflow-0.6.0-py2-none-any.whl$ conda install -c conda-forge tensorflow
Fetching package metadata .........
Solving package specifications: ..........
Package plan for installation in environment /Users/ukilucas/anaconda3:
The following packages will be UPDATED:
protobuf: 3.0.0-py35_0 conda-forge --> 3.1.0-py35_0 conda-forge
tensorflow: 0.11.0-py35_0 conda-forge --> 0.12.1-py35_1 conda-forge
Proceed ([y]/n)? y
Unlinking packages ...
[ COMPLETE ]|#####################| 100%
Linking packages ...
[ COMPLETE ]|#####################| 100%
$
$ python --version
Python 3.6.0 :: Continuum Analytics, Inc.
$ conda create -n tensorflow python=3.5
$ conda install python=3.5
$ conda install -c conda-forge tensorflow
Fetching package metadata .........
Solving package specifications: ..........
Package plan for installation in environment /Users/ukilucas/anaconda3:
The following packages will be UPDATED:
protobuf: 3.0.0-py35_0 conda-forge --> 3.1.0-py35_0 conda-forge
tensorflow: 0.11.0-py35_0 conda-forge --> 0.12.1-py35_1 conda-forge
Proceed ([y]/n)? y
Unlinking packages ...
[ COMPLETE ]|#####################| 100%
Linking packages ...
[ COMPLETE ]|#####################| 100%
$
$ python --version
Python 3.6.0 :: Continuum Analytics, Inc.
$ conda create -n tensorflow python=3.5
$ conda install python=3.5