code: def test_quant_linear(self):
      def _test(per_channel):
          linear_q = QuantLinear(
              2,
              4,
              quant_mode=True,
              per_channel=per_channel,
              weight_bit=weight_bit,
          )
          linear_dq = QuantLinear(
              2,
              4,
              quant_mode=False,
              per_channel=per_channel,
              weight_bit=weight_bit,
          )
          linear_weight = torch.tensor(
              [[-1.0, 2.0, 3.0, -4.0], [5.0, -6.0, -7.0, 8.0]]
          ).T
          linear_q.weight = nn.Parameter(linear_weight)
          linear_dq.weight = nn.Parameter(linear_weight)
  
          q, q_scaling_factor = linear_q(x, x_scaling_factor)
          q_int = q / q_scaling_factor
          dq, dq_scaling_factor = linear_dq(x, x_scaling_factor)
  
          if per_channel:
              q_max = linear_weight.abs().max(dim=1).values
          else:
              q_max = linear_weight.abs().max()
          expected_scaling_factor = q_max / (2 ** (weight_bit - 1) - 1)
  
          # scaling factor should follow the symmetric quantization rule
          self.assertTrue(
              torch.allclose(
                  linear_q.fc_scaling_factor,
                  expected_scaling_factor,
                  atol=1e-4,
              )
          )
  
          # output of the normal linear layer and the quantized linear layer should be similar
          self.assertTrue(torch.allclose(q, dq, atol=0.5))
  
          # output of the quantized linear layer should be integer
          self.assertTrue(
              torch.allclose(q_int, q_int.round(), atol=1e-4)
          )
  
      weight_bit = 8
      x = torch.tensor([[2.0, -5.0], [-3.0, 4.0]])
      x_scaling_factor = torch.tensor([1.0])
      _test(True)
      _test(False)
  
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 3 for calling the IBertModelIntegrationTest obj's underlying member method code with example usage: obj.test_quant_linear() without return types