Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise an error if mixed-precision models are being converted #607

Merged
merged 3 commits into from
Feb 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions larq_compute_engine/mlir/python/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def convert_keras_model(
"Using `experimental_default_int8_range` as fallback quantization stats. "
"This should only be used for latency tests."
)
if hasattr(model, "dtype_policy") and model.dtype_policy.name != "float32":
raise RuntimeError(
"Mixed precision float16 models are not supported by the TFLite converter, "
"please convert them to float32 first. See also: "
"https://github.com/tensorflow/tensorflow/issues/46380"
)
func = concrete_function_from_keras_model(model)
if version.parse(tf.__version__) >= version.parse("1.15"):
frozen_func = convert_variables_to_constants_v2(func, lower_control_flow=False)
Expand Down