This is my personal list of to-do things for a new Macbook.
👉 My dockerfiles on Github.
<aside> ☝ Updated on March 22, 2022 : There is no way to install Tensorflow with Docker on Mac M1.
</aside>
<aside> ☝ For simplicity, use Lightning AI (instead of Google Colab).
</aside>
# Install XCode (from Appstore)
# Install XCode Command Line Tolls
xcode-select --install
# Download & install miniforge3
# <https://github.com/conda-forge/miniforge>
# (Choose "MacOSX-arm64" version)
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
# Restart terminal and check
which python
# /Users/thi/miniforge3/bin/python
which pip
# /Users/thi/miniforge3/bin/pip
# Init conda with zsh?
conda init zsh
source ~/.zshrc
<aside> ☝ Updated on December 5, 2023: Introducing Accelerated PyTorch Training on Mac | PyTorch
</aside>
Make sure the package on anaconda supports osx-arm64
and try:
pip3 install torch torchvision
# Verification
import torch
x = torch.rand(5, 3)
print(x)
# Return
tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])
👉 Getting Started with tensorflow-metal PluggableDevice | Apple Official doc (required macOS 12.0+)
# Create virtual env
conda create -n ds-tf2.5 python=3.10
conda activate ds-tf2.5
# Install Tensorflow
python -m pip install tensorflow
# (tf <= 2.12)
python -m pip install tensorflow-macos
# Install metal plugin
python -m pip install tensorflow-metal
python
# In python environement
import tensorflow as tf
print(tf.__version__)
Or checking the working of GPU, CPU,...
# Jupyter Notebook
jupyter lab
Then in the notebook,
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=False)
model.compile(optimizer="adam", loss=loss_fn, metrics=["accuracy"])
model.fit(x_train, y_train, epochs=5, batch_size=64)