Installing Tensorflow with Keras GPU for Mac M1/M2 using Conda

Posted by

How to Install Tensorflow Keras GPU for Mac M1/M2 with Conda

If you have a Mac with an M1 or M2 chip and want to take advantage of the GPU capabilities for running Tensorflow Keras, using Conda is the recommended way to install everything you need. Follow these steps to set up your environment and get Tensorflow Keras running on your Mac.

Step 1: Install Miniforge

Miniforge is a Conda distribution that is optimized for M1/M2 chips. First, download and install Miniforge from the official website. Make sure to select the appropriate version for your architecture.

Step 2: Create a Conda Environment

Once Miniforge is installed, open a terminal and create a new Conda environment for your Tensorflow Keras setup. You can do this by running the following command:

conda create -n tf-gpu python=3.8

This will create a new Conda environment called tf-gpu with Python 3.8 as the default Python version.

Step 3: Activate the Environment

Once the environment is created, you can activate it using the following command:

conda activate tf-gpu

Step 4: Install Tensorflow and Keras

Now that the environment is activated, you can install Tensorflow and Keras with GPU support using the following command:

conda install -c anaconda tensorflow-gpu keras-gpu

This will install the necessary packages for Tensorflow and Keras with GPU support in your Conda environment.

Step 5: Test the Installation

To ensure everything is working correctly, you can run a simple test script that uses Tensorflow Keras with GPU support. Create a new Python script with the following contents and run it:

import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))

If everything is set up correctly, you should see output indicating that a GPU device is available for use with Tensorflow Keras.

Conclusion

By following these steps, you can install Tensorflow Keras with GPU support on your Mac with an M1/M2 chip using Conda. This will enable you to take advantage of the GPU capabilities for training and running deep learning models, providing a significant performance boost for your machine learning tasks.

0 0 votes
Article Rating
26 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@emirhankaplan2632
6 months ago

THANK YOU SIR!

@marttiarminen4349
6 months ago

Hi, I keep getting this error when running the last part:
#print(f"Keras Version: {tensorflow.keras.__version__}")
AttributeError: module 'tensorflow.keras' has no attribute '__version__'

@ilkot1234
6 months ago

for those who can't find the yml file I just copy paste from the video – open a new file in a text editor. save below content as tools.yml
the rest is the same. it installs the latest versions except python, a thing to consider.

channels:
– apple
– conda-forge
dependencies:
– python=3.10
– pip>=19.0
– jupyter
– scikit-learn
– scipy
– pandas
– pandas-datareader
– matplotlib
– pillow
– tqdm
– requests
– h5py
– pyyaml
– flask
– boto3
– ipykernel
– pip:
– tensorflow-macos
– tensorflow-metal
– bayesian-optimization
– gym
– kaggle

@ClaireWang-nt7vy
6 months ago

Thank you for this useful video! However, the page to the yaml is not found so I couldn't download it.

@MouaadAGOURRAM
6 months ago

Thank you for sharing your experience. I've encountered an issue where, despite installing TensorFlow GPU, the model compiles using only the CPU without any notification that it's utilizing the GPU. If anyone has faced this problem and discovered a solution, I would greatly appreciate it if you could share it with me.

@Yahyaahmed0
6 months ago

anyone know how much storarge this whole installation will take?

@al.d9592
6 months ago

Hi there! unfortunately the YAML file is no longer in your repo

@ttyrone626
6 months ago

If y’all was smart yall would just screenshot the command in the video. The link was for the commands. That are already in the vid

@pramodk4565
6 months ago

I cant find the yml file😊

@user-ve4qm5kb4e
6 months ago

This .yml file is not available in the given git branch, even not the whole repo

@yauhooi
6 months ago

I tried to get hold of the yaml file – the link no longer works.

@fj0n452
6 months ago

Thank you very much for this video. It helped me a lot.

@AlyssonJalles
6 months ago

The git links are broken

@sawyerluoliu9781
6 months ago

tools.yml' file not found, how to solve this problem? I'm still struggling😭

@Dani-hh3qd
6 months ago

The github link is not active

@DeLux320
6 months ago

I followed your instructions, but I am getting GPU is NOT AVAILABLE … ?

@anneryan4051
6 months ago

The Github links above say "not found"

@krishpatel8342
6 months ago

There is no repository as of now in your github link. I installed it a year ago using your previous tutorial which worked like a charm before but now i just cannot do it. I tried everything and I am in the arm's version only ( I tried reinstalling everything, creating new environment, working on main environment, i even from the video made that yml file which worked on terminal but doesn't work in my notebook it just doesn't) and i need my mac's gpu for sure for the project i am working on. If anyone can help me it would be a big help.

and my error is as follows
dlopen(/Users/my_file_path/lib/python3.10/site-packages/tensorflow-plugins/libmetal_plugin.dylib, 0x0006): symbol not found in flat namespace '__ZN10tensorflow8internal10LogMessage16VmoduleActivatedEPKci'

@user-yp4rz7tf2u
6 months ago

There is a 404 Not found error in the link you gave