code: def var(input: DTensor, *args, **kwargs):
      dim = None
      if len(args) > 0:
          dim = args[0]
      if "dim" in kwargs:
          dim = kwargs["dim"]
      if isinstance(dim, int):
          dim = (dim,)
      dtype = kwargs.get("dtype", None)
      if dtype is None:
          if not input.dtype.is_floating_point:
              raise RuntimeError(
                  f"var(): could not infer output dtype. Input dtype must be either a floating point or complex dtype. Got: {input.dtype}"
              )
          dtype = input.dtype
      unbiased = kwargs.get("unbiased", True)
      keepdim = kwargs.get("keepdim", False)
      if dim is None:
          if "keepdim" in kwargs:
              raise TypeError(
                  f"var() received an invalid combination of arguments - got (Tensor, keepdim=bool), but expected one of\n"
                  "* (Tensor input)\n"
                  "* (Tensor input, tuple of ints dim, bool keepdim)\n"
                  "* (Tensor input, tuple of names dim, bool keepdim)"
              )
  
      if dim is None or input.shardings.shapes.axis in dim:
          if dim is None:
              n = input.shape.numel()
              sq, s = input.shardings.map_reduce_shard(
                  mapper_func=lambda x: (
                      torch.sum(torch.square(x)),
                      torch.sum(x),
                  ),
                  reducer_func=lambda a, b: (
                      torch.add(a[0], b[0]),
                      torch.add(a[1], b[1]),
                  ),
              )
          else:
              n = 1
              for d in dim:
                  n *= input.shape[d]
              sq, s = input.shardings.map_reduce_shard(
                  mapper_func=lambda x: (
                      torch.sum(
                          torch.square(x), dim=dim, keepdim=keepdim
                      ),
                      torch.sum(x, dim=dim, keepdim=keepdim),
                  ),
                  reducer_func=lambda a, b: (
                      torch.add(a[0], b[0]),
                      torch.add(a[1], b[1]),
                  ),
              )
          output = torch.sub(
              torch.div(sq, n), torch.square(torch.div(s, n))
          )
          if unbiased:
              output = torch.mul(output, n / (n - 1))
          return output
  
      return DTensor(
          input.shardings.map_shard(
              lambda x: torch.var(x, dim=dim, unbiased=unbiased),
              shapes=input.shardings.shapes.squeeze(dim, keepdim),
          )
      )
  
file_path: FATE/python/fate/arch/tensor/distributed/_ops_agg.py
imports: from typing import Tuple
  import torch
  from ._tensor import DTensor, implements
label_desc: Use image node_id 4 for calling a global function with example usage: var(input) and returns: DTensor, output