torchtsetlin: Fast, Interpretable Tsetlin Machines for PyTorch

Vajira Thambawita, Pål Halvorsen, Ole-Christoffer GranmoarXiv 2026

Imagine it’s late, you’ve been debugging gradient descent issues all day, and you’re starting to wonder if there’s a way to build a model that doesn’t feel like a "black box" of floating-point mystery. Enter the Tsetlin Machine (TM)—a logic-based alternative that learns simple IF-THEN rules instead of weights.

While TMs are fascinating, they’ve historically been "outsiders" in the machine learning world, trapped in specialized C++ and CUDA libraries that don't play nice with the modern PyTorch ecosystem. This paper introduces torchtsetlin, a library that finally brings Tsetlin Machines into the PyTorch fold as first-class citizens, making them easier to use and, surprisingly, much faster.

TL;DR

torchtsetlin integrates Tsetlin Machines—interpretable, logic-based models—directly into PyTorch as standard nn.Modules. By rethinking the way these models learn on GPUs using a novel "batched feedback" approach, the authors achieved speedups of up to 10x over previous state-of-the-art GPU libraries while maintaining full interpretability.

What Problem Does This Paper Address?

Deep learning is powerful, but it has two major "hidden costs": it’s often a black box (hard to explain why a decision was made), and it’s computationally expensive (requiring heavy floating-point math). Tsetlin Machines offer a different path. They represent classes using conjunctive clauses (logic rules) over Boolean features. This makes them readable by humans and incredibly cheap to run on edge devices.

However, existing TM software has been stuck in a silo. If you wanted to use a TM, you usually had to leave your PyTorch pipeline, convert your data to NumPy, and use a wrapper that didn't support standard features like .to(device), state_dict(), or easy integration with PyTorch’s DataLoader. Furthermore, TMs traditionally learn "online" (one example at a time), which leaves powerful GPUs mostly idle.

Methods

The core innovation of torchtsetlin is treating the internal states of a Tsetlin Machine as standard PyTorch tensors.

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 in- clude/exclude boundary between 𝑁and 𝑁+1 (inset).

1. Tsetlin Machines as PyTorch Modules

By implementing TMs as nn.Modules, the authors allow them to behave like any other layer. You can move them to a GPU with one command, save them easily, and even mix them with other PyTorch components.

2. Batched Feedback

To solve the GPU idling problem, the authors moved away from the traditional one-at-a-time update. Instead, they process a mini-batch of examples and count how many times each logic rule would have been rewarded or penalized. They then perform a single "commit" for the whole batch. Mathematically, they realized that many individual Bernoulli trials (the standard TM update) can be collapsed into a single draw from a Binomial distribution. This allows the GPU to do massive amounts of work in parallel.

3. Fused Triton Kernels

For the "fast path" on GPUs, they used OpenAI’s Triton language to write fused kernels. This minimizes the overhead of moving data between different parts of the GPU memory, which is crucial for the bit-level operations TMs rely on.

Datasets

The authors evaluated torchtsetlin on ten diverse benchmarks commonly used in the TM community to ensure a fair comparison:

  • Logic/Synthetic: Noisy XOR, 2-D Noisy XOR.
  • Vision: MNIST, Fashion-MNIST (including convolutional variants).
  • NLP: IMDb sentiment analysis.
  • Tabular/Regression: California Housing, Breast Cancer.
  • Medical: ECG signal analysis.

Key Insights and Ideas

  • Interpretability is a Feature, Not a Bug: Because TMs learn logic rules, you can literally print out what the model has learned. Interpretation tools showing pixel importance for MNIST and learned "stroke" clauses for a convolutional machine.

  • The "Binomial Trick": The shift from online learning to batched binomial updates is the "secret sauce" that makes this library competitive. It bridges the gap between the sequential nature of Tsetlin Automata and the parallel nature of modern hardware.

  • Pure Python, High Performance: Despite being "pure Python" at the top level, the library achieves its speed by leveraging PyTorch's underlying C++ engine and custom Triton kernels for the heavy lifting.
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).

Key Results

  • Massive Speedups: On GPUs, torchtsetlin is 2.4–10.9x faster than the previous fastest GPU library (PyTsetlinMachineCUDA) and up to 81x faster than other common implementations like tmu.
  • Inference Speed: For a standard MNIST task, it can predict 10,000 images in just 0.016 seconds—roughly 32x faster than previous methods.
  • Accuracy Parity: Despite the change to batched learning, the models match the accuracy of the original sequential algorithms on almost all benchmarks.
Figure 4: Where torchtsetlin is faster: the time of each com- parison 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.

Limitations and Future Work

  • CPU Training: On CPUs, torchtsetlin is actually slower than some specialized C libraries. This is because standard dense tensor operations can't easily use the "bit-level tricks" that custom C kernels employ for small batches.
  • Batch Size Sensitivity: Introducing batching adds a new hyperparameter. While small batches (16–64) work well, very large batches can cause the model's logic to "overshoot" and degrade accuracy.
  • Future Directions: The authors suggest that future work could involve even tighter integration with deep learning, perhaps using TMs as interpretable "heads" on top of traditional neural feature extractors.

Summary updated

Abstract

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/.
BibTeX
@misc{thambawita2026torchtsetlin,
  author = {Vajira Thambawita and Pål Halvorsen and Ole-Christoffer Granmo},
  title = {{torchtsetlin: Fast, Interpretable Tsetlin Machines for PyTorch}},
  year = {2026},
  eprint = {2611.28195},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.28195},
}
Figure