Browse Source

feat(mge/quantization): add cambricon-quantization-example

GitOrigin-RevId: ed578ca92b
tags/v1.0.0-rc1
Megvii Engine Team 4 years ago
parent
commit
387867f8ae
2 changed files with 5 additions and 3 deletions
  1. +1
    -1
      python_module/megengine/module/qat/module.py
  2. +4
    -2
      python_module/megengine/module/quantized/linear.py

+ 1
- 1
python_module/megengine/module/qat/module.py View File

@@ -52,7 +52,7 @@ class QATModule(Module):
self.weight_fake_quant = safe_call(qconfig.weight_fake_quant)

def _enable_exec(self, with_module, func, enable):
if not with_module:
if not with_module or not func:
return
if enable:
func.enable()


+ 4
- 2
python_module/megengine/module/quantized/linear.py View File

@@ -32,11 +32,13 @@ class Linear(QuantizedModule):
inp_scale = mgb.dtype.get_scale(inp.dtype)
w_scale = mgb.dtype.get_scale(self.weight.dtype)
bias_dtype = mgb.dtype.qint32(inp_scale * w_scale)
return F.linear(
ret = F.linear(
inp,
self.weight,
None if self.bias is None else self.bias.astype(bias_dtype),
).astype(self.output_dtype)
)
ret = ret if self.output_dtype is None else ret.astype(self.output_dtype)
return ret

@classmethod
def from_qat_module(cls, qat_module: QAT.Linear):


Loading…
Cancel
Save