code: def test_embedding_bag_dimension_errors(self, device):
      funcs = (
          lambda x, y, z: torch.nn.functional.embedding_bag(y, x, z),
          torch.embedding_bag,
          torch._embedding_bag,
          torch._embedding_bag_forward_only,
      )
      for i, f in enumerate(funcs):
          err_type = ValueError if i == 0 else RuntimeError
  
          weight = torch.full(
              (
                  2,
                  6,
              ),
              0,
              dtype=torch.float64,
              device=device,
          )
          indices = torch.full(
              (
                  2,
                  0,
                  0,
                  6,
                  6,
              ),
              2,
              dtype=torch.int64,
              device=device,
          )
          offsets = torch.full(
              (2, 0, 0, 6, 6), 0, dtype=torch.int64, device=device
          )
  
          if i == 0:
              error_msg = "input has to be 1D or 2D Tensor"
          else:
              error_msg = "input has to be a 1D or 2D Tensor"
          with self.assertRaisesRegex(err_type, error_msg):
              f(weight, indices, offsets)
  
          weight = torch.full(
              (2, 2), 0, dtype=torch.float64, device=device
          )
          indices = torch.full(
              (2,), 1, dtype=torch.int64, device=device
          )
  
          with self.assertRaisesRegex(
              err_type, "offsets has to be a 1D Tensor"
          ):
              f(weight, indices, offsets)
  
          weight = torch.full(
              (2, 2, 2), 0, dtype=torch.float64, device=device
          )
          indices = torch.full(
              (2,), 2, dtype=torch.int64, device=device
          )
          offsets = torch.full(
              (2,), 0, dtype=torch.int64, device=device
          )
  
          with self.assertRaisesRegex(
              err_type, "weight has to be a 2D Tensor"
          ):
              f(weight, indices, offsets)
  
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 12 for calling the TestEmbeddingNNDeviceType obj's underlying member method code with example usage: obj.test_embedding_bag_dimension_errors(device) without return types