Hi and welcome back to the course in this section, we'll take a look at PyTorch Lightning, which is
a feature rich, high level PyTorch interface library that makes working with PyTorch much easier.
It makes it much more like us.
So let's take a look at that.
So what is PyTorch lighting?
Well, it's an open source Python library that provides a high level interface for PyTorch.
And here's basically a snapshot of all the cool features it offers here, all of which we'll touch on
in the next coding lesson.
So why use lightning, though?
What's the point of it?
I mean, yes, it's a high level, easy to use library, but it's so much more.
It offers a nice, easy to use modular approach to cutting applied to edge models, so you become more
organized and less focused on the Python coding side and more focused on creating your deep learning
models.
It was intended for researchers to focus more on the science and research and spend less time worrying
about how they deploy the model or scale up during training.
A model created using lightning can be trained on multiple GPUs quite easily, as well as CPUs and also
with using floating point sixteen precision, which can aid inference time significantly.
So therefore, the couple's research could from engineering, meaning that you have more time to focus
on your model as opposed to the coding.
And also, it integrates so easily with logging tools such as Tensor Bullet Ml Fluid Neptunian, a comedy
and one which is basically weights and biases, which is a very cool app.
All of these are very cool, actually, and we'll be using Tensor Void in our coding demonstrations.
It also provides an ultimate selection, auto learning read selection, as well as the ability to use
callbacks which you would have seen in Keros.
So let's take a look at the Lightning philosophy.
Lightning proposes that we increase all our models in building blocks into a lightning module.
This is a high level diagram that basically shows this is an auto encoder, CNN, and basically shows
what the lightning module does.
It requires basically us to reorganize our existing PyTorch code, though, so let's take a look at
that.
So here's a minimal example of applied applied to watch lightning coding, and you can see it does look
somewhat familiar.
However, notice something here.
There are five sections in this model.
Is this lightning model?
There's a competition here.
This is our model here.
It is a training loop which is down here, the training step.
There's a validation step which isn't pictured in this diagram, unfortunately, but it's not another
function that does the validation forward step.
There's a test loop also from this diagram and then it optimizes, which are theme here and you can
see the death in it, which we'll talk about in the next slide is quite similar to the existing PI itself.
And you can see that here more clearly.
This here is a pocket watch model, a simple, linear model.
Here you can see it's just a neural network.
There's no CNN's in this network.
This layer one layer, two layer treed or all declared here in the deaf init function in this class.
Remember, the soup of the super function here basically means you're inheriting everything from this
class that you input here.
So all the functions that are available in this class and then module class are inherited in this class
now, which is a very cool, object oriented style programming.
So now you can see we have two fold parts where we just run our model through the steps of pipeline,
basically, if you will, the sequential steps that generate output to the end function coming from
the South Max.
And you can see the pie torch lighting module.
It's pretty much exactly the same this part of the network, isn't it?
The only difference here is besides the name is that we're inheriting now from the the pipe down the
lightning module.
So let's get started with this now.
Let's take a look at the trainers.
This is where the big changes are.
And this is where lightning makes your life so much easier to remember.
In PyTorch, we had to manually run our training loop using the actually calling the epochs the fourth
epoch in number of epochs and then running to batch getting the data out of it and then doing the same
thing for the validation loop.
Well, lightning cleaned it up quite a bit.
Lightning by using this def trading setup and validation step, which I would have shown you in the
previous diagram, but there was some space.
You can actually see how easy it is.
You just have the training batch to batch it forward propagated here.
Use across cross entropy loss logos.
Things returned to lost functions, similar for the validation step.
It's quite simple and quite easy, and it saves you so much coding the time and space here and it just
works out of the box.
Just cool your network like this, and then you can run a double model that fit and lightning.
And it works.
So here's some more changes as well.
You can see this is the pie to its tail where we get the pie torch model that we created.
Then you can set the optimizes like this here in pie torch lighting.
You actually create a optimizer function inside of the class, and it's basically the same thing, the
same line of code.
Similarly, for the cross entropy loss, you do the same thing as well.
So now this is the big, big deal here.
So, no, you can see how we can condense all of this trading stuff here that's going on in the existing
pie.
Too much good and compress it basically into this here.
So we have all pie torch model, lightning or pie torch lightning.
So that's that's what this play is, Trina.
And then we could do Trina that fit using our model.
We created model class, and that's it.
It's actually quite simple.
So you can take a look at this here.
This is also with the data modules, because you may have been wondering.
So we've cleaned up the trading steps.
We've made it much simpler and more, I guess module modular.
However, what about the data loading part of it, despite all its lightning clean that up to?
And yes, it does.
So you can see before we had a transforms, we had to get amnesty to set, split and then get the test
data, then create our data.
Lueders.
Now to us, lightning has made it much simpler as well.
So don't worry if I'm not going into too much detail with this code, we'll do this in the coding lesson
and colab.
But let's take a look at this.
So now there's a function that basically prepares the transforms to the standard, and this just gets
to the data here.
Then there's a trimmed data loader here where you have to transform, so we have to get this again.
Then we have the random splits here and then the data loader here, which we create similarly for this
file and to test as well.
So it's this one isn't as simple as maybe the others, but it's it's quite it's a bit more organized.
Also, PyTorch towards lightning offers something called lightning bolts, which is basically similar
to torture vision, where it's a bunch of other ones.
Things like state of the art models and communities and pre-trained models predict with more advanced
callback functions, data sets, data modules.
So it's quite high level and quite expensive.
There's a lot more being added to this.
So in the next lesson, we'll take a look at applied towards lightning exercises.
We will convert our cats versus dogs by touch code into a lightning module will use the automatic size
finder will also used auto learning.
Read Selector will implement callbacks which are really stopping model, check pointing, logging as
well.
So I'll see you in the next section where we implement those things in code.
Thank you.