[P] Re-engineered the Fuzzy-Pattern Tsetlin Machine from scratch: 10x faster training, 34x faster inference (32M+ preds/sec) & capable of text generation

Hi everyone,

I’ve recently finished re-engineering the Fuzzy-Pattern Tsetlin Machine (FPTM) from the ground up. My goal was to leverage low-level optimizations to see just how much throughput I could squeeze out of the architecture.

The results are pretty wild. By focusing on cache locality and SIMD instructions, the new implementation is up to 10× faster in training and 34× faster in inference compared to the original FPTM.

MNIST Benchmarks (Ryzen 7950X3D):

  • Throughput: 4 GB/s
  • 🧠 Inference: 32M+ predictions/sec (98% accuracy)
  • ⏱️ Training: 1000 training epochs in just 11 seconds

Key Engineering Optimizations:
To get this performance, I focused on:

  • Extensive use of Bitwise operations and SIMD instructions.
  • A specialized, cache-friendly memory layout.
  • BitSet indexing over literals for handling very large, sparse binary vectors.
  • Automatic selection of UInt8/UInt16 TA states.
  • Model “compilation” to minimize memory overhead.

Why speed matters (Generative Tsetlin Machines):
Because this implementation is so efficient, it is now practical to explore generative tasks with Tsetlin Machines. I implemented a character-level text generator using FPTM with HDC hypervectors and Monte Carlo sparse context subsampling.

Here is the raw output from the model generating text in the style of Shakespeare:

ROMEO: The father's death, And then I shall be so; For I have done that was a queen, That I may be so, my lord. JULIET: I would have should be so, for the prince, And then I shall be so; For the princely father with the princess, And then I shall be the virtue of your soul, Which your son,-- ESCALUS: What, what should be particular me to death. BUCKINGHAM: God save the queen's proclaim'd: Come, come, the Duke of York. KING EDWARD IV: So do I do not know the prince, And then I shall be so, and such a part. KING RICHARD III: Shall I be some confess the state, Which way the sun the prince's dead; And then I will be so. 

Code & Examples:
The code is open source and available here:
https://github.com/BooBSD/Tsetlin.jl

I’d love to hear your thoughts on the optimization approach or the generative output!

submitted by /u/ArtemHnilov
[link] [comments]

Liked Liked