# torchtsetlin: Fast, Interpretable Tsetlin Machines for PyTorch

> torchtsetlin brings Tsetlin rule machines into PyTorch and batches feedback events, committing once per mini-batch. Its final-epoch batch accuracy lies within peer spread except on B4; on IMDb, GPU training takes 1.94 s/epoch versus pyTM-CUDA's 21.2, about 10.9× faster.

- arXiv: https://arxiv.org/abs/2611.28195
- Authors: Vajira Thambawita, Pål Halvorsen, Ole-Christoffer Granmo
- Published: 2026-11-25
- Topic: Inference & systems
- Visual carousel: https://instaxiv.com/p/2611.28195
- Explanation by InstaXiv, a secondary educational summary. Cite the original paper for exact results. InstaXiv is not affiliated with or endorsed by arXiv or Cornell University.

## Can Tsetlin rules learn at GPU speed?

**10.9×** IMDb GPU train s/epoch vs pyTM-CUDA

## The model is a readable rule voter

1. **Include or exclude**: Each automaton controls whether one Boolean feature or its negation enters a clause.
2. **Build a clause**: Included literals are ANDed, giving a rule that can be inspected directly.
3. **Vote by class**: Matching positive and negative clauses cast signed votes; the highest-vote class is predicted. Evaluation uses bitwise operations and counting.
4. **Learn by feedback**: Reward and penalty shift automaton states; training does not use gradients.

## The missing piece was the software boundary

**Existing libraries:** They kept automata in native buffers behind separate APIs, outside PyTorch tensor state.

**torchtsetlin:** It uses ordinary PyTorch modules with tensor-buffer automata: .to(device), state_dict() and update(x, y) work in the framework. Variants include weighted, coalesced, regression, convolutional, segmentation and graph machines.

The interface gap is a contribution in its own right.

## Batched feedback becomes event counting

1. **Evaluate from one snapshot**: The batch is Booleanized, then clauses and class votes are computed from automata at call start.
2. **Select and count feedback**: Per-example Type I/II feedback selections produce counts of each automaton's transition events.
3. **Sample transition totals**: For each transition type, equal-probability Bernoulli trials sum to a binomial draw instead of serial updates.
4. **Commit the batch**: One commit updates the batch; when it fits one chunk, fused Triton code counts events, samples draws and writes state and include mask.

## Batching changes when feedback takes effect

**Sequential reference:** Each example updates the automata immediately, so the next example's votes use that changed state.

**Mini-batch update:** All examples use the batch-start state and votes. Margin-based feedback can stack several pushes on an automaton before the commit.

Batch size affects learning fidelity; sequential mode preserves the per-example algorithm.

## B7: a faster convolutional MNIST epoch

| Method | Seconds/epoch |
| --- | --- |
| pyTM-CUDA | 9.53 |
| tmu GPU | 41.2 |
| **torchtsetlin b100 (2.4× vs CUDA)** | **3.99** |

_B7 convolutional weighted MNIST; b100 means batch size 100. RTX 3090 GPU, median seconds/epoch (epochs 2–30), one run._

## The timing pattern spans multiple workloads

![Figure 4](https://cdn.instaxiv.com/figures/2611.28195/figure4.webp)

Each ratio is comparison-library time divided by torchtsetlin's GPU batch time; values above 1 mean torchtsetlin is faster. Training and test-set prediction are shown; B8–B10 include GPU libraries only. (Figure 4)

## Accuracy mostly matches, with one exception

| Method | Accuracy (%) |
| --- | --- |
| pyTM-CUDA | 98.21±0.05 |
| tmu GPU | 97.97±0.15 |
| **torchtsetlin batch (−0.31 pp)** | **97.90±0.12** |

_B4 MNIST; final-epoch accuracy, mean ± SD over five GPU seeds. pyTM-CUDA is the strongest comparator._

## Batch size changes accuracy and cost

![Figure 5](https://cdn.instaxiv.com/figures/2611.28195/figure5.webp)

Batch size vs clauses per class. Left: test accuracy at best validation epoch; right: GPU hours to reach it. Batches 16–64 were most accurate and cheapest across flat, 2-D and 3-D models; one seed per cell. (Figure 5)

## The speedup has clear boundaries

- **Large-batch fidelity**: Examples share their starting state; larger batches can stack updates before feedback is recalculated and degrade accuracy.
- **CPU training**: Dense tensor operations miss the bit-level tricks of C kernels, so CPU training is slow; B4 CPU inference was fastest among CPU libraries.
- **One-machine comparison**: Cross-library tests used one machine and published settings without tuning; they do not establish performance on other hardware.

Best used when: Prefer GPU use in PyTorch pipelines; start with batches of 16–64, or use sequential feedback when exact per-example updates matter.

## Key takeaways

- On B7, torchtsetlin's 100-example GPU batch cut epoch time from 9.53 to 3.99 seconds versus pyTM-CUDA.
- Start with 16–64 examples per batch; use sequential feedback when matching the exact online update matters.
- Do these speed and fidelity trade-offs persist on hardware beyond the single machine tested?

## Links

- arXiv: https://arxiv.org/abs/2611.28195
- PDF: https://arxiv.org/pdf/2611.28195
- Code: https://github.com/vlbthambawita/torchtsetlin
- Project page: https://pypi.org/project/torchtsetlin/

## Citation

```bibtex
@article{thambawita2026torchtsetlin,
  title   = {torchtsetlin: Fast, Interpretable Tsetlin Machines for PyTorch},
  author  = {Thambawita, Vajira and Halvorsen, Pål and Granmo, Ole-Christoffer},
  journal = {arXiv preprint arXiv:2611.28195},
  year    = {2026},
  url     = {https://arxiv.org/abs/2611.28195}
}
```
