boundlab.diff.net.diff_net#
- boundlab.diff.net.diff_net(net1, net2)[source]#
Merge two structurally-identical ONNX models by pairing initializer inputs.
For each aligned node pair in
net1/net2, any input position where both sides consume initializers is replaced by a sharedboundlab::diff_pairvalue in the merged graph. This generalizes beyond affine operators (e.g.Gemm/MatMul) to any operator that reads parameters as initializers.At concrete runtime,
diff_pairis a no-op that returns branch-1 values (net1 semantics). Under differential interpretation, the paired values are lifted intoDiffExpr2.- Parameters:
net1 (ir.Model | str | Path) – ONNX models with the same graph structure. Each may be an
onnx_ir.Model, astr, or apathlib.Path.net2 (ir.Model | str | Path) – ONNX models with the same graph structure. Each may be an
onnx_ir.Model, astr, or apathlib.Path.
- Return type:
A merged
onnx_ir.Model.
Examples
>>> from boundlab.diff.net import diff_net >>> from pathlib import Path >>> nets = Path("compare/veridiff/examples/nets") >>> merged = diff_net(nets / "single_layer_ref.onnx", nets / "single_layer_alt.onnx") >>> any(n.domain == "boundlab" and n.op_type == "diff_pair" for n in merged.graph) True