Skip to content

2.3.7

Choose a tag to compare

@PINTO0309 PINTO0309 released this 12 Mar 10:36
· 2004 commits to main since this release
d1f1fe8

2.3.7

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 brings the feat-torch3 work to main with a focus on two practical improvements:

  • significantly broader native PyTorch package generation coverage, especially for recurrent models and dynamic-shape cases
  • substantially better flatbuffer_direct correctness, graph cleanup, and validation diagnostics

Before these changes, several recurrent models still fell back to non-native execution backends, which meant TorchScript / Dynamo ONNX / ExportedProgram artifacts were skipped even when the generated package was otherwise usable. In parallel, flatbuffer_direct still had a few correctness gaps, including recurrent alias repair issues, layout-sensitive flatten behavior, redundant transpose chains, and a major AveragePool border-semantics mismatch that could produce visible accuracy regressions on real models.

The goal of this branch was not just to patch isolated failures, but to make the native export path and the direct flatbuffer path more robust as product features.

2. Summary of corrections

  • Added broader native recurrent support in the PyTorch exporter, including sequence LSTM / bidirectional LSTM handling, sequence RNN support, and native codegen for REVERSE_V2-based reverse-direction recurrent paths.
  • Reduced avoidable fallback to saved_model / tflite execution backends by keeping supported recurrent graphs on the native backend instead of forcing unrolled primitive fallback in those cases.
  • Improved generated native package reliability for dynamic-shape models by making the emitted shape helpers, layout handling, and recurrent wrappers compatible with TorchScript, Dynamo ONNX export, and ExportedProgram export.
  • Fixed NHWC/NCHW public-boundary inference and flatten/layout handling so native PyTorch packages preserve the intended logical tensor layout in more cases.
  • Repaired recurrent lowering issues in flatbuffer_direct, including orphan final-step tensor aliases that could leave unbound internal inputs in GRU-derived graphs.
  • Optimized multiple redundant transpose chains in flatbuffer_direct, especially the split/concat patterns exposed by res2net50_48w_2s_Opset16.onnx, to reduce unnecessary NCHW/NHWC round-trips.
  • Fixed AveragePool(count_include_pad=1) border semantics in flatbuffer_direct by materializing zero padding explicitly before VALID pooling when needed, instead of relying on TFLite SAME behavior that does not match ONNX exactly at the padded border.
  • Improved additional direct-builder correctness paths, including lowered flatten metadata propagation, shape-chain dtype consistency, selected INT64 unary/scatternd handling, and op-error reporting coverage.
  • Expanded regression coverage substantially across native exporter tests and flatbuffer_direct runtime/lowering tests.
  • Updated GitHub Actions workflows to Node 24.

3. Before/After (If there is an operating log that can be used as a reference)

Native export behavior before this branch:

  • supported recurrent models could still degrade to execution_backend=saved_model or execution_backend=tflite
  • requested TorchScript / Dynamo ONNX / ExportedProgram artifacts could be skipped for dynamic recurrent packages

Native export behavior after this branch:

  • covered recurrent models remain on execution_backend=native
  • the generated native packages emit the expected artifact set for the validated dynamic LSTM cases

flatbuffer_direct accuracy before the AveragePool semantic fix:

  • command:
    • onnx2tf -i res2net50_48w_2s_Opset16.onnx -cotof -tb flatbuffer_direct
  • result:
    • max_abs=0.22682 rmse=0.0500467 cosine=0.999387 pass=False

flatbuffer_direct accuracy after the fix:

  • command:
    • onnx2tf -i res2net50_48w_2s_Opset16.onnx -cotof -tb flatbuffer_direct
  • result:
    • max_abs=4.76837e-06 rmse=8.87476e-07 cosine=1 pass=True

Validation executed on this branch:

  • pytest -q tests/test_tflite_builder_direct.py -k "average_pool_include_pad or average_pool_exclude_pad"
    • 4 passed
  • pytest -q tests -k flatbuffer_direct
    • 668 passed, 352 deselected, 3 warnings

4. Issue number (only if there is a related issue)