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

Ineffective Python TFLite ImportOption 'save_temp_tfl_input' #19537

Open
riestmo-nxp opened this issue Dec 20, 2024 · 1 comment
Open

Ineffective Python TFLite ImportOption 'save_temp_tfl_input' #19537

riestmo-nxp opened this issue Dec 20, 2024 · 1 comment
Labels
bindings/python Python wrapping IREE's C API bug 🐞 Something isn't working integrations/tensorflow TensorFlow model import and conversion integrations/tosa Tensor Operator Set Architecture (TOSA) import, tests, etc.

Comments

@riestmo-nxp
Copy link

What happened?

The Python API of the compiler for tflite exposes an import option save_temp_tfl_input for debugging purposes. However, it is unused in the upstream TFLite to TOSA API and consequently the import option is ineffective, e.g. no TFLite representation of the model is saved. I would expect to either remove the import option or to (re-)add the creation of a TFLite representation if the option is set.

Steps to reproduce your issue

  1. Follow the TensorFlow Lite integration guide
  2. Run the iree_tflite_compile.compile_file method with passing the save_temp_tfl_input option
  3. See that no TFLite representation of the model is created

What component(s) does this issue relate to?

Python

Version information

v3.0.0

Additional context

No response

@riestmo-nxp riestmo-nxp added the bug 🐞 Something isn't working label Dec 20, 2024
@ScottTodd ScottTodd added integrations/tensorflow TensorFlow model import and conversion bindings/python Python wrapping IREE's C API integrations/tosa Tensor Operator Set Architecture (TOSA) import, tests, etc. labels Dec 20, 2024
@ScottTodd
Copy link
Member

(well this turned into a wall of text, sorry about that 😅)

This is some old code that could use some help with maintenance, patches are welcome.

History

Looking through the git history with git log -S save_temp_tfl_input, that option was part of an early API implementation which was replaced with a newer implementation that included the option but did not use it. See where #7201 deleted bindings/python/iree/compiler/tflite.py.

Relevant source files from history:

Back then, we had a C++ dependency on TensorFlow and TensorFlow Lite. We eventually broke that hard dependency and replaced it with a Python dependency instead. The current files are here:

Looks like I updated some TensorFlow code in #13287 to remove unused options like save_temp_tf_input and save_temp_mid_level_input but missed the TensorFlow Lite code.

What to do now

I would expect to either remove the import option or to (re-)add the creation of a TFLite representation if the option is set.

I think at this point the save_temp_tfl_input and save_temp_iree_input options should be merged, e.g. by deleting save_temp_tfl_input

      save_temp_tfl_input: Optionally save the IR that results from importing
        the flatbuffer (prior to any further transformations).
      save_temp_iree_input: Optionally save the IR that is the result of the
        import (ready to be passed to IREE).

All that iree-import-tflite does in iree_import_tflite/__main__.py now is call the upstream tflite_to_tosa_bytecode function from tensorflow.mlir.experimental, which is "ready to be passed to IREE".

Other details

I think the temp file should also be saved as .mlirbc since it is bytecode (not text) here:

# Saving the file, use tfs.
tfl_iree_input = tfs.alloc_optional(
"tfl-iree-input.mlir", export_as=options.save_temp_iree_input
If you want to get MLIR text (in the TOSA dialect), you can run the bytecode through iree-opt or iree-ir-tool like so

iree-ir-tool cp tfl-iree-input.mlirbc -o tfl-iree-input.mlir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bindings/python Python wrapping IREE's C API bug 🐞 Something isn't working integrations/tensorflow TensorFlow model import and conversion integrations/tosa Tensor Operator Set Architecture (TOSA) import, tests, etc.
Projects
None yet
Development

No branches or pull requests

2 participants