Setup Mac for Machine Learning with TensorFlow in 13 minutes (works for all M1, M2)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello there and welcome to the m1 machine learning cooking show i mean recently you might have picked up one of these new bad boys this is a 14 inch macbook pro you can tell with the magsafe it's one of the new ones with the m1 pro chip i'm not going to go over what it is it's a beautiful machine it's brand new i can show you that it's an m1 pro here there's m1 max the code in this video will work for the m1 m1 pro and m1 max at least it should from my test we're going to go ahead and set up an environment or get our machines ready for machine learning uh specifically using some data science the common data science packages like pandas numpy map plot lib scikit-learn and jupiter and tensorflow and even more importantly running tensorflow on the gpu that's inside the m1 m1 pro and m1 max so without any further ado let's get into it i'm going to jump in if you want any of the links by the way they'll be in the description below this is on my github this is just some code that i use to set up an environment to do a speed test of all these new machines so i'm going to open up terminal i'm going to zoom in here let's go over there so this is going to be a relatively fast paced tutorial if you'd like an explanation of anything that i'm doing please refer to the links below there'll be a longer text-based explanation and you can see the stuff there so let's jump in so the first thing that we're going to do is get homebrew from brew.sh now there's a beautiful one-liner of a code here homebrew is a package manager that should really come installed on macs and apple laptops but it doesn't it helps you install other software so when you copy this code into here you're going to have to enter your password i've just entered mine it doesn't show up because it hides it automatically we'll press enter it's going to install a whole bunch of different stuff here i'll press enter again it might take a few minutes depending on your internet connection and so i'm going to speed this up until it gets to the next step and then we'll go over that together beautiful and that took a couple of minutes on my machine your experience may vary now homebrew tells us a whole bunch of things that it did you can go back and read those if you like as you can see here installation successful but now it says to run these two commands in your terminal to add homebrew to your path this will just allow you to use the brew command such as like here now i will put a little caveat here that is there are ways to do this without installing homebrew but just take it from me that you should install homebrew because you're going to eventually end up using it it has a bunch of useful stuff for you now let's go back to instructions we're going to now download mini forge 3 which is a conda installer if you'd like to learn more on that there's links in the resources but this link is going to directly download an sh file to our machine we see there mini forge 3 mac os x arm 64. basically homebrew and miniforge are package managers and package managers help us install other software to our machine so once we've downloaded that i've got it saved to downloads there you can also see it down here we're going to run these three commands here this is step three install mini forge three into home directory chmod changes the permissions on the file to make it executable that's what the x is sh is just basically saying hey run this shell program and then source mini forge three bin activate is going to activate the environment if it gets installed successfully i'm going to run all three of these press enter follow the prompts you have to read this you have to go right down to the bottom and once you get down to the bottom you can press yes so let's just get there this is basically saying you agree to all of the license terms where do you want to install it i'm just going to install it in my home directory under daniel press enter it's going to install a whole bunch of stuff it's going to enable us to use conda that's the most important thing we get python 3.9.7 do we wish to initialize conda yes beautiful thank you for installing mini forge 3. now we're going to clear this again and to make sure the changes take effect we're going to restart terminal you might also notice that there's now base here in front of our command prompt that's just to say that the conda prompt is available now but sometimes it messes up so i'm going to restart terminal just to quit it and open it up terminal there we go just zoom in so you can see take that to the side now i'm going to create a directory to test a tensorflow environment i'm going to call it tensorflow test using the mkdir function and then i'm going to change into that you can call this directory anything so if you're working on a project say tensorflow computer vision you might make a directory called tensorflow computer vision you can really call this whatever you want so make the tensorflow test change in that directory beautiful now you see we've got tensorflow tests here ls there's nothing in there we're still in the base environment beautiful now it's time to make a conda environment an environment i think of it as like a room in your house so you can imagine in the kitchen you've got all the tools to cook stuff and it'd be weird to have an oven in say your bedroom you might have an oven in your bedroom i don't know but it's the same on your machine you create an environment in this case we're using conda other other tools to do it a virtual env and whatnot but we're using conda to create an environment so that we can work on different projects within that environment and have access to the tools that we need so they're not getting mixed up in different rooms on our computer or different files on our computer it's going to copy this condo create prefix environment the dot here means that it's going to create an environment in the file path everything before slash m so it means create an environment that lives in everything before m and then we're going to activate that m i'll show you what that looks like beautiful environment location so see what i mean because i put the dot there it meant that i didn't have to type all of this so now my environment and i called it mv is going to live within the tensorflow test folder so i'm going to say proceed thank you and now to activate the environment you can type in the long version of conda activate the file path uses daniel tensorflow test m or in my case or in our case we just ran conda activate dot slash m which means hey the current directory slash m now if we go ls we've got the m folder there i'm going to clear all this so we've got some room now we can get into the fun part we've got an environment ready to go we've got a room ready on our computer that we can install different software let's now install apple's apple's tensorflow dependencies so apple have made it really accessible to start using tensorflow on new m1 machines so they've created a conda channel called apple this is what this command stands for conda install from channel apple tensorflow dependencies now tensorflow is quite a large piece of software which is why it comes with lots of dependencies so let's run that it's going to take a few minutes depending on your internet connection and you'll see a whole bunch of things come up here in a second that it's just going to install a lot of different software within our current environment we're going to say yes please install all of that the os x arm 64 stands for arm 64 is the software arc or the hardware architecture that the m1 chip is built on and this is going through nice and quick i've got some good internet where i am at the moment so we see carers pre-processing there's a package being installed there a few more other things there's tensorboard wonderful so i'm going to clear that again make the screen a little bit more clear now we can install base tensorflow so that's with this command here i'm going to run that and talk about it so python m pip install tensorflow mac os tensorflow mac os is apple's fork of base tensorflow so it's the exact same as what you'd find on tensorflow.org tensorflow.org wrong website tensorflow.org except it's been optimized for apple hardware oh beautiful that installed nice and click quick let's go back to the github and then we can now install tensorflow metal now this is one of the most important points it's going to install quite quick beautiful look how quick that was tensorflow metal is going to enable gpu acceleration on m1 m1 pro and m1 max why is it called tensorflow metal well if we look up apple metal metal is apple's gpu framework yeah accelerating graphics and much more so if you're using a mac which if you're watching this video you probably are it uses metal to accelerate graphics and if we go apple tensorflow metal apple have developed a tensorflow metal plugin which is a plugable device in tensorflow to enable there we go accelerate training with metal on mac gpus long story short if you only install tensorflow mac os which is what we did here you can still use tensorflow it just won't leverage the gpu that's on your new m1 device so that's why if you want to use gpu computing we install tensorflow metal so now let's get rid of that finally if you want to install tensorflow data sets and run the benchmarks that are included in the repo i'm going to have another video that's going over the m1 machine learning test you can install tensorflow data sets i might just do that because it's nice and quick that'll give you access to a whole bunch of different data sets packaged within tensorflow so we'll clear that and then if you want to install some standard common data science packages you can run conda install this is going to install jupiter for jupyter notebooks pandas numpy matplotlib and scikit learn i use these almost every day i'm going to go yes please install all of that a fair few packages here so i'm going to speed this up as well beautiful now that's all done i'm going to clear the screen make it more visible and then to test it we can start out of jupiter notebook that's going to open up a jupiter notebook in my browser wonderful if everything worked you should get something like this i'm going to start a new notebook and i'm going to copy this command here bring that into the notebook just going to maximize that zoom in so you can see and so this is going to import numpy pandas scikit-learn tensorflow stf and matplotlib and it's also going to check whether tensorflow has gpu access or not and the current version of tensorflow so let's run that it may take a little while if you're importing things for the first time so once again i'm going to speed this up and i'll come back when it's got the output beautiful look at that now that took about a minute maybe two minutes on my machine so it says here that tensorflow now has access to the physical device it has access to the cpu and it also has access to the gpu which if we have a look at here system information we have on the m1 pro we have a 14 core gpu wonderful so that just means that oh there's metal metal gpu family apple so that just means if we run tensorflow code now not only will it be able to leverage the cpu it will also be accelerated on the gpu so with all that being said happy machine learning oh typo and if you have any questions leave them in the comments below and if you have any further resource needs check out the links below it's got all the information there
Info
Channel: Daniel Bourke
Views: 111,314
Rating: undefined out of 5
Keywords:
Id: _1CaUOHhI6U
Channel Id: undefined
Length: 13min 1sec (781 seconds)
Published: Sun Dec 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.