[KongchangAI]
· 2 min read· 1,243 words

Hard-Logic Circuits from Neural Networks: Interpretable Conversion of Attention Models and FPGA Acceleration

Hard-Logic Circuits from Neural Networks: Interpretable Conversion of Attention Models and FPGA Acceleration

New study converts attention networks into hard-logic predicate circuits, enabling interpretable and FPGA microsecond-level inference.

The study converts a trained attention network into a hard-logic predicate circuit, where each unit is a 0/1 predicate over tokens with truth-table-minimized mappings. Using a Ship-of-Theseus-style block replacement, DistilGPT2 reaches 66.5% accuracy on TweetEval-emotion (BERT-base 70.0%), about 8.5 points below the teacher. The circuit needs no multipliers or weight transfer, is bit-for-bit reproducible, and runs in 1-2 microseconds on FPGA—two to three orders of magnitude faster than GPU.

Converting a trained attention network as a whole into a hard-logic predicate circuit while preserving the attention mechanism sounds like science fiction, but a new study has achieved exactly that. Each circuit unit is a 0/1 predicate over tokens, and the mappings between predicates are minimized truth tables. This technique not only makes the model interpretable but also enables microsecond-level inference on FPGA.

From Soft Attention to Hard Logic: The Conversion Method

The core idea of the study is to convert each computational unit in an attention network into a hard-logic predicate circuit. Specifically, each unit is a 0/1 predicate over input tokens, and the mappings between units are realized by minimizing truth tables. For short truth tables (such as the product of query codes and key codes), exact minimization is possible; for broad feature-to-feature transformations, noise-tolerant minimization converts them into implication rules.

The entire conversion process adopts a "Ship of Theseus"-style replacement strategy: starting from the output end, blocks in the network are replaced one by one, and after each replacement, the remaining soft parts re-adapt to the frozen circuit. This gradual replacement ensures the circuit's behavior aligns with the original network.

rss source: How to Turn an Attention Neural Network into an Interpretable Hard-Logic Predicate Circuit: Truth-Ta

Attention selection takes two forms: one is row-by-row comparison based on integer scores (sequential selection), and the other is learned rules (rule selection). Both forms are fitted only on the ordinary training set and use only samples that the teacher network classifies correctly, ensuring the circuit imitates the teacher where the teacher is correct.

Soft Attention vs. Hard-Logic Predicates

In soft attention mechanisms, attention weights are continuous values between 0 and 1, computed via dot products and softmax, representing the model's "degree of focus" on each token. In contrast, a hard-logic predicate circuit quantizes each computational unit into a 0/1 Boolean judgment over tokens—for example, "whether the token belongs to a certain part of speech" or "whether the token appears at a certain position." This discretization allows the network's behavior to be precisely described by truth tables.

Truth Table Minimization and Implication Rules

Truth table minimization is a classic problem in Boolean logic: given the truth table of a Boolean function, find the simplest sum-of-products (or product-of-sums) expression. For short truth tables (such as the product of query codes and key codes, typically only tens to hundreds of rows), the minimal expression can be found exactly. For broad feature-to-feature transformations (truth tables may contain millions of rows), exact minimization is infeasible, so noise-tolerant minimization is used—allowing a certain proportion of misclassifications and converting the mapping into a set of implication rules (if condition A holds, then conclusion B holds), thereby balancing interpretability and conciseness.

Experimental Performance: The Trade-off Between Accuracy and Efficiency

On the TweetEval-emotion dataset, the full-circuit version of DistilGPT2 achieves a test gold-standard accuracy of 66.5 ± 1.3% under sequential selection and 57.4 ± 2.5% under rule selection (three random seeds), compared to 74.7% for the teacher network and 64.0% for a bag-of-words model fitted on the same tweets. The BERT-base circuit achieves 70.0 ± 0.5% under sequential selection and 63.7 ± 1.2% under rule selection, compared to 77.8% for the teacher network.

The circuit requires no multipliers and no weight transfer, and its exported hardware description can reproduce the circuit's behavior bit-for-bit. According to synthesis estimates, classifying a single tweet on an FPGA card takes only about 1-2 microseconds (DistilGPT2) and 3-5 microseconds (BERT); on a palm-sized board (module power consumption 7.5-15 watts), it takes 5-9 microseconds. This is two to three orders of magnitude faster than network inference on a GPU with batch size 1 (measured at 0.9-2.6 milliseconds for DistilGPT2, including an optimized CUDA graph baseline). The cost is a drop in gold-standard accuracy of 8.5 (DistilGPT2) and 8.6 (BERT) percentage points for the synthesized seed-0 circuits.

TweetEval-emotion and the Teacher Network

TweetEval-emotion is a sentiment classification subtask within the TweetEval benchmark, containing four tweet sentiment categories (such as anger, joy, optimism, and sadness), and is a commonly used dataset for evaluating models on short-text sentiment recognition. The teacher network refers to the original trained attention network (such as DistilGPT2 or BERT-base), whose outputs serve as the target for circuit fitting. The circuit is fitted only on samples the teacher classifies correctly, ensuring the circuit imitates the teacher's "correct" behavior rather than its errors.

FPGA and Synthesis Estimates

FPGA (Field-Programmable Gate Array) is an integrated circuit whose hardware logic can be configured through programming, suitable for low-latency, low-power custom inference. Synthesis estimates refer to the process of converting the circuit's high-level hardware description (such as Verilog) into an FPGA configuration, and estimating resource usage and timing accordingly. The circuit requires no multipliers (multipliers are high-energy-consumption units in GPUs and CPUs) and no weight transfer (traditional neural network inference requires loading weights from memory), thus enabling microsecond-level inference on FPGA.

Interpretability and Hardware Advantages

The biggest advantage of hard-logic predicate circuits is interpretability. Each predicate and truth table corresponds to explicit logical rules, allowing the model's decision process to be traced step by step. In addition, the circuit requires no multipliers or weight transfer, which brings significant convenience for hardware deployment. The exported hardware description can be directly implemented on FPGA and is bit-for-bit consistent with the software circuit.

This conversion method provides a new path for neural network interpretability and efficient inference. Although accuracy drops, this trade-off may be highly attractive in edge scenarios sensitive to latency and power consumption.

Bit-for-Bit Reproduction and Hardware Description

Bit-for-bit reproduction means that the software-simulated circuit and the FPGA-implemented circuit are completely identical on every bit of output, ensuring the determinism and verifiability of the circuit's behavior. The exported hardware description typically refers to a circuit netlist written in a hardware description language (such as Verilog or VHDL), which can be directly used for FPGA synthesis and deployment. Since the circuit is pure combinational logic (no clock, no state), its latency depends only on the number of logic gate levels, thus achieving microsecond-level performance.

Future Directions and Challenges

The current method still suffers from accuracy loss, and narrowing the gap with the teacher network is a key challenge for the future. In addition, the method currently targets classification tasks primarily, and whether it can be extended to more complex tasks (such as generation or sequence labeling) remains to be explored. Regardless, this study opens up new possibilities for the fusion of neural networks and hard-logic circuits.

One-line Summary

A new study converts attention networks into hard-logic predicate circuits, achieving interpretable and FPGA microsecond-level inference.

Paragraph Summary

The study proposes converting a trained attention network as a whole into a hard-logic predicate circuit, where each unit is a 0/1 predicate over tokens and mappings are realized by minimizing truth tables. The conversion uses a "Ship of Theseus"-style block-by-block replacement strategy, starting from the output end, with the remaining soft parts re-adapting to the frozen circuit. On TweetEval-emotion, the DistilGPT2 circuit achieves 66.5% accuracy (sequential selection) and BERT-base achieves 70.0%, but about 8.5 percentage points lower than the teacher network. The circuit requires no multipliers or weight transfer, its exported hardware description can be reproduced bit-for-bit, and inference on FPGA takes only 1-2 microseconds (DistilGPT2) and 3-5 microseconds (BERT), two to three orders of magnitude faster than GPU. This work provides a new path for interpretable AI and efficient edge inference, but accuracy loss and task generalization remain challenges.

#hard-logic predicate circuit#attention network#FPGA acceleration#interpretable AI#truth table minimization
Share:

Related articles