Probing Opaque Operators to Make Their Backward Passes Sparse

Training code is full of functions the compiler cannot see into: hand-written CUDA kernels, Python message functions in graph libraries, simulators wrapped as layers, and compiled routines called through a foreign-function interface. We call these opaque user-defined functions (UDFs). An automatic-differentiation engine can still back-propagate through them using whatever backward routine the author supplied. The graph compiler, however, has to treat each one as a wall. It cannot move a linear layer across it, and it cannot skip work when most of the gradient arriving at it is zero. This proposal tests whether a compiler can recover the few properties it actually needs, safely and automatically, by running the black box on chosen inputs and observing what happens. It does not read the source or ask the author.

The core idea fits in two sentences. Before training, we probe each opaque function to test, with explicit failure probabilities, whether each output row depends only on its own input row, and whether the function commutes with a right-multiplied matrix. When a property holds, the compiler applies two rewrites with runtime guards. First, it gathers only the rows that carry nonzero gradient and runs the function's backward on that smaller dense batch. Second, it reorders linear operations across the boundary to minimize arithmetic.

Core Claim

Most of the speedups that sparse back-propagation and graph rearrangement deliver on transparent models are lost the moment an opaque function sits in the path. A small, testable "contract" per function is enough to get them back. The contract consists of three things: row-locality, left-linearity, and a coarse Jacobian block pattern. The contract can be inferred by black-box probing rather than declared by hand, and periodic audits catch the cases where probing was fooled.

The rewrite that matters most is row compaction. It turns dynamic, input-dependent gradient sparsity into a dense problem of smaller size. This sidesteps the conflict the literature documents between sparse kernels and dense hardware. Hector concludes that lowering to dense matrix-multiply templates beats custom sparse kernels on GPUs. SparseProp finds that unstructured sparse kernels overtake dense libraries only above about 90% sparsity. Gathered rows run on dense kernels, so compaction should pay off at far lower sparsity than unstructured kernels need.

Formally, let an opaque function $f$ map a batch $X$ with $n$ rows to output $Y=f(X)$. Call $f$ row-local if row $Y_i$ depends only on row $X_i$. Let $G=\partial L/\partial Y$ be the gradient flowing back into $f$, and let $S=\{i : G_i \neq 0\}$ be the set of active rows. If $f$ is row-local, then

$$ \left(\frac{\partial L}{\partial X}\right)_S = \mathrm{vjp}_f(X_S, G_S), \qquad \left(\frac{\partial L}{\partial X}\right)_{\bar S} = 0, $$

where $\mathrm{vjp}_f$ is the function's own vector-Jacobian product routine and $\bar S$ is the set of inactive rows. The backward cost therefore falls roughly in proportion to $|S|/n$, and no sparse index formats are involved.

The second property is left-linearity: for any weight matrix $W$ of compatible shape, $f(HW)=f(H)W$. Neighbor aggregation in graph networks has this property. When it holds, the compiler may apply the aggregation-versus-transformation reordering that Hector and GraphAGILE use, choosing the order from the input and output feature dimensions, even when the aggregation is a user's Python function.

Where This Sits

The closest work splits into three groups, and each supplies one ingredient while missing another.

The first group makes opaque code optimizable by having someone state its semantics. Enhanced abstract data types (see also; E-ADTs: Turbo-Charging Complex Data) ask type designers to declare rewrite rules and costs. Cedar uses lightweight user hints about randomness and dependencies to reorder Python transforms in input pipelines. Raven statically analyzes Python model scripts into a combined relational and linear-algebra representation. All of these motivate our contract idea, but all of them are forward-only. They also depend on declarations or analyzable source. We infer properties from behavior and use them in the backward pass.

The second group constrains our design. PRISM shows that forcing procedural code fully into the optimizer's view can be catastrophic. Its outlining beats naive inlining by an average of 298.73x on SQL Server ProcBench. We therefore keep opaque regions opaque and expose only properties, never their internals.

The third group supplies the method. SparseConnectivityTracer.jl detects global and input-dependent Jacobian sparsity by tracing with overloaded operators. It fails on compiled binaries and foreign calls, and it does not reorder computation. We borrow its distinction between global and local sparsity, and we use it as ground truth when calibrating our black-box detector. LoRS and Hector reorder backward computations, but only over modules whose algebra is known in advance, and the reordering is fixed statically. SparseProp supplies the reference point for what unstructured sparse kernels achieve.

Research Program

The system has three parts.

The prober. It receives an opaque function together with its forward and backward entry points, plus a sample of real training batches. It runs three tests.

The row-locality test perturbs a random subset of input rows and checks that the untouched output rows stay bit-identical or within a set tolerance. The test runs on real batches, because dependence across rows is often data-dependent. Batch-statistics normalization is the canonical violator, and our test suite will include it deliberately.

The left-linearity test compares $f(HW)$ with $f(H)W$ for random Gaussian $W$ and real $H$. A function that is not linear in this sense will fail at a random probe except on a set of measure zero. Piecewise-linear functions, however, can pass on probes that land in a single linear region. For that reason the test draws $H$ from many batches and records the observed residual distribution, not a single pass or fail.

Jacobian block structure is estimated with compressed random probes applied to the backward routine. This yields a pattern that is valid only at the probed points. We report it as a union over probes and do not claim it holds globally.

The rewriter. It lives inside a PyTorch-style graph capture. It replaces backward calls into certified row-local functions with gather–compute–scatter, and it reorders adjacent linear operations around certified left-linear functions, using the shape-based cost rule from Hector. The decision to compact is made per step from the observed active fraction $|S|/n$, using a measured crossover point for each device and operator, because the active set changes from step to step.

The guard. On a sampled fraction of steps it runs the uncompacted, unreordered backward and compares gradients. If the gradients disagree, it revokes the contract for that function. The guard is what makes probabilistic certification acceptable. We will measure both its overhead and its detection latency.

The application regime is relational graph neural networks, that is, graph networks with typed edges such as RGCN and RGAT. In these models users routinely write message and aggregation steps as Python UDFs. Gradient sparsity there arises naturally from two sources. One is supervision on a small labeled subset of nodes. The other is dynamic sources that change per step, which we will introduce deliberately: margin-based losses that zero out confidently classified nodes, and selection of high-loss nodes for each step.

A secondary regime is scientific computing. There, the opaque function is a compiled right-hand side of a partial differential equation, and the question is whether black-box probing recovers the sparsity pattern that tracing finds.

Baselines

The naive reference point is DGL with user-defined message functions and ordinary dense back-propagation. Gradients for inactive rows are computed and happen to be zero. This baseline will run with the same models, graphs, hardware, and number of training steps as every other system.

The strongest existing method is Hector running the same RGCN and RGAT models written natively in its language. In that setting the compiler knows the algebra, so Hector acts as an oracle for the reordering half of our system. Hector reports up to 43.7x training speedup over public systems, and up to 3.8x from linear operator reordering combined with compact materialization (Hector). Our system beats it in a meaningful sense in two ways. On UDF-written models it should recover most of the gap between the naive baseline and Hector-native without the model being rewritten. On dynamic-sparsity workloads, which Hector treats as dense, it should exceed Hector-native, because row compaction adds savings Hector does not attempt.

A third baseline is static receptive-field pruning: precompute, once, the subgraph that can reach labeled nodes, and train on that subgraph. This captures the static part of the gradient sparsity at zero runtime cost. Our system must beat it on dynamic-loss workloads to justify itself.

A fourth baseline is oracle annotations: the same rewriter driven by hand-written, correct contracts in the style of Cedar. It bounds what inference can achieve.

The ablations are compaction only, reordering only, and probing without the guard. The last one measures how often unguarded certification silently corrupts gradients.

For the scientific-computing check, the baseline for pattern recovery is SparseConnectivityTracer.jl run on the transparent Julia version of the same function. It reports over 1,000x speedup of sparse over dense differentiation on the Brusselator system (SparseConnectivityTracer.jl).

All tuning budgets for the crossover thresholds and guard rates are fixed on the AIFB dataset and then reused unchanged on the other graphs.

Why not just…?

Why not just ask users to annotate their functions, as Cedar and E-ADTs do? This is the most serious alternative. When annotations exist and are correct, they are cheaper than probing, and the oracle-annotation baseline will show by how much. Our claim has two parts. First, probing should match oracle annotations within a small margin at negligible setup cost. Second, wrong annotations are the real danger, because a false "row-local" hint silently corrupts gradients. We will seed incorrect hints into a test suite of functions, such as hidden batch-statistics normalization and cross-row attention, and measure how many are caught by the prober and by the guard. If probing adds nothing beyond verifying hints, the paper becomes a hint-verification paper, which is still a useful contribution.

Why not just rewrite the UDF in a traceable language, or trace it as SparseConnectivityTracer.jl does? Tracing requires source code and operator overloads all the way down. SparseConnectivityTracer.jl cannot pass through compiled binaries or foreign calls. PRISM shows that pulling procedural code into the optimizer's view can make plans much worse. Wherever tracing is possible, we use it as ground truth and report how closely black-box probing agrees with it.

Why not just let dense autodiff multiply by zeros and rely on fast dense kernels? Hector is right that dense matrix-multiply templates win on GPUs, which is exactly why compaction gathers rows into dense batches instead of using sparse formats. The naive baseline and a sweep over the active fraction will locate the crossover point. We expect it to be far below the roughly 90% sparsity that SparseProp reports for unstructured kernels. If it is not, compaction does not earn its place.

Why not just prune to the labeled nodes' receptive field once? For a fixed labeled set and a standard loss, this probably captures most of the benefit, and we say so openly. The proposal stands only if dynamic sparsity, which changes per step, adds a measurable gain on top. The static-pruning baseline tests exactly that.

Proposed Experiments

The primary benchmarks are the relational graph datasets AIFB, MUTAG, and FB15k from DGL, and ogbn-mag from the Open Graph Benchmark. We train RGCN and RGAT written with Python message and aggregation UDFs. Metrics are time per epoch, peak memory, out-of-memory failures, and final test accuracy, which must match the dense baseline within seed variance. No reported result found on Lacuna for UDF-written RGNN training throughput, so the naive baseline will be measured by us.

The first decisive check is the dynamic-sparsity sweep. We vary the loss margin and node-selection rate so that the active fraction ranges from 1 to 0.05. The proposal fails if gains over static receptive-field pruning vanish across the whole sweep.

The second decisive check is certification soundness. We use a suite of about forty opaque functions with known properties, including adversarial ones that are row-local on most inputs but couple rows on some inputs. For each, we report false-accept rates for the prober alone, and the number of steps until the guard revokes the contract.

The third check is pattern recovery on the Brusselator system, compiled as a black box. We compare against tracing ground truth, reporting probe count against recall of the true sparsity pattern, and we state explicitly that probing recovers local, not global, sparsity.

Together these checks separate three outcomes. A clear win shows up as gains over static pruning on dynamic workloads, with zero undetected corruptions. A verification-only result shows up as probing equal to annotations but with corruptions caught. A negative result shows up as compaction losing to dense execution at realistic active fractions.