mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-11 12:31:23 +08:00
calling self.forward() -> self() (#1211)
* self.forward() -> self() * update changelog Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
This commit is contained in:
co-authored by
Jirka Borovec
parent
2a4cd479e2
commit
d394b80ac8
@@ -24,7 +24,7 @@ that change in the `Autoencoder` model are the init, forward, training, validati
|
||||
x, _ = batch
|
||||
|
||||
representation = self.encoder(x)
|
||||
x_hat = self.forward(representation)
|
||||
x_hat = self(representation)
|
||||
|
||||
loss = MSE(x, x_hat)
|
||||
return loss
|
||||
@@ -38,7 +38,7 @@ that change in the `Autoencoder` model are the init, forward, training, validati
|
||||
def _shared_eval(self, batch, batch_idx, prefix):
|
||||
x, y = batch
|
||||
representation = self.encoder(x)
|
||||
x_hat = self.forward(representation)
|
||||
x_hat = self(representation)
|
||||
|
||||
loss = F.nll_loss(logits, y)
|
||||
return {f'{prefix}_loss': loss}
|
||||
|
||||
@@ -319,7 +319,7 @@ in the LightningModule
|
||||
|
||||
def training_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
logits = self.forward(x)
|
||||
logits = self(x)
|
||||
loss = F.nll_loss(logits, y)
|
||||
return {'loss': loss}
|
||||
# return loss (also works)
|
||||
@@ -371,7 +371,7 @@ For clarity, we'll recall that the full LightningModule now looks like this.
|
||||
|
||||
def training_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
logits = self.forward(x)
|
||||
logits = self(x)
|
||||
loss = F.nll_loss(logits, y)
|
||||
|
||||
# add logging
|
||||
@@ -684,7 +684,7 @@ sample split in the `train_dataloader` method.
|
||||
class LitMNIST(pl.LightningModule):
|
||||
def validation_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
logits = self.forward(x)
|
||||
logits = self(x)
|
||||
loss = F.nll_loss(logits, y)
|
||||
return {'val_loss': loss}
|
||||
|
||||
@@ -740,7 +740,7 @@ Just like the validation loop, we define exactly the same steps for testing:
|
||||
class LitMNIST(pl.LightningModule):
|
||||
def test_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
logits = self.forward(x)
|
||||
logits = self(x)
|
||||
loss = F.nll_loss(logits, y)
|
||||
return {'val_loss': loss}
|
||||
|
||||
@@ -827,7 +827,7 @@ within it.
|
||||
|
||||
def training_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
logits = self.forward(x)
|
||||
logits = self(x)
|
||||
loss = F.nll_loss(logits, y)
|
||||
return loss
|
||||
|
||||
@@ -855,7 +855,7 @@ In this case, we've set this LightningModel to predict logits. But we could also
|
||||
|
||||
def training_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
out, l1_feats, l2_feats, l3_feats = self.forward(x)
|
||||
out, l1_feats, l2_feats, l3_feats = self(x)
|
||||
logits = torch.log_softmax(out, dim=1)
|
||||
ce_loss = F.nll_loss(logits, y)
|
||||
loss = perceptual_loss(l1_feats, l2_feats, l3_feats) + ce_loss
|
||||
@@ -880,7 +880,7 @@ Or maybe we have a model that we use to do generation
|
||||
def training_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
representation = self.encoder(x)
|
||||
imgs = self.forward(representation)
|
||||
imgs = self(representation)
|
||||
|
||||
loss = perceptual_loss(imgs, x)
|
||||
return loss
|
||||
|
||||
@@ -207,7 +207,7 @@ to illustrate why this is needed, let's look at dataparallel
|
||||
|
||||
def training_step(self, batch, batch_idx):
|
||||
x, y = batch
|
||||
y_hat = self.forward(batch)
|
||||
y_hat = self(batch)
|
||||
|
||||
# on dp or ddp2 if we did softmax now it would be wrong
|
||||
# because batch is actually a piece of the full batch
|
||||
|
||||
Reference in New Issue
Block a user