Use PyTorch and TensorFlow with an NVIDIA GPU in the Windows Linux Subsystem (WSL)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so i've always liked unix or linux for cloud and for server operations the gui just gets in the way i just want a command line that i can automate and deploy things up to aws or azure or wherever wherever they're going however for i mean linux on the desktop it's just never happened i've been hearing about that for decades literally and yes some people have have run linux on the desktop i've run linux on the desktop but really mac or windows gives you the the more polished user interface well the problem with mac is it's a fairly small segment relatively speaking of the market share also they don't put nvidia on macs anymore so this makes it very difficult to actually run real deep learning sort of technology on a macbook the thing that i've still always really liked about a mac is that it has a unix command shell however it's kind of a mackified unix command shell that often gets into permission issues and things break as apple does their not so linux more bsd approach with the underlying core of the operating system windows i've never really disliked the interface to it it's gotten a lot better since the early days when i i dealt with i mean i've dealt with windows since it was windows 3.1 running on top of dos so it's it's a pretty good interface but it it has the dos prompt the command prompt which is not unix wsl is the windows service layer for linux it lets you literally run a command line linux inside of windows so you can pop open a a command prompt and it's a full blown linux minus the gui which is not what i really need from that and that lets me be able to run say the latest version of tensorflow or other machine learning libraries that just haven't gotten around to repackaging a conda environment for their latest version so using wsl wsl-2 to be exact along with the new nvidia driver i can really get the best of both worlds and i'm starting to give windows kind of a new look as a potential replacement for my macbook i know i know heresy heresy i just got 30 dislikes right there i i can feel it there was a disturbance in the force but this is something that i am experimenting with so in this video i'm configuring this new computer that i've that i've gotten which has a high-end nvidia gpu on it and i'm trying to see really what i can do as far as a windows workstation for machine learning i know heresy but it can work so i'm going to show you the wsl environment how i set this up how i was able to basically get the latest version of tensorflow which as of the recording of this video was 2.2 which they haven't bothered to release a conda windows cuda version of this that gives me access to the gpu so i'm kind of getting the best of both worlds i've got linux running literally right under windows but it's not often a virtual machine with an ubuntu gui kind of in its own separate world it's really like a second shell on windows and i'm going to show you how i set this up to see all my videos about kaggle neural networks and other ai topics click the subscribe button and the bell next to it and select all to be notified of every new video so at this point to get access to a wsl version that can access a gpu you have to join the windows insider program it's pretty easy just you click it and you can then install a new beta pre-release version of windows that has this advanced functionality now eventually they're going to build the gpu support into the official version of windows and this won't be necessary anymore to have to go through the insider program the insider program you get lots of updates and it's a bit chaotic they'll tell you that the build that you're on is going to expire and it's definitely not for everyone so as of july 2020 this is the way that you need to do this this will change in the future so this is just my installation video for 2020 and i will have a separate video where i show kind of how to set everything up in wsl for your use as a data science to store machine learning nvidia has a really nice guide for this so let's google nvidia wsl2 and there's the guide you need to follow every step and in order click on the link for documentation and scroll down on this document and you'll see the three steps under getting started the first step is really just getting the right build of windows installed the second is installing the nvidia driver in windows that will allow wsl to have access to your nvidia card and the third step is actually installing wsl2 windows insiders is really pretty easy just search for inside on your type here to search under cortana and you'll see it there click it and now you're supposed to choose what channel you would like the dev channel is the one that is needed to get access to this very very new feature that is built into windows to support nvidia and now we're going to search for updates and we're going to allow windows to install this new version of windows that has been found as a result of joining this so while this build installs we'll go ahead and fast forward through this so let's double check what version we need here we need the build that is 20145 and let's check and see what's currently being pulled in okay 20161 and that's later that'll be great we can see it's 10 downloaded so far so this is going to take a bit while this is downloading let's check the version that we actually have installed you can always run wenver and that will show you the current build and windows version number that you have and there we see it and that's a much earlier version that's what's currently installed we are upgrading this as we watch this now this will take a while for this to completely download and install so i am fast forwarding through this right now go back and click the link to download the driver so we're downloading the actual nvidia driver and it's just a normal windows program this is actually a pretty easy part you just run that accept the dialogue and it begins to decompress and we fast forward through this part accept all of the defaults on this program and let it run i'm fast forwarding through this part it's can take it a little while to completely install everything it is done just click close and you're on your way looking back at the nvidia guide we're on step three so let's go ahead and install wsl this is really just copying and pasting these commands into powershell this part should go through pretty smoothly so just launch powershell and it's a good idea to launch powershell in administrator mode like i'm doing here so right click do administrator you need to approve that and we're just going to take this first command and copy and paste that and place it into powershell back to powershell paste that in there press enter and it will install the first part okay now we're updating to wsl2 we copy this command that is going to update windows so that it'll use that version paste that into powershell let it run it downloads it and we need to set wsl 2 as our default version we do have to reboot before this happens when you come back it does warn you that this build of windows will expire soon such is the chaos of being windows insider now there's no new build available for me yet so i haven't upgraded yet the reason that i'm in this situation is the latest build that's supposed to replace this one does have a bug with amd and i have a thread ripper so there's no version available for me yet but these come out weekly so it won't be much problem now if you click on the helpful link that they give you unfortunately it doesn't give you much information so it's actually an error page but such such is the chaos of trying these newer versions uncomfortable with this cutting edge of things stay with the current versions of windows now what we're going to do is open up powershell and we're going to complete this last part to getting us to wsl2 now notice the area that it gives you there you have to update the kernel for wsl before you can set wsl 2 as the current version they give you a helpful link which we copy there and we run the program found at that link it's very easy to run you just run it it's going to update the kernel we'll actually have to update the kernel once more before we're done with this but this is the first part now we're going to go back into powershell try that exact same command we just ran and now it works successfully okay let's go get a version of ubuntu they have links here on the microsoft page that we were just at we're going to use version 20 of ubuntu i'm not going to sign up i get enough email and we'll click get click that to continue we have to go to the store store loads up we get to click get again this time in the store and now we click install they want to be really sure and i'm just fast forwarding through as it downloads ubuntu now when you try to start up ubuntu you might get this error it just means that you need to enable virtualization now that's a bios setting so i've got my camera actually pointed at my screen here and i'll show you real quick how i set this setting on my msi bios this will be different depending on what machine you have but i'm just going to restart to get into bias it's restarting press the delete key to get in okay there's my monitor kicking in and there's the bios this is actually under the overclocking settings and you go down to it's not really overclocking but it's in the cpu settings cpu features and see that svm disabled you need to turn that on and that allows virtualization of the type that is needed for the subsystem now be aware that some other virtual systems may require that to be off so that's that's somewhat tricky but this is sort of the microsoft way that a lot of their products do this now i'm rebooting with this change in effect this is a change that you would have to make irregardless of if it's a previous irregardless of new technology just this is how microsoft does virtualization and here comes windows and now we're launching ubuntu for the first time you can also just search for it with ubuntu on type here to search at the courtney thing at the bottom it'll say taking a few minutes when it first comes up you have to put in a username this can be anything you want i make it the same as what i had on the computer you can give it any password you want this password is important when you're running things as root so don't forget it all right now we're at a unix command prop pwd and it shows you where you're at print working directory this part did cause me some confusion so let me explain you have got to get all these versions to exactly what nvidia is saying or greater or it's just not going to work so let me check this version this gives me the kernel version of wsl i'm going to run this following the nvidia instructions and it's it's too old of a version and i couldn't figure out why it's not updating it and i tried this command this didn't work but this was on there they said you might try this i copy that and then it section and then run powershell i'm going to paste that in run it checking for updates grat no updates but yet i'm not on the latest version what the heck so we look at these advanced options here that's what i need to do i need to turn that setting on that they're showing there i need to receive other updates because the one that i need is classified as a quote-unquote other update so i'm going to go to check updates this only took me like an hour to figure out but honestly i'm not bitter yeah so click on advanced options there and set that first setting just like they suggested other updates are now on so i'm now able to receive this update okay let's go back to windows updates we should see this available now i have to check for updates this takes a moment i'll fast forward through this okay now it's downloading and you can see the version number the subsystem for linux update and it's there so now let's go back to powershell we'll run that same command again and alleluia we have the right version we'll check for updates just to make sure there's nothing else fast forward through this because it does take a bit no updates so we're good there we're going to restart just for good measure okay at this point it's really just like regular linux i'm not going to install the cuda driver into wsl itself because i'm using pi torch and tensorflow which i can install that under conda and i have to worry about versions so now i am pulling down into my ubuntu system the miniconda python distribution that i'm going to use you can also use anaconda if you want to have everything completely installed for you so i'm going to install both tensorflow and pytorch just to show you how both of them work and we can even create a jupiter notebook that has both of them available and we can just switch between those two environments without even having to exit jupiter which is not something that's as easy to set up in windows but doing that in this subsystem gives you that ability and makes makes this really pretty easy because you have the full windows gui but you have linux running underneath giving you the latest version of both of these tools so now that we have miniconda downloaded i'm going to copy this command which is the command and this is all from the miniconda installation page and we run that and it's going to install miniconda just accept its prompts and go ahead and download it this does take some time so i am going to fast forward through it just say yes and you're done you now have miniconda installed now i'm following instructions that i have on my course website is i give you complete instructions on how to install these tensorflow that is and also pytorch i'm going into the install directory and i am going to open the tensorflow install july 2020 which corresponds to this video if you do see a later one here use that and i probably have a link to the video that i would have updated for it let's install jupiter first we'll actually run the browser to get into jupiter from windows that's one of the nice things about using this linux subsystem you're running linux under windows yet you're using the nice windows gui with its browsers we'll fast forward through this and next we'll create a virtual environment to hold tensorflow we'll create a similar one for torch as well we just run this into ubuntu it takes it a moment to create this we'll fast forward through now it's very important we've got to activate that tensorflow virtual environment all the drivers and cuda stuff will be held in here so that we can have different versions of watts now we need to install this so that we can actually attach it to jupiter we'll just fast forward through this okay that part's complete and notice the version numbers windows only has 2.1 we will have 2.2 of tensorflow since we'll be installing the linux version linux is usually ahead on tensorflow we're going to copy the command for gpu and cpu if you only have a cpu just copy that earlier command i'll demonstrate this for the gpu but cpu is just using that other command we'll run that you can see that going we'll say yes and i'm fast forwarding through this part because this does take a while register this new environment inside of jupiter so that jupiter can find it that's actually three seven i have that mislabeled i'll fix that but that doesn't matter it's it's just a label we paste that into here this runs very quickly and now it's available in jupiter and now i'm going to download the entire archive for my course see i'm grabbing this url and i'm just going to use get to get it so get clone and that url and that will basically download all my course material because there's a script that i want to run in there tools.yml if you don't want to download the whole course just use just grab the tools yml file we'll fast forward through this while it downloads now that we've downloaded the tools yaml file we need to change into that directory and we're going to run it with the command that we have from github this takes a moment we'll fast forward through this and now it's done we don't need to activate like it's talking about there and now we're ready to test it we run jupyter notebook don't worry about that in the red that's not actually an error we open up a browser log in with our password that we set before and now we can run the whole thing and by the way the password that we saw before you have to copy the token when you first bring that up and then you set a password so you don't have to keep reusing that token but we set our environment here and now we're going to run the whole thing and we should see now that we have successfully installed the gpu gpu is available now there's a little warning there from something deprecated i need to fix that but it's just a warning but it's available and now we're going to install pi torch so i opened up my installer for pi torch it's in the installs directory same place and we're going to now create an environment for pi torch this is really very similar to what we did for tensorflow so we deactivate tensorflow we'll literally have both of these side by side but if you just want one you can do one but not the other if you don't want pi torch you're done now so we're copying that command to create the environment we run that and we say yes it takes it a moment it has to install another 37 python 37 now we activate this pi torch environment and we're going to do kind of install just the tools that we need so that we can attach it to jupiter and it installs those now we're going to copy the command that we need to actually install pytorch if you want the gpu make sure you install the conda toolkit as well it'll probably just not use the gpu if if you install that anyway and you don't have a gpu but you can choose which one is most appropriate to your hardware setup so we're installing that and running that this takes a while so i am fast forwarding through this as it installs all these various cuda components and pi torch itself pi torch is installed and ready to go so we're going to run the tools file we're already in the directory that we downloaded my course into so make sure you're in that t81 558 directory if you skip the tensorflow part but we run this and it's installing tools yaml just make sure that tools yaml file is in the same directory or you'll get an error it is running through all of the tools these are just supplementary machine learning tools that i like to use you don't need to use the kind of activate that they're talking about here that is not necessary we do need to link pytorch environment to jupiter and that's what i'm doing here make sure you're in the torch environment okay it's all nice and linked so you should see both environments i'm going to kind of deactivate just to show a really neat feature of this that you can do in unix and not so easy in windows all right we launch it don't worry about the red that just means that it couldn't launch a browser from inside the linux environment which is true we're going to run the browser in windows and then we open up that same pie torch install script that i provided you the install notebook and you can see that we also need to select the environment you can see that there's two environments available we have both the pi torch and tensorflow you can choose which one you want choose pi torch re-run this entire script and you'll see that the gpu is available thank you for watching this video and if you find things about artificial intelligence and machine learning interesting please subscribe to my youtube channel and give me a like thank you very much
Info
Channel: Jeff Heaton
Views: 29,277
Rating: undefined out of 5
Keywords:
Id: mWd9Ww9gpEM
Channel Id: undefined
Length: 24min 15sec (1455 seconds)
Published: Wed Jul 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.