No `training_step()` method defined

Hi,
I implemented autoencoder from ‘Lightning in 2 steps’ on Colab. I am getting an error No training_step() method defined though I have the training_step() defined. What is the issue.
Below is my code for the Lightnig Module:

class LitAutoEncoder(pl.LightningDataModule):

def init(self):
super().init()
self.encoder=nn.Sequential(
nn.Linear(2828,64),
nn.ReLU(),
nn.Linear(64,3)
)
self.decoder=nn.Sequential(
nn.Linear(3,64),
nn.ReLU(),
nn.Linear(64,28
28)
)

def forward(self,x):
embedding=self.encoder(x)
return embedding

def training_step(self,batch,batch_idx):
x,y=batch
x=x.view(x.size(0),-1)
z=self.encoder(x)
x_hat=self.decoder(z)
loss.F.mse_loss(x_hat,x)
self.log(‘train_loss’,loss)

def configure_optimizers(self):
optimizer=torch.optim.Adam(self.parameters,lr=1e-3)
return optimizer

Can you share the colab notebok?

should be

class LitAutoEncoder(pl.LightningModule):

Hi,
Thanks for pointing it out. I had missed it completely.
Where do you set the number of training epochs in trainer?

Trainer(max_epochs=epochs)
1 Like

Hi,
I want the train and valid losses foe each epoch updates alongwith the progressbar. The valid_loss seem to update only once after the first epoch and then its value does not change. The Colab notebook is attached.

I tried it and it’s changing after every epoch.

Ya, It is changing. It was not changing for the lr I was using earlier. Presently trying with lr scheduling to see if it improves things.

Hi, Tried the same solution for my code as well, but getting the same error. Please help with this.
MisconfigurationException : No training_step() method defined. Lightning Trainer expects as minimum a training_step(), train_dataloader() and configure_optimizers() to be defined.

Thanks in Advance

Even iam getting the same error…Any idea why and how to overcome this error