code: def test_attach_grad():
      def check_attach_grad(x):
          assert x.grad is None
          x.attach_grad()
          with record():
              y = x * 2
              assert y.grad is None
              y.backward(out_grad=mx.nd.ones_like(y).tostype(x.stype))
          assert (x.grad.asnumpy() == 2).all()
  
      zeros = mx.nd.zeros((10, 10))
      stypes = ["default", "row_sparse", "csr"]
      for stype in stypes:
          x = zeros.tostype(stype)
          check_attach_grad(x)
  
imports: import functools
  import mxnet.ndarray
  from mxnet.ndarray import zeros_like
  from mxnet.autograd import *
  from mxnet.test_utils import *
  from common import xfail_when_nonstandard_decimal_separator
  from mxnet.test_utils import environment
  import pytest
label_desc: Use image node_id 12 for calling a global function with example usage: test_attach_grad() without return types