code: def test_grad(requires_grad):
      x = np.arange(10)
      t = torch.tensor(
          x, dtype=torch.float, requires_grad=requires_grad
      )
  
      if requires_grad:
          t.grad = torch.zeros_like(t) + 1
  
      t2 = deserialize(*serialize(t))
  
      assert t2.requires_grad is requires_grad
      assert t.requires_grad is requires_grad
      assert np.allclose(t2.detach().numpy(), x)
  
      if requires_grad:
          assert np.allclose(t2.grad.numpy(), 1)
  
imports: from __future__ import annotations
  import pytest
  from distributed.protocol import deserialize, serialize
label_desc: Use image node_id 2 for calling a global function with example usage: test_grad(requires_grad) without return types