docstr: 检查得到的paddle张量设备和梯度情况的工具函数
docstr_tok: ["\u68c0\u67e5\u5f97\u5230\u7684paddle\u5f20\u91cf\u8bbe\u5907\u548c\u68af\u5ea6\u60c5\u51b5\u7684\u5de5\u5177\u51fd\u6570"]
code: def check_paddle_tensor(self, tensor, device, stop_gradient):
      """
      检查得到的paddle张量设备和梯度情况的工具函数
      """
  
      assert isinstance(tensor, paddle.Tensor)
      if device == "cpu":
          assert tensor.place.is_cpu_place()
      elif device.startswith("gpu"):
          paddle_device = paddle.device._convert_to_place(device)
          assert tensor.place.is_gpu_place()
          if hasattr(tensor.place, "gpu_device_id"):
              # paddle中，有两种Place
              # paddle.fluid.core.Place是创建Tensor时使用的类型
              # 有函数gpu_device_id获取设备
              assert (
                  tensor.place.gpu_device_id()
                  == paddle_device.get_device_id()
              )
          else:
              # 通过_convert_to_place得到的是paddle.CUDAPlace
              # 通过get_device_id获取设备
              assert (
                  tensor.place.get_device_id()
                  == paddle_device.get_device_id()
              )
      else:
          raise NotImplementedError
      assert tensor.stop_gradient == stop_gradient
  
imports: import pytest
  from fastNLP.envs.imports import _NEED_IMPORT_JITTOR, _NEED_IMPORT_PADDLE, _NEED_IMPORT_TORCH
  from fastNLP.modules.mix_modules.utils import paddle2torch, torch2paddle, jittor2torch, torch2jittor
label_desc: Use image node_id 1 for calling the TestTorch2Paddle obj's underlying member method code with example usage: obj.check_paddle_tensor(tensor, device, stop_gradient) without return types