TensorFlow on M1/M2 (Apple Silicon) - How to install TensorFlow on Macbook in 10 minutes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
foreign [Music] I hope all of you are doing fine 2023 has just arrived and there are times where I feel that the computation power that I have locally isn't sufficient for me which is where I decided to upgrade to the new Macbook Air M2 MacBook Air M1 has very fond memories which is the previous laptop that I used it is extremely useful for day-to-day tasks it is also extremely useful for your data science workflows which is where now I decided to upgrade to MacBook Air M2 so that I can utilize the power of the improved gpus as well as work on my day-to-day task more efficiently in this video I'll show you a step-by-step process on how to install tensorflow on MacBook Air M1 and M2 basically if you have any MacBook with the new chips that is the M1 or M2 chips this entire process will kind of hold true for you what you will get is the amazing CPU and GPU performance of the new Macbook devices so without wasting any further time let's kick start the video the new laptops that is the MacBook Air MacBook Pros and even the Mac minis which are powered by Apple's own silicon all of these are kind of standing out in terms of performance this CPU performance is Top Notch but the GPU performance will blow your mind and all of this is happening at a very low power consumption with the introduction out of the way let me start by installing the necessary things that you require to start using tensorflow on MacBook Air M1 or M2 I'll first install Python and I'll use the Anaconda distribution for installing python so this is the website you just have to search for Anaconda python download and you would be redirected to this particular site once you've reached the website all you have to do is you have to reach to the Mac OS section in the installation section as well you have multiple versions available I'll go forward and select the 64-bit M1 command line installer which is 472 MB in our case so I'll quickly download this particular file now my file is in the download section all I have to do is I have to open up the terminal navigate to the downloads folder which is something that I achieve using CD space downloads just to check if the file is present in the downloads folder or not I'll type the command LS hyphen Al and that will give me the list of all the files that are present in the downloads folder so as you can clearly see the file is present now in order to install Anaconda all I have to do is run the command bash space anaconda and the file name would follow if you press the tab button before starting the recording for this particular video I had already installed Anaconda so technically if I type in the command conda list it will give me all the packages that are installed in this particular Anaconda distribution so as you can clearly see all the packages are there with me up and running just to be more clear what I'll do is I'll type in the command python so I have Python 3.9.13 and what I'll do is I'll import some modules to check if I have python with me or not so I'll kick start the activity by importing numpy SNP and the command runs perfectly fine that means I have the Anaconda distribution up and running and now I'll exit the python prompt the next thing that you require in order to execute the entire process successfully is xcode what exactly is xcode well xcode is Apple's integrated development environment or an IDE for Mac OS which is used to develop software for Mac OS iOS iPad OS and the others that are there so essentially for all the installations to be in place you require xcode now the way you install xcode is xcode hyphen select space double hyphen install so this is the command that you have to enter this process will take good amount of time so you'll have to be patient with the entire process the pop-up window says that the software has been installed so we have xcode in our setup so we are good to move forward as well so let's move forward now is the stage where you start installing tensorflow dependencies for your MacBook Air M1 or so by default it would have and the first time so if Anaconda is working for you it will give me the exact location of the installation of anaconda So currently this is the installation folder I'll have to use this installation folder and then go forward and install tensorflow I can also create an environment and do the entire process again but I want tensorflow to be part of my base installation itself which is where I'm doing this so what I do is I kind of enter the directory where Anaconda is present which is CD space users bhavish part and Anaconda 3 so let me press enter after this now we'll start installing the tensorflow dependencies the command that I'll be using for installing tensorflow dependencies is conda space install space hyphen c space appen space tensorflow hyphen dips so all of the dependencies that are required for tensorflow to run on Apple silicon which would be kind of installed using this particular command it says do you want to proceed I type in y and I'll go ahead with the installation now the dependencies have been installed the next thing that I'll require is basically tensorflow so what I'll do is I'll type in the command pip install tensorflow hyphen Mac OS so and I'll press enter I also require tensorflow's metal plugin which is something that I'll achieve using the command pip install tensorflow hyphen metal and I'll press enter so this has also been installed a lot of developers stop at this point which is where the errors start creeping in so I would urge you to watch the entire video so that you are able to successfully run tensorflow on your MacBook Air M1 or M2 device although you have Anaconda installed you have tensorflow and the other dependencies installed there is one mistake that generally happens which is compatibility issues with respect to individual libraries and tensorflow for GPU which is where you will have to upgrade various libraries so that there is compatibility between tensorflow on GPU as well as your python installation so what you require is you have to upgrade numpy the way you do that is PIP install nump by hyphen hyphen upgrade then you will have to upgrade pandas I have to upgrade matplotlib I have to upgrade scikit-learn I have to upgrade scipy and finally I also have to upgrade plotly once these upgrades are done now let's check if I can use tensorflow on my MacBook Air M1 or M2 I have a Macbook M2 so I'll firstly quickly start python Let Me Now quickly check the platform that python is running on so I'll quickly type in import platform and I'll call the function platform from platform so I'll say platform dot platform and it Returns the output which is Mac OS 12.6.2 arm 64 arms 64-bit so so this is the current platform that I'm utilizing so it's basically an arm 64 architecture on which the entire Python program is running now I'll go forward and import tensorflow stf let me check the tensorflow version as well so the current version that I'm on is 2.11 just to check if I'm using the GPU or not I'll type in the command GPU equal to length of pf.config dot list underscore physical underscore devices and inside the bracket will be GPU again so let me press enter before pressing enter will the list give me a value greater than 0 is what I want to check if this entire thing is running on a GPU then this value of GPU would be true so let me check my assumption let me start by typing in GPU oh sorry I made a goof up I I had GPU in all gaps so I kind of retype GPU in small letters it simply says that tensorflow is utilizing the GPU so this is amazing right let us kind of pick that particular section of code which is tf.config.list physical devices paste it as a new command and press enter so it says physical device and name of the physical device which is a GPU so this is it guys we've successfully installed tensorflow the GPU version on MacBook Air M2 this will work on any Arm based MacBook devices I hope you found this video informative and I'm assuming you are now able to run tensorflow on your GPU based MacBook Air thank you so much for watching the video and before I end it would be really motivating if you can press the Subscribe button and also press the Bell icon to be notified for amazing videos on data science and machine learning thank you so much for watching the video foreign [Music]
Info
Channel: Bhavesh Bhatt
Views: 44,100
Rating: undefined out of 5
Keywords: tensorflow, macbook, installing tensorflow on macbook, Install TensorFlow on Mac M1/M2 with GPU support, How to Install TensorFlow GPU for Mac M1/M2 with Conda, TensorFlow On Apple Silicon. Step-by-Step Instructions
Id: 2C-B1VFMq58
Channel Id: undefined
Length: 11min 13sec (673 seconds)
Published: Mon Jan 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.