ITADN

`TestCreateInterpreter` tests fail with "Could not open 'model.tflite'" when `ai_edge_litert` is installed

#1068Openomkar-334 创建于 2026-05-25
O
omkar-334commented
## Description The 5 tests in `tests/export/test_tflite_inference.py::TestCreateInterpreter` fail with `ValueError: Could not open 'model.tflite'` in any environment where `ai_edge_litert` is installed (Colab, a full TensorFlow install, or a dev machine with the `[tflite]` deps). They pass in CI only because the CPU test job installs neither `tensorflow` nor `ai_edge_litert`, so the failure goes unnoticed. Failing tests: - `test_uses_tflite_runtime_when_available` - `test_allocate_tensors_called` - `test_returns_interpreter` - `test_logs_input_and_output_shapes` - `test_accepts_path_object` `test_falls_back_to_tensorflow_when_tflite_runtime_missing` passes. ## Explanation (root cause) `rfdetr/export/_tflite/inference.py::_create_interpreter` tries interpreter backends in order: 1. `ai_edge_litert.interpreter` 2. `tflite_runtime.interpreter` 3. `tensorflow.lite` The `_mock_tflite_runtime` fixture injects a fake `tflite_runtime` into `sys.modules` but does not mask `ai_edge_litert`. So when `ai_edge_litert` is importable, `_create_interpreter` selects it first (before the mocked `tflite_runtime`), and the real `ai_edge_litert.Interpreter` tries to load the test's placeholder path `'model.tflite'`, raising `ValueError: Could not open 'model.tflite'`. `test_falls_back_to_tensorflow_when_tflite_runtime_missing` passes because it already masks `ai_edge_litert` in its own `sys.modules` patch. ## Reproduce the bug Colab link - https://colab.research.google.com/drive/1QkWqc9MY5OEVnT5nX-_OPR2W6k4uDrIJ?usp=sharing ```python # Reproduce the TFLite interpreter test failure on a clean Colab (proves it's not local-only). # The trigger is ai_edge_litert: develop's fixture masks only tflite_runtime, so _create_interpreter # tries the REAL ai_edge_litert first and opens a fake 'model.tflite'. !git clone -q -b develop https://github.com/roboflow/rf-detr.git %cd rf-detr !pip install -q -e . ai_edge_litert pytest pytest-doctestplus print("ai_edge_litert installed:", __import__("importlib.util", fromlist=["util"]).find_spec("ai_edge_litert") is not None) # Expect: 5 failed, 1 passed (ValueError: Could not open 'model.tflite') !python -m pytest tests/export/test_tflite_inference.py::TestCreateInterpreter -q ``` The same occurs locally whenever `ai_edge_litert` is importable.
0 条评论