- Quick start boilerplate for GPU acceleration working with Tensorflow and PyTorch on Macbook Air M1 (ARM-64 architecture)
- Uses Metal to access the GPU capabilities
- Doesn't require Conda / Miniforge
- Doesn't need a Jupyter notebook
- Works with Python 3.8
- Dependencies installed via Pyenv and Poetry
- Install Homebrew
- Run
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
- Run
- Run
brew install hdf5 pyenv pyenv-virtualenv
- Run
export HDF5_DIR="$(brew --prefix hdf5)";
- Add the following lines to your
~/.zprofile
file if using Zsh or~/.bash_profile
file if using Bash (you can check Zsh vs Bash by typingecho $SHELL
in your terminal):
export PATH="$HOME/.poetry/bin:$PATH";
export PYENV_VIRTUALENV_DISABLE_PROMPT=0;
eval "$(pyenv init -)";
eval "$(pyenv virtualenv-init -)";
- Restart your terminal or reload the profile, e.g.
source ~/.zprofile
orsource ~/.bash_profile
- Install Poetry, by running
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
- Install Python 3.8 into Pyenv, by running
pyenv install 3.8.10
- Create a Pyenv virtual environment to work in, by running
pyenv virtualenv 3.8.10 tfexperiment
- Activate the Pyenv virtual environment, by running
pyenv activate 3.8.10/envs/tfexperiment
- Check that
python --version
says3.8.10
andwhich python
says something like/Users/.../.pyenv/shims/python
- Finally,
cd
to the directory with thepyproject.toml
file, then runpoetry install
- After following steps above in "Before anything else" section, running
poetry run tf
should execute the code insrc/tf.py
- If you want only PyTorch and its dependencies, check out the
torch
branch - Run
poetry install
to install the Nightly build of PyTorch - Run
poetry run torch
to check if everything is working - Modify
tensorexperiments/torch.py
as needed - You will want to use
torch.device('mps')
to leverage GPU capabilities
- H5Py
- If you have an issue with H5Py:
- Make sure you have run
export HDF5_DIR="$(brew --prefix hdf5)";
- install with
pip install --no-binary=h5py h5py
- Make sure you have run
- If you have an issue with H5Py: