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

ref: reduced all simplified_forward #3126

Merged
merged 3 commits 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
42 changes: 15 additions & 27 deletions pytorch_lightning/trainer/training_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,16 +1162,7 @@ def run_training_teardown(self):
model.cpu()
torch.cuda.empty_cache()

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
# ---------------
def build_train_args(self, batch, batch_idx, opt_idx, hiddens):
# enable not needing to add opt_idx to training_step
args = [batch, batch_idx]

Expand All @@ -1189,25 +1180,22 @@ def training_forward(self, batch, batch_idx, opt_idx, hiddens):
if self.truncated_bptt_steps is not None:
args.append(hiddens)

# distributed forward
if self.use_ddp or self.use_ddp2 or self.use_dp:
output = self.accelerator_backend.training_step(args)

# horovod
elif self.use_horovod:
output = self.accelerator_backend.training_step(args)
return args

# single GPU forward
elif self.use_single_gpu:
output = self.accelerator_backend.training_step(args)

# TPU support
elif self.use_tpu:
output = self.accelerator_backend.training_step(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)

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

is_result_obj = isinstance(output, Result)

Expand Down