LFM3-style 125M (base)

A small 125M-parameter language model with the LFM3 layout. It was trained from scratch on 2B tokens of English web text.

Try it in your browser: MostLime/lfm3-style-canvas. The model downloads once and then runs on your computer.

What this is

  • A base model. It predicts the next token. It does not follow instructions and it cannot chat.
  • A replica of the LFM3 architecture at a small size. It is not a Liquid AI model and it does not contain Liquid AI's weights. All weights were trained from random init.
  • It was made to compare the LFM3 layout with the LFM2 layout at the same size, on the same data, with the same training recipe.

Architecture

  • 24 layers in the published LFM3 order: c c G c S c G c S c G c S c G c S c G c S c G c
    • c: 13 gated short-conv layers, kernel 7
    • G: 6 global attention layers, partial RoPE (half the head dims), theta 1e6
    • S: 5 sliding-window attention layers, window 256, full RoPE, theta 1e4
  • Width 512. Attention has 4 query heads, 1 key/value head, head dim 128, QK RMSNorm and a sigmoid output gate for each head.
  • Sandwich norm: RMSNorm before and after each operator and each MLP.
  • SwiGLU MLP, hidden size 1920 (3.75x).
  • Tied input and output embeddings.
  • LFM2's tokenizer, 65,536 tokens. (The real LFM3 uses a 128K tokenizer.)
  • 125.3M parameters in total, 91.7M without the embedding.

Training

  • Data: Ultra-FineWeb, English, files 1 to 7.
  • 2.0B tokens, sequence length 2048, 524,288 tokens per step (3,814 steps).
  • Each document starts with the <|startoftext|> token (id 1). Documents are packed into one stream.
  • AdamW (0.9, 0.95), learning rate 2e-3, weight decay 0.1, clipping 1.0, 5% warmup, cosine decay to 10%, bf16.
  • One B200 GPU, about 50 minutes.

Results

Validation loss on 8.4M held-out tokens of Ultra-FineWeb English (file 2048, never used in training):

model (125M, same data and recipe) val loss
this model (LFM3-style, seed 1) 3.148
LFM3-style, seed 0 3.153
LFM2-style twin, seed 0 3.211
LFM2-style twin, seed 1 3.208

The LFM2-style twin has 20 layers (13 conv, 7 global attention), conv kernel 3 and no sandwich norm, at the same parameter count. It reached its best loss with learning rate 1e-3.

How to run

PyTorch, CPU or GPU. You need torch, safetensors, tokenizers and huggingface_hub. The model code is one file, modeling_lfm3_style.py, in plain PyTorch. It uses scaled_dot_product_attention and does not need flash-attn.

pip install torch safetensors tokenizers huggingface_hub
hf download MostLime/lfm3-style-125m --local-dir lfm3-style-125m --exclude "onnx/*"
python lfm3-style-125m/modeling_lfm3_style.py lfm3-style-125m "The best way to learn a new language is"

From Python:

import sys
sys.path.insert(0, "lfm3-style-125m")
from modeling_lfm3_style import LFM3Style

model, tok = LFM3Style.from_pretrained("lfm3-style-125m")   # a local folder or the repo id
print(model.complete(tok, "The best way to learn a new language is", max_new_tokens=40, temperature=0.7))

model(input_ids) gives logits for every position. model.generate() uses a cache (key/value for attention, the last 6 inputs for each conv layer), so each new token costs one step. Put token id 1 (<|startoftext|>) before your text, as complete() does. The model makes token id 1 when it thinks a document ends.

This code gives the same logits as the training code (largest difference 1e-5 in fp32).

ONNX (browser or onnxruntime)

onnx/model_int8.onnx (161 MB) is a step graph with int8 weights (dynamic quantization, per channel). The Space uses it with onnxruntime-web.

  • Inputs: ids [1, N], pos [N] (positions of the new tokens), past_pos [P], past_k{i} and past_v{i} [1, 1, P, 128] for each attention layer, past_c{i} [1, 6, 512] for each conv layer.
  • Outputs: logits [1, 65536] for the last new token, and present_* with the new state.
  • To start, use one empty slot: past_pos = [-1], and zeros for all states. onnx/meta.json lists the layer numbers.
  • int8 costs a little quality: on 512 validation tokens, the loss goes from 3.267 (fp32) to 3.281 (int8).

Limits

  • It is small and saw only 2B tokens. It writes fluent English, but it often states false facts and it repeats itself.
  • It was trained only on English web text. It has no instruction tuning and no safety tuning.
  • It was trained on sequences of 2048 tokens. Longer inputs are not tested.
  • No downstream benchmarks were run. Only validation loss was measured.

Files

  • model.safetensors: weights, fp32
  • config.json: model settings
  • modeling_lfm3_style.py: model code (plain PyTorch)
  • tokenizer.json, tokenizer_config.json, special_tokens_map.json: the LFM2 tokenizer, unchanged, from LiquidAI/LFM2-350M
  • onnx/model_int8.onnx, onnx/meta.json: int8 ONNX step graph

Licenses

  • Weights, model code and ONNX file: Apache 2.0 (LICENSE).
  • 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. In short, 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: Ultra-FineWeb is released under Apache 2.0. Its English part is filtered from FineWeb, which is under ODC-By 1.0.
  • "LFM" and "Liquid" are names of Liquid AI. This model is not made, checked or endorsed by Liquid AI.
Downloads last month
35
Safetensors
Model size
0.1B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Dataset used to train MostLime/lfm3-style-125m

Space using MostLime/lfm3-style-125m 1