Enjoying this issue?
Get tomorrow's AI & engineering digest in your inbox — hand-picked, summarized, and always spam-free.
TLDR
Looping a transformer's attention block multiple times — an idea from the 2019 Universal Transformer paper — improves reasoning on narrow tasks like math and logic, but the gain comes from repeated computation on token representations, not from the loop structure itself. Modern implementations like GLM 5.4 and Inkling 2 mini fix input and output layers and loop only the middle layers, which balances reasoning gains with minimal performance drop on other tasks. The key insight is that better reasoning correlates with more depth, not more parameters, making looping a memory-efficient way to add depth.
Key points
Universal Transformers from 2019 introduced looping to improve generalization, not memory efficiency.
Modern looped models like GLM 5.4 and Inkling 2 mini loop only middle layers, not all layers.
Looping improves reasoning tasks like math and logic but hurts question-answering on long prompts.
The optimal configuration loops 4 middle layers with fixed input and output layers.
Better reasoning from looping comes from repeated computation on token representations, not from the loop itself.
Tools mentioned
Techniques
- adaptive compute time
- latent space reasoning
- middle layer looping
Stop scrolling. Start reading smarter.
Receive the day's most important AI & engineering updates in one concise email. No spam.
Transcript (captions)
What if we take a regular transformer model and just downscale it to a single attention block and just loop it over many times? Wouldn't this just save a lot of footprint since GPU only needs to
hold like 10% of what the actual model would take? This seems like an easy win, right? This idea of looping the model by bringing recurrence into transformers actually goes back to 2019 with this
paper called universal transformers. And this was before the famous scaling law, which means the primary objective back then in looping wasn't to make the model smaller per se in footprint, but it was
to actually make the model generalize better. The research paper actually says right here, transformers fail to generalize in simple tasks that recurrent models handle with ease. So
looking from where we are at right now, a lot of us might want to incorporate looping into our model because we want them to be more VRM efficient. But back then, the main reason for incorporating
looping into the model was to see if transformer models can generalize better by simply looping the model. And the idea is actually simple in theory. We just simply carve out an attention block
like this and feed the input into the layer for self attention. and in our case a simple multi-layer perceptron and the output gets straight back into the model which means the raw vector
representation gets refined iteration after iteration until it goes through softmax for next token prediction and the original implementation right here actually was a little bit more intricate
when we look into the details we're given a sequence that says something like does Caleb even write code anymore when the model processes this sequence it uses what's called adaptive compute
time by letting each token give a probability score at each loop iteration which gets accumulated per token. In other words, each token dynamically gets halted when it passes that threshold
allowing the model to essentially modulate at a per token level to loop certain tokens more than the others as you can see. And at the end, the same probability that was used to accumulate
was used to do a weighted sum to be projected into softmax for next token prediction. Pretty intricate right now. As much as letting the model just loop dynamically like this seems like a
pretty cool idea, this is kind of an engineering nightmare if you think about it during inference time. If you think about inference engines like VLM, it's already hard enough right now trying to
manage multiple users where each prompt from the user takes a different amount of compute. But a looped model like this means now every token needs a different amount of compute to factor in. And
looking at how modern adaptations of loop models today look like, like GLM 5.4 or even Inkling 2 mini, we just simply don't modulate at a per token level anymore, which means every token
gets the same number of recurrence. Okay, so if saving memory isn't the only reason for bringing looping into our model today, what other reasons do we have for looping the model? As far as
when it was first added to see if bringing looping into the model would mean maybe the model would generalize better. The evidence actually does support that looping actually does let
the model generalize in narrow domain tasks. As you can see, early results show that universal transformer that loops many times over and over again was better at basic algorithmic tasks like
simple addition, reversing digits, and copying characters. Even a basic word prediction benchmark right here where the model has to guess the right next token. Looping the model six times
compared to the baseline had a significantly lower perplexity showing higher certainty with the next token than a regular transformer model that is not looped in comparison. What's also
interesting to look at is right here when it compares the model that was looped eight times and nine times the score actually goes back up at the ninth iteration which shows a diminishing
return right here as you can see. So this is really the critical part when it comes to looped models because it raises two really important questions for us to dig into which is first what is the
ideal amount of time we should be looping the model and second why does looping the model actually makes it better like what specifically about looping itself that makes the model
somehow better at generalization but first let's talk about your agent since context seems to be king these days and firecrawl who's sponsoring this video can help enrich your agent with high
quality quality context. I've talked about firecrawl before as a way to collect information from the web. But with a new feature called Alexandria, your agent can access curated
information from sources like Apollo, Shopify, Wikipedia, and benzinga or particle for podcasts. Here I ask my coding agent to use Alexandria to retrieve AI model information from a
hugging face and build an interactive application to explore their architectures. Now I can search for models like Llama, Quen, and DeepSeek and explore their parameter counts,
transformer layers, and compare different architectures side by side. Pretty cool, right? Rather than navigating websites filled with HTML and unnecessary metadata, Firecrawl helps
turn that information into clean structured data your agent actually can use. And I can also connect my coding agent directly to Firecrawl through their MCB server or install Cloud
Connector in just few clicks at firecrawl.dev/plugins. And instead of manually collecting all that information, my agent can retrieve the data and turn it into something I
can actually use. Firecrawl makes it easy to give your agent the context it needs to get things done. Try firecrawl for free without an API key. Link in the description below. Let's tackle the
first question, which is how many times should we loop the model? As you can imagine, there are so many different permutations of how we can actually set this ablation study. We can have a
simple model like this one attention block like this. Let's say 1 billion parameter model. And using that same attention block, we can now loop it many times over and over again arbitrarily
like this. And we can add a control experiment right here with a regular transformer model that does not loop, but it does match the depth of the loop model on the left here, making them both
compute equivalent. Hence, we call it isoflop baseline or making the parameters the same on the left here, which is why we call it isopre baseline. all the way to the right here. This is
actually where most modern adaptations of loop model actually look like, which is having an input block and an output block separately and only letting the looping happen in the middle layer right
here. Okay, now that we have the control experiment set up like this, our goal is to first find out what is the optimal setup when it comes to looping the model. Looking at this benchmark, it
uses a baseline as a 1 billion parameter model that has 24 layers total. And the baseline model does not loop, but it runs through the entire 24 layers once and only once. And below them are
different configurations of layers from 12 layers being looped twice or the middle loop right here where the first four layers are fixed and the middle four layers are looped four times and
the final four layers are done only once. And the eight layer section right here is being looped three times. And the six layers being four times and the four layers six times. All of these rows
right here should be computationally equivalent to the baseline where all them should run through some layer 24 times in total. But as you can see, we can broadly draw the line right in the
middle like here like this. And clearly looping the model seems to do extremely well when it comes to reasoning tasks like math and reasoning primitives compared to the baseline. But when it
comes to tasks like questions and answering after reading a large prompt, looping the model actually makes it fall behind. Even though these all use the same amount of compute in theory, in
looking at this, the most optimal way to loop the model seems to be this middle loop right here where we have the first four layers fixed and only the middle layers are looped four times and the
last four layers fixed as well. And the performance drop was the least in comparison while still gaining a decent amount in reasoning primitives like counting, arithmetic skills, and logical
deductions. Which makes sense because when we look at modern adaptations of looping, they actually take the middle loop right here. When we look at models like GLM 5.4, Inkling 2 mini or even
Nvidia Dory 1.04B, they all have input and output layers fixed while having the middle layer loop. Now looking at the benchmark again and seeing this part right here, you might have wondered why
loops model tend to perform better at reasoning specifically which brings us to the second part of our question earlier which is why does looping the model somehow make them better at
reasoning. If you think about the fact that we're trying to extract better reasoning from the model over the years we've used different methods to make the model reason better. More recently, we
gave the model the ability to reason outside of the model by letting it generate reasoning tokens, which means we're giving the model token space reasoning to happen right here. We also
often distill larger models by extracting the reasoning traces and using them during mid-training to use SFT to let the model learn how to reason from them, which is at the data level.
And the oldest trick in the book is actually in our prompt where we give the model our chain of thoughts by giving the model reasoning examples in the prompt. So the model learns in context
at the prompt level. So naturally what we're talking about is reasoning to happen inside the model so that the architecture allows latent space reasoning where the token representation
itself can be used to reason internally and looping the model actually lends for reasoning to occur more simultaneously like this where unlike chain of thought reasoning that is bound by auto
reggressive token generation which means you can only have one thought at a time progressively the fact that looped model operates at a latent based representation means that it can
theoretically have multiple thoughts in parallel in a single iteration like this. Even in comparison to token level reasoning where you can have the model generate multiple reasoning trajectories
in parallel to then search for the best path. Working in latent reasoning is not only more compute efficient. It also prevents the model from converting the representation into natural language to
find the answer but letting the model continue to chew through its thoughts internally in loops. And what researchers in this paper have found is that better reasoning actually doesn't
come from making the model have more parameters, but it's more about having the model have more depth, which is why looping the model can often lead to better reasoning. And to prove where the
gain from reasoning actually comes from, they tried to isolate the model by experimenting on a regularization technique that encourages different blocks in a regular transformer blocks
to be more similar to each other, but by having 24 independent layers that are very similar. And this small experiment showed that despite being 24 slightly modulated layers, the reasoning capacity
still stayed the same, which suggests that the inductive bias that the looping model has actually comes from the fact that the act of repeating computation on the token representation rather than the
sheer act of looping itself. And this is really something for all of us to think about because each model architecture whether it's RNN, CNN, LSTM transformers, GPT and now loop
transformers, they all have their own inductive bias by virtue of how the model architecture forces how information is learned by the model. So if we take a step back from loop models,
we still have a lot of capacity in how model architecture can expand its raw ability to learn and demonstrate better generalization. Not just in scaling the model bigger per se, but seeing
different techniques like this to make better use of the architecture while maintaining the integrity of the model's intelligence.