code: def _torch2jittor(
      torch_tensor: "torch.Tensor", no_gradient: bool = None
  ) -> "jittor.Var":
      """
      将 :class:`torch.Tensor` 转换为 :class:`jittor.Var` 。
  
      :param torch_tensor: 要转换的 **torch** 张量；
      :param no_gradient: 是否保留原张量的梯度。为``None``时，新的张量与输入张量保持一致；
          为 ``True`` 时，全部不保留梯度；为 ``False`` 时，全部保留梯度；
      :return: 转换后的 **jittor** 变量；
      """
      no_gradient = (
          not torch_tensor.requires_grad
          if no_gradient is None
          else no_gradient
      )
  
      if not no_gradient:
          # 保持梯度并保持反向传播
          jittor_var = jittor.Var(torch_tensor.detach().numpy())
          jittor_var.requires_grad = True
          hook = jittor_var.register_hook(
              lambda grad: torch.autograd.backward(
                  torch_tensor, torch.tensor(grad.numpy())
              )
          )
      else:
          jittor_var = jittor.Var(torch_tensor.detach().numpy())
          jittor_var.requires_grad = False
  
      return jittor_var
  
file_path: fastNLP/fastNLP/modules/mix_modules/utils.py
imports: from typing import Any, Optional, Union
  import numpy
  from fastNLP.core.utils import paddle_to, apply_to_collection
  from fastNLP.core.log import logger
  from fastNLP.envs.imports import _NEED_IMPORT_JITTOR, _NEED_IMPORT_TORCH, _NEED_IMPORT_PADDLE
label_desc: Use image node_id 4 for calling a global function with example usage: _torch2jittor(torch_tensor, no_gradient) and returns: jittor_var