Abstract
This paper introduces ∇AMC, a unified framework for computing gradients across diverse mathematical structures (semirings) in the context of Algebraic Model Counting. By generalizing backpropagation to arbitrary semirings and optimizing memory complexity from $O(e)$ to $O(n)$, the authors enable efficient learning in neurosymbolic systems. Implementation in the Kompyle library demonstrates speedups of up to three orders of magnitude over standard deep learning frameworks like PyTorch and Jax, while maintaining a significantly lower memory footprint.
Introduction
In the evolving field of Neurosymbolic AI, researchers aim to bridge the gap between the low-level pattern recognition of neural networks and the high-level reasoning of symbolic logic. While Algebraic Model Counting (AMC) has successfully unified various logical inference tasks—answering questions like "What is the probability this formula is true?"—the learning aspect of these models has remained fragmented.
Existing deep learning tools such as PyTorch and Jax are designed for massive, dense matrix multiplications. They are poorly suited for the complex, sparse logic circuits required for symbolic reasoning. Furthermore, computing gradients for these circuits typically requires memory proportional to the number of edges, leading to significant resource bottlenecks. This paper addresses these challenges by extending AMC into the domain of learning through the introduction of the algebraic gradient (∇AMC).
Methods: ∇AMC and Algebraic Backpropagation
The authors bridge the gap between inference and learning by treating gradients as a generalized algebraic operation. Their approach consists of four primary components:
- Defining the Algebraic Gradient: The authors define the algebraic gradient as a vector of "conditional" model counts. In a probabilistic context, the gradient of a formula is mathematically equivalent to the probability of that formula being true, given that a specific variable is true. This elegant insight implies that an efficient inference engine can be transformed into a learning engine.
- Generalized Backpropagation: The framework adapts standard backpropagation to function over any semiring (a set of algebraic rules). This allows the same algorithm to be used for diverse tasks by simply swapping the underlying mathematical structure.
- Memory Optimization: Standard backpropagation on circuits typically scales with the number of edges ($e$). By exploiting semiring properties such as cancellation (the ability to "undo" a multiplication) and ordering, the authors reduce memory complexity to the number of nodes ($n$).
- The Kompyle Library: To validate these methods, the authors developed
Kompyle, a Rust-based library specifically engineered for high-performance algebraic backpropagation.
Experimental Evaluation
The authors evaluated their approach using 100 logic formulas from the MC2021 Competition (Track 2). These formulas were compiled into deterministic Decomposable Negation Normal Form (d-DNNF) circuits using the d4 compiler, providing a standard benchmark for tractable symbolic reasoning.
Key Results
- Computational Speed:
Kompyledemonstrated massive performance gains over general-purpose frameworks. In thePROB(probability) semiring,Kompylecomputed gradients in approximately 7.8ms, whereas PyTorch required 7662ms—a 1000x speedup. - Memory Efficiency: While Jax frequently encountered Out-of-Memory (OOM) errors on the test circuits within a 16GB limit,
Kompylehandled them efficiently due to its $O(n)$ memory optimization. - Algorithmic Refinement: The specialized "dynamic" backpropagation algorithm introduced in this work was found to be 2-3x faster than naive algebraic backpropagation implementations found in existing literature.
Theoretical Insights
The versatility of ∇AMC is best demonstrated through the "Semiring Swiss Army Knife" concept. By changing the semiring, the algorithm performs different functions:
- PROB/LOG semirings: Used for standard neural training and numerically stable Expectation-Maximization (EM).
- GRAD semiring: Computes Shannon entropy and information gain.
- VITERBI semiring: Calculates the gradient of the "Most Probable Explanation."
However, the authors also established a theoretical boundary: while first-order gradients are efficient, computing second-order information (Hessians) in linear time is likely impossible. This suggests that first-order optimizers like Adam remain the most viable choice for these symbolic models.
Limitations and Future Work
Currently, ∇AMC is restricted to exact gradients on tractable circuits. If a logic formula cannot be compiled into a tractable form (like a d-DNNF), the method requires approximation techniques not covered in this scope. Additionally, while the Rust implementation is highly optimized for CPUs, adapting these sparse, graph-based operations to the dense-matrix architecture of GPUs remains a significant engineering challenge. Future research may explore specific semirings where second-order information might be more accessible or investigate hardware-accelerated sparse graph processing.
Summary updated