Hi HDCharles.
Code you mention is not what’s needed, it refers to C++ compiled implementation of ops.quantized.add. It was very complicated to figure out where is the actual code.
I found it via googling in issues to pytorch in github repository
  

      github.com
  

  
    pytorch/pytorch/blob/b56ba296b1cb5d65a3fe2e33cc1d910481baa644/aten/src/ATen/native/quantized/cpu/kernels/QuantizedOpKernels.cpp#L1173-L1240



          
        
            // Note: out is assumed to be the same size as self and other.
            // Note: Addition is only supported when self, other, out are of the same dtype.
            template <bool ReLUFused = false>
            void qadd_kernel(Tensor& out, const Tensor& self, const Tensor& other) {
              int64_t zero_point = out.q_zero_point();
              // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
              float scale = out.q_scale();
              float inv_scale = 1.0f / scale;
              int64_t self_zero_point = self.q_zero_point();
              // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
              float self_scale = self.q_scale();
              int64_t other_zero_point = other.q_zero_point();
              // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions)
              float other_scale = other.q_scale();
            
            
  // Broadcast out the parameters here to amortize out that cost across
              // loop iterations.
              // TODO: we can optimize dequantization by doing a premultiplication
              // of the zero point by scale and doing FMA on scale*x_q - (scale*zero_point)
              auto self_zero_point_vec = Vectorized<float>((float)self_zero_point);
        
      
    


  This file has been truncated. show original

  

  
    
    
  

  


I still not yet reproduced these operations, because implementation is obscured by other fucntions like  Vectorized::dequantize which obscure the actual implementation and there are lots of different implementations  of that.