Hello and welcome to this tutorial.
All right.
So in the previous tutorials we made the brain or if you want the brains for the A-3 see now we need
to train this brain.
But in order to trained his brains we need an optimizer that's this tool use and stick a cigarette in
the center to take the weight according to how much they contribute to the error between the predictions
and the targets.
And what we did up until now in the first and second module we used the atom optimizer by torche in
the training.
But as I told you we are dealing with a very challenging problem that is break out and the A-380 algorithm
by itself is not enough to solve this problem.
We need some customized optimizers and a lot of different tricks to solve this problem without waiting
for ages.
So that's the purpose of doing this and that is why we have a separate custom optimizer based on the
atom optimizer.
And that is contained in this shared enemy class and why shared atom.
It's because it is actually the atom optimizer but that will work on shared States.
So we're going to explain how it works and it's to toile So we're going to go through the different
functions here without killing them because you know we want to keep some energy for the next and in
addition that is the train that I fell which will take more than one hundred lines of code.
So be ready for that.
And therefore we will try to explain what's going on here in one Statoil Statoil.
And let's start right now.
All right so first we introduce this class sharing atom that will contain three functions the init function
the shared memory function and the step function.
So what we do first is that we inherit from optin that atom which is of course the atom optimizer and
that we get from the Upton module from the torch library.
So here we are plain heritance to get the tools all related to the atom optimizer and then we start
with the init function.
So what happens here.
First we use the superfunction to inherit from all the tools and all the basic parameters from the atom
the Atom class and these basic parameters are here.
Harams learning race baiters Epsilon and weight decay.
And then we start a follow up.
This first Foluke for group itself that Paramo groups.
So for us what is parum groups set up around groups contains all the attributes of the optimizer.
And among these attributes we have the parameters that we have to optimize these parameters that we
want atomize other ways of the network that are contained in self parum groups perhaps.
So there we go group belongs to self-help groups.
And here we have the second Faltu which will get these parameters that we want to optimize and that
are exactly contained in self-doubt parum groups perhaps.
So basically we go through self-help groups that contains all the parameters and for each group of parameters
and self-talk from groups we are going to go through the parameters that we want to optimize.
Therefore for the group Paramo here means for each Tancer of weights that we want to optimize.
So for each sensor weights that we want to optimize and then what happens inside this group with these
four lines of code.
Basically what happens is that the update made by the optimizer is based on an exponential moving average
of the gradient.
That's this line of code here.
That's the exponential moving average of the gradient of moment one that is of order one.
But the objects made by atom is not only based on that it is also based on an exponential moving average
of the square of the gradient.
That is an exponential moving average of the gradient of momentum to or two.
So here is the exponential moving average of all of one.
And here is the exponential moving average of two for each of them that EMJ have degraded.
So that what happens here.
And now if you want to get more in depth of how the exponential moving average works well I highly encourage
you to have a look at this research paper Adam method for stochastic optimization because basically
the atom optimizer that we're implementing right now is based on the algorithm one here.
So if you want to have more details on how the algorithm works well this paper will be definitely helpful.
And then you have some further explanations on the algorithm with the atoms and the rules.
And so you know that's only if you want to attack this before attacking the big train function that
will make afterwards.
OK so let's go back to bison.
And now let's move on to the second function shared memory.
So now I'm just going to say a few words.
The idea of this shared memory function is kind of like tensor that kuda you know is an accelerator
based on a view.
And so basically what happens here is that we have these tensors of the states that share memory here
here and here that behave a little bit like tenso that could to accelerate accelerated computation.
But the difference is that here the sensors that share memory send the computation to a part of the
GP you or you that is accessible to all the paralyzed threat.
So that's basically what is done here.
That's a little bit like 10 to that kuda but it's only sent to a part of the GP to be accessible to
the parallelize threats.
All right.
And then we have the last function step.
So you know this function it's like the step method of the atom optimizer that we are use in this course.
And so again this is based on the algorithm one of the same paper that we saw before.
So this algorithm.
So again you want to understand in details the following lines of code.
Well again I Ingrid's you to have a look at this algorithm one by this paper.
And besides what is done here is not totally compulsory because this is actually a copy paste of the
step method acting that atom class.
So basically what is done here we could have done it by using our inheritance because here we inherit
from Acton that Adam and so to use our inheritance Well what we can do instead of doing all this is
just going to write here comment is just use the superfunction that we apply to our shared Adam class
then our object self and here we just add step with parenthesis step is the method of the act in that
class and that's exactly the same.
That's why I was just saying that here is just a copy paste of the step method of the act in the Atom
class.
So I think that if you replace all this by this super function applied to share Adam and the step method
well we might get exactly the same thing.
All right so that was interesting to have a quick look at it.
Basically you can see this as the Adam optimizer.
It's like we had a deeper look at it.
But again if you want to go in more details of all this and if you want to understand what happens behind
the scene Well I encourage you to have a look at this research paper.
I'll put the link in the comments here.
You know remember you will have all the code connected in great details.
So it's really good if you can have a look at it.
And now I hope you have some great energy because we are going to move on to the train file which will
contain this huge train function and that will basically train our brains which now we can do because
we have our optimizer.
So have a good break now.
Have a good sleep and whenever you feel in great shape.
Let's move on to the next step.
Until then enjoy AI.