Transformers Are Graph Neural Networks
It&#x27;s interesting watching these attempts to understand Transformers.  Are they Graph networks?  Are they Hopfields networks?  Are they convolutions?<p>There was this research: <a href="https:&#x2F;&#x2F;www.lesswrong.com&#x2F;posts&#x2F;AcKRB8wDpdaN6v6ru&#x2F;interpreting-gpt-the-logit-lens" rel="nofollow">https:&#x2F;&#x2F;www.lesswrong.com&#x2F;posts&#x2F;AcKRB8wDpdaN6v6ru&#x2F;interpreti...</a><p>Turns out, GPT-like architectures appear to use the same representation throughout all the layers.  So you can use the final head layer as a lens to see what words the network is thinking of as it ... &quot;thinks&quot;.  That&#x27;s a bit contrary to what I imagined a GPT-like architecture was doing.  I would have assumed that its embedding of ideas changed throughout the network, only reaching a sensible embedding near the end.  At least from the perspective of the head layer, that doesn&#x27;t appear to be the case.<p>Facebook&#x27;s research demonstrates that the MLP layer can be dropped in favor of more attention over learned knowledge vectors: <a href="https:&#x2F;&#x2F;ai.facebook.com&#x2F;blog&#x2F;making-transformer-networks-simpler-and-more-efficient&#x2F;" rel="nofollow">https:&#x2F;&#x2F;ai.facebook.com&#x2F;blog&#x2F;making-transformer-networks-sim...</a><p>&gt; Reading new Transformer papers makes me feel that training these models requires something akin to black magic when determining the best learning rate schedule, warmup strategy and decay settings.<p>I found GPT-*&#x27;s schedule straightforward.  In fact, most training schedules these days are &quot;boring&quot;.  Adam with warmup and either a linear or cosine decay.  CNNs have been doing that for awhile, and the hyperparameters now are fairly robust.  If you get within an order of magnitude you&#x27;ll land within a few percent of optimal accuracy.<p>The OpenAI paper Scaling Laws for Neural Language Models does a good job of exploring the hyperparameters of GPT-like networks.  It&#x27;s a fascinating read.<p>That paper suggests another thing about Transformers that we don&#x27;t understand.  Beyond some minimums, the layer count, embedding size, and number of attention heads _isn&#x27;t important_.  The most important factor in the performance of a model is simply the number of parameters.<p>That&#x27;s quite unusual, as the classic intuition is that adding more layers to a model improves performance.  Yet for GPT-like architectures that isn&#x27;t the case.  You can get the same performance gains by just increasing the embedding size.  4 heads?  12 heads?  Doesn&#x27;t matter.  Weird.<p>&gt; Initially introduced for machine translation, Transformers have gradually replaced RNNs in mainstream NLP. The architecture takes a fresh approach to representation learning: Doing away with recurrence entirely<p>The more I study Transformers, the more I suspect that their success has more to do with our utter failure to train RNNs.  In theory, RNNs have infinite attention.  In practice, the only tool we have for optimizing models is backprop, and so to train an RNN we have to use BPTT.  This defacto creates a learning horizon.  There is absolutely no training signal that tells an RNN to remember something beyond the BPTT horizon.  So why would it?<p>Our training loop for RNNs involves giving them, for example, 1024 tokens, running them for 1024 iterations, and computing loss on 1024 predictions.<p>A Transformer&#x27;s training is nearly identical.  They get 1024 tokens of context, make 1024 predictions, and compute loss.<p>The difference?  Let&#x27;s consider a scenario where it&#x27;s the last prediction, and that prediction should be a copy of the first word in the sequence.  Very simple, right?  Yet for an RNN to learn how to do that, it needs to backprop the loss through 1024 iterations of its model.  Even for a simple 1 layer RNN that makes it look like a 1024 layer model.  Vanishing gradients turned up to 11!!<p>For a Transformer this is dead simple.  Its attention mechanism allows the last column of the Transformer to directly use knowledge from the entire sequence.  Not only can it see the first token in the sequence, it can see all the computations it previously performed on the sequence, all at once.  All with easy backprop.  No vanishing gradients here.<p>So is it really any surprise that Transformers have dominated RNNs?  Given the exact same compute, memory, parameters, etc Transformers make much more efficient use of the resources.  (During training)<p>To put it another way, a Transformer is exactly like an RNN.  It just uses attention to access history rather than recurrence.  And we know that backprop and recurrence are incompatible.  So Transformers win.<p>Of course, that&#x27;s a huge problem.  We have a temporary win.  A HUGE win.  But Transformers haven&#x27;t solved what RNNs were meant to solve.  By the end of a book, human brains can remember things from the beginning of the book.  RNNs trained with BPTT cannot.  Transformers cannot.  Even Transformers with linear attention mechanisms cannot.  There&#x27;s another leap here left to do.<p>We need some kind of long term memory mechanism.  A big Transfomer model can probably approximate the active parts of a human brain.  The image-gpt model and papers using Transformers in place of CNNs for classification tasks have shown that Transformers are a generic substrate.  But the big missing puzzle piece is long term memory.  Give a Transformer some method to query a bank of memory and I think we&#x27;re going to see that next big leap.  Plus, with access to a memory bank, a Transformer can free up all the resources its using today to behave _like_ long term memory and instead use them for more &quot;thinking&quot;.<p>Yet we have absolutely no mechanisms available to us today to build such a thing.  To teach any kind of model to act as long term memory requires some way to show to an example from its distant past, see how well it remembers it, and then ... backprop that.  But we can&#x27;t backprop it, because we can&#x27;t backprop across an entire book, let alone WikiText or WebText2.<p>We&#x27;re really back at square one.  We need some way to make the theory of RNNs a reality.  Transforms haven&#x27;t bought us that.  They&#x27;ve only bought us a short-term cheat in performance.<p>EDIT: Just so it&#x27;s clear, none of my comment is meant as a criticism of the linked article.  I actually thought the OP was great and sources a lot of research in trying to understand the mechanisms of Transformers.  Really I just springboarded off the article to dump some of my own musings.