code: def test_quant_embedding(self):
      weight_bit = 8
      embedding = QuantEmbedding(
          2, 4, quant_mode=True, weight_bit=weight_bit
      )
      embedding_weight = torch.tensor(
          [[-1.0, -2.0, -3.0, -4.0], [5.0, 6.0, 7.0, 8.0]]
      )
      embedding.weight = nn.Parameter(embedding_weight)
  
      expected_scaling_factor = embedding_weight.abs().max() / (
          2 ** (weight_bit - 1) - 1
      )
      x, x_scaling_factor = embedding(torch.tensor(0))
      y, y_scaling_factor = embedding(torch.tensor(1))
  
      # scaling factor should follow the symmetric quantization rule
      self.assertTrue(
          torch.allclose(
              x_scaling_factor, expected_scaling_factor, atol=1e-4
          )
      )
      self.assertTrue(
          torch.allclose(
              x_scaling_factor, expected_scaling_factor, atol=1e-4
          )
      )
      self.assertTrue(
          torch.allclose(
              y_scaling_factor, expected_scaling_factor, atol=1e-4
          )
      )
  
      # quantization error should not exceed the scaling factor
      self.assertTrue(
          torch.allclose(
              x, embedding_weight[0], atol=expected_scaling_factor
          )
      )
      self.assertTrue(
          torch.allclose(
              y, embedding_weight[1], atol=expected_scaling_factor
          )
      )
  
imports: import copy
  import unittest
  from transformers import IBertConfig, is_torch_available
  from transformers.testing_utils import require_torch, slow, torch_device
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
label_desc: Use image node_id 1 for calling the IBertModelIntegrationTest obj's underlying member method code with example usage: obj.test_quant_embedding() without return types