Dear PyTorch community,
I have an application that outputs a weird loss curve :

I don’t understand why there are recurrent patterns in the loss curve. In my program, the total loss consists of three L1 losses. And this curve visualize one of the L1 loss.
Is it because some problems in my code? This is how I calculate the total loss:
    for data, x, y in dataloader:
        latent1 = encoder(data)
        recon_dat = decoder(latent1)
        recon_x = func(recon_dat)
        recon_y = func(recon_dat)
        loss1 = criterion(recon_dat, data)
        loss2 = criterion(recon_x, x)
        loss3 = criterion(recon_y, y)
        optimizer.zero_grad()
        loss1.backward(retain_graph=True)
        loss2.backward(retain_graph=True)
        loss3.backward()
        optimizer.step()
        loss4 = loss1.item() + loss2.item() + loss3.item()
        loss_history.append(loss4)

Here, the dataloader outputs data, x, y. Here x and y are both transforms for data.
The network is an autoencoder for data only, which will output recon_dat. The, func is a function that will generate the reconstructed x and y for the recon_dat.
The total loss is the sum of L1 loss between 1) dat and recon_dat, 2) x and recon_x, 3) y and recon_y.
Am I coding everything right?
Thanks!