Hi @ptrblck , here is the cleaner code to reproduce the error. I found if I delete code related to self.register_buffer, it works fine.

import torch
import torch.nn as nn
from tqdm import tqdm
import learn2learn as l2l
import torchvision.models.resnet as resnet

def set_dropout_eval(m):
    classname = m.__class__.__name__
    if classname.find('Dropout') != -1:
        m.eval()

def freeze_dropout(model):
    model.apply(set_dropout_eval)
    return model

class Model(nn.Module):
    def __init__(self,):
        super(Model, self).__init__()
        self.model = resnet.resnet50(pretrained=True)
        init_pose = torch.randn(1, 3,256,256)
        self.register_buffer('init_pose', init_pose)
        self.register_buffer('init_pose2', init_pose)
        self.register_buffer('init_pose3', init_pose)
    
    def forward(self, x):
        batch_size = x.shape[0]
        init_pose = self.init_pose.expand(batch_size, -1, -1, -1)
        init_pose2 = self.init_pose2.expand(batch_size, -1, -1, -1)
        init_pose3 = self.init_pose3.expand(batch_size, -1, -1, -1)

        x = x + init_pose
        x = x + init_pose2
        x = x + init_pose3
        
        out = self.model(x)
        return out

device = torch.device('cuda')
model = Model()
model = l2l.algorithms.MAML(model, lr=0.001, first_order=False).to(device)
optimizer = torch.optim.Adam(model.parameters(), lr=0.00001)

X = torch.randn(16,3,256,256).to(device)
Y = torch.randn(16,1000).to(device)
criterion = nn.MSELoss().to(device)

# traning
for i in tqdm(range(10000), total=10000):
    model.train()
    model = freeze_dropout(model)
    X = torch.randn(16,3,256,256).to(device)
    Y = torch.randn(16,1000).to(device)
    learner = model.clone()
    optimizer.zero_grad()
    # inner update
    loss1 = criterion(learner(X), Y)
    learner.adapt(loss1)
    # outer update
    loss2 = criterion(learner(X), Y)
    loss2.backward()
    optimizer.step()