0
$\begingroup$

Consider the following method related to buffers in PyTorch

buffers(recurse=True)

Returns an iterator over module buffers.

Parameters

    recurse (bool) – if True, then yields buffers of this module and all submodules. Otherwise, yields only buffers that are direct members of this module.

Yields

    torch.Tensor – module buffer

buffers() is a method used for models (say neural networks) in PyTorch. model.buffers() contains the tensors related to the model and you can see it from the example provided below.

>>> for buf in model.buffers():
>>>     print(type(buf), buf.size())
<class 'torch.Tensor'> (20L,)
<class 'torch.Tensor'> (20L, 1L, 5L, 5L)

The following method informs that a model in PyTorch has both parameters and buffers. So, buffers cannot be same as the parameters (say weights) of the model.

 cpu()

    Moves all model parameters and buffers to the CPU.

I am not aware of any numbers to store for a model other than its parameters. So, I have no idea on what buffers of a model in PyTorch store. But, this implies that there are some other numbers related to model need to be stored for efficiency or other purposes.

What are those numbers, other than parameters, need to be stored for a model?

$\endgroup$
6
  • $\begingroup$ This question seems to be about an API and not strictly related to AI, although you probably thought that a "buffer" was something special in AI (but I don't think it is, i.e. a buffer is just some data structure that holds something in PyTorch: see this discussion), so I think it's off-topic. So, if you also think this is a programming question, I will close it as off-topic. Feel free to provide an answer to this question before I close it, if you think this post could be useful in the future. $\endgroup$
    – nbro
    Jul 28 at 21:19
  • $\begingroup$ @nbro The question is not about buffer. The question is about what do buffer store.Buffer is a tensor and stores numbers related to a neural network. I am asking about those numbers and their nature. $\endgroup$
    – hanugm
    Jul 28 at 21:48
  • $\begingroup$ I think this is still a programming question, as you're asking about the API and how it works. In PyTorch, apparently, these buffers can store some statistics (according to the link above), but this is not strictly related to AI. $\endgroup$
    – nbro
    Jul 28 at 21:50
  • $\begingroup$ If I ask Are there any numbers to store other than parameters of a model? then will it be okay? @nbro $\endgroup$
    – hanugm
    Jul 28 at 21:56
  • 1
    $\begingroup$ I think rephrasing is useful, but this still seems to be related to some specific thing about PyTorch. Maybe other libraries don't have these "buffers". I will leave it open for now. $\endgroup$
    – nbro
    Jul 30 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.