Apple silicon Installation of Transformers

What follows is a ‘hint sequence’ to get Transformers working on Big Sur 11.1 @ Apple Silicon M1.
Please try it with most care, and consider it “AS IS” -it has been proven twice, but I cannot be responsible for any unintended behaviour-

  1. Install Xcode cmd line tool chain
    $ xcode-select --install

  2. Install homebrew
    /bin/bash -c "(curl -fsSL"

  3. …and a couple of utils. Rustup from source is the key to get Transformers working on M1.
    brew install vim wget brew install --build-from-source rustup-init

  4. Install miniforge -put it in a temp directory of your choice-
    wget bash

  5. refresh your env variables (run again the shell bash/zsh: effective while inelegant :stuck_out_tongue: )
    bash conda config --set auto_activate_base false && conda deactivate

  6. Download TensorFlow 2.4 from Apple M1 BUT DON’T INSTALL IT, YET!
    $ cd $HOME && git clone && cd tensorflow_macos/arm64

  7. Create a Conda (virtual) environment -and always restart a shell session-
    bash && conda create --name tf24transformers conda activate tf24transformers && conda install -y python=3.8.6
    $ conda install -y pandas matplotlib scikit-learn jupyterlab

  8. Install Apple Tensorflow (ATF)2.4. You’re already in arm64. (If not cd to $HOME/tensorflow_macos/arm64).

$ pip install --force pip==20.2.4 wheel setuptools cached-property six

7.2) Install the packages from Apple
$ pip install --upgrade --no-dependencies --force numpy-1.18.5-cp38-cp38-macosx_11_0_arm64.whl grpcio-1.33.2-cp38-cp38-macosx_11_0_arm64.whl h5py-2.10.0-cp38-cp38-macosx_11_0_arm64.whl tensorflow_addons-0.11.2+mlcompute-cp38-cp38-macosx_11_0_arm64.whl

7.3) Some dependencies…
$ pip install absl-py astunparse flatbuffers gast google_pasta keras_preprocessing opt_einsum protobuf tensorflow_estimator termcolor typing_extensions wrapt wheel tensorboard typeguard

7.4) Install ATF
$ pip install --upgrade --force --no-dependencies tensorflow_macos-0.1a1-cp38-cp38-macosx_11_0_arm64.whl

7.5) Refresh your shell once more and you are done
bash && conda activate tf24transformers python -m pip install --upgrade pip
pip install tokenizers transformers python -c “from transformers import pipeline; print(pipeline(‘sentiment-analysis’)(‘we love you’))”

[{‘label’: ‘POSITIVE’, ‘score’: 0.9998704791069031}]

Many thanks to Fabrice Daniel for the tutorial about AFT2.4.


1 Like

what’s up with step 2? What does it say?

this can't be that hard

Do you mean?
brew install vimwget

and then
brew install --build-from-source rustup-init

@emininno ?

How did you manage to install tokenizers? The tokenizers version required for transformers is not compatible with the native rust version. I got builds error when pip install tokenizers transformers

How did you get transformers to see the TensorFlow installation?

None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.