r/MachineLearning • • 21d ago

Project Do looped transformers save HBM traffic? Profiling weight reuse in Huginn on a B200 [P]

Post image

Do looped transformers, which reuse the same weights at every iteration, also save HBM traffic? In my new post I cover the looped architecture (Huginn), then model and measure its performance on a B200: how much data each iteration reads from memory, how long it takes, and why the shared weights usually don't stay on chip until the next iteration.
A few results:

- A chain of eight matmuls with one shared 72 MiB weight ran 24% faster than the same chain with eight identical copies, and read almost nothing from HBM. At 288 MiB, larger than L2, the difference disappeared.

- In a full Huginn Core (teaching implementation, random weights), eight iterations took about eight times as long as one and read about eight times as much data from HBM.

- Sharing saves storage, but by itself it doesn't stop the GPU from reading the weights from HBM again at every iteration.

👀Post: https://dinara-dl.github.io/posts/looped-transformer/

🤖Code and raw Nsight Compute data: https://github.com/dinara-dl/looped-transformer

I'd be curious whether anyone has tried keeping recurrent weights on chip across iterations, for example with a persistent kernel.

8 Upvotes

4 comments sorted by

1

u/PinkysBrein 20d ago edited 20d ago

Batch 1 vs batch 8 on a single matmul has a fair bit more speedup, so why is it only 24% here?  L2 not much faster than HBM?

1

u/2dayyy6 20d ago

Batching and this chain reuse W at different levels. In a batch 8 matmul each weight tile is loaded on chip once and used for all 8 rows. In my chain each step needs the previous output, so every step streams all of W again, just from L2 instead of HBM. So the ceiling is the L2/HBM bandwidth ratio. On B200 this ratio is only ~2-2.6x (Chips and Cheese measured 17-21 TB/s for L2 vs 8 TB/s HBM). In practice the shared chain reads W at ~6.1 TB/s from L2 vs ~4.6 TB/s from HBM for the copies, so ~1.3x faster which means 24% less time

1

u/choHZ 15d ago

I am not an infra expert but the common understanding is that registers and shared memory are too small to hold a typical LLM layer’s weights, let alone its (now looped) KV cache. A persistent kernel won't change this constraint so HBM reads are kinda expected.