def fake_quant(x, scale): x = x / scale x = F.round(x) x = F.clip(x, -128, 127) x = x * scale return x
def forward(self, x): maxv, minv = x.max(), x.min() scale = F.maximum(maxv, -minv) / 127 return F.round(x / scale) * scale
def fake_quant(x, scale, qmin, qmax): x = x / scale x = F.round(x) x = F.clip(x, qmin, qmax) x = x * scale return x
def forward(self, x): return F.round(x)