Back to Index

Live coding 4


Chapters

0:0 Create an notebook
4:13 Symlink from persistence storage
19:24 Create pre-run.sh from scratch
33:15 Create SSH keys from scratch

Transcript

So let's see how to do that paper space stuff that we did in the last session, but from scratch like step by step. And one very reasonable comment on the forum after yesterday's session was like this all seems kind of complicated and it is and like definitely one option is like don't worry about it for now, but I would say like trying to get this working is a pretty good exercise actually so you know it's totally up to you but I you know I think it's I think it's probably worth worth trying to get working and ask lots of questions about anything that you're not sure if it doesn't make sense or it doesn't work for you or whatever.

Okay so if I say share screen here we go share portion of screen I've never tried this before and I think what happened share move that this is cool okay do you see my browser window. Yes, yes, all right okay I'm successfully sharing a portion of the screen. Paper space.

So what I did this morning was I just went in and moved all of my paper space set up in persistent storage out of the way so that when I create a notebook. It's going to be totally empty. Now let's create a notebook. How did you move it out of the way to raising the best options.

I know I mean I just like I went into slash storage and moved the files to rename to them to give them a light dot bak extension or whatever so they wouldn't be run and moved everything into a different order, that's all. This should look like what you should also say, so I got to delete the workspace URL so we have something totally empty which I think is actually probably best right and yeah so follow along if you want and if anything doesn't work for you let me know.

And then what I thought we would do is I like to learn as few things as possible because I'm lazy and so the way to get away with being lazy and learning as few things as possible is to learn things which are really versatile and powerful so that they can like do a lot of things so in particular I haven't really spent the time to learn bash scripting very well I know it a little bit because I have instead spent the time to learn to use python as an effective scripting language and I can also use python for machine learning I can also use python for creating web services I can also use python for creating console applications I can you know use python for creating continuous integration scripts etc so that way I can be lazy and I like being lazy it's one of Larry Wall's three virtues of a great programmer is laziness along with impatience and hubris and I would like to be a great programmer so I follow those principles so let's try to use python to to kind of automate the things we want to do so remember that you know we're going to avoid using the weird proprietary GUI because we're lazy we don't want to learn it and also because it's not that good so I'm just going to open up a second tab and so over here I'll click jupyterlab and so what we should find is that we're in a totally empty spot here we go so this morning I did do some reading of documentation which is also a great thing to do if you're lazy because if you read documentation then you can like find out straight away how things work rather than spending ages trying to figure it out and so the documentation for paper space was actually very useful and it explained how their different folders work exactly so in the root directory um this would be a bit bigger I think there we go um actually I think if I go view presentation mode or something it makes it a bit bigger anyway that didn't do anything at all okay um in the root directory there's a couple of particularly interesting folders most of the folders you see here are the same that you would find in any linux box but the notebooks and storage folders are interesting and one of the ways we know they're interesting is if I go df minus h which you might remember is disk free it lists all the mounted disks uh in human form um it's made it way too wide so we can't really read it yeah never mind um okay I make it smaller just for the purpose of showing you this um so the uh slash notebooks is actually on a whole separate 500 gigabyte disk and slash dot storage is on a whole separate 500 gigabyte disk um the uh so what paper space does is slash storage anything I put in there is going to be seen by every single notebook server I create and in fact if you've got I think if you've got like multiple people in the organization they might see the same thing as well um so that's going to be shared across um yeah or any notebook server I create that's um that's going to be handy because anything I want to use on every one of my servers if I put it in there then I don't have you know I don't have to worry about recreating it each time um something we didn't mention last time is slash notebooks is interesting that's also persistent storage but it's persistent storage just for this one server um so stuff that's in there we will see every time we start up this server if we delete this server it's it's gone unless we back it up um so that's where we would put things that we don't want on every server but just on just on this one um you pay for storage um and you pay I think it's like 30 cents a gigabyte or something like that per month um and they don't limit you you know except for the 500 gig limit so it's up to you to be careful of that um you will find in your account there's a section called billing that shows you how much storage you're using um so they will add up stuff in slash storage that just appears once and every single one of your notebook servers slash notebooks that will all be added together okay um so the first thing we did last time was we tried installing something extra from pip um so one conversation that we had on the forum since then is like are you sure that's not going to mess me up because you know paper space is installed stuff I believe using condor um and pip and condor are different things for installing python libraries um so you know is that going to mess things up and the the official answer is yes it will don't do it um but the unofficial answer is you know we've got tens of thousands of people on our forums and I've never heard of anybody in practice actually having any problem with using both pip and condor slash mamba so I'm just going to say don't worry about it um as we said yesterday I think the only the place you really need to use condor or mamba is is for stuff that uses the GPU um and particularly for pytorch or if heaven forbid you have to use tensorflow um yeah so I gotta say don't worry about it and and the reason we um we actually want to use pip in this particular case is we want to be able to install the packages into a into our home directory into a different place um yeah the reason the reason we want to use mamba or condor for stuff that requires the gpu is that they have a way of installing dependencies right like uh they they have a way of installing the uh the cuda toolkit requirements so we don't have to install the cuda sdk um is basically the reason and that's um and and it's not just like one less thing to install but more importantly it's one less thing to maintain like you don't like your cuda version and your pytorch version have to the mesh correctly otherwise it'll break and if you just use condor that happens automatically but if you use pip then it's up to you to make sure you're installing the correct meshing versions of each things um it's also more challenging in something like paper space because you know installing things like the the cuda sdk into your home directories i don't even know how you would do it without using condor frankly yep does that answer your question radik yes thank you very much okay great um so somebody's got a loud plicky keyboard they should probably mute themselves um yes hi hi if if the pip installation and do something wrong yeah i mean kind of you can always just type pip uninstall um or just delete your member forge directory and start again um but you know people always like i mean or you can just you know install a condor package over the top of it like it shouldn't really be an issue generally speaking um the issue tends to be more if you accidentally install something into your system python um yeah but the idea is that you want to feel like you can blow away your member forge mini condor or whatever directory anytime and recreate it um yeah because you don't want to be in a situation where things work but you don't know why they work and you don't know if you can get them back to a working state again that's really unsustainable um but yeah the short answer is you can just type pip uninstall to remove a module thank you what about when when it says that some packages are going to be downgraded that's okay yeah that's okay if it's going to downgrade packages i mean i did i'd kind of check how much it's been downgraded but sometimes it'll be like one or two you know you know zero point zero two zero point zero point zero two difference in version or something it's not going to matter i mean if it's downloading it or downgrading it by a lot that might mean that something wrong is happening um but yeah that's not necessarily a problem uh okay so and i think like pip almost never downgrades things condor does sometimes um so let's try um so the thing we learned yesterday is we can go pip install and if you want to upgrade something it's minus u and there was this one extra thing we typed which was minus minus user and so so the key thing that does is it puts it into our home directory um and so in our home directory the place it put it is the dot local folder um so what the so the thing we wanted to do was to make sure that the next time we start up our computer we want that that dot local um to be there um so that means we have to move it to persistent storage so that's easy enough to do by using move so we can move it into our persistent storage um and you know what i would be inclined to do actually is to create a folder in there just for the stuff that we're where you the things in storage that we're using specifically for like configuration like this so um i was just about to delete this line when i realized i haven't taught you folks how to delete lines yet so to delete the um everything left of the cursor it's control u and to delete everything right of the cursor it's control k so hit control u um and so let's create a directory for this so we'll go make a directory in storage which we'll call like i don't know cfg for our configuration stuff okay and so then we'll make a sim link from oh so then we're going to move okay so we're going to move our dot local folder into there now do you remember the way to say the last thing i typed on the last line is um is exclamation mark dollar so i can say move dot local to slash storage slash config by doing move dot local and then exclamation mark dollar and you can see it's filtered out here to show me so it's a quick shortcut and then so i want to sim link that back again into this directory so create a sim link from slash storage config dot local to here and here is the default right so i don't have to say to here and so you can see we've never seen core dot local and it's not a real normal folder it's just a pointer to this other place but i it acts like a normal folder as you can see and so that should mean that i can import fast core and get fast core dot version should be one four three control d twice to exit okay everybody happy with that so far jimmy i had a doubt so which part was the dot local actually there like in which folder was not the dot local is in my home directory and so see how here i typed cd so cd takes you back to your home directory and you can tell where i am because it's the bit before the pound sign and tilde means in my home directory basically everything it creates for like kind of your configuration will be somewhere in your home directory so in that um what we're talking about jimmy i noticed that when doing cd backslash what cd space backslash probably means cd space forward slash forward slash that one um that went to a different place to the home where it goes cd space tilde yeah so cd space slash takes you to the root directory okay so that's the top level where i'll cd enter or cd tilde same thing takes you to your home directory so if i go to cd slash and i type print working directory it says oh you're in slash and if i just type cd and say print working directory it says oh you're you're in your home and since we're root that's our home normally the home directory is slash home slash username roots a special case does that answer that question yep thank you just a quick question jeremy like in terms of starting your um the instance that you just started is that uh without an image right i used the fastai image um but i used the trick that we learned yesterday which is to go to advanced and then delete the contents of the git workspace so i clicked on create i clicked on fastai make sure you do choose the fastai image because it's got all the stuff we need to make this stuff work but i then clicked advanced options and deleted that and the only impact of that is it just it doesn't put the contents of this git repo into your notebooks directory that's the only thing that's okay so i could try all these things that you're doing right now without because i do have a notebook already created but it's with the fastbook document yeah so you could like just delete them you know uh you know just rm star.ipynb or or just ignore them or yeah absolutely okay cool thank you no worries um jeremy can i ask one more question anytime um the uh so now you've you've the dot local that you've created now let's say you uh so it's on your storage so it's persistent now you reboot the system and you don't download another you pip install something else and you move that new dot local that it's going to create isn't that going to overwrite what's in your storage yeah so we haven't got to that bit yet so we're at this point we've got something that's working just for this instance but it's not going to work for a future one so we need to um we need to what we're going to do mark is we're going to create a little python script that um that is before it starts the server before it starts jupiter in the server it's sim links it creates this sim link and then in the future if i type pip install minus minus user it'll store it in dot local slash bla that's dot local will already be pointing at slash storage so it'll actually stick it in slash storage and that's that's the secret trick i got it okay thank you cool and mark i think you were the one who said on the forum about like are we sure this is a good idea was that was that you and yeah that's me i don't want to i don't want to make it all about me but i've had so many well i want to make it about you because like you you're at my target demographic here is people who aren't particularly confident at the show so no not at all it's just um you're the one person who was brave enough to join in i think despite having less um experience at the terminal so i actually want you to be particularly happy to interrupt anytime something's not clear yeah no i i've started this course a few times and every time the problem is always the thing that always makes me stop is this stuff yeah and i end up like getting conflicts and i remember there was an old version of i think it was paper space i can't remember that you were recommending and it kept crashing and i kept losing work and yeah so i guess i'm a little paranoid about creating things that are going to create yeah so to be clear mark i don't feel like we've had a great solution for running fast ai cheaply and easily until now so the reason you've had problems before is that like there wasn't a great solution before so so this is the first time i'm actually saying to you i really do think this is going to work and so anytime something goes wrong like feel free to like share your screen or anything because that debugging process will also be useful so i'd say for now you know suspend disbelief give it a go and you know if it all falls apart blame me and i will happily fix it and so it goes for anybody as long as you're roughly following along with these depths if you do something totally different maybe i won't be so patient okay so so look at what we did here we did two things we first of all moved out local to storage and then we sim linked it back now we're not going to have to do that move ever again right with that that was just enough to kind of create a dot local slash storage slash config dot local so all we need to do next time we um next time we uh create an instance is to create the sim link um like so so um let's do it like if there's something so simple because i said i'm going to show you how i would do things for something so simple i would actually create a bash script for this um and this is where things are going to get particularly interesting because um well okay i'm going to show you the proper way to do this and i'm also going to show you the slightly improper way to do this i'm going to show you how to use vim which is actually a highly recommended editor that works in your terminal but i'm also going to show you a trick for how you can use the jupyter text editor so jupyter has an in browser text editor which currently we can't really use because it's it's pointing at slash notebooks so how would we change stuff how would we edit stuff that's in slash storage but what we could do is if we see data slash notebooks and then we create a sim link from excuse me jerry yeah um just letting you know on my screen at least uh your cursor is just cut off from the bottom of the screen like so like i need to like make the uh browser a little bit sounds like jupyter is not quite showing this properly so you can see it now cool thank you thanks let me know um so if i sim link slash storage into slash notebooks then what should happen there we go is it appears here because this is showing me the contents of slash notebooks so um that would be one simple way to um create a script here would be i could click plus and i could click text file and we've got a text file and so now we could um copy and paste our sim link so maybe copy let's see copy oh that's annoying i think that's very annoying can't copy stuff from the terminal oh you're writing scoundrel i just did it with ctrl c and ctrl b yeah i oh it's because i'm on a mac now i have to press command not control right thank you okay um and um you need to make sure you're in your home directory for this to work so cd okay um and to run this as a script you have to tell it it's a script um and the reason why it doesn't matter too much but the official the the the kind of correct way to do that is to you first of all say hash bang that means the first line of the file in linux and mac tells it what program to run it with and we want to run it with bash and you're meant to do it like this for slightly obscure reasons slash user slash bin slash and bash that will run this script with bash okay file save um the slightly less correct way to do it is you could just say which bash to find out where bash is and it's actually slash bin slash bash and you know you can also type this that would also work so that says when to linux or mac when you run this file run it using this program you're sorry run it using this program okay so file save all right so let's rename that and so in um paper space um the special file called prerun.sh is run when it starts a new instance now you might remember that you know um in fact let's let's it's good to before you just go ahead and start an instance let's try to like run it and see if it works so if i type dot slash pre run dot sh and press enter it doesn't work and so the reason why it doesn't work hopefully you're starting to remember now is that we need we need permissions to be set correctly and in particular we're missing the x here the execute permission and so in the past lessons i've shown you you can type chmod u plus x to add the execute permission to a file like so um but i also actually kind of lied i don't normally use that way of setting permissions normally i set all the permissions at once um i would actually normally type this i would 7 5 5 pre run dot sh now let me explain why 7 5 5 um and the reason i did it the other way before is it required less explanation um 7 5 5 is not the number 755 it's actually three separate numbers the number seven the number five and the number five it says these are permissions for the user these are permissions for the group these are permissions for everybody and then um uh the permissions oh just a moment um so uh actually it's not quite 555 that i want but that's okay um so basically for each one it's going to add up three numbers a one a two and a five a one if it's executable a two if it's writable and a four if it's readable so seven means readable and writable and executable for the user four means readable for the group and then this four means readable for everybody so if i check this now you can see it's got okay so this r w x is four plus two plus one equals seven uh dash dash that's four plus zero plus zero dash dash four plus zero plus zero so this these permissions are seven four four um so that's yeah slightly weird if you've done stuff with bit flags in your programming before it'll look pretty familiar and then if you haven't it might look weird um this kind of thing does come up quite a lot actually in programming as a surprising amount so it's probably worth getting familiar with the idea of bit flags uh so that now should um be able to be runnable and it is now runnable and so it's good we ran it because it tells us that oh you can't create a symbolic link because it already exists now um i'm not sure before jupiter starts if this directory will be here or not um so it would probably be a good idea to assume it does um so to avoid that we could first of all go remove recursively and forcefully the any dot local directory or file that exists um and so if i now save that and try to run it again okay it's worked so that's good so we should now be able to create a new notebook and i will i'm not really doing anything with the gpu at the moment so i'm not going to spend their money unnecessarily so let's just create teeny tiny little instance here next space start there we go um okay so that's uh gonna go ahead and start so that's um that's done that bit from scratch um so let's now do our our keys from scratch as well um so and you know i would probably not do that ssh keygen thing in real life so let's let's do it all the way i would do it so i would just say make dot ssh that's where our keys are going to go okay um and then upload my keys whoops okay there they are um and so then let's cd to dot ssh and move i put them in storage so so storage id rsa star into here whoops oh crap i just messed it up now i'd have to upload them again sorry move them into here okay so there they are um in fact let's do la because that tells us dot which is the permissions on this directory okay so the dot ssh directory nobody else should be able to access it so if i go ch mod 700 700 0 that means four plus two plus one so all permissions for me the user and no permissions for anybody else on the directory okay and then um actually well and then for the id rsa it's just readable and writable say 600 for my private key and then for the public key it's readable and writable by me but only readable by everybody else so there we've got it okay so this is what 700 permissions look like this is what 600 permissions look like and this is what 6 4 4 permissions look like and after a while actually you start getting used to the idea of like oh 6 4 4 anything that you can read and write and other people can read you know 700 any directory that you can fully access 600 anything that only you can read and write they kind of become like standard little concepts in your head so at that point we should be able to test this now by ssh into the username git at github.com and i've successfully authenticated now if that doesn't work for you it's almost always because of permissions but you can get a lot more information by running ssh verbosely by typing minus v and it's quite cute the more v's you type the more verbose it is so very very very verbose um okay and it'll tell you all the stuff it's doing um and so now we've done that hopefully you won't be too surprised to hear that we want to do exactly the same thing with our .ssh folder which is we want to move it into our persistent storage and then link it back again so move .ssh into /storage config and then sim link it back again now rather than manually doing that we could just go into our script and copy and paste these two lines okay and do it for our ssh folder as well so save that and so if i run that script now you can see my ssh is now sim linked and if i test it so i pressed control r git gets me back the last thing i typed with git in it yep it still works okay and this notebook has hopefully finished starting yes it has and i'll just quickly use the paper space ide just because i'm testing and we can test yep so this is a brand new instance i started in another tab and my .local has successfully appeared there so we can see that our pre-launch thingy is working okay i think that's everything that i wanted to show today does anybody have any questions before i go sorry about the slow start one quick question yeah um jeremy uh you've you can see a file structure there on the left hand side um i i see just nothing that's yeah so this is my yeah so my persistent storage already had stuff in it so i've just been deleting stuff okay the reason we see storage is because of that sim link i created earlier um so if i type history part crap when you start the instance when you open the left hand tab you will be looking at your notebooks directory exactly that is your notebooks directory and so you might have missed it but earlier on what i did was i sim linked my slash storage directory into my notebooks directory so that i could edit and so if you missed that bit just watch the video and you'll see it happen but yeah it was this is this line here ln minus s slash storage and i put it into notebooks otherwise i was going to have to show you how to use vim but i might show you how to use vim next time but this way we can use our our editor great and the the thing that makes it work across new servers is that the pre-run file is in the storage um the pre-run file is is special um so you might have noticed that when you go to the advanced options when you start the instance it says what program should it run when it starts and it's a default it runs a program called run.sh and if you look at that run.sh it says here run the pre-run.sh so that it has to be that exact place and that exact name it's a special file this is a paper space specific thing okay so as long as pre-run is in storage with that exact format it will be across servers exactly right yeah it'll be across servers because it's in slash storage and it will be run because the run.sh file runs it um as you know um yeah exactly so jeremy just a quick question about pre-run did did you created that right i created the pre-run.sh file it was not there yeah so in bash this if here actually says if minus f is this file exists then run it that's what that bash means and so paper space that you know i said to paper space could you please add that to our to our image and so everybody who uses the the fastai image will will have this and so if you create a pre-run.sh in here then it's going to run it right so we would be creating that it won't be pre correct the way i created it and again go back and watch the video if you if you missed this and you want to see it again i double clicked on storage and then i clicked on plus and i clicked on text file and then that created a text file called untitled.txt which i then right clicked on and i said rename and i renamed it to pre-run.sh right there was one before like i saw the dot back so i did the dot back one yeah don't worry that that's so that's the one i moved out of the way that's my actual one that i went for myself i saw that already and i was like okay did it did the system created for you yeah yeah that was just trying to get mine out of the way so it didn't make me cheat all right so then the last step of course we have to do is to stop our server tell me one quick question yeah how do we ensure that we are not disturbing system python many times have i when i'm installing in my system i somehow i i mess up things um have you watched the previous three uh three walkthroughs last one i missed okay so watch that uh where we basically answer that question i believe but if you have any if that doesn't answer your question then please ask next time thank you thank you no worries all right thanks all bye thanks thank you everyone thanks you