The Tsetlin machine learns propositional rules with teams of Tsetlin automata that are driven by reward and penalty rather than gradients, so its models are interpretable by construction and cheap to evaluate. Its software, however, consists of C and CUDA kernels behind scikit-learn-style wrappers that sit outside the deep learning ecosystem. torchtsetlin implements the Tsetlin machine family as ordinary PyTorch modules: vanilla and weighted, coalesced, regression, convolutional over sequences, images and volumes, and dense per-pixel segmentation. The automata are a tensor buffer, so a model moves with .to(device), is saved with state_dict() and learns from a mini-batch with one update(x,y) call. Its core technique is a batched formulation of Type I and Type II feedback, in which automaton transitions become event counts realised as binomial draws, with one commit per mini-batch. On ten benchmarks taken from the existing libraries, it matches their accuracy, and on all but the two smallest it trains 2.4-10.9X faster than PyTsetlinMachineCUDA and 10.3-81.2X faster than tmu on the same GPU. The package is pure Python, MIT-licensed and on PyPI; every number in this paper is reproduced by one script. Code: https://github.com/vlbthambawita/torchtsetlin; package: https://pypi.org/project/torchtsetlin/.
Figures & tables
Figure 1. A Tsetlin machine at a glance: each row of automata defines a clause, matching clauses vote with their polarity, and feedback moves each automaton’s state across the include/exclude boundary between N and N+1 (inset).
Figure 2. torchtsetlin layer by layer. Models combine an output layer with an input structure; all of them share the learning loop of TsetlinMachineBase , whose update runs on stateless tensor maths, compiled CPU kernels or fused Triton GPU kernels, on top of PyTorch. Each layer builds only on the one below it. The legend names the icons, in the order of the boxes.
Figure 3. Output of torchtsetlin ’s interpretation and plotting tools ( interpret , viz ). (a) Global importance of each pixel literal for each MNIST class in a flat machine. (b) Heavily weighted clauses of a convolutional MNIST machine, drawn as 10×10 patch templates with their weights. (c) A dense segmentation machine on a synthetic street scene: input, ground truth, prediction and the vote sums for building (red: for, blue: against). One seed, five to eight epochs each ( code/fig_viz.py ).
pyTM
pyTM-CUDA
tmu
GT
torchtsetlin
Backend
C
PyCUDA
C / PyCUDA
C++
PyTorch
CPU and GPU, one class
✗
✗
✓
✗
✓
Conv. 1-D / 2-D / 3-D
✗ ✓ ✗
✗ ✓ ✗
✗ ✓ ✗
✗ ∘ ✗
✓✓✓
Regression / coalesced
✓ ✗
✓ ✗
✓✓
✗ ✓
✓✓
Dense segmentation
✗
✗
✗
✗
✓
Graphs (message passing)
✗
✗
✗
✗
✓
Table 1. Features of TM software ( ✓ yes, ∘ partial, ✗ no). GT’s 2-D convolution exists but fails at training through its public API. Graph machines otherwise ship in a separate CUDA library ( Granmo et al., 2025 ) .
Glimsdal et al. (2024, Tab. I) (cross-library); Abeyrathna et al. (2021)
Table 2. Benchmarks, all taken from existing TM libraries or their papers. C = clauses per class, T = threshold, s = specificity, w = weighted clauses. Every library implementing the model runs on the same Booleanised data.
existing libraries
torchtsetlin (GPU)
Bench
pyTM
Par
CUDA
tmu
GT
seq
batch
b100
B1
100.00
100.00
100.00 ± 0.00
100.00 ± 0.00
54.94
100.00 ± 0.00
100.00 ± 0.00
100.00 ± 0.00
B2
98.62
99.97
98.82 ± 1.22
99.73 ± 0.56
–
99.60 ± 0.46
99.61 ± 0.27
92.47 ± 3.83
B3
99.12
98.25
97.50 ± 1.30
97.32 ± 1.25
97.37
97.49 ± 1.37
97.42 ± 1.48
96.86 ± 1.74
B4
98.02
98.08
98.21 ± 0.05
97.97 ± 0.15
98.05
–
97.90 ± 0.12
97.54 ± 0.13
B5
98.12
98.07
98.11 ± 0.08
98.17 ± 0.12
10.49
–
98.15 ± 0.08
98.14 ± 0.06
Table 3. Test accuracy (%) at the final epoch, mean ± sd over runs; B10: RMSE (lower is better). pyTM, pyTM-Par and GT ran once; – not run or not supported.
CPU
GPU (RTX 3090)
torchtsetlin
Bench
pyTM × 1
Par × 16
GT × 16
tmu × 1
torchtsetlin × 16
CUDA
tmu
seq
batch
b100
B1
0.00786
0.00657
0.417
0.445
–
0.0136
1.13
0.112
0.0421
0.0136
B2
0.0118
0.00741
–
0.226
–
0.00884
0.579
0.102
0.0439
0.00902
B3
0.0337
0.00643
0.0434
0.0766
–
0.00635
0.125
0.0163
0.00426
0.00153
B4
9.32
2.99
46.3
32.4
69.6
3.44
19.3
–
1.59
0.788
Table 4. Training time, seconds per epoch (median of epochs 2– E , one exclusive run). Bold: the fastest GPU entry. ×k : threads. torchtsetlin on the CPU: three epochs, batch mode.
Library
C=10
C=100
C=1000
C=2000
C=5000
acc. (%)
pyTM CPU × 1
9.07 (4.5)
20.1 (9)
95.8 (47)
174 (84)
422 (197)
96.6 ± 0.0
pyTM-Par CPU × 4
2.25 (1.1)
5.48 (2)
37.1 (17)
97.3 (47)
262 (149)
96.9 ± 0.2
pyTM-Par CPU × 16
1.61
2.64
11.8
36.9
115
96.8 ± 0.1
GT CPU × 1
1.04 (0.3)
3.60 (2)
35.0 (18)
70.6 (36)
177 (90)
89.6 ± 0.3
GT CPU × 4
12.8 (4)
11.9 (5)
26.0 (11)
42.9 (18)
97.1 (31)
89.1 ± 0.4
GT CPU × 16
–
29.4
36.4
45.7
79.2
89.0 ± 0.6
Table 5. B6, the protocol of Glimsdal et al. (2024, Tab. I) : seconds to build a model and train 5 epochs with a test-set prediction after each (median of 3 repeats); in brackets the published value (Intel i9-12900K + RTX 3090). Accuracy at C=5000 , mean ± sd over the repeats.
ID
Library and check
Acc. (%)
Train s/epoch
R1
pyTM, B5 (README)
98.16 (98.19)
8.38 (8.8)
R2
pyTM-Par × 10, B5 (README)
98.16 (98.14)
4.43 (1.7)
R3
pyTM-CUDA, B8 8000 clauses (README)
90.70 (90.94)
42.2 (44.02)
R4
tmu, B5 (example)
98.22
33.1
R6
torchtsetlin seq, B1 ( Granmo, 2018 , Tab. 15)
100.00 (99.30)
–
Table 6. Reproduction checks: each library on its own published configuration, seed 0. In brackets the published value.
Figure 4. Where torchtsetlin is faster: the time of each comparison library divided by that of torchtsetlin (GPU, batch mode) on the same benchmark, for one training epoch and for predicting the test set. Right of 1× , torchtsetlin is faster. pyTM-Par is the fastest CPU library; B8–B10 were run on the GPU libraries only.
Figure 5. Batch size against clauses per class on MNIST, for the flat model of B4, the convolutional model of B7 and a 3-D convolutional model over the eight bit planes of each pixel. Left: test accuracy at the best validation epoch. Right: GPU hours to reach that epoch (logarithmic colour scale). One seed per cell, T scaled with the clause count, early stopping with a patience of 25 epochs; darker is higher. The accuracy colour scales are clipped at the stated value.