pytorch
0c48092b - Resets rnn _flat_weights on _apply (#28562)

Commit
5 years ago
Resets rnn _flat_weights on _apply (#28562) Summary: Currently when _apply() is called on RNNBase (or one of its children, like LSTM), the _flat_weights attribute may or may not be updated. In particular, when using .to() and sending a module like LSTM to XLA, a third party device type, the tensors in _flat_weights will not be updated and will remain on CPU. This causes the LSTM forward to fail since the forward call receives a mix of XLA and CPU tensors. This occurs because third party device types, like XLA, may not be a compatible shallow copy type to native tensors. When this is the case and _apply is called Module parameters are replaced, not updated. RNNBase would not sync _flat_tensors with its params in this case, and that caused the references in _flat_tensors to not reflect the module's current params. This small change forces a resync of the _flat_tensors and the actual params on each _apply. This lets .to('xla') work for LSTMs, for example. A test will be added to PyTorch/XLA (which runs in our CI) to validate this behavior after the change appears in PyTorch. Pull Request resolved: https://github.com/pytorch/pytorch/pull/28562 Differential Revision: D18138863 Pulled By: mruberry fbshipit-source-id: 284092cbe4ecff9dd334a9413c330cacdd5e04fd
Author
Mike Ruberry
Parents
Loading