code: def test_EmbeddingBag_per_sample_weights_failures(
      self, device, dtypes
  ):
      # Failure 1: mismatched embeddings / per_sample_weights dtype
      es = nn.EmbeddingBag(5, 2, mode="sum").to(
          dtype=torch.float, device=device
      )
      input = torch.tensor(
          [3, 1, 1, 1, 4, 0], dtype=dtypes[0], device=device
      )
      offsets = torch.tensor(
          [0, 0, 3, 3, 6], dtype=dtypes[1], device=device
      )
      per_sample_weights = torch.randn_like(
          input, dtype=torch.double, device=device
      )
      if device == "cpu":
          with self.assertRaisesRegex(
              RuntimeError, "have the same type as"
          ):
              es(input, offsets, per_sample_weights)
      else:
          with self.assertRaisesRegex(
              RuntimeError, "expected scalar type"
          ):
              es(input, offsets, per_sample_weights)
  
      # Failure 2.1: input/per_sample_weights have different sizes (1d input)
      input = torch.tensor(
          [3, 1, 1, 1, 4, 0], dtype=dtypes[0], device=device
      )
      offsets = torch.tensor(
          [0, 0, 3, 3, 6], dtype=dtypes[1], device=device
      )
      per_sample_weights = torch.randn(
          5, dtype=torch.float, device=device
      )
      with self.assertRaisesRegex(
          ValueError, "same shape as the input"
      ):
          es(input, offsets, per_sample_weights)
  
      # Failure 2.2: input/per_sample_weights have different sizes (2d input)
      input = torch.randint(5, (7, 3), dtype=dtypes[0], device=device)
      offsets = None
      per_sample_weights = torch.randn(
          7 * 3, dtype=torch.float, device=device
      )
      with self.assertRaisesRegex(
          ValueError, "same shape as the input"
      ):
          es(input, offsets, per_sample_weights)
  
      # Failure 3: Unsupported per_sample_weights and mode=('max', 'mean')
      for unsupported_mode in ("max", "mean"):
          es = nn.EmbeddingBag(5, 2, mode=unsupported_mode).to(
              dtype=torch.float, device=device
          )
          input = torch.randint(
              5, (7, 3), dtype=dtypes[0], device=device
          )
          offsets = None
          per_sample_weights = torch.randn(
              7, 3, dtype=torch.float, device=device
          )
          with self.assertRaisesRegex(
              NotImplementedError, "only supported for mode='sum'"
          ):
              es(input, offsets, per_sample_weights)
  
imports: import unittest
  import random
  import itertools
  from itertools import product
  import torch
  from torch.testing._internal.common_utils import run_tests, set_default_dtype, skipIfTorchDynamo, instantiate_parametrized_tests, parametrize, _assertGradAndGradgradChecks, IS_JETSON
  from torch.testing._internal.common_cuda import TEST_CUDA
  from torch.testing._internal.common_nn import NNTestCase
  from torch.testing._internal.common_device_type import onlyNativeDeviceTypes, dtypes, instantiate_device_type_tests, dtypesIfCUDA, onlyCUDA, TEST_WITH_ROCM, skipCUDAIf, skipMeta
  import torch.nn.functional
  import torch.nn
  from torch.testing._internal.common_utils import dtype2prec_DONTUSE
label_desc: Use image node_id 13 for calling the TestEmbeddingNNDeviceType obj's underlying member method code with example usage: obj.test_EmbeddingBag_per_sample_weights_failures(device, dtypes) without return types