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

參考鏈接:

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