How to Install TensorFlow GPU for Mac M1/M2 with Conda

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi this is jeffy and welcome to applications of deep neural networks with washington university so let's get tensorflow installed on a mac m1 this is one of the options that you can use for this course if you don't want to go through a lot of installation to get access to a gpu you can also use google collab and i've got videos discussing this but in this video we're going to make use of the gpu built into an m1 mac or an m2 and one max this is an m1 mac that i am presently using but it should work the same on the higher models so we're going to go ahead for the first thing and look at the installation instructions that i have here i'll have a link to this notebook page in the description of this video we're going to make use of a full conda environment to do this we're going to make use of miniconda and this basically is going to allow you to not have to use mini vorge which is how we did this in the past this lets us use one environment across we're going to install the arm 64 version of python if you don't install the arm 64 version if you get the x86 version this won't work at all and i'll show you how to double check this at each step so let's first just go to a command prompt now you can see that i have python already installed here you can see by the fact that i have base if i do python nice vice version you can see there's already a python installed there i'm going to go heavy-handed i'm going to yank the entire python version that i have out you might want to skip this step that's totally up up to you but if you're running into a lot of problems this might not be a bad idea but just with the disclaimer you're removing the python that you had in there before and you may or may not want to to do that this is how you ins remove a previous installation of anaconda so remove anaconda they have a nice description of how to do this i've gone through this a couple of times and it works really pretty well i'm going to copy this line here it installs a package that removes a lot of the junk that anaconda installs in various locations so we're going to go ahead and proceed we're going to run that and it's it's there so now we're just going to do anaconda clean just like they have right here and it asks you yes or no on a few things and it it removes it then we'll go down to mac they want you to run these three remove commands now we're doing this completely from minnaconda minicon is what i installed before so if you look in opt which is where this usually is i have miniconda and this is opt underneath my user directory so i could run these commands they're just nuking it at every possible location that it could be i'm just going to do essentially the equivalent and throw my opt folder completely away what could possibly go wrong now if there's more than just that in your opt folder obviously don't throw your entire opt folder away so now we're going to close this open up a new one and there's no python so i'm going to install miniconda i like minneconda i like controlling what's in my environment rather than having everything in the kitchen sink installed you may if if you're more entry level you may want to have everything in the kitchen sink installed so no shame there at all if you want to install anaconda instead of minniconda but i'm going to do miniconda download and you'll see it here download this one absolutely download this one this is where so many people mess up i did a whole video just on this if you install this one the x86 it'll work your mac m1 is smart enough that it'll just flip into rosetta and it will emulate and run the intel chip so we're going to download this one and if you don't do this you're going to not find packages when you go to con to install them tensorflow depths will be the one that you first see on that so we're pulling this down i'm going to go ahead and run it this is where people in youtube in my comments tell me i followed every every single step that you told me to and usually one of the most common ones is you click that link instead of that link so let's go ahead and continue i agree go ahead and install this takes a moment if you're doing the full-blown anaconda this will take much longer because it has to install everything and the kitchen sink we're just installing the kitchen sink here okay it wants to access my downloads folder that's acceptable and we're done sure let's move it to the trash so now if we open open a new one of these and we do python we're now in three 3.9.12 released in april 5th 2022 at least at this point when i recorded it do this import platform platform dot platform you better see arm 64 here if you don't see arm 64 and you're using a python that you already installed go back to the first step uninstall python put a new one on here this just will cause you all kinds of trouble if you're trying to get the m1 chip to actually work you can't have rosetta running the intel code and then use the mac gpu as well just just not gonna happen okay so back over to my instructions i said to install i need to fix that let's install miniconda not miniforge we used to use miniforge so that's the top on my to-do list by the time you read this it'll be it'll be updated so we're going to install this this gives you get and other utilities i already have it installed so it's gonna it's gonna tell me already installed but if this was not installed it would it would go through the whole the whole nine yards for you there i've never seen a problem installing this then we're going to install jupiter that is the main ide or editor that you're using for this course this takes a moment we'll go ahead and fast forward through this okay that's done we now have jupiter i'm going to do conda deactivate i have not ever found this to make a difference but people on my previous youtube comments have sworn by this so we'll kind of deactivate notice the base environment goes away and now we need to move to the directory that has this tensorflow apple metal conda so you'll want to download the course material that i have so to do that you would go to here and you'd go to code and you would download the zip if you want everything if you just want that yaml file it's and this is the yaml file the important things here are these channels if you don't have the channels right it's not going to find things like tensorflow depths and that's that's the one that'll usually give you the the issue and if you are not in an arm 64 environment also not going to find it believe me that is probably one of the most common errors that people run into so you could just get this file raw save it somewhere and uh and and run it from that i already have my entire class downloaded so i'm just going to go into and there you can you can see it so we'll go ahead and we'll go ahead and run this command this does a lot this installs the whole thing and all the additional packages that you need for my course and it creates it all in an environment called tensorflow so you'll always activate that environment to to make use of the course material we'll go ahead and fast forward through this this takes a while and this is where if something is going to go wrong it'll usually go wrong do post errors that you get doing this in the youtube comments i do watch those and i often investigate just believe me this stuff shifts over times and i have to make i have to make changes to my installation instructions often as a result so that's that's usually my first radar to let me know that something has changed is what you're posting in the comments i get a lot of requests for me to work one-on-one with people to help them install unfortunately i i barely have the time to to even teach a course in addition to to working and to lead in a data science team as my day job go ahead and fast forward through the rest of this okay it's installed nothing went wrong and that does that so now we've got tensorflow there so that's good and we need to register our environment this is so that it shows up as a kernel when you're on jupiter otherwise you're not going to see it on the list of supported environments so we'll go ahead and run that that takes a moment and it's done and now we're going to test it i'm going to open this file that i was viewing in github here that we are running the instructions from i'm going to do jupiter notebook this is the file that we were just following all the instructions from and i'm going to run this section right here before i do that though let's make sure that kernel change kernel you want to make sure you're in python39 tensorflow that's the one that we just created if you don't see it on the list make sure you ran that last command that i gave you that that registers that environment so let's run this it takes a moment for it to load everything up all right good news gpu is available that's what you want to see i print this here you should be in rm64 if you're not you'll have a problem but this is it you're now ready for the course thank you for watching this video and please subscribe if you want to follow along with additional material as i edit for the course or things beyond the course where i get into some of the more advanced topics with machine learning and artificial intelligence and if this video was helpful for you please give me a like thank you
Info
Channel: Jeff Heaton
Views: 57,703
Rating: undefined out of 5
Keywords:
Id: 5DgWvU0p2bk
Channel Id: undefined
Length: 11min 35sec (695 seconds)
Published: Thu Aug 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.