PacktPublishing / Deep-Learning-with-PyTorch-Lightning

Getting Started with PyTorch Lightning, Published by Packt
MIT License
150 stars 82 forks source link

Chapter02/Github_Copy_of_Cancer_Detection.ipynb #9

Closed drkp4 closed 2 years ago

drkp4 commented 2 years ago

Shouldn't def training_step(self, batch, batch_idx): / outputs = self.forward(inputs) instead of outputs = self(inputs)?

Shivam6693 commented 2 years ago

@drkp4 Yes, either should work because the training_step passes the input through the forward method. But PyTorch Lightning documentation suggests - "In Lightning we suggest separating training from inference. The training_step defines the full training loop. We encourage users to use the forward to define inference actions. Of course, nothing is preventing you from using forward from within the training_step.

It really comes down to your application. We do, however, recommend that you keep both intents separate.

https://pytorch-lightning.readthedocs.io/en/1.6.0/starter/introduction.html#step-1-define-lightningmodule

So, it's more of a guideline than a rule.

kunal-savvy commented 2 years ago

Closing as no further response is received.