Boilerplate for GPU-Accelerated TensorFlow and PyTorch code on M1 Macbook
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install hdf5 pyenv pyenv-virtualenv
export HDF5_DIR="$(brew --prefix hdf5)";
~/.zprofile
file if using Zsh or ~/.bash_profile
file if using Bash (you can check Zsh vs Bash by typing echo $SHELL
in your terminal): export PATH="$HOME/.poetry/bin:$PATH";
export PYENV_VIRTUALENV_DISABLE_PROMPT=0;
eval "$(pyenv init -)";
eval "$(pyenv virtualenv-init -)";
source ~/.zprofile
or source ~/.bash_profile
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
pyenv install 3.8.10
pyenv virtualenv 3.8.10 tfexperiment
pyenv activate 3.8.10/envs/tfexperiment
python --version
says 3.8.10
and which python
says something like /Users/.../.pyenv/shims/python
cd
to the directory with the pyproject.toml
file, then run poetry install
poetry run tf
should execute the code in src/tf.py
torch
branchpoetry install
to install the Nightly build of PyTorchpoetry run torch
to check if everything is workingtensorexperiments/torch.py
as neededtorch.device('mps')
to leverage GPU capabilitiesexport HDF5_DIR="$(brew --prefix hdf5)";
pip install --no-binary=h5py h5py