Repository navigation
feat(models): export the TorchScript models to ONNX, one graph per depth - #7
Merged
Merged
Conversation
builds/ONNX/export_onnx.py exports a model of impact-torchscript-models at the depth given on the command line (`TS/M730.pt --layers 7` -> TS/M730_depth7.onnx), with a JSON of metadata beside it: channels and stride per layer, whether the graph reads stats, the input's multiple, and the orientation the consumer applies (the .pt's Canonical). A graph takes x and stats and returns the layers the .pt returns for that nb_layers, called with no direction. It is checked against the .pt in torch (values and input gradient) and with ONNX Runtime at another size than the export's. The READMEs describe the files and download_models.sh fetches them with --onnx.
Runs export_onnx.py on TS/M291 at depth 2 and Anatomix at depth 1 with its own checks against the TorchScript models (layers, input gradients, ONNX Runtime at another size), and checks the download script's syntax.
In float32 the TorchScript model and the rebuilt network round differently wherever the CPU's convolution routine does, and an activation at its kink sends the gradient one way or the other: the gradient check passed at 2e-6 on one machine and failed at 2e-4 on a CI runner. In float64 the two agree to 1e-14, so the check now runs there with a 1e-10 bound. The exported graphs are unchanged.
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.
Adds
Data/Models/builds/ONNX/export_onnx.py, which exports any IMPACT TorchScript model to ONNX at a given depth (export_onnx.py TS/M730.pt --layers 7), the same choice the.pttakes at run time throughnb_layers. Each graph outputs the list of layers the.ptreturns for that depth, takesxandstats, and comes with a.jsondescribing its layers (channels, stride, classes), its normalisation and its orientation convention.Every export is checked against the
.pt: features and input gradients in torch (≤ 1.7e-6 relative L2), and ONNX Runtime at another input size (≤ 1.5e-6, head labels identical).The exports are published next to the
.ptfiles on https://huggingface.co/VBoussot/impact-torchscript-models (commit 590f5da4c), anddownload_models.sh --onnxfetches them.