LaughLM-Loop-135M
Pilot looped-depth transformer on Cloud TPU
2 min read
This compact 135M-parameter language transformer uses a recurrent architecture trained on a Google Cloud TPU v5e-1. Instead of fixed layers, it loops through 4 wide shared blocks (loop depth R=4), creating an effective depth of 20 layers with an anchor-fixing mechanism. This setup lowers perplexity without adding parameters and lets you explore depth scaling at inference.
Key features
- Native TPU support: Runs directly via the torch-tpu and JAX stacks with no torch_xla dependencies.
- Custom Pallas kernels: Optimized attention and RMSNorm operations for efficient hardware utilization.
- Loop scaling: Flexibly adjust recursion depth during inference ($R \in \{1, 2, 4, 6, 8\}$).
- High utilization: Reaches around 63.6% MFU (Model Floating-point Utilization) on a single TPU v5e-1 chip.
What you can do
- Run inference: Generate text at different recursion depths ($R$).
- Explore scaling: Test how changing recursion settings affects output quality and perplexity.
- Integrate into pipelines: Use the repository through the TrainLM library for your own TPU experiments.
Example
import torch
from transformers import AutoTokenizer
from trainlm.model import LaughLMLoopForCausalLM
repo_id = "Dhiraj45/laughlm-loop-135m-pilot"
tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/SmolLM2-135M")
model = LaughLMLoopForCausalLM.from_pretrained(
repo_id,
subfolder="final_model",
torch_dtype=torch.bfloat16,
).eval()
inputs = tokenizer("In 1969, engineers at NASA", return_tensors="pt")
with torch.no_grad():
out = model.generate(**inputs, max_new_tokens=64, do_sample=True, temperature=0.8, top_p=0.9)
print(tokenizer.decode(out[0], skip_special_tokens=True))Read more
DetailsBenchmarks: 68.02 PPL on a held-out set (a 44.7% improvement over R=1)
Hardware: Single Cloud TPU v5e-1 chip (16 GB HBM)
Limitations: Research pilot (131.07M tokens), not fine-tuned for instruction following
Training details: PyTorch 2.14.1, jax 0.7.1, SmolLM2-135M tokenizer










Comments