Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

First Order MAML? #63

Closed
MurtyShikhar opened this issue Jun 20, 2020 · 8 comments
Closed

First Order MAML? #63

MurtyShikhar opened this issue Jun 20, 2020 · 8 comments

Comments

@MurtyShikhar
Copy link

MurtyShikhar commented Jun 20, 2020

Hi,
Thanks for this very useful piece of software!

I was wondering if there's an easy way to implement first-order MAML with higher. I currently have an implementation of (full) MAML with higher, but wanted to compare it with just first order MAML.

EDIT: It appears that torch.autograd.grad(query_loss, fmodel.parameters()) would give the gradients corresponding to FOMAML and torch.autograd.grad(query_loss, fmodel.parameters(time=0)) can be used to get MAML gradient?

@Nithin-Holla
Copy link

Yes, I think that's correct! Additionally, you could set the track_higher_grads argument to False.

@egrefen
Copy link
Contributor

egrefen commented Jun 22, 2020

Unless I'm missing something, you actually don't need to use higher if you're doing the first order version. Just copy your model, do k forward steps, take a derivative, as you've suggested, of the meta-loss with regard to the latest model weight, and manually map the grads.

As @Nithin-Holla points out, you can use track_higher_grads if you want to just wrap your higher loop in first-order/forward mode, which is equivalent.

@brando90
Copy link

brando90 commented Feb 2, 2022

Hi, Thanks for this very useful piece of software!

I was wondering if there's an easy way to implement first-order MAML with higher. I currently have an implementation of (full) MAML with higher, but wanted to compare it with just first order MAML.

EDIT: It appears that torch.autograd.grad(query_loss, fmodel.parameters()) would give the gradients corresponding to FOMAML and torch.autograd.grad(query_loss, fmodel.parameters(time=0)) can be used to get MAML gradient?

hi @MurtyShikhar how did you end up implemented your fo MAML?

hi @Nithin-Holla I tried setting track_higher_grads to False (to run first order maml) but now my gradients are empty! i.e. they are None. Are you suer ethat setting that flag to False is a good idea? Did you try it yourself?

@brando90
Copy link

brando90 commented Feb 2, 2022

@egrefen what is the official way to run first order MAML with higher?

@kamalojasv181
Copy link

@Nithin-Holla can you confirm if I have understood you correctly or not. MAML to FoMAML can be done just by setting track_higher_grads = False, nothing else?

@brando90
Copy link

@Nithin-Holla can you confirm if I have understood you correctly or not. MAML to FoMAML can be done just by setting track_higher_grads = False, nothing else?

@kamalojasv181 @egrefen whenever I set track_higher_grads=False I get my gradients are Non. I have this check:

            assert outer_opt.param_groups[0]['params'][0].grad is not None

in my train loop. Is this incorrect or is there something wrong? There should be gradients even if it's FO maml, no? What happens to you when you do: track_higher_grads=False?

@brando90
Copy link

brando90 commented Nov 1, 2022

I think this is the solution: #102 to FO

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants