Adding Tensors to buffer but avoid saving tensors

I have a tensor that I compute once-off in the model and whose values are not optimised. I add this Tensor to the buffer of the model (such that it can me mapped between CPU and GPU as needed). However, I do not want the Tensor to be saved when saving all the model weights. What is the preferred way of achieving this?

I understand I could save this Tensor (like all other model params). However I prefer not to save it to reduce file size.


register_buffer(…, persistent=False) argument was added in 1.6

1 Like