MCPcopy Create free account
hub / github.com/pytorch/examples / repackage_hidden

Function repackage_hidden

word_language_model/main.py:117–123  ·  view source on GitHub ↗

Wraps hidden states in new Tensors, to detach them from their history.

(h)

Source from the content-addressed store, hash-verified

115###############################################################################
116
117def 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.

Callers 2

evaluateFunction · 0.85
trainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected