code: def masked_mae_loss(y_pred, y_true):
      mask = (y_true != 0).float()
      mask /= mask.mean()
      loss = torch.abs(y_pred - y_true)
      loss = loss * mask
      # trick for nans: https://discuss.pytorch.org/t/how-to-set-nan-in-tensor-to-0/3918/3
      loss[loss != loss] = 0
      return loss.mean()
  
file_path: dgl/examples/pytorch/dtgrnn/utils.py
imports: import dgl
  import numpy
  import scipy.sparse
  import torch
  import torch.nn
label_desc: Use image node_id 1 for calling a global function with example usage: masked_mae_loss(y_pred, y_true) and returns: loss