Given an FP32 tensor and a floating-point scale factor, convert the input FP32 tensor to an INT8 tensor by dividing by the scale factor and casting to int8
Asked in the HM phone screen stage. Reported follow-up: how would asymmetric quantization change the conversion if a zero point were provided?
Implement convert_to_int8(tensor, scale). tensor is a non-empty, rectangular nested list of finite floating-point values. Divide each value by the positive scale, truncate toward zero, and saturate the result to the INT8 range [-128, 127]. Preserve the tensor's shape and return nested lists of Python integers.
def convert_to_int8(tensor, scale):