code: def check_gradient_numerical(channels=4):
      (
          value_paddle,
          sampling_locations_paddle,
          attention_weights_paddle,
      ) = get_test_tensors(channels)
      value_paddle.stop_gradient = False
      sampling_locations_paddle.stop_gradient = False
      attention_weights_paddle.stop_gradient = False
  
      value_cuda = value_paddle.detach().clone()
      sampling_locations_cuda = (
          sampling_locations_paddle.detach().clone()
      )
      attention_weights_cuda = attention_weights_paddle.detach().clone()
      value_cuda.stop_gradient = False
      sampling_locations_cuda.stop_gradient = False
      attention_weights_cuda.stop_gradient = False
  
      output_paddle = ms_deform_attn_core_paddle(
          value_paddle,
          spatial_shapes,
          level_start_index,
          sampling_locations_paddle,
          attention_weights_paddle,
      )
      output_paddle.sum().backward()
  
      output_cuda = ms_deformable_attn(
          value_cuda,
          spatial_shapes,
          level_start_index,
          sampling_locations_cuda,
          attention_weights_cuda,
      )
      output_cuda.sum().backward()
  
      res = paddle.allclose(
          value_paddle.grad, value_cuda.grad, rtol=1e-2, atol=1e-3
      ).item()
      print(f"*tensor1 {res} check_gradient_numerical(D={channels})")
  
      res = paddle.allclose(
          sampling_locations_paddle.grad,
          sampling_locations_cuda.grad,
          rtol=1e-2,
          atol=1e-3,
      ).item()
      print(f"*tensor2 {res} check_gradient_numerical(D={channels})")
  
      res = paddle.allclose(
          attention_weights_paddle.grad,
          attention_weights_cuda.grad,
          rtol=1e-2,
          atol=1e-3,
      ).item()
      print(f"*tensor3 {res} check_gradient_numerical(D={channels})")
  
file_path: PaddleDetection/ppdet/modeling/transformers/ext_op/test_ms_deformable_attn_op.py
imports: from __future__ import absolute_import
  from __future__ import print_function
  from __future__ import division
  import os
  import sys
  import random
  import numpy
  import paddle
  from ppdet.modeling.transformers.utils import deformable_attention_core_func
label_desc: Use image node_id 3 for calling a global function with example usage: check_gradient_numerical(channels) without return types