code: def distance(perturb, clean, dis_type="ce", data=None, p=2):
      """
      Distance between logits of perturbed and clean data.
      Parameters:
      ---------
      perturb: torch.Tensor [n, C]
      clean: torch.Tensor [n,C]
      type: loss type
      labels: ground truth labels, needed when type='cw'
      p: fro norm, needed when type='fro'
  
      Return
      ------
      Distance: torch.Tensor [n,]
      """
      # if type=='cos':
      #     return perturb*clean / torch.sqrt(torch.norm(perturb,p=2) * torch.norm(clean))
      if dis_type == "fro":
          return torch.norm(perturb - clean, p=p)
  
      elif dis_type == "ce":
          p_ = F.softmax(clean, -1)
          logq = F.log_softmax(perturb, -1)
          return -(p_ * logq).mean()
  
      elif dis_type == "kl":
          logq = F.log_softmax(perturb, -1)
          p_ = F.softmax(clean, -1)
          logp = F.log_softmax(clean, -1)
          return (p_ * (logp - logq)).mean() * 100
  
      elif dis_type == "cw":
          perturb, clean, labels = (
              perturb[data.train_mask],
              clean[data.train_mask],
              data.y[data.train_mask],
          )
          eye = torch.eye(labels.max() + 1)
          onehot_mx = eye[labels]
          one_hot_labels = onehot_mx.to(labels.device)
          # perturb
          ptb_best_second_class = (
              perturb - 1000 * one_hot_labels
          ).argmax(1)
          margin = (
              perturb[np.arange(len(perturb)), labels]
              - perturb[np.arange(len(perturb)), ptb_best_second_class]
          )
          ptb_loss = -torch.clamp(margin, max=0, min=-0.1).mean()
          # clean
          clean_best_second_class = (
              perturb - 1000 * one_hot_labels
          ).argmax(1)
          margin = (
              clean[np.arange(len(perturb)), labels]
              - clean[np.arange(len(perturb)), clean_best_second_class]
          )
          clean_loss = -torch.clamp(margin, max=0, min=-0.1).mean()
  
          return (ptb_loss - clean_loss) * 100
  
file_path: AutoGL/autogl/module/nas/estimator/grna_estimator.py
imports: import torch
  from deeprobust.graph.global_attack import Random, DICE
  import numpy
  import scipy.sparse
  from tqdm import tqdm
  import time
  import torch.nn.functional
  from .None import register_nas_estimator
  from ..space import BaseSpace
  from .base import BaseEstimator
  from ..backend import *
  from ...train.evaluation import Acc
  from ..utils import get_hardware_aware_metric
label_desc: Use image node_id 1 for calling a global function with example usage: distance(perturb, clean, dis_type, data, p) and returns: torch, unknown, unknown, unknown