Reject quantized type tensor with zero scales in flatbuffer importer.

PiperOrigin-RevId: 320648545
Change-Id: If31a8b3ae8598fbd06129f052211fbf8d4583990
This commit is contained in:
Chuan He 2020-07-10 12:05:51 -07:00 committed by TensorFlower Gardener
parent fc0b3b42ea
commit d4a0544a49

View File

@ -152,6 +152,14 @@ StatusOr<QuantizedType> GetQuantizedType(const TensorT& tensor, Builder builder,
uint32_t flags =
is_signed ? mlir::quant::QuantizationFlags::FlagValue::Signed : 0;
// Rejects if quantized tensors have zero scales.
for (float scale : quant_params.scale) {
if (scale == 0) {
return errors::InvalidArgument(
"Quantized tensors must have non-zero scales");
}
}
// Scale size can't be zero as it is checked before.
if (quant_params.scale.size() != 1) {
llvm::SmallVector<double, 4> scales(quant_params.scale.begin(),