ML Notes

Hugging Face and Sentence Transformers on M1 Macs

Easy guide to Hugging Face and Sentence-Transformers on M1 with GPU-acceleration

James Briggs
2 min readJun 3, 2022

--

Photo by Dmitry Chernyshov on Unsplash

Prerequisites

Python Environment

We first setup a new Python environment that uses osx-arm64 and install the latest version(s) of PyTorch.

  • Open terminal
  • Create new environment with conda create -n ml python=3.9 anaconda
  • [Alternative]: If using the non-M1 distribution of Anaconda use CONDA_SUBDIR=osx-arm64 conda create -n ml python=3.9 -c conda-forge
  • Switch to new environment with conda activate ml
  • Set the sub-directory variable with conda env config vars set CONDA_SUBDIR=osx-arm64
  • Reactivate the environment with conda activate followed by conda activate ml

PyTorch Installation

GPU-acceleration on the new M1 chips is a new feature for PyTorch. For this, we need PyTorch v1.12 or later, as of 3rd June 2022 this is only available via the PyTorch nightly release.

--

--

James Briggs
James Briggs

Written by James Briggs

Freelance ML engineer learning and writing about everything. I post a lot on YT https://www.youtube.com/c/jamesbriggs

Responses (2)