II don’t found   reduction variable. So the loss calculation are corrected in this way?
for epoch in range(EPOCHS):
      
        for j, data in enumerate(loader_train):
            global_i += 1

            if j % 10 == 0:
                print(time.time() - start_time)
                start_time = time.time()

            optimizer.zero_grad()

            images_tr = data["data"].to(device)
            labels_tr = torch.LongTensor(data["label"]).to(device)
            outputs_tr = model(images_tr).to(device)

            # backward
            loss = criterion(outputs_tr, labels_tr)
            loss.backward()

            optimizer.step()

            # check test set
            if j % int(len(loader_train) / 2) == 0 and j != 0:
                model.eval()
                with torch.no_grad():

                    losses_sum = 0
                    num_samples_test = 0

                    for data_test in loader_test:

                        images_ts = data_test["data"].to(device)
                        labels_ts = torch.LongTensor(data["label"]).to(device)

                        outputs_ts = model.forward(images_ts)

                        loss_test_sum = criterion(outputs_ts, labels_ts).item()
                        losses_sum += loss_test_sum
                        num_samples_test += 1

                    loss_test_avg = losses_sum / num_samples_test
                    
                    

                    last_loss_test = loss_test_avg
                val_epoch_tr_loss=loss.item()/len(loader_train)
                losses_tr.append(val_epoch_tr_loss)
                losses_ts.append(loss_test_avg)

                del images_ts, labels_ts

            iteration += 1
            del images_tr, labels_tr
            gc.collect()
            model.train()


Is it correct? the loss of training are calculate on the number of data in the training and the loss of  test are calculate with the number of element  of training
Thanks for the kind help!