At the moment I have something like this:
# Loop for the epochs
for epoch in range(1, args.epochs + 1):
        model.train()
        epoch_loss = 0
        # Loop through sequences of frames returned by the Dataloader
        for i, sequence in enumerate(training_data_loader):
            optimizer.zero_grad()
            loss = 0
            im_out = i % args.image_freq == 0

            # I initialize the previous prediction as a black image
            prev_est = torch.zeros(sequence['input'].size(0), 3, sequence['input'].size(3), sequence['input'].size(4)).cuda(args.gpu, non_blocking=True)
            # Loop over the sequence of 10 frames, I pass to the network 2 frames (t-1, t)
            for j in range(sequence['input'].size(2) - 1):
                inputs = torch.index_select(sequence['input'], 2, torch.tensor([j,j+1])).cuda(args.gpu, non_blocking=True)
                t = torch.squeeze(torch.index_select(sequence['target'], 2, torch.tensor([j+1])), 2).cuda(args.gpu, non_blocking=True)
                output, l = model(inputs, prev_est, t, i, writer, im_out)
                loss += l 
                # Set the previous estimate as the output from the network
                prev_est = output   
            
            epoch_loss += loss.item() / sequence['input'].size(2)
            # Here I should achieve the backpropagation through time but I am not sure is doing it correctly
            loss.backward()
            optimizer.step()

            writer.add_scalar('learning_rate', args.lr , total_iter)
            writer.add_scalar('train_loss', loss.item(), total_iter)

            print("===> Epoch[{}]({}/{}): Loss: {:.4f}".format(epoch, i, len(training_data_loader), loss.item()))
            total_iter += 1

        print("===> Epoch {} Complete: Avg. Loss: {:.4f}".format(epoch, epoch_loss / len(training_data_loader)))

The train_data_loader provides a tensor containing a sequence of 10 frames. Is it correct the way I am doing BPTT?