tensorflow: Converting Model to TFLite using Tensorflow 2.16.1 fails - works w/ 2.15.0
1. System information
- OpenSUSE Leap 15.5 AMD64 - Python 3.11
- MacOS 14.4 Sonoma - Python 3.12
- TensorFlow installation: pip package
- TensorFlow library: 2.16.1
2. Code
#converter = tf.lite.TFLiteConverter.from_saved_model(save_path)
converter = tf.lite.TFLiteConverter.from_keras_model(best_model)
# This is supposed to work. I copied it from the tf website, but
# it blows up.
#
print(f"Calling converter.convert()")
tflite_model = converter.convert()
print("Writing output")
with open(os.path.join(output_directory, 'model.tflite'), 'wb') as f:
f.write(tflite_model)
3. Failure after conversion
WARNING: All log messages before absl::InitializeLog() is called are written to STDERRW0000 00:00:1710168763.106515 29073 tf_tfl_flatbuffer_helpers.cc:390] Ignored output_format.W0000 00:00:1710168763.107037 29073 tf_tfl_flatbuffer_helpers.cc:393] Ignored drop_control_dependency.
2024-03-11 08:52:43.107570: I tensorflow/cc/saved_model/reader.cc:83] Reading SavedModel from: tftest/trained_model
{{2024-03-11 08:52:43.107869: I tensorflow/cc/saved_model/reader.cc:51] Reading meta graph with tags { serve }}}
2024-03-11 08:52:43.107881: I tensorflow/cc/saved_model/reader.cc:146] Reading SavedModel debug info (if present) from: tftest/trained_model2024-03-11 08:52:43.110991: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:388] MLIR V1 optimization pass is not enabled
2024-03-11 08:52:43.111327: I tensorflow/cc/saved_model/loader.cc:234] Restoring SavedModel bundle.2024-03-11 08:52:43.134688: I tensorflow/cc/saved_model/loader.cc:218] Running initialization op on SavedModel bundle at path: tftest/trained_model
2024-03-11 08:52:43.138356: I tensorflow/cc/saved_model/loader.cc:317] SavedModel load for tags { serve }; Status: success: OK. Took 30788 microseconds.
2024-03-11 08:52:43.158539: I tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc:268] disabling MLIR crash reproducer, set env var `MLIR_CRASH_REPRODUCER_DIRECTORY` to enable.
loc(fused["ReadVariableOp:", "sequential_1/dense_1/add/ReadVariableOp@__inference_serving_default_124025"]):
error: missing attribute 'value'LLVM ERROR: Failed to infer result type(s).Abort trap: 6
5. (optional) Any other info / logs
This issue was reported on #62610 originally.
I’ve tested this on Linux AMD 64, and on Mac OS 14.4 ARM and the same error occurs.
Per the comment from @adamantivm, I tried using Tensorflow 2.15.0 on Linux AMD64, and it worked as expected.
I tried setting the env variable for MLIR_CRASH… and running, but no output was found.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (3 by maintainers)
Hi @gsexton,
I have reproduced the code with TF 2.15 and TF 2.16. With 2.15 it’s working fine as expected. As you mentioned, it’s getting aborted with TF2.16.1 at TFLite conversion . Right now, TF2.16 has an issue with Keras 3.0. As a workaround install Keras 2 as follows.
pip install -U tf_keras # Keras 2import osos.environ["TF_USE_LEGACY_KERAS"] = "1". Here is the gist with TF 2.16 and keras2 workaround.Thank You