learnables / learn2learn

A PyTorch Library for Meta-learning Research
http://learn2learn.net
MIT License
2.59k stars 348 forks source link

AttributeError: 'NoneType' object has no attribute 'data' #428

Open ren01140201 opened 2 months ago

ren01140201 commented 2 months ago

Error message: p.grad.data.mul_(1.0 / meta_batch_size) AttributeError: 'NoneType' object has no attribute 'data'

For lines;

Average the accumulated gradients and optimize

    for p in maml.parameters():
        print(p)
        p.grad.data.mul_(1.0 / meta_batch_size)
    opt.step()

I encountered the error message in #387 and did as recommended, added the parameter allow_unused=True.

Would it be wrong if I changed the aforementioned lines to: with torch.nograd(): for p in maml.parameters(): if p.grad is not None: p.grad.data.mul(1.0 / meta_batch_size) opt.step()