code: def test_gradient_value():
      """Test that we don't mutate the gradients during backward"""
      model = Linear(2, 2, bias=False)
      optim = AdaScale(
          SGD(model.parameters(), lr=0.1), num_gradients_to_accumulate=2
      )
  
      # fwd 1
      out = model(Tensor([0.0, 1.0]))
      out.sum().backward()
      assert np.allclose(
          model.weight.grad.numpy(), [[0.0, 1.0], [0.0, 1.0]]
      ), model.weight.grad
  
      # fwd 2, grad is accumulated
      out = model(Tensor([0.0, 1.0]))
      out.sum().backward()
      assert np.allclose(
          model.weight.grad.numpy(), [[0.0, 2.0], [0.0, 2.0]]
      ), model.weight.grad
  
      # assert gain and grad value before/after step/zero_grad
      assert np.allclose(optim.gain(), 1.0000002499999376), optim.gain()
      optim.step()
      assert np.allclose(
          model.weight.grad.numpy(), [[0.0, 2.0], [0.0, 2.0]]
      ), model.weight.grad
      optim.zero_grad()
      assert np.allclose(
          model.weight.grad.numpy(), [[0.0, 0.0], [0.0, 0.0]]
      ), model.weight.grad
  
imports: import tempfile
  import numpy
  import pytest
  import torch
  from torch import Tensor
  from torch.nn import Linear, Sequential
  from torch.optim import SGD
  from torch.optim.lr_scheduler import LambdaLR
  from fairscale.fair_dev.testing.golden_testing_data import adascale_test_data
  from fairscale.fair_dev.testing.testing import make_cudnn_deterministic, skip_if_no_cuda
  from fairscale.fair_dev.testing.testing_memory import find_tensor_by_shape
  from fairscale.optim import AdaScale
label_desc: Use image node_id 9 for calling a global function with example usage: test_gradient_value() without return types