We convert a trained attention network as a whole, attention included, into a hard-logic predicate circuit that runs in its place. Every unit of the circuit is a 0/1 predicate on tokens, and every map between predicates is a minimised truth table. Each block is fitted once on the teacher's own states, with interfaces defined from the output down, and the rules of the whole chain are then refitted on the states it produces. Attention selection takes two forms, a row-wise comparison of integer scores (order selection) and a learned rule (rule selection). Both are fitted on the ordinary training set alone, and only on the examples that the teacher classifies correctly. On TweetEval-emotion, the complete circuit of DistilGPT2 reaches a test gold accuracy of 67.7 $\pm$ 0.8% with order selection and 56.4 $\pm$ 1.4% with rule selection over five seeds, against 74.7% for the teacher and 64.0% for a bag of word pieces fitted on the same tweets, and that of BERT-base truncated to 6 blocks reaches 71.1 $\pm$ 1.1% and 61.8 $\pm$ 5.0% against 80.0% (bag of words 63.8%). On four GLUE tasks, order selection reaches a mean test gold accuracy of 70.6% (DistilGPT2) and 70.9% (BERT), above the bag of words (68.6% and 68.4%). The circuit needs no multiplier and no weight traffic, and its exported hardware description reproduces it bit for bit. By a synthesis-based estimate averaged over the five tasks, it classifies one example in 1.1-2.0 $μ$s on an FPGA card, 180-420 times faster than the network on a GPU at batch 1 with CUDA graphs (measured, 0.35-0.46 ms), and in 3.3-6.4 $μ$s with 25-96 $μ$J on a palm-sized board of 7.5-15 W, 550-2,400 times less energy per example than the GPU.
翻译:暂无翻译