Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re: training forward refactor #3134

Merged
merged 1 commit into from
Aug 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions pytorch_lightning/trainer/training_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,13 +1007,14 @@ def optimizer_closure(self, split_batch, batch_idx, opt_idx, optimizer, hiddens)
# FORWARD (TRAINING STEP + TRAIN STEP END)
# ---------------------------
with self.profiler.profile('model_forward'):
args = self.build_train_args(split_batch, batch_idx, opt_idx, hiddens)
if self.amp_backend == AMPType.NATIVE and not self.use_tpu:
with torch.cuda.amp.autocast():
training_step_output = self.training_forward(split_batch, batch_idx,
opt_idx, hiddens)
training_step_output = self.accelerator_backend.training_step(args)
training_step_output = self.call_hook('training_step_end', training_step_output)
else:
training_step_output = self.training_forward(split_batch, batch_idx, opt_idx,
hiddens)
training_step_output = self.accelerator_backend.training_step(args)
training_step_output = self.call_hook('training_step_end', training_step_output)

# ----------------------------
# PROCESS THE RESULT
Expand Down Expand Up @@ -1186,26 +1187,6 @@ def build_train_args(self, batch, batch_idx, opt_idx, hiddens):

return args

def training_forward(self, batch, batch_idx, opt_idx, hiddens):
"""
Handle forward for each training case (distributed, single gpu, etc...)
:param batch:
:param batch_idx:
:return:
"""
# ---------------
# FORWARD
# ---------------
args = self.build_train_args(batch, batch_idx, opt_idx, hiddens)

# distributed forward
output = self.accelerator_backend.training_step(args)

# Training step end
output = self.call_hook('training_step_end', output)

return output

def update_learning_rates(self, interval: str, monitor_metrics=None):
"""Update learning rates.

Expand Down