boundlab.diff.ops#

Custom operators that mark differential structure inside a model.

These are ordinary Python functions that lower to custom-domain ONNX nodes (boundlab::DiffPair, boundlab::HeavisidePruning, …) when the model is exported with boundlab.interp.onnx_export(). The BoundLab interpreter turns those nodes back into DiffExpr2 / DiffExpr3 values; run eagerly, each op evaluates the second (modified) network so the very same module can be executed concretely for Monte-Carlo checks.

Importing this module registers the custom ONNX op names with boundlab.interp, so boundlab:: nodes dispatch to the handler names diff_pair, heaviside_pruning, softmax_pruning and topk_pruning.

Functions

diff_pair

Mark x and y as the two branches of one differential value.

heaviside_pruning

Mock score-based pruning: network 1 keeps data, network 2 masks it.

softmax_pruning

Mock softmax pruning: network 1 is softmax(data), network 2 masks it.

topk_pruning

Mock top-k pruning: network 2 keeps the k highest-scoring positions.

Classes

DiffLinear

Two parallel linear layers paired through diff_pair().

DiffPair

Lift a boundlab::DiffPair node into a DiffExpr2.