peal.architectures.onnx_predictor¶
ONNX classifiers as PEAL predictors.
PEAL accepted .onnx predictors before, but only as an onnxruntime closure:
fine for the analysis half (DiDAE’s sweep, CFKD’s counterfactual search only
ever query the student), useless for the correction half, whose finetuning
needs an nn.Module with parameters. This module closes that gap:
load_onnx_as_torch()converts the graph withonnx2torchinto a trainableOnnxPredictor(annn.Modulethat pickles, deep-copies and re-exports), after normalising the graph so the converter accepts whattorch.onnx.exportproduces (weights aliased throughIdentitynodes,Constantnodes instead of initializers). The converted module is checked against onnxruntime on a random batch before it is trusted.load_onnx_runtime()is the old closure, kept as the fallback for graphs onnx2torch cannot convert, with a CPU provider fallback instead of the hard-coded CUDA provider (the CPU-only wheel is what pip gives you on aarch64 hosts such as the DGX Spark).export_to_onnx()writes a finetuned predictor back out, so a user who uploaded an ONNX file gets a corrected ONNX file back.inspect_onnx()reads the declared input/output shapes, which the web demo uses to validate a user’s mandatory fields against the graph.
Set PEAL_ONNX_CONVERT=0 to skip the conversion and always use the runtime
closure (the behaviour every pre-2026-09-25 config saw).
Functions
Export a predictor to ONNX with a dynamic batch axis. |
|
Locate the classifier's final linear layer in an ONNX graph. |
|
Declared interface of an ONNX graph. |
|
Convert an ONNX classifier into an |
|
What |
|
The pre-conversion behaviour: an onnxruntime closure (not trainable). |
|
Rewrite an ONNX model in place so onnx2torch accepts it. |
|
Write a copy of the classifier at |
|
Write a copy of |
|
Replace the final layer's weights for the selected classes. |
Classes
A trainable torch module converted from an ONNX classifier. |