mofengenden's picture
Add files using upload-large-folder tool
527b1a3 verified
|
Raw History Blame Contribute Delete
24.4 kB

Ocelot-1.8B: Compute-Constrained Pretraining with Muon, Document Masking and a Wall-Clock-Aware WSD Schedule

Abstract

We pretrain a 1.8B-parameter decoder-only language model from scratch under a hard budget of 1,048 H100 GPU-hours and 23.5 hours of wall-clock time (which also had to cover data preparation, tokenizer training, ablations, and evaluation). The target metric is bits-per-byte (BPB) on held-out text from unknown domains (unweighted mean over domains). Our recipe: (i) a 24-source data mixture (web, code, math, papers, encyclopedic, books, Q&A, legal/government, conversational and multilingual text), (ii) a custom 64K byte-level BPE tokenizer, (iii) a Llama-style architecture with QK-norm and document-masked attention so that training matches the scoring protocol (each document scored independently from a BOS token), (iv) the Muon optimizer, chosen after a controlled ablation in which it beat a tuned AdamW by 2.3% BPB, and (v) a warmup-stable-decay schedule whose cooldown start is decided online from measured throughput so the run ends exactly at a wall-clock deadline. The final model was trained on 120.6B tokens in ~19 hours on 48 H100s (42.5% MFU after fixing two distributed- training bottlenecks that initially cost 25% of throughput). With the official scorer it reaches a mean of 0.666 BPB over 24 held-out in-distribution domains and 0.734 BPB over 5 external test sets (C4, WikiText-103, PG-19, GSM8K, HumanEval), and 0-shot HellaSwag 63.4 / ARC-Easy 72.8 / PIQA 74.8 / WinoGrande 61.1 / SciQ 93.0.

1. Motivation and constraints

  • Compute: 1,048 H100-hours; at most 48 GPUs (6 nodes x 8) at once; 23.5 h total, shared with all preparation.
  • Metric: BPB = total NLL (bits) / UTF-8 bytes, per domain, unweighted mean over domains; documents truncated to ~18k characters; scored with the model's declared context (sliding window, stride = window/2), BOS prepended.
  • Requirements: lossless tokenizer, causal, deterministic across processes (2e-3 nats tolerance), loadable with AutoModelForCausalLM (trust_remote_code=True).

Because the evaluation domains are unknown and the metric is an unweighted mean over domains, a single weak domain (e.g. code or non-English text) can dominate the score; we therefore optimise for breadth rather than for web text only. Because wall-clock is as binding as GPU-hours, every design decision favoured approaches that could be validated quickly and that keep 48 GPUs busy for as long as possible.

2. Data

We assembled 24 sources (all public Hugging Face datasets with inline text; ~460 GB compressed, downloaded in ~10 minutes) and tokenized ~335B tokens. Gated or blob-only code datasets (StarCoderData, Stack-Edu) were unavailable, so code comes from the Common-Pile Stack-v2-Edu subset and the StarCoder portion of OLMo-mix (StarCoder <reponame>/<filename>/<gh_stars> metadata headers stripped; GitHub-issues/commit/notebook-structured subsets excluded because they contain StarCoder-specific markup).

Design principles for the mixture:

  1. High-quality web text is the backbone (FineWeb-Edu and DCLM-baseline, 28% each): it carries most general knowledge and drives downstream task quality, and the two filters are complementary (educational vs. instruction-like/ELI5 quality).
  2. Because the score is an unweighted mean over unknown domains, every plausible domain gets a non-trivial share: code 13%, math 6%, scientific papers 6%, encyclopedic 4%, books 4%, Q&A 3%, legal/government 1.5%, spoken/chat 1%.
  3. A 4% multilingual hedge (FineWeb-2, 16 languages): a model that never sees non-English text is typically far worse on it (and the tokenizer would also compress it poorly), while 4% of the budget costs English domains little.
  4. No source is repeated more than ~1.2 epochs.
source description tokens available (B) mixture weight
fwedu FineWeb-Edu (sample-100BT, first 56 shards) 41.03 28.28%
dclm DCLM-baseline 1.0 (300 shards, strided) 39.75 28.28%
stackedu Stack-v2-Edu (Common Pile; educational code) 16.59 9.09%
starcoder StarCoder subset of OLMo-mix (~50 languages, metadata headers stripped) 22.73 4.04%
finemath4 FineMath-4+ 9.44 3.03%
owm OpenWebMath 11.57 1.52%
finemath3 FineMath-3+ (22 shards) 5.83 1.01%
algstack Algebraic Stack 5.73 0.51%
arxiv arXiv (RedPajama, via OLMo-mix) 9.48 3.03%
pes2o peS2o (Semantic Scholar papers) 3.10 2.02%
pubmed PubMed (Common Pile) 4.27 1.01%
wiki Wikipedia + Wikibooks (OLMo-mix) 3.69 4.04%
pg19 PG-19 train 2.73 2.02%
gutenberg Project Gutenberg (Common Pile) 4.89 1.01%
pre1929 Pre-1929 books (Common Pile) 2.62 1.01%
stackex StackExchange (Common Pile) 11.19 3.03%
caselaw Caselaw Access Project 2.17 0.71%
uspto USPTO patents 4.42 0.40%
usgpo US GPO documents 1.47 0.40%
youtube YouTube transcripts (CC) 4.09 0.51%
irc Ubuntu IRC logs 1.76 0.25%
hansard UK Hansard 2.00 0.25%
flan FLAN (Dolmino) 1.67 0.51%
fw2 FineWeb-2: 16 languages (de,fr,es,ru,zh,ja,it,pt,pl,nl,ko,vi,tr,ar,hi,id) 9.60 4.04%

(FineWeb-2 shards were capped at 0.6B tokens per language file. Tokens available = after our tokenizer.)

Held-out evaluation data: for every source, the first 400 documents of its first shard (truncated to 18,000 characters, as in the official scorer) are reserved for validation; training skips the first 1,000 documents of that shard. We additionally evaluate on external sets never used for training: C4 validation, WikiText-103 test, PG-19 test, GSM8K test and HumanEval.

3. Tokenizer

Byte-level BPE with a 65,536-entry vocabulary (8 special tokens; <|endoftext|> = id 0 serves as BOS/EOS), trained with Hugging Face tokenizers on a 3 GB sample drawn from the mixture (2.5 minutes on 16 cores). Pre-tokenization uses the GPT-4 (cl100k) split regex (digits grouped in 1-3, case-insensitive contractions, whitespace runs kept for code indentation). There is no Unicode normalization, so decode(encode(x)) == x for any string (verified on all validation documents by the official checker). Compression: 4.74 bytes/token on FineWeb-Edu, 4.52 on DCLM, 3.5-3.7 on code, 3.1 on arXiv LaTeX, 4.1 on the multilingual mix. For throughput we converted the learned merges to tiktoken (identical output on every sampled document) and tokenized at ~330 MB/s with 15 processes. Documents are stored as uint16 streams with BOS prepended to each document.

Bytes per token on the held-out documents: FineWeb-Edu 4.66, DCLM 4.35, Wikipedia 4.60, PubMed 4.31, PG-19 4.11, StackExchange 3.98, multilingual 3.95, OpenWebMath 3.86, arXiv 3.80, Stack-Edu code 3.90, IRC 3.01, Ada code 2.60.

4. Model and training system

Architecture. Llama-style pre-norm decoder: RMSNorm, SwiGLU MLP, rotary embeddings (theta = 1e5), no biases, untied input/output embeddings, plus RMS QK-norm on queries and keys (improves stability at high learning rates). Main model: d_model 2048, 28 layers, 16 heads x 128, FFN 6144, context 4096: 1.80B parameters (1.66B non-embedding incl. LM head).

Document masking. Sequences are fixed 4,097-token windows over the concatenated token stream, but attention is restricted to tokens of the same document (FlashAttention-2 varlen with cu_seqlens at every BOS and row start). This matches the scoring protocol — every evaluation document is scored independently from its own BOS — and avoids wasting attention FLOPs on unrelated context.

Loss. Cross-entropy plus z-loss (1e-4 * logsumexp^2), computed in 8K-token chunks to bound fp32 logit memory.

Optimizer. Muon for all 2-D hidden matrices (Nesterov momentum 0.95, 5 Newton-Schulz iterations in bf16, update scaled by 0.2*sqrt(max(m, n)) so its RMS matches AdamW's, decoupled weight decay 0.1); AdamW (beta = 0.9/0.95, wd 0.1 on embeddings/head, none on norms) for embeddings, LM head and norm gains. Newton-Schulz work is sharded across the 8 GPUs of each node and all-gathered over NVLink in bf16, so its cost is ~2-5% of a step.

Parallelism and kernels. DDP across 6 nodes (EFA, 370 GB/s all-reduce bus bandwidth measured), bf16 autocast with fp32 master weights, torch.compile, gradient accumulation (4 micro-batches of 3x4096 tokens per GPU, 2.36M tokens per optimizer step). Measured 40K tokens/s/GPU (46% MFU) on one node.

Schedule. Warmup (1,000 steps) - stable - decay (WSD). Because the binding constraint is wall-clock, the cooldown is not scheduled in advance: rank 0 measures the realised step rate (including evaluation and checkpoint overheads) and, once the current step reaches 80% of the steps that still fit before the deadline, fixes the total step count and starts a 1-sqrt decay to zero over the remaining 20%; the decision is broadcast to all ranks and stored in checkpoints so restarts reproduce it.

Data loading. Deterministic, resumable mixture sampling: for each global step a seeded RNG assigns each of the 576 sequences to a source according to the mixture weights; within a source, chunks are visited in a seeded random permutation (epoch-wise), so resuming at step s replays only cheap counters.

Checkpointing. Asynchronous (state copied to CPU, written by a background thread; Muon momentum shards written by the 8 node-0 ranks), every 1,000 steps.

5. Ablations

All ablations used a 340M-parameter model (d_model 1024, 16 layers, FFN 2816; 205M non-embedding), the full 24-source mixture (frozen snapshot of shards), 4,000 steps x 0.5M tokens = 2.1B tokens (~10 tokens per non-embedding parameter; a fixed, equal budget per run), 1 node (8 GPUs, ~22 minutes each, four runs in parallel), WSD with 20% linear cooldown. Metric: mean BPB over the 24 held-out domains (200 docs each, truncated to 4,096 tokens).

optimizer peak LR BPB @1000 BPB @2500 (stable phase) final BPB @4000
AdamW 1e-3 1.1557 1.0305 0.9474
AdamW 2e-3 1.1371 1.0204 0.9368
Muon 1e-3 1.0895 0.9930 0.9217
Muon 2e-3 1.0803 0.9896 0.9148

Muon beats the better AdamW setting by 0.022 BPB (2.3%), consistently on all 24 domains (e.g. FineWeb-Edu 0.918 vs 0.938, code 0.572 vs 0.592, arXiv 0.888 vs 0.911, multilingual 1.086 vs 1.115). The advantage is largest early in training and shrinks but persists through the cooldown. Throughput cost of Muon at this scale was ~2%. For the main run we transferred LR by the compute-optimal scaling rule of DeepSeek-LLM (eta proportional to C^-0.125, a factor ~0.5 for the ~300x larger compute), giving 1e-3.

ablation curves

6. Main run

Configuration. 1.80B parameters (Section 4), Muon (LR 1e-3) + AdamW (LR 1e-3) for embeddings/head/norms, weight decay 0.1, 576 sequences x 4,096 tokens = 2.36M tokens per step, 1,000 warmup steps, constant LR, then a time-triggered 1-sqrt cooldown over the final 20% of steps, ending at 23:15 UTC (2h15m before the hard deadline, to leave time for export and evaluation). 48 H100s (6 nodes) for ~19 hours.

Why 1.8B parameters. With ~1e21 FLOPs available, Chinchilla-style fits (Hoffmann et al. parametric law) are very flat between 1.5B and 2.5B parameters (predicted loss differences of <0.3%); we picked the size that maximised predicted loss reduction while keeping the micro-batch (3 x 4,096 tokens) within 80 GB without activation checkpointing (65 GB peak). The run consumes ~65-70 tokens per parameter.

Systems debugging (the most consequential engineering of the project). The first launch reached only 1.45M tokens/s (35% MFU) although a single node had measured 46% MFU:

attempt change tokens/s (48 GPUs) MFU
1 baseline: DDP(torch.compile(model)), memmap data loader 1.45M 35%
2 data loader rewritten (pread + 16 threads + pinned prefetch) 1.46M 35%
3 torch.compile(DDP(model)) + bf16 gradient all-reduce 1.64-1.79M (spiky) 39-43%
4 + Python GC disabled, synchronized gc.collect()+gc.freeze() every 500 steps 1.77-1.79M (stable) 42.5%

Lessons: (i) with DDP(torch.compile(m)), AOTAutograd produces all gradients at the end of one fused backward, so DDP cannot overlap its all-reduce with computation — negligible on NVLink, but ~0.4 s/step (25%) across 6 nodes; compiling around DDP lets dynamo's DDPOptimizer split the graph at bucket boundaries and overlap communication. (ii) Once communication overlapped, per-rank CUDA-event timing (reduced with MAX/MIN over ranks) revealed intermittent 2x stragglers (one rank's compute-only micro-batch taking 550-610 ms instead of ~265 ms); disabling the automatic cyclic GC (whose full passes over torch.compile's object graphs hit random ranks at random times) removed them. (iii) The data-loader hypothesis was wrong: measuring before fixing would have saved one restart. All restarts were deterministic continuations (identical losses), and the last one resumed from the step-1000 checkpoint, so the debugging cost ~35 minutes of cluster time in total.

7. Results

7.1 Training trajectory

held-out BPB during the main run

Mean held-out BPB over the 24 in-distribution domains (in-training evaluator: 200 docs/domain, first 4,096 tokens):

step tokens phase mean BPB
1,000 2.4B end of warmup 0.969
2,000 4.7B stable 0.868
4,000 9.4B stable 0.809
8,000 18.9B stable 0.771
14,000 33.0B stable 0.749
22,000 51.9B stable 0.736
30,000 70.8B stable 0.728
40,000 94.4B stable (plateau) 0.723
40,900 96.5B cooldown decided (total 51,124 steps)
46,000 108.5B cooldown 0.687
48,000 113.2B cooldown 0.679
50,000 117.9B cooldown 0.673
51,124 120.6B final (LR 0) 0.6714

During the stable phase the improvement slowed to ~0.001 BPB per 1,000 steps (2.4B tokens); the 1-sqrt cooldown then removed a further 0.051 BPB (0.7228 at step 40,000 -> 0.6714; -7.1%) in 10,224 steps (24B tokens).

7.2 Final model, official scorer

All numbers below are produced by the official evaluate.py (validity checks: loads, lossless tokenizer, start token, output contract, determinism, consistency and causality — all passed), fp32 weights, context 4,096 with the scorer's sliding window. (The evaluation was split into 8 shards run in parallel on one node; one shard first failed to load because the 8 processes shared one Hugging Face module cache and one read a half-copied configuration_ocelot.py. Re-run alone with a private cache — as the official scorer does — it passed; the scorer additionally passed in --isolate yes mode, i.e. as an unprivileged user without network.) In-distribution domains: 100 held-out documents each (never trained on; first 18,000 characters). External sets: never used in any way during training.

in-distribution domain BPB in-distribution domain BPB
stackedu (code) 0.3950 arxiv 0.6343
flan 0.4155 algstack (math code) 0.6350
usgpo (gov. docs) 0.4502 finemath3 0.6356
uspto (patents) 0.5122 hansard 0.6529
finemath4 0.5645 wiki 0.6642
pubmed 0.5932 pes2o 0.6711
starcoder (Ada shard) 0.5995 owm (OpenWebMath) 0.6723
caselaw 0.6056 fwedu (FineWeb-Edu) 0.7052
stackex 0.7080 gutenberg 0.8605
fw2 (16 languages) 0.7548 youtube (transcripts) 0.8659
pg19 0.7718 pre1929 (OCR books) 0.8934
dclm (web) 0.8314 irc (chat) 0.8981
mean of 24 0.6663
external test set BPB
HumanEval (prompt + solution) 0.5446
WikiText-103 test (articles) 0.6927
GSM8K test (question + answer) 0.7341
PG-19 test (first 18K chars) 0.8466
C4 validation 0.8530
mean of 5 0.7342

Observations. (i) The external sets are 0.07 BPB harder on average than the held-out shards of the training sources, as expected (distribution shift and, for C4, noisier web text than the filtered DCLM/FineWeb-Edu). (ii) Structured and formulaic text (code, government documents, patents, FLAN templates) is cheapest; informal or noisy text (IRC chat, OCR'd pre-1929 books, YouTube ASR transcripts, unfiltered web) is the most expensive, and these hardest domains dominate the unweighted mean. (iii) The multilingual domain (4% of training tokens spread over 16 languages) reaches 0.755 BPB, close to English web text, which supports the cheap-hedge argument of Section 2. (iv) The official scorer (100 docs/domain, full documents with sliding windows, fp32) and the in-training evaluator (200 docs/domain, first 4,096 tokens, bf16) agree on the mean to within 0.005 BPB (0.6663 vs 0.6714); per-domain differences of up to ~0.05 come from the different document samples and from scoring the full 18K-character documents rather than their first 4,096 tokens.

7.3 Downstream tasks (0-shot, lm-evaluation-harness)

lm-evaluation-harness 0.4.13, 0-shot, BOS prepended, fp32. The 340M ablation model (Muon, 2.1B tokens) is shown as a reference point for the effect of scale (5x parameters, 57x tokens).

task metric Ocelot-1.8B (120.6B tokens) 340M ablation (2.1B tokens)
HellaSwag acc_norm 0.634 0.320
ARC-Easy acc 0.728 0.506
ARC-Challenge acc_norm 0.398 0.244
PIQA acc_norm 0.751 0.626
WinoGrande acc 0.611 0.517
LAMBADA (OpenAI) acc / ppl 0.625 / 5.61 0.319 / 40.1
SciQ acc 0.930 0.824
OpenBookQA acc_norm 0.412 -
BoolQ acc 0.665 -
MMLU (57 subjects) acc 0.290 -

For orientation only (different evaluation settings and harness versions, so not a controlled comparison): these numbers are roughly in the range publicly reported for open ~1B models trained on far more tokens (e.g. HellaSwag ~0.6, PIQA ~0.73, WinoGrande ~0.59 for 1.1B-1.2B models trained on ~3T tokens), with ARC/SciQ on the high side, consistent with the educational-web share of the mixture. MMLU (0-shot) remains near chance, as is typical at this scale.

8. Analysis: what worked, what did not

Worked.

  • Muon. +2.3% BPB over tuned AdamW at equal tokens in the ablation, ~2-5% step-time overhead when the Newton-Schulz work is sharded within a node, ~10 GB less optimizer memory than AdamW at 1.5B.
  • Measuring before optimising the system. Per-rank CUDA-event timing reduced with MAX/MIN identified both the non-overlapped all-reduce and the GC stragglers; together these fixes raised throughput by 23% (35% -> 42.5% MFU), worth ~23B extra training tokens over the run.
  • Time-aware WSD. The run decided its own cooldown start from the measured step rate, so a fixed wall-clock deadline was met without guessing the total step count up front, and all restarts (three, during the first hour) were free of schedule bookkeeping.
  • Deterministic, resumable data pipeline. Every restart reproduced the previous run's losses to the 4th decimal.
  • Breadth hedges look cheap (observational, not ablated). Domains with only 0.25-0.5% of the mixture reach BPB comparable to the large web domains in the final model (Hansard 0.65, YouTube 0.87, IRC 0.90 vs. DCLM 0.83), and the 4% multilingual slice reaches 0.75; we did not run the counterfactual without them.

Did not work / mistakes.

  • Wrong first hypothesis on throughput (data loading); one restart was spent on it. The loader rewrite was still kept since it is strictly better (GIL-free I/O, pinned async H2D).
  • Single-node throughput tests do not predict multi-node throughput when compute/communication overlap is broken: the 46% MFU measured on one node fell to 35% on six.
  • Validation-set construction (first shard of each source) produced unrepresentative domains for two sources (StarCoder -> Ada; peS2o -> short abstracts).

Context length. Per-position BPB on 30 long held-out documents (step-8000 checkpoint): 0.95 for tokens 0-64, 0.83 for 64-256, ~0.81 for 512-1K, ~0.79-0.80 beyond 1K tokens. Most of the benefit of context is realised within the first 1-2K tokens, so a 4,096-token window with a 2,048-token sliding stride (the scorer's protocol) loses little relative to full-document context on <=18K-character documents.

9. Key findings

  1. Under a fixed, short wall-clock budget, systems efficiency is a first-order modelling lever: two distributed-training issues invisible on a single node (non-overlapped gradient all-reduce caused by the DDP(torch.compile(...)) wrapping order, and Python-GC stragglers) cost 25% of throughput until found with per-rank event timing; fixing them bought ~23B extra tokens.
  2. Muon gave a consistent 2.3% BPB gain over tuned AdamW across all 24 domains at small scale and trained the 1.8B model stably at LR 1e-3 with no loss spikes over 51K steps.
  3. WSD with a deadline-aware cooldown is well suited to wall-clock-bounded training: the stable phase had plateaued (~0.001 BPB per 2.4B tokens), and the final 20% cooldown delivered a 7.1% BPB reduction.
  4. A broad 24-source mixture produced a model whose worst domains are informal/noisy text (chat, OCR, ASR, raw web) rather than whole missing modalities: code, math, papers, legal and 16-language multilingual text all score between 0.40 and 0.76 BPB.

10. Limitations

  • Single main run, no seeds/error bars. Under the wall-clock budget only one full-scale run was possible; the optimizer decision rests on a 340M-parameter, 2.1B-token ablation (Muon's advantage is reported to shrink with scale), and the main-run learning rate was transferred by a scaling rule rather than tuned.
  • Mixture weights are priors, not measurements. No mixture ablations were run; weights were set by judgement about likely evaluation domains. The validation domains are drawn from the same sources as the training data (held-out documents), so in-distribution BPB overstates generalisation; the external sets (C4, WikiText-103, PG-19 test, GSM8K, HumanEval) are a partial check. Some sources (CommonCrawl-derived web sets) may overlap each other and possibly external evaluation text.
  • Validation-set construction quirks. Each domain's validation documents come from the first shard of the source; for the StarCoder source this is Ada code (alphabetical shard order), and for peS2o mostly short abstracts, so those two domains are not representative of their sources.
  • Context length 4,096. Documents longer than ~4K tokens (books, papers, long code files truncated at 18K characters) are scored with a sliding window (stride 2,048); a longer-context phase was not attempted.
  • No decontamination against downstream benchmarks beyond what upstream dataset builders performed (OLMo-mix sources are decontaminated against several benchmarks; FineWeb-Edu/DCLM are not explicitly).
  • Efficiency headroom. 42.5% MFU (FlashAttention-2, DDP, no FA3/FP8, no sequence packing balance across ranks); roughly 10-15% more throughput was likely available with more engineering time.

11. Resources and artifacts

  • Compute used: 965.7 of 1,048 H100-hours (main run ~930: 48 GPUs x ~19.4 h; ablations ~22; development, failed launches and evaluation the rest). Wall-clock: data + tokenizer + ablations + launch in the first ~1.5 h, main run 03:51-23:12 UTC, export/evaluation 23:16-23:45 UTC.
  • /workspace/final_model: HF checkpoint (fp32 safetensors, trust_remote_code modeling/config files with KV-cache support, tokenizer, model card). Bit-identical to training checkpoint step 51,124.
  • /workspace/code: data download/tokenization (download.py, pretokenize.py, train_tokenizer.py), training (train.py, model.py), export (export_hf.py, hf/), evaluation (final_job.sh, collect_results.py), figures (make_figures.py). /workspace/notes.md: chronological lab notes.
  • Evaluation outputs: /workspace/final_eval (official scorer JSON per shard, lm-eval outputs); training metrics: /workspace/ckpt/main/metrics.jsonl; ablations: /workspace/ckpt_abl/*/metrics.jsonl.