code: def get_spatial_gradient_kernel3d(
      mode: str,
      order: int,
      device: Optional[Device] = None,
      dtype: Optional[Dtype] = None,
  ) -> Tensor:
      r"""Function that returns kernel for 1st or 2nd order scale pyramid gradients, using one of the following
      operators: sobel, diff."""
      KORNIA_CHECK(
          mode.lower() in {"sobel", "diff"},
          f"Mode should be `sobel` or `diff`. Got {mode}",
      )
      KORNIA_CHECK(
          order in {1, 2}, f"Order should be 1 or 2. Got {order}"
      )
  
      if mode == "diff" and order == 1:
          kernel = get_diff_kernel3d(device=device, dtype=dtype)
      elif mode == "diff" and order == 2:
          kernel = get_diff_kernel3d_2nd_order(
              device=device, dtype=dtype
          )
      else:
          raise NotImplementedError(
              f"Not implemented 3d gradient kernel for order {order} on mode {mode}"
          )
  
      return kernel
  
imports: from __future__ import annotations
  import math
  from math import sqrt
  from typing import Any, Optional
  import torch
  from kornia.core import Device, Dtype, Tensor, concatenate, cos, stack, tensor, where, zeros, zeros_like
  from kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_IS_TENSOR, KORNIA_CHECK_SHAPE
  from kornia.utils import deprecated
label_desc: Use image node_id 26 for calling a global function with example usage: get_spatial_gradient_kernel3d(mode, order, device, dtype) and returns: kernel