I found one implementation of MAML in PyTorch here,

  
      github.com
  
  
    wyharveychen/CloserLookFewShot/blob/master/methods/maml.py 25
# This code is modified from https://github.com/dragen1860/MAML-Pytorch and https://github.com/katerakelly/pytorch-maml 

import backbone
import torch
import torch.nn as nn
from torch.autograd import Variable
import numpy as np
import torch.nn.functional as F
from methods.meta_template import MetaTemplate

class MAML(MetaTemplate):
    def __init__(self, model_func,  n_way, n_support, approx = False):
        super(MAML, self).__init__( model_func,  n_way, n_support, change_way = False)

        self.loss_fn = nn.CrossEntropyLoss()
        self.classifier = backbone.Linear_fw(self.feat_dim, n_way)
        self.classifier.bias.data.fill_(0)
        
        self.n_task     = 4
        self.task_update_num = 5


  This file has been truncated. show original

  
  
    
    
  
  


they use fast weights for each layer in model, and do
loss_q = torch.stack(loss_all).sum(0)
loss_q.backward()

for summed loss