tshadley:

can maximum memory efficiency be achieved with only the hidden state (hidden_v) being volatile here, rather than also the input data_v? Or both to be safe?


volatile is a viral flag. if one input is volatile, all inputs become volatile.
3: yes.
Looks good overall. Instead of repackage_*, you can use hidden.detach_(), but I am not sure if that frees the memory (it might be an outstanding bug).
This concept of trading off memory for compute in autodiff engines is called checkpointing.
In my opinion (i didn’t see the full code), you can clean this up and make it a more generic checkpointing function, that takes a model, data and number of max timesteps to checkpoint at.