La Forge

A small French language model (16.9M parameters), written and trained from scratch

Role
Everything: corpus, tokeniser, model, training
Tools
  • PyTorch (MPS)
  • BPE
  • RoPE
  • RMSNorm
  • SwiGLU
Status
In progress
Training and validation loss over 4,000 steps, and measured throughput.
Training and validation loss over 4,000 steps, and measured throughput.
parameters
16.9M
tokens, 279 public-domain books
51.6M
validation loss at step 4,000
3.80
per step on Apple GPU
1.1–1.4 s
The problem
Mastering the full language-model pipeline, from corpus to serving, with no cloud, on a 16 GB laptop.
For whom
Personal research project: showing the end-to-end command expected of an AI engineer.
The outcome
Stage 1 done: 16.9M parameters pre-trained on 51.6M tokens, validation loss 3.80 at step 4,000.

Context

Running the full language-model pipeline on a 16 GB MacBook with no cloud: pre-train, then align (SFT, DPO, GRPO), then serve while measuring throughput and latency.

What I built

  • Cleaned French Gutenberg corpus, split 98/2.
  • Byte-level BPE tokeniser, 16,384 tokens (3.64 characters per token).
  • Transformer written from scratch: RoPE, RMSNorm, SwiGLU, tied embeddings.
  • Loop with checkpoints, resume, CSV log and sampler.

Architecture 6 blocks

  1. 01 · InputCorpus279 French Gutenberg books, cleaned, split 98/2
  2. 02 · ToolBPE tokeniserByte-level, 16,384 tokens, 3.64 characters per token
  3. 03 · ModelTransformerFrom scratch: RoPE, RMSNorm, SwiGLU, tied embeddings
  4. 04 · ToolTrainingAdamW, warmup then cosine, micro-batches of 8
  5. 05 · DataCheckpointsEvery 1,000 steps, CSV log, resume
  6. 06 · OutputSamplesGenerated text and loss curves

Next stages on the roadmap: SFT and DPO, GRPO, then quantised serving.

Pipeline 4 steps

  1. Pre-trainingDone: 4,000 steps, 19 Oct 2026.
  2. SFT + DPONext: LoRA on Qwen2.5-0.5B (a different, larger model), hand-written DPO.
  3. GRPONext: reinforcement with verifiable rewards.
  4. ServingNext: GGUF, quantisation, P50/P95 latencies.

Decisions the choice, the reason, the alternative ruled out

  1. D1
    Accumulate gradients in micro-batches of 8, with periodic MPS cache purges.

    Logits of about 1 GB per step plus the MPS cache pushed the process to 11 GB: memory cut by four, same maths.

    Ruled outThe full batch of 32 at once: 17–19 s per step, measured.

  2. D2
    Checkpoint every 1,000 steps and support resuming.

    When the machine slept at step 3,750, training resumed from step 3,000.

    Ruled outA single uninterrupted run, to redo after any stop.

  3. D3
    A byte-level BPE tokeniser, trained on the corpus.

    3.64 characters per token on literary French, exact round trip checked.

  4. D4
    Write the model from scratch, in PyTorch only.

    Every block is understood and checked: initial loss of 9.65, matching ln 16,384 ≈ 9.70.

    Ruled outStarting from an existing model library.

Results

« En l’an de grâce, un homme de raison vint à la ville et le trouva toujours comme un autre. »
Raw sample at step 4,000: the shape of literary French is learned.

Deliverables 4

  • Full code: corpus download, tokeniser, model, training loop, sampler.
  • Loss curve (training and validation) and measured throughput over 4,000 steps.
  • Raw samples at step 4,000.
  • Memory diagnosis logs, kept.

Environment

Hardware and measurement setup

  • Pre-trained on a 16 GB MacBook Pro, Apple GPU (MPS): 1.1 to 1.4 s per step, about 1 h 20 of cumulative compute.
  • Memory diagnosis: gradient accumulation in micro-batches of 8, memory divided by four, same maths.
  • Checkpoint resume proven in real conditions: after the machine slept at step 3,750, training restarted from step 3,000.

Reproduce README commands

Private code: read access under NDA, or a 30-minute live demo. Request access →

P=~/Documents/ComfyUI/.venv/bin/python
$P corpus/telecharger.py --objectif-mo 200
$P corpus/preparer.py
$P tokeniseur/entrainer.py
$P train/entrainer.py --pas 4000 --micro 8
$P train/entrainer.py --reprendre train/sortie/dernier.pt
$P train/echantillonner.py --invite "Il était une fois"
  • About 1 h 20 of cumulative compute on Apple GPU (MPS), 1.1 to 1.4 s per step.
  • Code and documents versioned; corpus and outputs regenerated by the scripts.

What this project means for you

The same know-how, on your problem.

01

Training your teams

I have written every block of an LLM: I can explain to your teams what really happens inside a model, with numbers.

02

Training under constraints

Memory diagnosis, checkpoint resume, a log of every step: the same method to train or fine-tune a model on your hardware.

03

Judging a model without illusions

Telling what a model imitates (form) from what it knows (meaning): a useful read before handing it a task.