mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +08:00
add more detail to tbptt example (#755)
* add more detail to tbptt example * warn user about new arg in training_step
This commit is contained in:
@@ -168,6 +168,14 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
|
||||
# Truncated back-propagation through time
|
||||
def training_step(self, batch, batch_idx, hiddens):
|
||||
# hiddens are the hiddens from the previous truncated backprop step
|
||||
...
|
||||
out, hiddens = self.lstm(data, hiddens)
|
||||
...
|
||||
|
||||
return {
|
||||
"loss": ...,
|
||||
"hiddens": hiddens # remember to detach() this
|
||||
}
|
||||
|
||||
You can also return a -1 instead of a dict to stop the current loop. This is useful
|
||||
if you want to break out of the current training epoch early.
|
||||
|
||||
@@ -448,6 +448,10 @@ class Trainer(TrainerIOMixin,
|
||||
# backprop every 5 steps in a batch
|
||||
trainer = Trainer(truncated_bptt_steps=5)
|
||||
|
||||
Using this feature requires updating your LightningModule's `training_step()` to include
|
||||
a `hiddens` arg.
|
||||
|
||||
|
||||
resume_from_checkpoint (str): To resume training from a specific checkpoint pass in the path here.k
|
||||
Example::
|
||||
|
||||
|
||||
Reference in New Issue
Block a user