(music)
>> This is a sponsored stream.
It's sponsored by Microsoft Azure.
What we're gonna be doing today
is continuing the series of streams
using Azure for ML.
But this time, instead of using just the studio
which is what we used last time,
we're going to see how Python can integrate with it.
If you want to be caught up with where I am,
in the link that I posted in chat,
you can also just use Exclamation Azure
if you wanna get caught up,
and this is part one.
So these things you need to do if you want to be caught up,
so it's actually pretty simple.
It is easiest to use with Conda,
so I would recommend doing that,
said Python 3.8 is the version you're gonna wanna use,
you know, create an environment
and install Azure ML core.
Once you have that installed,
create a directory where we're gonna be doing
this tutorial code.
So once you do that, like name your workspace,
something I think I called mine like tutorial.
You wanna put your Azure subscription ID here,
make up a resource group name,
I think I also called my tutorial and then your region.
So this, you might have to look up,
like for me, of course it's East to US too,
but depending on where you are,
you might need a different location.
And then run this script,
and it will write out all these configuration details
to a JSON file,
and then step two is gonna be creating
your compute cluster.
Again, most of this should be pretty standard,
I called mine tutorial cluster.
But you should be able to use the vast majority
of this code just as is.
And once it is completely, it's run, it's good.
You know, your computer hasn't caught on fire.
Go back to that ML Studio that you've been using
and you should be able to see your resources.
So I believe I can show you mine,
so you can see it's succeeded,
right now we have zero nodes.
That's good, we don't want it sitting here
using like resources
while we don't have anything to deploy on it,
but we're good,
we've got our wonderful little compute cluster
all set up and ready to go.
But we are going to, let's see.
How do we submit a script to our compute cluster?
We need to make a new directory,
I'm gonna do this real quick
just in my command line.
We need a SFC, all right.
And then let's see here.
Here we go, we've got our source directory
and they want us to have a hello.py.
Oh, it's bringing me back.
Bringing me back to the early days.
Okay. A control script.
So this is something new.
Control script allows you to run your hello.py script
in the cloud.
Use the control script to control
how and where your machine learning code is run. Cool.
So I'm gonna copy this,
and then I'm gonna try to take a look at it
line by line and see what's going on.
All right. So this we've seen before.
This is just taking essentially that JSON file
that we made earlier
with all the workspace configuration details
and pulling that.
So, and now we're making a new experiment.
Now we're gonna run, ScriptRunConfig,
so we're gonna tell it what directory,
what script and what compute target.
It seems pretty straightforward.
This is interesting.
So we have like, it actually reminds me
a little bit of GameDev,
of like how you have like kind of a controlling script
that's gonna manage and kind of figure out when to call
and what to do with your other scripts.
So let's run this.
Oh, I got an error. Cool.
Let's see. Why are you cranky? Bad argument.
What was the bad argument?
Unknown compute target.
Oh, that's me.
So we called this.
I called my compute cluster tutorial, cluster,
and forgot to change it here.
So also let me just make this a little bit easier
for all of you to see.
So here we need this to be tutorial cluster obviously.
Now let's run this again and see what happens.
It looks like a ran.
So it gave me a URL to follow, to see,
I guess what happened,
or I guess the link into our studio.
While that is loading,
let me show you what we got here.
So you can see it's preparing it,
it's getting ready to make this run,
should be all good,
like, all right, run,
we have a run ID.
We have the script that we fed it, that makes sense,
and environment, cool.
So this looks how it should.
So let's go back to the tutorial
while this is like percolating
and see what we need to do next.
At first, you'll see the status of preparing good,
we didn't break everything.
The first run will take five to 10 minutes to complete.
Cool. We can hang out in the meantime,
so I will pull up.
Let's pull up our studio again.
We'll give it a moment to do its thing,
we're gonna have our outputs here.
It is pairing.
Oh, no. It failed.
Dear friend, why did you fail?
Failed. Let me just rerun something, give me one sec.
Okay. So we'll see if that works,
I switched something.
Alright, so did we fail again?
No, we didn't.
Well, that's hilarious,
'cause I literally just re-run it, but cool, whatever.
And it's completed.
Let's go back to our tutorial
and see what it wants us to do next.
We got our Hello world output,
we are rulers of the universe.
It worked, isn't that great?
Okay. So let's see what it's actually having us do,
let's break this down.
Okay. So it's just a basic, oh, like real basic.
So it's taking it from this introductory example form.
Oh, like a really basic image classifier.
Okay. All right. So that's pretty basic.
So we've got convolutional layer, pooling layer
another convolutional layer,
some fully connected layers.
So wants this in a model.py, okay?
Let's go ahead and make that.
So this is our model architecture,
I'm less familiar with PyTorch honestly,
but I feel like this is pretty readable.
So makes sense really, really basic.
So now we create a training script.
Well, since this is kind of like,
this is a smaller font,
let me copy this into code first,
and then write into our editor here,
and then we'll take a look
where it's a little bit more readable.
All right. So what are we doing?
Downloading a dataset.
We're importing this architecture that we've defined
and we are setting it up right here.
Optimize our SGD.
So we are using Stochastic gradient descent.
All right. So this is just downloading the data.
We have a forward pass and then our statistics.
All right. So this actually,
this is pretty straightforward.
Create a file in the Azure ML.
Yes. Okay?
So in here we need a PyTorch stack.
YML file that is giving us oh,
yeah, okay. That's pretty our little environment details.
Oh, I need torchvision, hold on.
Let's get that installed, let's see.
All right. So we're activating this environment.
Cool bananas,
and then we want to use our training,
oh, to download the data.
That makes sense
So it looks like it wants us to make a new Python file.
So this is our control.
So we're following the same kind of structure
we did last time,
but instead of running Hello world,
we have grown-up coders now.
And we're gonna have our little baby
CNN that we're gonna run.
So let's put this into larger fonts
so we can all see it and let's take a look.
So same thing, right?
This is just pulling those conflict details
from the JSON file we made earlier,
we're gonna make an experiment.
We are going to same thing, but this time I'm smart,
and I can also spell the tutorial.
This is fine, we've got that, we made that.
We're gonna running, like yes in this environment.
That's also cool,
I like that you can just pass
like an environment YAML file to Azure.
All of this, actually, this is pretty straightforward.
I'm not sure why I expected it to be more convoluted
but at least for, well, it's a tutorial.
Let's keep that in mind.
So here's the thing, right?
It makes us,
again, I don't get this whole environment change
that they want us to do.
They want us to change environments, right?
Well, if you go back
and you look at this PyTorch environment,
you wanna know what's missing, the Azure stuff.
The dependencies for Azure are entirely missing.
So then when you try to run this script,
is it just assuming that you're going to change back
to your previous environment,
like, why are you changing environments that doesn't know.
Why? You don't need to do, whatever.
All right. So we've got a URL.
That's good, it means nothing is crashed and burned yet.
Pull up her studio here.
All right. So it's preparing our run and,
it's running, yay.
It is in progress.
Train, go forth and train.
All right. Let's take a look at our documentation
and see what we're doing next.
Okay. So we've got this, do, do, do, do.
I still don't see why we needed two environments, but fine.
We have submitted zee run, do, do,
okay, the whole run might take five to 10 minutes.
Environments can be registered to workspace with this.
They can be easily shared, reused and versioned.
Oh, that's kinda cool though.
So you've got a multiple that's very handy,
also curated environments
that cover common machine learning scenarios.
That also seems very helpful.
If we look at our studio here, we can see it's completed.
And if we go to our logs,
we can see that our loss has been printed out here.
Look at that,
that's probably overfitting, but that's cool.
Yup. That looks like an overfit unless this is progress.
Not, this is probably progress, not accuracy.
'Cause yeah, if our loss is still that then let's see here.
So it wanted us to add some more metrics.
Yes. You know me, I love my metrics.
This wants us to add this so we can get,
let's see get him on run from current context,
download the data.
Oh, we already downloaded the data,
but we want this run get context.
So let me see two more lines of code, unless it's counting.
I guess it's counting that.
But the current training script
prints metrics to the terminal,
Azure ML provides a mechanism for logging metrics
with more functionality.
Ah, and then here.
And then we wanna log things
and probably then we can pull if that's added to,
is that part of the context then?
It's this run.context.
Yeah. Okay. Get context.
That makes sense then.
All right. So let's you train.py,
you can just run object
from within the training script itself.
That makes sense.
Okay. We will rerun this, but it did say
it's gonna run a little bit faster now, thankfully.
And hopefully we'll be able to look at some more metrics.
What do you mean you failed?
Why did you fail?
Why are you pooping yourself?
Run is not defined.
Oh, I forgot to probably import something deny,
it's entirely my fault.
Like why did you fail?
It's probably your fault.
Yeah. I didn't.
So what was the import that we're missing?
It's on my other tab.
Whop, that was maybe not the greatest.
All right. That's fine though.
It'll be all right.
It's okay.
We figured it out.
Yeah. Go away. Run details.
So not export into anything,
export either stopped
or there is no data.
That's interesting.
Well, there's definitely data,
'cause we're logging it here.
That's interesting. Let's take a look at this.
I am just going to fully copy and paste this
to make sure that I didn't miss anything.
So just in case, let's see here, this should all be fine.
Yep. That should be good.
I'm gonna run it just one more time
and see if I can get those like live metrics to pop up.
Okay. So it still didn't,
that's interesting.
It didn't export.
We're just copy pasting from the tutorial.
So we'll have to debug that, that's interesting,
But okay, we've updated this, we submitted, yeah.
I ran into an issue, see what happens.
Which section are you having trouble with?
Let's see, where's our logs.
Let's just like, we'll just let them know.
You know?
Let's see, train.py
did not output logs.
All right, there we go. Cool.
So nevertheless, let us move right along.
This shows the workflow that you've used
to work with your own data.
Let me just minimize that.
So this like the first time I just edited it,
kind of like more organically,
the second time when it didn't work
I just copied this straight from the tutorial.
At the end of the loop, there is a run of log.
So we'll see what goes,
we'll see what they say.
Maybe we missed something, maybe we didn't, who knows.
We are going to be adding in some, all right.
Command line arguments, that's fine.
The data path that we're giving it,
so this all looks very, very similar.
We're just adding in some command line arguments
so that we can feed it our own data.
And let's see,
he has used the odd parse library,
yes thank you very much,
learning rate and momentum, blah, blah, blah.
And let's see the train.py script has been updated.
Do use user defined parameters, sweet.
Alright, so, yup.
That's fine.
That'll works.
I will just double check that is our...
It is indeed our structure.
Why do we need, do you see...
Did they update the environment?
They didn't.
Why did they want us to...
Okay. We already did that.
So we're fine.
I'm not usually one to have expensive tastes
with anything but electronics.
Let me just make sure this all looks the same.
Yeah. So this is fine.
Like this is, we have a different name for it,
but whatever, let's go back to train.
So we should be fine.
So let's run this in the command line.
Now we need to create a control script.
So we need to create this new control script.
Did I do it yet?
I did not do it.
Yes, I did, ha ha. I'm prepared.
So we have our control script.
So let's take a look at what this is doing.
We're familiar with this.
We're using that JSON config,
now we also have our data store
that we've uploaded our dataset to,
now we're telling it go find the data
that I uploaded in the data store.
And he said, what are you using for the data store?
Azure. 'Cause Azure is built in wonderful data store.
Then we have our experiments.
This should all look really familiar.
This is other than the data set,
this data set from files line.
All of this is stuff that we've done previously,
so it should be pretty, pretty straightforward.
Now we've done our script to run config before.
So this all looks fine.
I did rename the compute target this time.
So it doesn't break.
Good job to me.
We're using that same environment
we've been using the whole time.
So a lot of this is just rehashing old stuff,
but instead of having the data store locally,
we're practicing uploading it to Azure first.
Let's run the thing.
Let's see what happens. Let's see if I broke it.
But, well this is running.
Let's take a look at our tutorial
and see what we're doing next.
Oh, and then clean up resources.
I do that usually after stream
'cause that's kind of like the more boring part.
Let's go back to our run, I'm gonna...
It is completed, whoop whoop.
So it has been completed.
I mean, so in terms of these outputs
like these are gonna look the exact same
but really what we're taking a look at here
is even though we're running the same model in the same data
like we ran it locally,
and then we ran it in the cloud
that had the data locally,
and now we had both the model
and with the running and the data in the cloud.
So that was cool.