Mean columnwise log loss implementation

My main concern is how & where should I keep the log_loss_metric in my pytorch training as well as for my evaluation loop to calculate the mean column wise log_loss value? As I am doing multilabel binary classification there are 206 prediction columns in total.

This is how I am writing my evaluation loop,

def eval_loop_fn(data_loader, model, device):
    running_loss = 0.0
    score = 0.0
    for batch_index,dataset in enumerate(data_loader):
        tabular_data = dataset["tabular_data"]
        output = dataset["output"]
        tabular_data =, dtype=torch.float)
        targets =, dtype=torch.float)

        outputs = model(tabular_data)
        loss = loss_fn(outputs , targets)

        running_loss += loss.item()
    valid_loss = running_loss / float(len(val_data))

    xm.master_print('validation Loss: {:.4f} '.format(valid_loss))