def simulated_quantize_compute(attrs, inputs, out_type, target): """Compiler for simulated_quantize.""" assert len(inputs) == 4 assert attrs.sign assert attrs.rounding == "round" data, scale, clip_min, clip_max = inputs # simulate rounding error scaled_data = topi.divide(data, scale) clipped_data = topi.maximum(topi.minimum(scaled_data, clip_max), clip_min) round_data = topi.round(clipped_data) # recover data rdata = topi.multiply(round_data, scale) return [rdata]
def simulated_quantize_compute(attrs, inputs, out_type, target): """Compiler for simulated_quantize.""" assert len(inputs) == 4 assert attrs.sign assert attrs.rounding == "round" data, scale, clip_min, clip_max = inputs # simulate rounding error scaled_data = topi.divide(data, scale) clipped_data = topi.maximum(topi.minimum(scaled_data, clip_max), clip_min) round_data = topi.round(clipped_data) # recover data rdata = topi.multiply(round_data, scale) return [rdata]
def simulated_quantize_compute(attrs, inputs, out_type): """Compiler for simulated_quantize.""" assert len(inputs) == 4 assert attrs.sign assert attrs.rounding == "round" data, scale, clip_min, clip_max = inputs if attrs.kind == QAnnotateKind.IDENTITY: return [topi.identity(data)] # simulate rounding error scaled_data = topi.divide(data, scale) clipped_data = topi.maximum(topi.minimum(scaled_data, clip_max), clip_min) round_data = topi.round(clipped_data) # recover data rdata = topi.multiply(round_data, scale) return [rdata]
def round_compute(attrs, inputs, output_type, target): assert len(inputs) == 1 return [topi.round(inputs[0])]