How to save strings and other information in Pytorch model's buffer?

Viewed 15

I see there is nn.Module.register_buffer() method that stores information in model's state_dict and not in model's parameters.

Its definition is

register_buffer(name: str, tensor: Tensor | None, persistent: bool = True) -> None

It seems to only accept tensors as buffers.

Now I want to save some other things in my model, like my model's nickname (a string), the first start time of training, and other integer information, so that I can save and restore them easily.

Is it a good idea? Can I do it?

0 Answers
Related