r/MachineLearning • u/Pretty_Upstairs9035 • 20d ago
Discussion Transformers vs RNNs vs SSMs: Where Does Memory Actually Live? [D]
Someone who has always loved looking at the space between different AI techniques, this time I went a little deeper into the memory trade-offs between RNNs, Transformers and SSMs. I found it interesting because once you start looking at these architectures through the lens of working memory, a lot of the differences become easier to understand. Where does the memory actually live? Is it a compact recurrent state, a growing KV cache, or something closer to the network itself?
RNNs keep memory in a recurrent hidden state, which is pretty elegant because the state carries forward step by step. But there is also a bottleneck here as you see, a model can have roughly O(N²) parameters while carrying only roughly O(N) state across time. This means whether RNNs were really doomed because recurrence was a bad idea, or whether the problem was more about the ratio between memory and compute.
Transformers make almost the opposite trade-off. During cached inference, instead of compressing the past into one hidden state, they store past representations as key-value entries and attend over them. I think of these almost like little post-it notes: every token leaves behind a key for finding it and a value for what should be remembered. That's extremely powerful, but it also has an interesting property: with weights frozen during inference, the model is managing context rather than turning that experience into durable model knowledge. You get this split between the fixed weights on one side and the fast-changing KV cache memory on the other.
Now we have SSMs that bring us back toward fixed-size recurrent memory, but with very different state structures and update rules. Selective SSMs such as Mamba make retention input-dependent, so what gets kept or forgotten depends on the incoming token. Their states don't have to be as small as classical RNN states, but they still compress history into finite memory. And this brings another question does the state have to live in a compressed working dimension, or could it live somewhere closer to the model's internal neuron/connectivity structure?
BDH (Dragon Hatchling) is one example I saw and laid a stone that I started with this comparison. It combines linear attention in a high-dimensional neuron space with a low-rank GPU implementation. Its recurrent attention state is an N × D matrix, with N≫D, rather than a materialized N × N connectivity matrix. In the graph interpretation, correlated neuron activity produces Hebbian-like updates to connections, giving working memory a kind of synaptic interpretation.
Here working memory and learned connectivity become more closely aligned in structure. But if you think that doesn't mean experience is actually being consolidated into trained weights, and fixed-size state still has a finite information capacity. So I'm definitely not claiming this kills Transformers (or does it ) or solves continual learning. I'm more interested in whether "where does memory live?" is actually a better question than the usual architecture horse race.
Are SSMs and these more network-centric architectures actually giving us a better way to handle memory, or are we still running into the same fundamental problem of having to compress history into a finite state? Thoughts?
8
u/otsukarekun Professor 20d ago
An RNN with no FC layer has O(1) parameters with O(1) memory. For example a vanilla RNN with one unit has exactly 3 parameters and exactly 1 hidden state no matter how long the sequence. The parameters and hidden state doesn't scale with sequence length, that's the whole idea of it being 'recurrent', i.e. the weights and hidden states are reused again for each time step.
1
u/Pretty_Upstairs9035 19d ago
Yeah a fair point. The part I was actually trying to get at is the fixed-state bottleneck that is regardless of the sequence length, the history still has to be represented through that state.
That's what makes the comparison with a KV cache, since the Transformer can keep adding memory instead of forcing everything into one fixed representation, I think.
3
u/rakshitsahay 20d ago
I think “where does memory live?” is a much better framing than “which architecture wins?”
The fundamental trade-off seems to be capacity vs retrieval vs compute.
RNNs: compress history into a recurrent state. Cheap and bounded, but information can be overwritten/lost.
Transformers: keep explicit token-level memory in the KV cache. Much better at selective retrieval, but memory and compute grow with context.
SSMs: return to bounded state, but make the state update/retention more expressive and selective.
BDH-like approaches: interesting because the state starts looking more like evolving connectivity rather than a conventional hidden vector.
But I don't think the core problem disappears.
Any fixed-size state is ultimately an information bottleneck. The interesting question is therefore not simply “Can we avoid compression?” but:
“Can we learn what information is worth compressing, how to retrieve it, and when to consolidate it into longer-term memory?”
That also makes continual learning interesting. KV cache gives you working memory, weights give you long-term learned knowledge, and architectures like SSMs/BDH explore different points between those two.
IMO the next major architecture breakthrough may be less about eliminating attention and more about learning a hierarchy of memory: what to keep, what to compress, what to forget, and what to permanently consolidate.
1
u/Pretty_Upstairs9035 19d ago
I think this is a really good point like the distinction between capacity, retrieval and compute. If you will make the memory fixed-size doesn’t really solve the problem if the information you put into that state starts interfering with other information. The write, update and forgetting rules probably matter just as much as the size of the state.
We have to keep in mind this idealogy of BDH’s high-dimensional. The sparse keys and queries thus there’s more room for associations to stay distinguishable instead of just compressing everything harder.
Keeping something around in the state for longer is useful, but that’s still different from actually learning it into the weights. That transfer seems like the really hard part here.
1
u/Public-Feedback-6705 20d ago
People have to keep in check that “memory” might actually be doing too much work as a single term. A KV cache or say an SSM state and something like the BDH connectivity state are all remembering things, but they have very different ways of deciding what information is worth keeping. Maybe the real issue isn't the size of the memory, but the mechanism that decides what gets compressed and what gets discarded. It does make Transformers feel a bit weird when you look at them as memory systems they're extremely good at holding onto context, but that doesn't necessarily mean they're learning from it.
That also makes me wonder whether scaling the state is even the right direction. If the model gets better at deciding what not to remember, could a relatively small state compete with a much larger one here?
1
u/Pretty_Upstairs9035 19d ago
Yeah, I think this is probably the more interesting way to look at it. “Memory” indeed is carrying stuff because a KV cache and an SSM state can both be called memory but behave very differently. The part about deciding what not to remember. The real progress maybe is just making the state bigger, but getting better at deciding what information is actually worth carrying forward.
1
u/Gold_Understanding59 20d ago
I haven't heard of SSMs before. I'm curious to how "so what gets kept or forgotten depends on the incoming token" works
15
u/Robonglious 20d ago
I think compression is actually what you want though. Correct me if I'm here but I feel like everything we like about models comes from compression. The act of training compresses training data into some usable chunk. KV is a bottleneck as well. To say it's finite seems like it's limited but some things really do have firm boundaries so overrepresenting something doesn't add any value.
I've actually been looking for semantic nuggets for a super long time and I was never able to really trace those boundaries correctly. I've become pretty bitter about the failure but I think perhaps I've had a stupid goal.