feat: export classifier and regressor pipelines to ONNX - #346
Merged
stephantul merged 2 commits intoAug 19, 2026
Conversation
Contributor
|
Hey this is cool, thanks for making it. We were about to add this ourselves, but nice you got to it first. I'll check it out ASAP |
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
Contributor
|
Thanks for adding this! I will make some changes to the exporting code in parallel, so this is fine to merge. |
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.
Closes #307.
scripts/export_to_onnx.pycould only export the encoder (StaticModel) — there was no way to get a trainedStaticModelForClassification/Regressionpipeline into ONNX, which is what the issue asks for. This teaches the same script to handle both: it auto-detects whether the given path is a plain encoder or a pipeline with a head, and exports accordingly, so the existing--model_path/--save_pathinterface is unchanged.The classifier path wraps the encoder plus the MLP head into one
torch.nn.Module. The head'sLayers store weights as[out, in]and computex @ weight.T + bias, which is exactlynn.Linear(in, out), so rebuilding them is a direct copy. The output activation matches the head: softmax/sigmoid produce probabilities, an identity head (regressor/projector) produces raw predictions, and the ONNX output is named accordingly.Added tests that export a trained pipeline and run it through onnxruntime, checking the result against
predict_probafor classifiers andpredictfor the identity head — single-label, multilabel, and projector cases all match within 1e-4. Existing inference tests still pass, and ruff/mypy are clean.