-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement MAML meta-opt #23
Conversation
Try to accomplish the task : #17 |
Changes in Learner Structureclass BaseLearner(Layer):
"""Abstract Base Learner Class"""
def __init__(self, module: Layer) -> None:
"""The constructor of BaseLearner
Args:
module (Layer): the model to be trained
"""
super().__init__()
self.module = module
@abstractmethod
def adapt(self, loss: Tensor) -> None:
"""Adapt the model to the current training loss
Args:
loss (Tensor): the current training loss
"""
raise NotImplementedError
- def new_cloned_model(self,) -> Layer:
+ def clone(self: Type[Learner]) -> Learner:
"""create cloned module and keep the computation gragh
Args:
self (Type[Learner]): the sub-learner
Returns:
Learner: the cloned model
"""
raise NotImplementedError
def forward(self, *args, **kwargs):
return self.module(*args, **kwargs)
- @abstractmethod
- def step(self) -> None:
- """Perform a step of training
-
- Args:
- loss (float): _description_
-
- Raises:
- NotImplementedError: _description_
- """
- raise NotImplementedError
-
- def clear_grad(self):
- """clear the gradient in the computation graph
- """
- self.optimizer.clear_grad() As the above code shown, there are mainly two changes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wj-Mcat Can you provide a detailed README.md to compare your empirical results with existing ones provided by PaddleFSL? You can put it in examples/optim. Thanks for the contribution!
Oh sorry, I have relaxed myself a few days. I will run the experiments to get the empirical results in the next few days. |
Metric Overview
|
Thanks for merging, I will try to fix #28 with another PR. |
Description
Try to refactor MAML meta learning algriothm to make it more reusable in paddle-based applications.
Consideration
In MAML module, there are three things which is wired against the normal model application code:
Design
adapt
: accumulate the gradient on cloned modelnew_cloned_model
: clone and save the modelstep
: run step on optimizer in parameters of source modelclear_grad
: clear the gradient