Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Apple Silicon [Work In Progress] #23

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vi3itor
Copy link
Contributor

@vi3itor vi3itor commented Jul 11, 2022

Hi @ageron,

I've recently got a machine with Apple Silicon and I tried running the notebooks on it natively. Given the official support, it only required to install Miniforge instead of Miniconda and make a few changes to the environment file:

--- a/environment.yml
+++ b/environment-apple-silicon.yml
 channels:
+  - apple
   - conda-forge
-  - defaults
 dependencies:
...
   - numexpr=2.8  # used only in the Pandas tutorial for numerical expressions
-  - numpy=1.22  # Powerful n-dimensional arrays and numerical computing tools
+  - numpy=1.21  # Powerful n-dimensional arrays and numerical computing tools
   - pandas=1.4  # data analysis and manipulation tool
...
   - scipy=1.8  # scientific/technical computing library
+  - tensorflow-deps=2.8  # TensorFlow dependencies from apple channel
   - tqdm=4.62  # a progress bar library
...
   - pip:
     - keras-tuner~=1.1.2  # used in chapters 10 and 19 for hyperparameter tuning
-    - tensorboard-plugin-profile~=2.5.0  # profiling plugin for TensorBoard
+    - tensorboard-plugin-profile~=2.8.0  # profiling plugin for TensorBoard
     - tensorboard~=2.8.0  # TensorFlow's visualization toolkit
     - tensorflow-hub~=0.12.0  # trained ML models repository, ready to use
-    - tensorflow-serving-api~=2.8.0  # or tensorflow-serving-api-gpu if gpu
-    - tensorflow~=2.8.0  # Deep Learning library
-    - transformers~=4.16.2  # Natural Language Processing lib for TF or PyTorch
+    # - tensorflow-serving-api~=2.8.0 # used only in chapter 19, should be manually installed by `pip install --no-deps tensorflow-serving-api~=2.8.0`
+    - tensorflow-macos~=2.8.0 # Deep Learning library for Apple Silicon
+    - tensorflow-metal~=0.5.0 # To accelerate training with Metal on Mac GPUs
+    - transformers~=4.16.2  # used only in chapter 16: Natural Language Processing lib for TF or PyTorch, on Apple Silicon requires tokenizers to be built from sources, so rust compiler should be installed
     - urlextract~=1.5.0  # optionally used in chapter 3, exercise 4

Also, to install transformers for Chapter 16 it requires to build one of its dependencies tokenizers, so rust should be also installed. According to the open issue in tokenizers, they will provide binary wheels as soon as Apple Silicon VMs are available on GitHub, so the rust dependency might be gone soon.

As for Chapter 19, tensorflow-serving-api has to be installed without dependencies (otherwise it uninstalls tensorflow-macos and can not proceed with installing tensorflow). Also, arm64-based docker image should be used (the source code is available here). I expect there will be a few changes to other notebooks, but the notebooks for the first 11 chapters run without any issues.

In this draft PR, I added the instructions to INSTALL.md on how to set up the environment, updated Chapter 19 notebook, and created environment-apple-silicon.yml.

What do you think about having several .yml files for conda environments?

  • environment.yml - for the base case,
  • environment-apple-silicon.yml - specifically for Apple Silicon,
  • environment-gpu.yml (or even better environment-nvidia-gpu.yml) for NVidia GPUs with Compute Capability, which should work well both on Linux and Windows, as I explained here.

Only I'm not sure if the last two files should be stored in the root of the repository or in a separate directory, such as extra-conda-envs?

@mervinTEE
Copy link

wow. this is fantastic. I was having some issues trying to follow through the setup on M1 Mac. The suggested instructions were very clear and helped to resolve the issue that I encountered.

@ageron
Copy link
Owner

ageron commented Sep 27, 2022

Hi @vi3itor ,

Oh wow, this is really great, thanks so much! 👍 I'm so sorry I missed this PR, I was traveling in France this summer, and I had quite a bit of catching up to do when I got back, it looks like I wasn't careful enough.

Sadly, I don't have a MacBook with Apple silicon, so I can't test this, but if you can confirm that it still works, I'm happy to merge your PR. There seems to be a conflict in the notebook 19, but I expect it won't be too hard to handle.

Note that I've recently updated all libraries in environment.yml, and I've tested it on a Windows 2020 Server VM on Google Cloud, and it worked fine with and without a GPU, so I don't think we need a dedicated environment-gpu.yml for the moment. I've recorded a video of the whole installation process, I think I'll post it on YouTube in the next few days.

However, an environment-apple-silicon.yml would definitely be most useful. I think it can live at the root.

Side note: I'm considering dropping requirements.txt, since it's not used anywhere, and anyone using it must install a bunch of libraries. What do you think?

@vi3itor
Copy link
Contributor Author

vi3itor commented Sep 28, 2022

Hi @ageron,

Thanks for getting back to me. Right after drafting this PR, I became a dad and had no free time to finish this PR and send a couple more. But things are returning to normal, so I will have an opportunity to update libraries, fix conflicts, and test the rest of the notebooks in the nearest future.

As for the requirements.txt, although I prefer to install as few additional tools as possible and try using vanilla pip as much as I can (especially for small projects) since it's shipped with Python, I agree that you should drop the support of requirements.txt in this repository. As you mentioned, it requires additional manual installations, especially for the machines with GPU(s).

@ageron
Copy link
Owner

ageron commented Sep 29, 2022

Wow, congratulations Victor, that's really life-changing! 👍 Having a child really changes your life for the better. And it only gets better over time, you're in for a wonderful ride!

Thanks so much for all your contributions for this project and for my book, your help is truly amazing, I'm very grateful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants