code: def test_embedding_bag_padding_idx_error(self):
      a = torch.tensor([[1, 3, 2], [0, 2, 1]], dtype=torch.long)
      num_embeddings = 4
      num_features = 3
      embeddings = torch.rand(
          num_embeddings, num_features, requires_grad=True
      )
  
      functional_err_msg = (
          r"padding_idx must be within the number of embeddings"
      )
      module_err_msg = r"padding_idx must be within num_embeddings"
  
      for padding_idx in range(
          -(num_embeddings + 2), (num_embeddings + 2)
      ):
          if (padding_idx < -num_embeddings) or (
              padding_idx >= num_embeddings
          ):
              with self.assertRaisesRegex(
                  RuntimeError, functional_err_msg
              ):
                  F.embedding_bag(
                      a, embeddings, padding_idx=padding_idx
                  )
              with self.assertRaisesRegex(
                  AssertionError, module_err_msg
              ):
                  torch.nn.EmbeddingBag(
                      num_embeddings,
                      num_features,
                      padding_idx=padding_idx,
                  )
          else:
              F.embedding_bag(a, embeddings, padding_idx=padding_idx)
              torch.nn.EmbeddingBag(
                  num_embeddings, num_features, padding_idx=padding_idx
              )
  
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 TestEmbeddingNN obj's underlying member method code with example usage: obj.test_embedding_bag_padding_idx_error() without return types