pytorch-rnn.flatten_parameters作用

最近翻阅pytorch的代码,常常发现这样一句:rnn.flatten_parameters,但却不知道作用,遂作此文

rnn.flatten_parameters作用

Resets parameter data pointer so that they can use faster code paths

翻译一下,就是重置参数的数据指针。其实就是contiguous(连续性)的问题,在pytorch issue上有这样的warning:

UserWarning: RNN module weights are not part of single contiguous chunk of memory. This means they need to be compacted at every call, possibly greately increasing memory usage. To compact weights again call flatten_parameters()

我的理解是,为了提高内存的利用率和效率,调用flatten_parameters让parameter的数据存放成contiguous chunk(连续的块)。类似我们调用tensor.contiguous

参考链接:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章