Wraps hidden states in new Tensors, to detach them from their history.
(h)
| 115 | ############################################################################### |
| 116 | |
| 117 | def repackage_hidden(h): |
| 118 | """Wraps hidden states in new Tensors, to detach them from their history.""" |
| 119 | |
| 120 | if isinstance(h, torch.Tensor): |
| 121 | return h.detach() |
| 122 | else: |
| 123 | return tuple(repackage_hidden(v) for v in h) |
| 124 | |
| 125 | |
| 126 | # get_batch subdivides the source data into chunks of length args.bptt. |