Skip to content
Darrel Danadyaksa Poli.
← all projects
// nvidia · ai research intern · jan-jun 2025

Can linear-attention RNNs recognise formal regular languages?

Attention-free recurrent models like RWKV promise linear-time inference. The open question is capacity: does the compressed recurrent state actually retain what a Transformer's full attention window retains? I built a controlled setting where the answer is checkable rather than vibes-based.

Fig. 1: per-language-class comparison across RWKV-v7, Transformer, LSTM and GRU.
Fig. 1: per-language-class comparison across RWKV-v7, Transformer, LSTM and GRU.

The benchmark

Four synthetic regular languages, chosen so each isolates a different failure mode rather than blending them:

L1Parity counting, requiring an unbounded modular counter in state.
L2Substring matching, requiring positional recall over long spans.
L3Language union, requiring tracking two hypotheses at once.
L4Composed constraints: the combination, as an upper-bound check.

Hard negatives

Random negatives are too easy: a model can pass by learning surface statistics. Every negative in the suite is a perturbation of a positive at edit distance 1-3, so a correct answer requires the decision boundary to sit exactly on the language, not near it.

accept a b a b a b ← positive
reject a b a b a a ← edit distance 1
reject a b b b a b ← edit distance 1, different position

The CUDA operator

RWKV's WKV state transition is sequential, so the naive PyTorch implementation launches a kernel per timestep and dominates training time. I wrote wkv_kernel.cu as a custom C++/CUDA extension with a fused forward and backward pass, which made sweeps over sequence length and model size affordable enough to run the full architecture grid.

// on results

Quantitative results from this internship are not published. The setup, benchmark design and kernel are described here in full; I'm happy to walk through findings and their limitations in conversation.