[Bug][TFLite][Relax] relax/test_frontend_tflite.py fails with AttributeError: type object 'Model' has no attribute 'Model'
Expected behavior
Running the relax TFLite frontend tests (e.g: pytest tests/python/relax/test_frontend_tflite.py -v) should successfully parse the converted TFLite model and execute the test cases without crashing.
Actual behavior
Running pytest tests/python/relax/test_frontend_tflite.py fails with:
AttributeError: type object 'Model' has no attribute 'Model'
Environment
- TVM: main branch (87f2915 (latest commit))
- Python: 3.10.20
- OS: Ubuntu (WSL2)
- tflite: 2.10.0
- tensorflow: 2.9.0
Other dependency versions
- absl-py 2.4.0
- apache-tvm-ffi 0.1.10.dev30+g63224e3f1
- astunparse 1.6.3
- attrs 26.1.0
- certifi 2026.2.25
- cffi 2.0.0
- charset-normalizer 3.4.7
- cryptography 46.0.6
- decorator 5.2.1
- exceptiongroup 1.3.1
- flatbuffers 1.12
- gast 0.4.0
- google-auth 2.49.1
- google-auth-oauthlib 0.4.6
- google-pasta 0.2.0
- grpcio 1.80.0
- h5py 3.16.0
- idna 3.11
- iniconfig 2.3.0
- keras 2.9.0
- Keras-Preprocessing 1.1.2
- libclang 18.1.1
- Markdown 3.10.2
- MarkupSafe 3.0.3
- numpy 1.26.4
- oauthlib 3.3.1
- opt_einsum 3.4.0
- packaging 26.0
- pip 23.0.1
- pluggy 1.6.0
- protobuf 3.19.6
- psutil 7.2.2
- pyasn1 0.6.3
- pyasn1_modules 0.4.2
- pycparser 3.0
- Pygments 2.20.0
- pytest 9.0.2
- requests 2.33.1
- requests-oauthlib 2.0.0
- scipy 1.15.3
- setuptools 79.0.1
- six 1.17.0
- tensorboard 2.9.1
- tensorboard-data-server 0.6.1
- tensorboard-plugin-wit 1.8.1
- tensorflow 2.9.0
- tensorflow-estimator 2.9.0
- tensorflow-io-gcs-filesystem 0.37.1
- termcolor 3.3.0
- tflite 2.10.0
- tomli 2.4.1
- typing_extensions 4.15.0
- urllib3 2.6.3
- Werkzeug 3.1.8
- wheel 0.46.3
- wrapt 2.1.2
Steps to reproduce
- Install
tflite==2.10.0 - Run
pytest test_frontend_tflite.py -v -k "nms" - Observe the
AttributeError.
The problem is a compatibility bug in the TVM test suite, specifically in how it interacts with different versions of the tflite Python package.
In test_frontend_tflite.py, the _get_mod_from_cfunc helper function tries to extract the root TVM model using a hardcoded nested namespace:
tflite_model = tflite.Model.Model.GetRootAsModel(converter.convert(), 0)
However, depending on the version of the tflite package installed via pip (e.g. tflite==2.10.0), the Model attribute is not nested. This leads to the following crash during pytest:
AttributeError: type object 'Model' has no attribute 'Model'
Proposed Solution:
The test should defensively attempt the nested extraction, and cleanly fall back to tflite.Model.GetRootAsModel(...) if AttributeError is raised.
tflite_model_buf = converter.convert()
try:
# Older / alternative tflite package structures
tflite_model = tflite.Model.Model.GetRootAsModel(tflite_model_buf, 0)
except AttributeError:
# tflite == 2.10.0 and similar structures
tflite_model = tflite.Model.GetRootAsModel(tflite_model_buf, 0)
Screenshot after applying the fix:
cc @junrushao @leandron
As an aside, while looking into this issue, I ran into severe dependency and compatibility roadblocks trying to get this test suite to run locally.
there's a Numpy/Tensorflow versions Conflict that is unmanaged in the TOML file, it just asks for "tensorflow" and "numpy". It doesn't specify that newer versions of Numpy (v2.x) break older versions of Tensorflow. Since pip defaults to the latest versions, a fresh install immediately gives a broken environment, which did happen in my case
i'll provide further details in another issue