code: def test_mixed_type_backward(self, device):
      f = torch.ones(
          [3, 3], dtype=torch.float, requires_grad=True, device=device
      )
      ten = torch.tensor([10.0], dtype=torch.double, device=device)
      tens = f * ten
      s = (tens + 2).sum()
      s.backward()
      expected = f.grad.to(torch.double)
      self.assertEqual(tens, expected)
  
      # If we don't convert the returned grad_input to the actual input type
      # we get an error like:
      # RuntimeError: Function SubBackward0 returned an invalid gradient at index 0 - expected type \
      # torch.FloatTensor but got torch.DoubleTensor
      f_dtypes = [torch.float, torch.double]
      if self.device_type == "cuda":
          f_dtypes = f_dtypes + [torch.half]
      i_dtypes = [torch.int, torch.long]
      for func in [
          torch.add,
          torch.sub,
          torch.rsub,
          torch.mul,
          torch.div,
      ]:
          for dtype1, dtype2 in itertools.product(
              f_dtypes, f_dtypes + i_dtypes
          ):
              x = torch.ones(
                  10, requires_grad=True, dtype=dtype1, device=device
              )
              y = torch.ones(10, dtype=dtype2, device=device)
              func(x, y).sum().backward()
  
imports: from functools import wraps
  import itertools
  import unittest
  import torch
  from torch.testing._internal.common_utils import TestCase, run_tests, load_tests, make_tensor, TEST_NUMPY, set_default_dtype, torch_to_numpy_dtype_dict, numpy_to_torch_dtype_dict, skipIfTorchDynamo
  from torch.testing._internal.common_device_type import instantiate_device_type_tests, onlyNativeDeviceTypes, dtypes, onlyCPU, expectedFailureMeta, skipMeta
  from torch.testing._internal.common_dtype import all_types_and_complex_and, get_all_math_dtypes, floating_types, get_all_dtypes, float_to_corresponding_complex_type_map
  import numpy
  import operator
label_desc: Use image node_id 14 for calling the TestTypePromotion obj's underlying member method code with example usage: obj.test_mixed_type_backward(device) without return types