Beyond Jupyter Notebooks (Windows 11/WSL2): MLOps Environment Setup & First Deployment

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome everyone today we're going to do a deep dive into a Windows setup this is on Windows 11 using wsl2 or Windows subsystem for Linux this is a follow-up video to the event that fourth brain did in collaboration with deep learning on the 28th of September called Beyond Jupiter notebooks mlops environment setup and first deployment So today we're going to go ahead and help you get your environment set up as if you just got a brand new job as a machine learning engineer on a Windows machine and we're going to help you do your first deployment using fast API and Docker through your interactive development environment that will be contained within vs code all right let's get right into it first we want to go to the fourth brain GitHub and we want to open up the software Dev for mlops 101 repo from here we can see the first we've got a quick review of some Unix command line commands it's important to specify Unix especially for Windows users because we need to make sure that we are aligning with Linux and Mac OS Unix terminal users so first thing is that we will probably use CD or change directory today we will also use sudo or this is for super user Privileges and we may use MK dir for make directory we'll also use Clear quite a bit okay we will be using in terms of tools we'll be using git for Source control and we'll go through we'll come back to these git commands when we get there we also use GitHub moreover we're going to use conda and pip conda allows us to manage our environments our virtual environments and pip allows us to easily install packages all right so let's get started with windows again we're going to be set up on Windows subsystem for Linux there are a lot of resources out there to get wsl2 set up so you're going to want to go ahead and follow this I've already got wsl2 set up on my machine so I'm not going to go through this right now I've also got Windows terminal installed this is very easy to just get in the Windows store as well as the Ubuntu add-on for Windows terminal this is very easy to get in the Windows store as well so these are all there and essentially you just want to make sure that you've got these key components in place before you get going and as you can see what we're essentially going for is when we open our terminal if we click this down arrow here that we see Ubuntu and we can open it right up so at this point it looks just like a terminal a Unix terminal that you would see on Mac or Linux and one that does not have Anaconda coming into play as soon as we initialize the terminal so we don't really need Powershell there and we'll keep just the Ubuntu terminal going we'll sort of start to make this a little bit easier for us and the first thing that we want to do is we want to go get an anaconda distribution that's going to work for us so that's what we're doing now with this W get command and once we once we sort of download this we want to install our anaconda and notice it's for a Linux distribution and we're going to install it sew that first we need to get through these license agreement terms and we're going to answer yes it says it will be installed here and The Bash command here is just sort of telling us that we want this to get going each time we open the terminal so we'll see what that looks like here in just a second but it's going to take a minute for Anaconda to actually install on our machine and once it installs then we'll sort of refresh the terminal and we'll see what it means for Anaconda to actually be instantiated when we sort of open or refresh the terminal that's what this source bash RC command is actually going to do for us it's going to Simply refresh the terminal okay so this is going to take a a little while and what we want to do is we want to make sure that once we get Anaconda installed we're actually going to go ahead and create our virtual environment with this Command right here and just at a high level what this is doing is it's going to create an environment we're going to name that environment and it's going to install also python as well as pip python of course is just going to allow us to code in Python pip is going to allow us to do package installation very very easily using pip install and then once we create our environment we're going to then activate our environment see how far along we are here and uh and then we'll install the additional packages that we need Okay so we see a question here at the end do you wish the installer to initialize Anaconda 3 by running conda init if we go back to here it says when prompted make sure to add conduct to init yes we do so you'll see this is still the same setup as when we opened however if we sort of refresh our terminal here you'll see that all of a sudden we are now using our base environment within conda but we don't want to use the base environment instead we want to create our own virtual environment because it's really aligned with best practices let's keep our base environment fresh and clean so we'll go ahead and create we'll go ahead and call it mlap's course that's what we'll call our environment here and we will install python 3.8 we'll install pip yes please once we install our environment we're going to go ahead and activate our environment so you see base changes here to ml apps course very nice okay clear it again now we're going to make sure that we have the packages that we need installed now for this particular demo we don't actually need matplotlib uh nor really I don't believe do we need numpy or pandas they're they're great to have though and certainly if you take our courses you will need those we will need however we will need fast API and we will also need pedantic before the day is through and I believe that that is all a little bit of yeah so we'll go ahead and install all of those make sure that we're good to go there and we'll scroll back down here make sure that we have updated our apt install so this is very similar to pip but we're just going to make sure everything's updated here and it's going to ask for the pseudo password so make sure that you have your password at hand I've recently updated mine so it shouldn't take too long here and I'm going to make sure that I have git which that also shouldn't take too long because I have installed it already and lastly I'm going to download Windows vs code just like this so in this case I'm downloading Windows notice I'm downloading the windows vs code not the Linux vs code and so that's why I'm going to go ahead and install it in a Windows file path okay so I'm going to go ahead and launch vs code and what I can do now after launching vs code so I can actually open a terminal so instead of using this terminal I'm going to go ahead and exit out of this terminal because we don't need it anymore I'm going to go ahead and create a WSL windows subsystem for Linux terminal directly here in vs code so this all of a sudden it's very nice I'm going to increase font size here just a tick and I'm going to activate my mlops course environment cleared out okay so here I am I'm doing exactly the same thing now I'm just inside of vs code the next thing to do is make sure that we have the appropriate extensions so we're going to make sure that we have the intellicode extension installed and go back down a size just for this portion so I've already got my intellicode extension is installed then I'm going to make sure I have python installed python mine is already installed make sure yours is as well I'm going to make sure that I have Jupiter notebooks installed mine is already installed make sure that yours is as well and now we are here and lastly I'm going to go ahead and set the python interpreter now you can open a new file or you can just directly open the command palette here and the command palette in a Windows system is done by Ctrl shift p and we can go to select interpreter and what we'll go ahead and select is we'll select that environment that we created there's a few environments that I have here yours should only have about one environment you don't want to create you don't want to select the root environment or the base environment you want to select the one that you created that is in the location that Anaconda told you it would be installing itself in okay so I'm going to go ahead and operate from there and as we can see um now we are essentially good to go we're ready to start coding so we want to additionally make sure that GitHub is ready to rock and the first thing that that's kind of important to do is to set up your SSH your secure Shell Key and to do this on GitHub you need to go to your GitHub profile you need to go to settings click down arrow click settings you need to go to SSH and gpg keys and you'll see that the SSH key I've already created one for wsl2 here I'm going to go ahead and create another one just for demonstration purposes and the way to do that is to use this exact line keep it simple and type this in enter file in which you want to save it that looks good it's going to ask me if I want to overwrite because I already had one there yes I want to overwrite no I do not want a passphrase I'm sure I do not want a passphrase and now I've got this great random art image here that's associated with my SSH key and on Windows the way for me to copy my SSH key copy paste I can go in here new SSH key I'm going to call it the same thing as I did before and I'm going to paste notice it starts with SSH RSA begins with SSH RSA that's what we're looking for okay add SSH key so now I've got this and I can go back here looks like I'm all set up and I'm really good to go on sshing okay great clear it out next what I want to do is I want to create a new repository in my GitHub so that I have a place to put stuff so I'm going to call this let's call it Beyond Jupiter WSL 2. and just according to this I'm going to put the name I'm not going to put a description I'm going to make it public I will add a readme I'll add a git ignore python template and I'll add an MIT license so we're going to make it public no description add a readme git ignore python this means I'm going to ignore anything that's not python related because that's what I'm coding in and then I'm going to put an MIT license and create the repo MIT license is very open very useful okay all right so I've got my ml Ops course virtual environment I've got my Beyond Jupiter wsl2 repo okay now let's follow along here what we want to do is we want to clone our repo down into our local machine and into our local development environment so what we want to do is we want to open our terminal and navigate to a place where we'd like to make a directory to hold all of our files for this class this isn't such a bad place to hold all of the files however potentially even better place might be exactly where we want it so if we go ahead and look at our file folders what we want to do is we want to figure out okay wait where is this environment and the first thing that we can notice is Linux is here so this is actually where we're going to work you'll see Docker desktop stuff is in here and we're actually going to work in Ubuntu because this is where this is where we're simulating our Linux environment our windows subsystem for Linux is here and this home Greg lock space this is where Anaconda 3 resides this is where everything that I've been doing so far really is so you can see Anaconda 3 is here if we go into ends then we see our ml Ops course environment right there so what we're going to do is we're going to work within this Greg lock space and we're just going to create a folder called ml Ops development okay so that's going to be our top level folder and once I'm there I basically just made a new directory once I'm there I'm going to go into it and I'm going to create another folder called code okay and from there this is where I want to put my cloned repository okay how do I do this well I have to get here all right now where am I if I do CD home then my home is actually home is a keyword in Linux and home is where is right here in the Ubuntu home okay if you look for home elsewhere so for example if you try to type in home slash greglock slash Anaconda 3. it's not going to work and the reason for this is because actually you'll notice that the WSL subsystem is at wsl.localhost slash Ubuntu home and now if I go to greglock now if I go to Anaconda 3 this will work so notice I wasn't in my home directory there instead I was in C users Greg l and that is a place that is actually located C users Greg L that's a place that's located on my windows system so it's it's very tricky it can be very tricky but you know I recommend going ahead and working directly on the subsystem so that way you know where everything is and where to find everything and get kind of tricky here all right so rather than work there I want to work from my WSL space and I'm going to go ahead and go into the ml Ops development and code folder that I just created so I'm going to CD into ml Ops rn2 Greg Locke slash ml Ops development slash code CD into Greg Locke foreign so let's just see where I am exactly oh I'm already in greglock so I'm a CD into ml Ops development and then CD into code so the home was actually the home that I get to with this tilde was actually home slash greglock okay worth noting all right so now I'm here and what I want to do next is I want to go ahead and clone this repo down and after playing with this a little bit earlier it became clear that the best way to clone this repo down was to not use the https but to use this SSH we did set up our SSH so we can do this straight away and once we clone this down then we can actually see if we're working locally in a folder that has this so for example we can open this folder now and we know kind of how to get there now because we have r location here so we can copy and paste it like this and there it is we've got our Beyond Jupiter wsl2 it's actually easier to look at directly in vs code we're going to go ahead and view our terminal again and we're going to make sure we're using WSL we don't need Powershell we're gonna activate our mlops course and you'll notice we've got our git ignore python we've got our license MIT and we've got our readme just like we told our repo to set up all right so now what we can do is we can do something very simple we can create just a new file let's go ahead and create just a quick Jupiter notebook let's make sure everything's working here x equals eight Z equals 10. let's go ahead and just print x times Z see if we are in a space where we feel comfortable and you know we've selected our our interpreter before but if it asks us we're going to go ahead and select the same interpreter when it asks us to select term to select kernel and we see boom there it is so we are coding in Python through a jupyter notebook in vs code at this point and what we can do is we can save this as a Jupiter test and let's go ahead and put it in a remote repo so now you see it's in there once it's in there you'll notice it's not up here in GitHub yet why not well this is where we go back to our git commands because now that we've cloned and we've created something new now we need to add and we can go ahead and add our Jupiter test Dot ipy and B but of course we have to be in the right git repo first Beyond Jupiter wsl2 then we can get add then we can get commit and we're just going to put a message here test commit for Jupiter notebook and then we're going to push our commit to our remote repository and the command we need for this it is git commit but we're going to see a few more details here down in this next part where this repo that we have up this allows you to clone a really fun game mystery repo that we have down and then to you know have some fun with that but what we want to do you know right now is we want to make sure that we're set up to be able to remote connect to our GitHub account from our local environment so before we commit we want to make sure that we have git remote setup so you see we've got our origin branch with Fetch and push options so you know Fetch and push and notice that's what we're trying to do here we're trying to push okay so we have a push option now and we also want to set up our Global configuration with our email that we use in GitHub and that way my name will be on everything we've added we've committed we there's no local Dev branches to merge and so we don't need to worry about that all we need to do is we need to do git push origin main now and you'll see that now all of a sudden we have our Jupiter test notebook up in GitHub and voila we are connected from the ground to the cloud and you just did your first git push so congratulations and you know feels pretty good feels pretty good okay ready for the next thing okay here's what we're gonna do next we're going to take a fast API app and a Docker container app from Deep learning and we're going to clone it down and we're going to get it running so we're going to go ahead and go into deep learnings ml Ops specialization GitHub course four week two Lab One and this is to deploy an ml model that's a simple wine classification data set model it's this data set in other words it's you know there's more details on it here the wine recognition data set it's pretty straightforward and essentially you give it 13 parameters it predicts which class of wine it is class 0 class 1 or class 2. and so let's go ahead and clear this out and how this lab works well the first thing that we need is we're going to git clone and notice we'll use our SSH our secure shell for this as well and notice since we're in code well actually we're in Beyond Jupiter wsl2 which you know that's kind of fun so we're working in Beyond Jupiter and now you know you'll notice if we uh we sort of refresh this we see our machine learning engineering right there and look at that we're in Beyond Jupiter wsl2 so what we can do here is we could push this back up we're not even going to worry about that instead what I'm going to do is I'm going to go ahead and go into course four week two Lab One and we're going to look a little bit closer at these files in the no batch so this is starting to get a little bit crazy so what I'd recommend is actually you know opening this directly and the easiest way to do that is just to open folder and we'll drill down course four week two fast API docker that looks good and as you notice from before we'll have to reopen our terminal we'll have to con to activate ml Ops course and we will be able to now look at everything in here very nicely Okay so as you saw a little bit earlier the reason that I wanted to install fast API and pedantic were to basically to be able to run this fast API app oh and there's one more when we look at this part one prediction request this sort of tells us how to build the fast API web app file and the next piece of this that we want to pay attention to is what we need to do to actually call the app foreign main colon app dash dash reload and what this is specifying is that if we are in the appropriate folder which means in the same directory as the main.py file in this app folder all we need to do is we need to call Main colon app and you'll see that what we're calling is we're calling this app okay so if we are in this folder which means we need to CDN we need CD into no batch into app then we can actually call unicorn main colon app if we pip install uvicorn and the other library that we also need will need is sklearn additionally in order to make this run directly without Docker right now the important modification we need to make is that since we're already in the app folder we don't need to specify drilling down into the app folder to find the Wine Dot pickle file so we can eliminate this we can save this and we can now run uvicorn main app and so we should say application startup complete if everything's working properly it allows us to click into this into our browser congratulations your API is working we can do backslash docs here and we can open up our wine class prediction we can try it out with a few of our wine examples for class is zero let's see if we predict class 0 here execute and we are predicting class zero let's try one more predict class two execute and we are predicting class two we are in business okay so we're gonna go ahead and close this out now and the last piece of this is we want to go ahead and put our app back we want to go ahead and CD back out to the no batch folder so now we've got our app and we've also got our Docker file and when we dockerize we want to understand what's happening in the docker file first of all we're saying okay we want this to run light we want to use a very simple mini conda version of python 3.7 we want to use a simple set of requirements with fast API uvicorn and scikit-learn and we want to make sure that we're using Port 80 and you'll see here I've got app.main colon app so this is now app dot main colon app okay all right so this is what the docker file is specifying and I'm calling uvicorn in the command line the same way as I was before only I'm doing it through the docker container so the real trick here is to go ahead and do the image build of the docker container just like this and since I've already built the image it will actually go relatively quickly for me and you'll see that it says the command Docker could not be found in this wsl2 distro so what we need to do is we need to install Docker desktop and we need to get it opened up and ready to rock once it's opened because one of the things to note about Docker desktop for Windows is that it says one of the requirements is the wsl2 back end so it works very well with wsl2 we're going to go ahead and delete everything that's in here and so once I'm open once I'm operating here my Docker desktop I'm connected it says connected to Hub now if I run my Docker build command now I can actually build my image here once I build my image I can run my image and this is sort of this command Docker run Happening Here since I've specified Port 80 one of the important points here otherwise you will run into an error is to specify port 80. within your Docker container once it's running you can see oh uh no such file or directory Wine Dot pickle that was because we are still waiting for me to click save on this since I changed app back so we're going to save this and we're going to go ahead and delete this go back to our image run it again now once we're good to go here oh of course we can't just run the same image again because the image contains the main.py file we have to create the image again so we're going to make sure our container is stopped our image is deleted we do a new build and we're going to now run this new build that has the appropriate main.py file in the container so cool little unicorn is a cool little learning there from uh from that little mess up so unicorn is now running on http basically on localhost and so we can actually access this through localhost Port 80 says congratulations your API is working now head over to localhost Port 80 slash Docs and we can see we've got the same setup the fast API backend the Swagger UI backend and we can try out our last wine example which is class one execute and we are predicting class one and there we have it we've got our interactive development environment setup with our file explorer our ability to look at python files and notebook files and our ability to use the command line directly we're going to go ahead and shut down our containers we're going to go ahead and close out our applications we're going to clear this out and now we're basically ready to rock and roll for whatever ml Ops development we may need to do in the future of course we could push our new development back up to our uh to our repo although I'm not going to do that today and the one thing that I want to just announce to you is that if this was of interest to you if you're interested in going deeper on git on how to take an app like this and make it something really cool we've got a brand new event coming up where I get to work with some of our amazing instructors directly live another collaboration with deep learning coming up on Wednesday November 9th where Chris and Melita will help me out talking about Branch development in GitHub well a lot deeper than we did here today and we'll also take that fast API and Docker framework and we will use it to deploy a cool state of the art text to image diffusion model so definitely register for that and check that out if you get a chance I hope this was useful to you I hope this helped you out I wish you the best in your careers and machine learning engineer don't forget to like comment and subscribe to the channel we've got more content like this coming out all the time and we're trying to do more and more of it so if you have any ideas leave it in the comment or email me directly at Greg forthrain.ai thank you so much and have a great rest of your day cheers
Info
Channel: FourthBrainAI
Views: 2,371
Rating: undefined out of 5
Keywords:
Id: C7fBf33nQ7E
Channel Id: undefined
Length: 39min 5sec (2345 seconds)
Published: Fri Oct 28 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.