-
Notifications
You must be signed in to change notification settings - Fork 74.9k
Closed
Closed
Copy link
Labels
TF 2.19awaiting PR mergeawaiting PR mergeawaiting PR mergetype:bugBugBugtype:docs-bugDocument issuesDocument issues
Description
Issue type
Documentation Bug
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
binary
TensorFlow version
tf v2.20.0-rc0-4-g72fbba3d20f 2.20.0
Custom code
Yes
OS platform and distribution
Linux Ubuntu 22.04
Mobile device
Linux Ubuntu 22.04
Python version
3.9
Bazel version
None
GCC/compiler version
None
CUDA/cuDNN version
None
GPU model and memory
None
Current behavior?
The doc of tf.quantization.quantize() shows its description as below:
tensorflow/tensorflow/python/ops/array_ops.py
Line 6133 in 5bc9d26
| quantize.__doc__ = gen_array_ops.quantize_v2.__doc__ |
| DefaultValuedOptionalAttr<TF_AnyStrAttrOf<["HALF_AWAY_FROM_ZERO", "HALF_TO_EVEN"]>, "\"HALF_AWAY_FROM_ZERO\"">:$round_mode, |
And for repro below, which shows that Round mode 'HALF_TO_EVEN' only supported for mode 'SCALED'. I accept that it should raise error, but it is something that need to be noted in doc string.
Error raised through codes below, which I think is needed to be format also, from "b ut mode is '" to "but mode is '":
tensorflow/tensorflow/core/kernels/quantize_op.cc
Lines 95 to 104 in 0724da0
| if (round_mode_string == "HALF_AWAY_FROM_ZERO") { | |
| round_mode_ = ROUND_HALF_AWAY_FROM_ZERO; | |
| } else if (round_mode_string == "HALF_TO_EVEN") { | |
| OP_REQUIRES(ctx, mode_string == "SCALED", | |
| errors::InvalidArgument("Round mode 'HALF_TO_EVEN' " | |
| "only supported for mode 'SCALED', " | |
| "b ut mode is '" + | |
| mode_string + "'.")); | |
| round_mode_ = ROUND_HALF_TO_EVEN; | |
| } |
Suggestions
- Note the limitation that
Round mode 'HALF_TO_EVEN' only supported for mode 'SCALED' - Fix the error format to make the description alright
Standalone code to reproduce the issue
import tensorflow as tf
input_tensor = tf.random.uniform(shape=[1, 3, 256, 256], minval=0, maxval=1)
(quantized_tensor, output_min, output_max) = tf.quantization.quantize(input=input_tensor, min_range=0.0, max_range=1.0, T=tf.qint8, mode='MIN_COMBINED', round_mode='HALF_TO_EVEN', narrow_range=False, axis=None, ensure_minimum_range=0.01)
print('Input Tensor Shape:', input_tensor.shape)
print('Output Tensor Shape:', quantized_tensor.shape)Relevant log output
InvalidArgumentError: {{function_node __wrapped__QuantizeV2_device_/job:localhost/replica:0/task:0/device:CPU:0}} Round mode 'HALF_TO_EVEN' only supported for mode 'SCALED', b ut mode is 'MIN_COMBINED'. [Op:QuantizeV2] name:Metadata
Metadata
Assignees
Labels
TF 2.19awaiting PR mergeawaiting PR mergeawaiting PR mergetype:bugBugBugtype:docs-bugDocument issuesDocument issues