docstr: Verifies that the autocast cache is global. This is done by
  mocking out cache clearing at the end of the forward pass,
  running forward+backward with an explicit call to autocast in the
  backward, and verifying that the weight only get cast to float16 once.
code: def test_cast_cache_is_global(self):
      """
      Verifies that the autocast cache is global. This is done by
      mocking out cache clearing at the end of the forward pass,
      running forward+backward with an explicit call to autocast in the
      backward, and verifying that the weight only get cast to float16 once.
      """
  
      data = torch.randn(2, 3).cuda()
      weight = torch.nn.Parameter(torch.randn(4, 3).cuda())
  
      with WeightDTypeCastCounterMode(weight) as mode:
          with torch.autocast(device_type="cuda"):
              output = CustomLinear.apply(data, weight)
              s = output.sum()
          s.backward()
  
      self.assertEqual(mode.dtype_cast_counter, 1)
  
imports: import collections
  import unittest
  import torch
  from torch.testing._internal.common_utils import TestCase, run_tests, IS_WINDOWS, skipIfTorchDynamo
  from torch.testing._internal.autocast_test_lists import AutocastCPUTestLists
  from torch.utils._python_dispatch import TorchDispatchMode
label_desc: Use image node_id 1 for calling the TestAutocastGPU obj's underlying member method code with example usage: obj.test_cast_cache_is_global() without return types