loopmm base
loopmm is a small language model that takes images and text as input. It has 189M parameters. Its 12 middle layers run three times for each token. It was trained from scratch on 9.16B tokens of text and image-text data.
This repo holds the pretrained base model. It continues text and writes captions for images, but it does not follow instructions. A post-trained chat version is pending.
Try it: the playground Space runs the model in your browser. The Mac app runs it offline.
loopmm uses the LFM3 layer layout, but it is not a Liquid AI model. It contains none of Liquid AI's weights. All of the weights were trained from random init.
Architecture
- Layers. 24 layers in the LFM3 order. There are 13 gated short-conv layers (kernel 7), 6 global attention layers and 5 sliding-window attention layers (window 256). The width is 640. Attention has 5 query heads and 1 key/value head of size 128, with QK RMSNorm, a sigmoid output gate for each head and a learned attention sink. Every operator and every MLP has an RMSNorm before it and after it. The MLP is SwiGLU with a hidden size of 2432.
- Loop. Layers 0 to 5 run once. Layers 6 to 17 (the core) run 3 times with the same weights. Layers 18 to 23 run once at the end. So each token goes through 48 layers, but the model stores only 24. Each pass through the core starts from the output of layers 0 to 5. From the second pass on, a gate mixes in a summary of the previous pass (the "start" variant of the Inkling 2 Mini message gate). Each pass has its own key/value cache.
- No residual stream. The model uses Block AttnRes (arXiv 2603.15031). The input of each sublayer is a learned softmax mix of the token embedding, the sums of earlier blocks of 6 sublayers, and the sum of the current block so far.
- Images. There is no vision encoder. An image is resized so that it fits in at most 256 tokens of 32 x 32 pixels (576 in the late phases of training). A small MLP turns each patch into a token. Each row of patches ends with a row-end token. Tokens of the same image attend to each other in both directions. Everything else is causal.
- Tokenizer. The LFM2-VL tokenizer from Liquid AI (65,536 tokens), unchanged. Input and output embeddings are tied.
- Size. 188.7M parameters: 41.9M in the embedding, 2.2M in the image stem, 144.3M in the 24 layers (71.8M of them in the looped core) and 0.3M in the AttnRes queries and the loop gate. With 3 passes, each token uses 288M layer parameters.
Training data
The model saw 9.16B tokens. About half of them come from text-only documents and half from documents with images. About a quarter of all tokens are image patches. The loss is computed on text tokens only.
Text-only data:
- Web: Ultra-FineWeb (English) and DCLM baseline
- Code: Stack-Edu (the Common Pile copy, openly licensed repos only)
- PDFs: FinePDFs-Edu and FinePDFs
- Math: FineMath and MegaMath-Web-Pro
- Wikipedia: FineWiki (English)
- STEM web pages from EssentialWeb
- Long documents for the long-context phases: arXiv papers and pre-1929 books from the Common Pile
Image-text data:
- Image-caption pairs: i1 (ImageNet-22k, Places365, iNaturalist, Pexels and rendered text), BLIP3o long captions, PixelProse and DOCCI
- Web pages with images: OBELICS (a high-quality 5M subset) and MMC4
- Documents as page images with their text: PDFA and MINT-1T arXiv
Training
- 9.16B tokens, 2^20 (about 1M) tokens per step.
- Phases. 7.9B tokens at a context of 4,096 with a flat learning rate, after a 1,000-step warmup. Then the learning rate decays to 0 over the last 1.26B tokens: 0.84B tokens at 4k on higher-quality data, then 0.42B tokens at a context of 32,768 on long documents (step 8,736).
- A 64k phase was planned at the end. Training crashed at that length, so it was dropped.
- Optimizer. Muon for the matrices inside the layers, and AdamW for the embedding, the image stem, the norms, the conv kernels, the AttnRes queries and the gate. Peak learning rate 2e-3, weight decay 0.1, gradient clipping at 1.0, bf16.
- Hardware. One node of 8 B200 GPUs on Modal, for about 2 hours of training.
Results
The benchmarks below are from the checkpoint at the end of the 4k phases (step 8,337, 8.74B tokens), before the 32k phase. The released weights are the final checkpoint (step 8,736), which adds the 32k phase and the end of the learning-rate decay. Its held-out loss at 3 loops, on the 4k validation sets used during training, is 2.809 on Ultra-FineWeb, 3.276 on DCLM, 1.261 on Stack-Edu code and 2.390 on FineWiki.
Zero-shot, with lm-evaluation-harness. Every model was scored with the same harness and the same prompts. The numbers are accuracy in %, except WikiText, which is bits per byte (lower is better).
| task | loopmm, 3 loops | loopmm, 1 loop | GPT-2 (124M) | GPT-2 Medium (355M) | Pythia-160M at 10.5B tokens |
|---|---|---|---|---|---|
| HellaSwag | 44.9 | 40.3 | 38.7 | 44.7 | 36.7 |
| PIQA | 64.9 | 60.5 | 61.9 | 65.9 | 59.3 |
| ARC-Easy | 49.7 | 43.7 | 40.9 | 44.1 | 40.1 |
| ARC-Challenge | 27.0 | 25.8 | 22.4 | 26.0 | 21.1 |
| SciQ | 75.1 | 66.8 | 64.0 | 66.9 | 61.3 |
| BoolQ | 60.7 | 48.7 | 52.2 | 60.1 | 55.1 |
| LAMBADA | 36.9 | 18.1 | 30.5 | 40.5 | 26.2 |
| BLiMP | 80.1 | 74.8 | 83.3 | 83.7 | 79.5 |
| MMLU | 24.8 | 24.6 | 22.9 | 23.0 | 23.0 |
| WikiText (bits per byte) | 0.892 | 1.062 | 0.980 | 0.890 | 1.031 |
| mean of 20 tasks | 45.4 | 41.7 | 42.6 | 45.2 | 40.6 |
The mean covers 20 tasks: the ones above plus WinoGrande, OpenBookQA, Social IQa, CommonsenseQA, MMLU-Redux 2.0, COPA, WSC273, RACE, MathQA, TruthfulQA MC2, StoryCloze and PROST. MMLU is at chance for every model in this table. Pythia-160M at 10.5B tokens is the checkpoint of Pythia-160M that has seen about as many tokens as loopmm.
Images (zero-shot, 3 loops):
- COCO captions: the loss per caption token is 3.24 with the image and 4.05 without it.
- COCO, pick the right caption out of 5: 50.7% (77.4% when each caption is scored against its loss without the image). Chance is 20%.
- A-OKVQA multiple choice: 31.2% with the image and 28.7% without it (chance 25%).
- POPE and ScienceQA-IMG are at the level of guessing. The base model answers "yes" to every POPE question. Question answering about images needs post-training.
Loop count
The model was trained with 3 passes through the core, but it can run with any number. The table shows the validation loss of the final weights at each loop count. Text is 8,192 tokens of Ultra-FineWeb; captions are 8 DOCCI image descriptions, scored with and without their image.
| loops | text | caption | caption, no image |
|---|---|---|---|
| 1 | 3.437 | 2.708 | 2.958 |
| 2 | 3.166 | 2.476 | 2.763 |
| 3 | 2.861 | 2.280 | 2.586 |
| 4 | 2.934 | 2.316 | 2.613 |
| 5 | 2.949 | 2.344 | 2.635 |
| 6 | 2.997 | 2.361 | 2.648 |
One pass costs 0.576 in text loss compared with 3. More passes than 3 make it worse (2.934 at 4 loops, 2.997 at 6). On the benchmarks above (step 8,337), going from 1 loop to 3 raises the mean accuracy from 41.7% to 45.4%, and 3 loops are better on 16 of the 20 tasks. At 4 loops the mean is 45.3%, about the same as at 3. The gap between 1 and 3 loops grew during training, from 0.04 at 0.5B tokens to about 0.5 at step 8,337 (held-out loss over all text sources). In the playground and the Mac app, the Loops slider sets this number.
How to run
In the browser or on a Mac
- Playground Space: runs in your browser, nothing is sent to a server.
- Mac app: works offline after the download.
PyTorch
You need torch, safetensors, tokenizers, huggingface_hub and pillow. The model code is one plain PyTorch file, modeling_loopmm.py. It does not need flash-attn.
pip install torch safetensors tokenizers huggingface_hub pillow
hf download MostLime/loopmm-base --local-dir loopmm-base --exclude "onnx/*"
python loopmm-base/modeling_loopmm.py loopmm-base "The best way to learn a new language is"
From Python:
import sys
sys.path.insert(0, "loopmm-base")
from modeling_loopmm import LoopMM
model, tok = LoopMM.from_pretrained("loopmm-base")
print(model.complete(tok, "The best way to learn a new language is", max_new_tokens=40))
print(model.complete(tok, "A photo of", image="cat.jpg", max_new_tokens=40)) # the image comes first
print(model.complete(tok, "Photosynthesis is", n_loops=1)) # run the core once
With transformers:
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("MostLime/loopmm-base", trust_remote_code=True)
tok = AutoTokenizer.from_pretrained("MostLime/loopmm-base", trust_remote_code=True)
print(model.complete(tok, "The best way to learn a new language is", max_new_tokens=40))
model(input_ids) returns logits for every position. Generation goes through complete() and generate_from(), which keep a cache, so each new token costs one step. transformers' own generate() is not supported. Put token id 1 (<|startoftext|>) before your text; complete() does this for you.
The release code gives the same logits as the training code (largest difference 1e-04 in fp32, at 1, 2, 3, 4 and 6 loops).
ONNX
onnx/ holds four graphs with fp16 weights. The Space and the Mac app run them with onnxruntime-web.
stem.onnx: image patches to embeddingsprelude.onnx: layers 0 to 5core.onnx: layers 6 to 17. Run it once per loop, and keep a separate cache for each loop.coda.onnx: layers 18 to 23 and the output head
onnx/meta.json lists the inputs of each graph. The engine.js file of the Space shows how to call them. The weights are stored in fp16 and computed in fp32, so the ONNX graphs give the same results as PyTorch: on validation text the loss is 3.7228 with ONNX and 3.7229 with PyTorch. The four files take 467 MB. Dynamic int8 quantization was tried first; on some checkpoints it raised the loss by up to 0.17, so it is not used.
Limitations
- It is a small model, and it was trained on only 9.16B tokens. Its output often contains false facts and repeats itself.
- It is a base model with no instruction tuning and no safety tuning.
- Most of the training data is in English.
- Its image skills are basic. Its captions name the main content of a photo, but they often get details, counts and text in the image wrong.
- It saw sequences longer than 4,096 tokens only in the last 0.42B tokens of training, at up to 32,768 tokens. It was never trained on inputs longer than 32k.
Licenses
- Weights: CC BY-NC 4.0 (non-commercial). Some of the image data allows only non-commercial research use. This applies to SA-1B and JourneyDB images in the BLIP3o data, to ImageNet-22k and Places365 in i1, and to part of iNaturalist. So the weights are released for non-commercial use only.
- Model code (
modeling_loopmm.py) and the ONNX export code: Apache 2.0. - Tokenizer files: these are Liquid AI's files under the LFM Open License v1.0 (
LICENSE_LFM). You need the tokenizer to use the model, so its terms also apply to you. It is close to Apache 2.0, but commercial use is not licensed for an organization with annual revenue of $10M or more. - Training data: each dataset has its own license, mostly ODC-By, CC BY and Apache 2.0. Wikipedia text is CC BY-SA. Images and PDFs from the web belong to their owners, and Common Crawl's terms of use apply to the data taken from it.
- "LFM" and "Liquid" are names of Liquid AI. This model is not made, checked or endorsed by Liquid AI.
Files
model.safetensors: weights, fp32config.json: model settingsmodeling_loopmm.py: model code (plain PyTorch, plus a transformers wrapper)tokenizer.json,tokenizer_config.json,special_tokens_map.json: the LFM2-VL tokenizer, unchanged, from LiquidAI/LFM2-VL-450Monnx/: ONNX graphs (fp16 weights) andmeta.json
- Downloads last month
- -


