MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / fakequant_lower

Function fakequant_lower

imperative/python/megengine/xla/rules/math.py:449–460  ·  view source on GitHub ↗
(ctx, *args: Union[HLOTensor, Sequence[HLOTensor]])

Source from the content-addressed store, hash-verified

447
448@register_lower_rule(mops.FakeQuant)
449def fakequant_lower(ctx, *args: Union[HLOTensor, Sequence[HLOTensor]]):
450 assert (
451 len(args) == 3 and len(ctx.vars_in) == 3
452 ), f"{len(args)}, {len(ctx.vars_in)}, {len(ctx.vars_out)}"
453 assert args[1].ndim == args[2].ndim, f"{args[1].shape}, {args[2].shape}"
454 qmax = np.array(ctx.param["qmax"], dtype=args[0].dtype)
455 qmin = np.array(ctx.param["qmin"], dtype=args[0].dtype)
456 inp, scale, zero_point = args[:3]
457 res = round(inp / scale) + zero_point
458 res = minimum(maximum(res, qmin), qmax)
459 res = (res - zero_point) * scale
460 return res
461
462
463@register_lower_rule("FakeQuantBackward")

Callers

nothing calls this directly

Calls 4

minimumFunction · 0.85
maximumFunction · 0.85
arrayMethod · 0.80
roundFunction · 0.50

Tested by

no test coverage detected