Feat: Add ONNX export support for LightOn OCR models#129
Open
remidesbois1 wants to merge 6 commits into
Open
Conversation
Registers lighton_ocr as a model type and exports it as three separate ONNX files: vision_encoder (ViT + projector), embed_tokens (embedding table), and decoder_model_merged (language model with merged KV cache support). Handles weight key remapping from lighton_ocr to Mistral3 internals and works around the >2GB protobuf limit during decoder merge.
Author
|
Note on Dynamo : |
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.
Note: This PR replaces and supersedes #128, which was an experimental draft. This PR provides the clean, final implementation.
This PR adds full ONNX export support for LightOn OCR Vision-Language Models (e.g.,
lightonai/LightOnOCR-2-1B) tooptimum.The export pipeline correctly splits the model into 3 dedicated ONNX sub-components:
vision_encoder,embed_tokens,decoder_merged.Since the official models on the Hub use
"mistral3"as theirmodel_typeinconfig.json,LightonOcrOnnxConfigis natively registered to handle themistral3architecture forimage-text-to-texttasks. (This might not be the correct way to do this so I'm open to suggestion).Enforce
FORCE_ONNX_EXTERNAL_DATA="1"strictly during themerge_decodersstep of the config to bypass the 2GB Protobuf limit.Testing: Added
lighton_ocrto the CI test suite with a tiny dummy model.Note: The export completes successfully and the output files are perfectly valid, but the validation step fails with a ShapeError on the present keys (e.g. (2, 2, 32, 8) vs (2, 2, 16, 8)). Since the logits are accurate, this appears to be a false positive related to how DynamicCache is returned vs ONNX. Let me know if there's a preferred way to handle this validation check!