Help clarifying repackage_hidden in word_language_model
<SCODE>def repackage_hidden(h):
    """Wraps hidden states in new Variables, to detach them from their history."""
    if type(h) == Variable:
        return Variable(h.data)
    else:
        return tuple(repackage_hidden(v) for v in h)
<ECODE> I dont think I fully understand what the “history” includes, can somebody helps clarify this? Thanks!
WenchenLi
apaszke
jekbradbury
apaszke
So we do not need to repackage hidden state when making predictions ,since we don’t do a BPTT ?
LaceyChen17
jdhao
<SCODE>def repackage_hidden(h):
    """Wraps hidden states in new Variables, to detach them from their history."""
    if type(h) == Variable:
        return Variable(h.data, requires_grad=True)
    else:
        return tuple(repackage_hidden(v) for v in h)
<ECODE> Thanks.
ratishsp
it has already been updated to be compatible with the latest PyTorch version: <SCODE>def repackage_hidden(h):
    """Wraps hidden states in new Tensors, to detach them from their history."""
    if isinstance(h, torch.Tensor):
        return h.detach()
    else:
        return tuple(repackage_hidden(v) for v in h)
<ECODE>
alphadl