ptrblck:

As far as I know, an setting a tensor as an attribute won’t register it as a buffer, but you would rather need to call self.register_buffer directly.


Thank you for validating that - hope @albanD then can edit his “accepted” solution to fix that.

You can call print(list(model.buffers())) or print(dict(model.named_buffers())) to get all buffers (adapted from the .parameters() / .named_parameters() methods).

Awesome, thank you, @ptrblck!
model.named_buffers is what I was after, model.buffers isn’t useful for debug since it’s unnamed data. In particular this gives me the listing of all registered buffers w/o data:
print(dict(learn.model.named_buffers()).keys())

So after doing self.register_buffer('mybuf1', tensor(0.)) the above printout give me:
dict_keys(['0.2.mybuf1', '1.2.mybuf1', '2.2.mybuf1'])

where 0.2 corresponds to group 0 layer 2, 1.2 group 1 layer 2, etc. Cool!