Repository navigation
[models] Keep the early stop of MASTER decoding out of the ONNX export - #2225
Merged
felixdittrich92 merged 2 commits intoNov 13, 2026
Merged
Conversation
The early stop added to MASTER.decode in mindee#2118 is traced by export_model_to_onnx (dynamo=False): the exported graph then runs only as many decoding steps as the dummy input needed, and longer words come out truncated or filled with a repeated character. Guard the stop with not self.exportable, as PARSeq does, and add a test that fails without the guard.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2225 +/- ##
==========================================
- Coverage 98.16% 98.15% -0.01%
==========================================
Files 172 172
Lines 11977 11977
==========================================
- Hits 11757 11756 -1
- Misses 220 221 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
felixdittrich92
requested changes
Nov 13, 2026
felixdittrich92
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @sibisrinivasb 👍
Only a small change and we can merge.
felixdittrich92
approved these changes
Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2224.
What
MASTER.decodenow skips its early stop when the model isexportable, the same guard PARSeq already has:Why
export_model_to_onnxtraces the model, so the stop added in #2118 was evaluated once on the dummy input and the exported graph kept only the decoding steps the dummy needed. PyTorch inference is unchanged and keeps the early stop.master(pretrained=True, exportable=True), exported withtorch.rand((2, 3, 32, 128))under five seeds, then run on 24 rendered words of 1 to 22 characters (all 24 read correctly by PyTorch):An exported MASTER therefore always runs
max_length - 1decoding steps, as before #2118.Test
test_master_decode_early_stopforces EOS at the first decoding step and counts the decoder calls: 1 withoutexportable,max_length - 1with it. It fails on main forexportable=Trueand needs no pretrained weights.Checked
pytest tests/pytorch/test_models_recognition_pt.py -k master: 12 passed, 1 skipped (themastercase oftest_models_onnx_export, under 16 GB here).ruff checkandruff format --checkon the two files: clean.