code: def weight2metis(weight: Tensor) -> Optional[Tensor]:
      sorted_weight = weight.sort()[0]
      diff = sorted_weight[1:] - sorted_weight[:-1]
      if diff.sum() == 0:
          return None
      weight_min, weight_max = sorted_weight[0], sorted_weight[-1]
      srange = weight_max - weight_min
      min_diff = diff.min()
      scale = (min_diff / srange).item()
      tick, arange = scale.as_integer_ratio()
      weight_ratio = (
          (weight - weight_min).div_(srange).mul_(arange).add_(tick)
      )
      return weight_ratio.to(torch.long)
  
imports: from typing import Optional, Tuple
  import torch
  from torch import Tensor
  from torch_sparse.permute import permute
  from torch_sparse.tensor import SparseTensor
label_desc: Use image node_id 1 for calling a global function with example usage: weight2metis(weight) and returns: weight_ratio, None