2.3.19
2.3.19
Important
Starting with onnx2tf v2.4.0, tf_converter will be deprecated and the default backend will be switched to flatbuffer_direct. With the v2.3.3 update, all backward compatible conversion options have been migrated to flatbuffer_direct, so I will only be doing minor bug fixes until April. If you provide us with ONNX sample models, I will consider incorporating them into flatbuffer_direct. I'll incorporate ai-edge-quantizer when I feel like it, but that will probably be about 10 years from now.
1. Content and background
This PR manually ports the optional dependency work from the experimental branch into feat-torch15 and updates the current codebase so that TensorFlow and PyTorch are no longer forced at base install time.
The main goal is to make the default onnx2tf installation lighter and safer for LiteRT / flatbuffer_direct users while keeping TensorFlow-backed and PyTorch-backed features available through explicit extras.
The branch also removes the remaining implicit TensorFlow dependency from -cotof when --tflite_backend flatbuffer_direct is used.
Important compatibility note:
TensorFlow is now fully optional. Users who need SavedModel export, H5 export, Keras v3 export, TFv1 PB export, or tf_converter must install the TensorFlow extra explicitly.
Recommended commands:
uv pip install -U "onnx2tf[tensorflow]"or
uv sync --extra tensorflowor
uv sync --all-extrasWithout that extra, TensorFlow-backed features now fail fast with an explicit install hint instead of importing TensorFlow eagerly at module import time.
Additional note for reviewers: on the current flatbuffer_direct path, a root SavedModel is still written by default unless --disable_model_save is specified. --flatbuffer_direct_output_saved_model is only needed when the intent is to request/guarantee the explicit flatbuffer_direct SavedModel export behavior, especially for split output handling. In all such cases, TensorFlow extra installation is still required because SavedModel generation itself is TensorFlow-backed.
2. Summary of corrections
This PR includes the following functional changes.
- TensorFlow is no longer a mandatory base dependency.
tensorflowandtf-keraswere moved out of the base dependency set intoonnx2tf[tensorflow].import onnx2tfandpython -m onnx2tf --helpno longer require TensorFlow.- TensorFlow-backed features now go through lazy loading and explicit fail-fast checks.
- PyTorch is no longer a mandatory base dependency.
- PyTorch-backed export and validation features were isolated behind
onnx2tf[torch]. - Native package export, TorchScript export, Dynamo ONNX export, ExportedProgram export, and PyTorch validation now fail fast with explicit install guidance if PyTorch is not available.
- The torch extra is pinned to
torch==2.11.0and uses the CPU wheel index in the uv configuration.
- TensorFlow-free runtime helpers were extracted for flatbuffer_direct.
- TensorFlow-independent runtime / schema / dummy-inference helpers were moved into a dedicated LiteRT runtime utility module.
- This allows flatbuffer_direct report generation and runtime checks to execute without pulling TensorFlow into the import path.
flatbuffer_direct-cotofno longer depends on TensorFlow.
- For
--tflite_backend flatbuffer_direct,-cotofnow means the TensorFlow-free report path only. - The flag continues to generate ONNX↔TFLite comparison output and, when requested, ONNX↔PyTorch or TFLite↔PyTorch comparison output.
- The implicit SavedModel validation path was removed from the flatbuffer_direct
-cotofflow, so-cotofitself no longer forces TensorFlow there. tf_converterkeeps the existing TensorFlow-dependent behavior.
- SavedModel behavior is now explicit.
- SavedModel export is still supported, but it is now clearly treated as a TensorFlow-backed optional feature.
- Users who need SavedModel-related workflows must install
onnx2tf[tensorflow]. - Documentation was updated so this requirement is visible from the install section and from the relevant option descriptions.
- Failure messages and developer ergonomics were improved.
- Optional dependency errors now suggest
uv-based install commands. - PyTorch runtime import failures caused by foreign
PYTHONPATH/LD_LIBRARY_PATHcontamination now return a clearer diagnostic instead of a raw traceback.
- Documentation and tests were updated.
- README / CONTRIBUTING were updated for the new extras-based installation model.
- New regression tests were added for TensorFlow-absent and PyTorch-absent environments.
- Existing tests were updated to match the new
flatbuffer_direct -cotofbehavior.
3. Before/After (If there is an operating log that can be used as a reference)
Before:
- Base installation always pulled TensorFlow.
- Base installation also effectively assumed PyTorch for several flatbuffer_direct-related flows.
import onnx2tfand some CLI entrypoints could fail early if TensorFlow / PyTorch were not available.flatbuffer_direct -cotofstill implicitly required TensorFlow because it triggered SavedModel validation.- SavedModel-capable flows were not clearly separated from the lightweight LiteRT-only installation path.
After:
- Base installation is lightweight and does not force TensorFlow or PyTorch.
- TensorFlow-backed features are explicitly installed with
onnx2tf[tensorflow]. - PyTorch-backed features are explicitly installed with
onnx2tf[torch]. import onnx2tfand CLI help work without TensorFlow / PyTorch.flatbuffer_direct -cotofworks without TensorFlow and stays on the TensorFlow-free evaluation/report path.- SavedModel users now have a clearer contract: install the TensorFlow extra before using SavedModel export or other TensorFlow-backed outputs.
Validation executed on this branch:
pytest -q tests/test_optional_tensorflow.py tests/test_optional_pytorch.py
pytest -q tests/test_flatbuffer_direct_op_error_report.py tests/test_pytorch_bulk_runner.py
pytest -q tests/test_tflite_builder_direct.py -k 'flatbuffer_direct_accuracy_report_generation or split_accuracy_report_fail_on_threshold'
pytest -q tests/test_optional_tensorflow.py
pytest -q tests/test_tflite2sm_phase1.py -k 'cotof and (flatbuffer_direct_output_saved_model or tflite_direct_input_saved_model)'4. Issue number (only if there is a related issue)
N/A
What's Changed
- Make TensorFlow/PyTorch optional and decouple flatbuffer_direct -cotof from TensorFlow by @PINTO0309 in #924
Full Changelog: 2.3.18...2.3.19