code: def test_embedding_bag_out_of_bounds_idx(
      self, device, dtypes, padding_idx, mode
  ):
      padding_idx = 0
      w_dtype, idx_dtype = dtypes
      # negative out-of-bound
      idx1 = torch.tensor([[-1, 1]], device=device, dtype=idx_dtype)
      # positive out-of-bound
      idx2 = torch.tensor([[11, 8]], device=device, dtype=idx_dtype)
      weight = torch.randn(10, 2, device=device, dtype=w_dtype)
      if mode == "sum":
          # Only `sum` supports per_sample_weight
          per_sample_weights = (
              None,
              torch.randn_like(idx1, device=device, dtype=w_dtype),
          )
      else:
          per_sample_weights = (None,)
  
      for p_s_weights, idx in itertools.product(
          per_sample_weights, (idx1, idx2)
      ):
          msg = "Expected idx >= 0 && idx < num_embeddings"
          with self.assertRaisesRegex(RuntimeError, msg):
              torch.nn.functional.embedding_bag(
                  idx,
                  weight,
                  per_sample_weights=p_s_weights,
                  padding_idx=padding_idx,
                  mode=mode,
              )
  
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 11 for calling the TestEmbeddingNNDeviceType obj's underlying member method code with example usage: obj.test_embedding_bag_out_of_bounds_idx(device, dtypes, padding_idx, mode) without return types