# Code associé : exécuter soi-même les algorithmes du cours

> Le dépôt associé à DMXSF propose 61 ateliers Python exécutables sur CPU, couvrant 66 articles du wiki et vérifiant leurs formules et mécanismes essentiels.

- URL: https://dmxsf.com/fr/code/
- Mis à jour: 2026-11-18

Le dépôt [dmxsf/dmxsf](https://github.com/dmxsf/dmxsf) propose des ateliers sur les tenseurs, les GPU, l’inférence locale, les agents, l’entraînement, l’évaluation et la sécurité. Chaque atelier comprend des consignes, une commande et les résultats. Aucun GPU ni poids externe n’est nécessaire.

## Démarrage rapide

```bash
git clone https://github.com/dmxsf/dmxsf.git
cd dmxsf
uv sync
uv run dmxsf list
uv run dmxsf run foundations/tensors-and-shapes
uv run dmxsf roadmap weekend
```

Nous recommandons [uv](https://docs.astral.sh/uv/) ; `pip install -e .` fonctionne aussi, sans le préfixe `uv run`.

## Lien entre le code et le cours

- Les ateliers suivent les chemins des articles dans `labs/<section>/<page>/` ; des sujets proches peuvent partager un atelier.
- Ils vérifient les formules et les mécanismes. Certaines expériences de performance utilisent de petits exemples CPU.
- Chaque README précise le périmètre et distingue les exemples pédagogiques des mesures complètes.
- La bibliothèque, les ateliers et les tests sont séparés. CI exécute les tests et une vérification rapide de chaque atelier.

## Utilisation

1. Lisez une page et choisissez une formule ou un tableau à vérifier.
2. Exécutez l’atelier associé et comparez le code à sa sortie.
3. Modifiez un paramètre, relancez-le, puis essayez les exercices.

## Environnement et durée

- Un CPU suffit. Le premier atelier avec un modèle préentraîné entraîne un petit modèle local.
- La durée approximative est indiquée ; `--quick` lance une vérification rapide.
- Les temps dépendent de la machine : comparez les rapports, pas les valeurs absolues.

## Toutes les expériences

Expériences associées aux pages du wiki. (61 expériences)

### Premiers pas

#### [What is an LLM? The whole loop, small enough to read](https://github.com/dmxsf/dmxsf/tree/main/labs/start/what-is-an-llm)

Predict one byte, append it, repeat: the whole loop on an 842,496-parameter GPT you can open, from tokens and embeddings to the softmax, the training objective and the three numbers (parameters, tokens, context). It ends with the map from every page of the course to its lab.

- Pages associées: [Un LLM, du token à l’assistant](https://dmxsf.com/fr/wiki/start/what-is-an-llm/), [Feuille de route LLM : la carte du wiki et quatre parcours](https://dmxsf.com/fr/wiki/start/learning-roadmap/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run start/what-is-an-llm`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/start/what-is-an-llm/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/start/what-is-an-llm/README.en.md)

#### [LLM formula sheet: parameters, memory and compute](https://github.com/dmxsf/dmxsf/tree/main/labs/start/cheat-sheet)

Cross-check released-model parameter counts, KV bytes, training FLOPs and pass@k.

- Pages associées: [Aide-mémoire des LLM : paramètres, calcul, mémoire et vitesse de décodage](https://dmxsf.com/fr/wiki/start/cheat-sheet/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run start/cheat-sheet`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/start/cheat-sheet/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/start/cheat-sheet/README.en.md)

### Fondements

#### [Tensor shapes: a linear layer by hand](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/tensors-and-shapes)

Track position and feature axes through a projection, bias and ReLU.

- Pages associées: [Python et formes des tenseurs : du tableau à la couche linéaire](https://dmxsf.com/fr/wiki/foundations/tensors-and-shapes/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run foundations/tensors-and-shapes`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/tensors-and-shapes/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/tensors-and-shapes/README.en.md)

#### [Next-token prediction and information theory](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/next-token-prediction)

Bigram counts on the page's toy corpus, entropy, cross-entropy and KL divergence checked against each other, character n-grams on Shakespeare until the counts run out, and a neural bigram that learns the count table by gradient descent.

- Pages associées: [De la modélisation du langage à la prédiction du prochain token](https://dmxsf.com/fr/wiki/foundations/next-token-prediction/), [Théorie de l'information : entropie, entropie croisée et divergence KL](https://dmxsf.com/fr/wiki/foundations/information-theory/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run foundations/next-token-prediction`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/next-token-prediction/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/next-token-prediction/README.en.md)

#### [Neural networks: gradients and XOR](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/neural-network-basics)

Check manual backpropagation with finite differences, then fit XOR with and without a hidden layer.

- Pages associées: [Bases des réseaux de neurones : des couches linéaires à la rétropropagation](https://dmxsf.com/fr/wiki/foundations/neural-network-basics/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run foundations/neural-network-basics`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/neural-network-basics/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/neural-network-basics/README.en.md)

#### [Tokenizers and embeddings](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/tokenizer-and-embeddings)

BPE by hand on the page's toy corpus, a byte-level BPE that never says <unk>, what the training text decides about a language's cost, an embedding table as a matrix multiply, and how much of a model the embedding table is.

- Pages associées: [Tokenizers et embeddings : BPE, taille du vocabulaire et table d'embedding](https://dmxsf.com/fr/wiki/foundations/tokenizer-and-embeddings/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run foundations/tokenizer-and-embeddings`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/tokenizer-and-embeddings/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/tokenizer-and-embeddings/README.en.md)

#### [Optimizers, schedules, mixed precision and loss spikes](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/optimizers-and-training-stability)

SGD, Adam and AdamW written out and checked against PyTorch in float64; why Adam wins on an ill-conditioned quadratic; decoupled weight decay; learning-rate schedules; mixed precision and master weights; one corrupted batch and what clipping and beta2 do about it.

- Pages associées: [Optimiseurs et stabilité d'entraînement : AdamW, warmup, précision mixte](https://dmxsf.com/fr/wiki/foundations/optimizers-and-training-stability/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run foundations/optimizers-and-training-stability`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/optimizers-and-training-stability/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/optimizers-and-training-stability/README.en.md)

### Architecture des modèles

#### [From RNN to attention: gradients and retrieval paths](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/from-rnn-to-attention)

Compare the gradient through a recurrent chain and a gated memory path, then recover an earlier value with attention.

- Pages associées: [Des RNN à l'attention : pourquoi le Transformer est apparu](https://dmxsf.com/fr/wiki/architecture/from-rnn-to-attention/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run architecture/from-rnn-to-attention`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/from-rnn-to-attention/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/from-rnn-to-attention/README.en.md)

#### [Attention, by hand and in a model](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/attention-basics)

The page's three-position example by hand, why scores are divided by sqrt(d) (the dot product has variance d), masks, heads and positions, and a small model that has to use attention to copy what followed the last occurrence.

- Pages associées: [Introduction au mécanisme d'attention du Transformer](https://dmxsf.com/fr/wiki/architecture/attention-basics/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run architecture/attention-basics`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/attention-basics/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/attention-basics/README.en.md)

#### [Position encodings and length extrapolation](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/positional-encoding)

Sinusoidal encodings as clocks, RoPE's score depending only on distance, the stretching recipes (position interpolation, NTK-aware, YaRN, the Llama 3.1 rule) computed side by side, and five position schemes trained on short text and tested on long text.

- Pages associées: [Les encodages de position en détail (absolu → relatif → RoPE)](https://dmxsf.com/fr/wiki/architecture/positional-encoding/), [Long contexte : extrapolation de position, recettes d'entraînement et coûts](https://dmxsf.com/fr/wiki/architecture/long-context/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run architecture/positional-encoding`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/positional-encoding/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/positional-encoding/README.en.md)

#### [The Transformer block and the modern recipe](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/transformer-block)

Count a GPT-2 small block (12d²+13d parameters), see where real models keep their parameters, measure signal and gradient by depth for pre-norm and post-norm, then walk from GPT-2 to Llama one change at a time.

- Pages associées: [Le Transformer Block complet, pièce par pièce](https://dmxsf.com/fr/wiki/architecture/transformer-block/), [Architecture des grands modèles modernes : de GPT-2 à Llama, Qwen et DeepSeek](https://dmxsf.com/fr/wiki/architecture/modern-llm-architecture/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run architecture/transformer-block`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/transformer-block/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/transformer-block/README.en.md)

#### [Efficient attention](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/efficient-attention)

KV-cache formulas against the page's table and against real tensors, MLA caching a latent vector, FlashAttention's tiles and online softmax, sliding-window attention, and converting an MHA model to GQA by mean-pooling heads.

- Pages associées: [Attention efficace : MQA, GQA, MLA et FlashAttention](https://dmxsf.com/fr/wiki/architecture/efficient-attention/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run architecture/efficient-attention`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/efficient-attention/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/efficient-attention/README.en.md)

#### [Mixture of experts: routing, load balance and the parameter accounts](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/mixture-of-experts)

A MoE layer that computes only the tokens an expert was chosen for, total against active parameters counted on real modules, a DeepSeek-V3-style toy model, expert capacity, the balance loss, how many experts a decoding batch touches, and a trained MoE against dense models of equal cost and equal size.

- Pages associées: [Mélange d'experts (MoE) : routage, équilibrage de chargé et activation éparses](https://dmxsf.com/fr/wiki/architecture/mixture-of-experts/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run architecture/mixture-of-experts`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/mixture-of-experts/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/mixture-of-experts/README.en.md)

#### [State space and hybrids: equivalent scans and memory](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/state-space-and-hybrid)

Compare recurrent and explicit causal forms of the same selective update and account for hybrid state and cache.

- Pages associées: [Espaces d'états et hybrides : un état fixe à la place du KV Cache](https://dmxsf.com/fr/wiki/architecture/state-space-and-hybrid/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run architecture/state-space-and-hybrid`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/state-space-and-hybrid/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/state-space-and-hybrid/README.en.md)

### Calcul et systèmes

#### [Hardware basics: storage and copy time](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/hardware-basics)

Compute tensor sizes and a copy-time lower bound with explicit units.

- Pages associées: [Matériel des grands modèles : CPU, GPU, mémoire et transports](https://dmxsf.com/fr/wiki/systems/hardware-basics/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run systems/hardware-basics`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/hardware-basics/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/hardware-basics/README.en.md)

#### [GPU roofline: bytes, FLOPs and tile reuse](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/gpu-and-roofline)

Compute the A100 and H100 ridge points, model a linear layer, and count matrix-multiply tile traffic.

- Pages associées: [GPU et modèle du toit : la bande passante mémoire comme limite](https://dmxsf.com/fr/wiki/systems/gpu-and-roofline/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run systems/gpu-and-roofline`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/gpu-and-roofline/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/gpu-and-roofline/README.en.md)

#### [GPU kernels: tiled GEMM and memory traffic](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/gpu-kernels)

Run tiled matrix multiplication on uneven shapes and verify logical memory traffic.

- Pages associées: [Noyaux GPU : matmul tuilé et fusion d'opérateurs](https://dmxsf.com/fr/wiki/systems/gpu-kernels/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run systems/gpu-kernels`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/gpu-kernels/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/gpu-kernels/README.en.md)

#### [Numerical precision: rounding, overflow and loss scaling](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/numerical-precision)

Reproduce low-precision stalled addition, stable softmax, and loss scaling with CPU tensors.

- Pages associées: [Précision numérique : pannes FP16, BF16 et FP8 à l'entraînement](https://dmxsf.com/fr/wiki/systems/numerical-precision/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run systems/numerical-precision`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/numerical-precision/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/numerical-precision/README.en.md)

#### [Collective communication: simulate a ring all-reduce](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/collective-communication)

Track each chunk through reduce-scatter and all-gather, then compare the observed per-rank bytes with the alpha-beta model.

- Pages associées: [Communication collective : pourquoi l'all-reduce a tant d'algorithmes](https://dmxsf.com/fr/wiki/systems/collective-communication/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run systems/collective-communication`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/collective-communication/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/collective-communication/README.en.md)

### Pré-entraînement

#### [The pretraining pipeline on a laptop: monitoring, data mix, resuming, leakage](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/training-pipeline)

Two free checks before spending compute, a baseline run and how to read its log, then three experiments on a laptop: the data mix, four ways to resume from a checkpoint (only one is exact), and validation text leaking into the training data.

- Pages associées: [Vue d'ensemble de la chaîne d'entraînement des grands modèles](https://dmxsf.com/fr/wiki/pretraining/training-pipeline/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run pretraining/training-pipeline`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/training-pipeline/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/training-pipeline/README.en.md)

#### [Data engineering: build and audit a dedup filter](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/data-engineering)

Compare exact duplicates and shingle similarity, then read the banding curve before choosing a deduplication threshold.

- Pages associées: [Ingénierie des données de pré-entraînement : filtrage, déduplication et mélanges](https://dmxsf.com/fr/wiki/pretraining/data-engineering/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run pretraining/data-engineering`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/data-engineering/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/data-engineering/README.en.md)

#### [Scaling laws: the formulas, the serving cost, and a tiny study of our own](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/scaling-laws)

The page's power laws and compute-optimal split recomputed, what serving cost does to the best model, a real tiny scaling study (tune the learning rate per size, train a grid, fit L(N, D), predict an unseen run), and what a 12-point fit can and cannot identify.

- Pages associées: [Lois d'échelle : comment répartir entre calcul, paramètres et données](https://dmxsf.com/fr/wiki/pretraining/scaling-laws/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run pretraining/scaling-laws`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/scaling-laws/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/scaling-laws/README.en.md)

#### [Training compute and memory: 6ND, MFU, model state and activations](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/compute-and-memory)

Every formula on the page checked against a measurement: PyTorch's FLOP counter, the tensors autograd saves for the backward pass, and the optimizer's state; then MFU, GPU hours and a full Llama 2 7B account on 8 x 80 GiB.

- Pages associées: [Compte de calcul et mémoire : FLOPs, MFU et budget mémoire](https://dmxsf.com/fr/wiki/pretraining/compute-and-memory/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run pretraining/compute-and-memory`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/compute-and-memory/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/compute-and-memory/README.en.md)

#### [Distributed training: gradients, ZeRO, tensor and pipeline parallelism](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/distributed-training)

Built and measured in a few processes on one machine: data-parallel gradient averaging, the ring all-reduce, data parallelism, ZeRO-1 and ZeRO-3 trained side by side (same weights, measured memory and communication), Megatron-style tensor parallelism, and pipeline schedules.

- Pages associées: [Entraînement distribué : données, tenseurs et pipeline](https://dmxsf.com/fr/wiki/pretraining/distributed-training/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run pretraining/distributed-training`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/distributed-training/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/distributed-training/README.en.md)

### Post-training et alignement

#### [SFT data: the loss mask, a data health check, and what data size, noise, masking and replay do](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/sft-data)

What the SFT loss averages over (the -100 mask, packing and padding), data health checks against planted ground truth, and four controlled experiments: run-to-run noise, examples per intent, wrong labels, loss on the prompt and replaying general text.

- Pages associées: [Données SFT : construction et contrôle qualité](https://dmxsf.com/fr/wiki/post-training/sft-data/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run post-training/sft-data`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/sft-data/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/sft-data/README.en.md)

#### [LoRA: the parameter bill, the mechanics, LoRA against full fine-tuning, merging, NF4](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/lora-finetuning)

LoRA written from scratch and compared with full fine-tuning: the exact parameter bill, learning-rate windows, rank and alpha, which matrices to adapt, how low-rank the learned update is, merging into the weights and into 4-bit (NF4) weights, memory and speed.

- Pages associées: [LoRA en pratique : fine-tuning pas a pas](https://dmxsf.com/fr/wiki/post-training/lora-finetuning/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run post-training/lora-finetuning`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/lora-finetuning/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/lora-finetuning/README.en.md)

#### [Reward models: pairwise scores and label noise](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/reward-models)

Fit Bradley–Terry scores on a connected comparison graph and reproduce the agreement ceiling under independent label flips.

- Pages associées: [Modèles de recompense : des préférences humaines au score](https://dmxsf.com/fr/wiki/post-training/reward-models/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run post-training/reward-models`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/reward-models/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/reward-models/README.en.md)

#### [Policy gradients: exact checks, baselines and GAE](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/rl-fundamentals)

Enumerate a tiny policy, compare gradients against finite differences, and vary lambda in a finite GAE trajectory.

- Pages associées: [Bases du RL : gradient de politique, avantage et PPO](https://dmxsf.com/fr/wiki/post-training/rl-fundamentals/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run post-training/rl-fundamentals`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/rl-fundamentals/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/rl-fundamentals/README.en.md)

#### [Preference optimization: the DPO loss, its closed form, and a real DPO run](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/preference-optimization)

The DPO loss by hand, its closed-form optimum checked against random competitors and fitted comparisons, a real DPO run on a small byte-level model (learning rate, beta, chosen log-probabilities that fall, the LoRA-off reference), and reward hacking as the KL budget grows.

- Pages associées: [Optimisation des préférences : de RLHF a DPO](https://dmxsf.com/fr/wiki/post-training/preference-optimization/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run post-training/preference-optimization`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/preference-optimization/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/preference-optimization/README.en.md)

#### [Reasoning RL: verifiers, GRPO advantages and loss, and a real RLVR run](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/reasoning-rl)

The verifier, group advantages, the GRPO loss, clipping and the k3 KL estimator checked exactly; then a real RLVR run in which a tiny model is updated from nothing but exact-match 0/1 rewards.

- Pages associées: [RL sur le raisonnement : RLVR et GRPO](https://dmxsf.com/fr/wiki/post-training/reasoning-rl/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run post-training/reasoning-rl`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/reasoning-rl/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/reasoning-rl/README.en.md)

#### [Reasoning RL systems: rollout and learner scheduling](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/rollout-and-training)

Replay serial and overlapping jobs, and verify policy lag and dropped batches.

- Pages associées: [Échantillonnage et entraînement en RL de raisonnement](https://dmxsf.com/fr/wiki/post-training/rollout-and-training/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run post-training/rollout-and-training`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/rollout-and-training/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/rollout-and-training/README.en.md)

### Inférence et déploiement

#### [First inference service: a local HTTP endpoint](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/first-inference-service)

Send real local HTTP requests to a toy decoder and check success and errors.

- Pages associées: [Premier service d inference](https://dmxsf.com/fr/wiki/inference/first-inference-service/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run inference/first-inference-service`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/first-inference-service/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/first-inference-service/README.en.md)

#### [Decoding and sampling: temperature, top-k, top-p, min-p, beam search, penalties](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/decoding-and-sampling)

The page's four-token example reproduced exactly (temperature, top-k, top-p, min-p, and why the order matters), whether samples follow the processed distribution, what each knob does to real text, beam search, repetition penalties, and whether batch shape changes greedy output.

- Pages associées: [Décodage et échantillonnage : température, Top-k, Top-p et beam search](https://dmxsf.com/fr/wiki/inference/decoding-and-sampling/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run inference/decoding-and-sampling`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/decoding-and-sampling/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/decoding-and-sampling/README.en.md)

#### [KV cache: the memory formula, exactness, the saving, prefill against decode](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/kv-cache)

The memory formula against real cache tensors, cached and uncached decoding agreeing exactly, and the saving counted two ways: token positions processed (exact) and time on a CPU (read the ratios), plus the prefill and decode split.

- Pages associées: [Cache KV et optimisation des performances d'inférence](https://dmxsf.com/fr/wiki/inference/kv-cache/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run inference/kv-cache`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/kv-cache/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/kv-cache/README.en.md)

#### [Prefix caching: cache reuse versus queues](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/prefix-caching)

Replay bursty and spaced arrivals with two cache routing policies.

- Pages associées: [Cache de préfixes et séparation PD : ne calculer qu'une fois ce qui se répète](https://dmxsf.com/fr/wiki/inference/prefix-caching/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run inference/prefix-caching`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/prefix-caching/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/prefix-caching/README.en.md)

#### [Quantization: the ledger, the grid, weights, activations, calibration, the KV cache](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/quantization)

The 80 GB ledger for Llama 3 8B, the rounding grid, and experiments on a small model: round-to-nearest, SmoothQuant, an AWQ-style scale search, GPTQ and a quantized KV cache, with outliers dialled in and labelled as constructed.

- Pages associées: [Quantification de modèles : principes et mesures d'INT8, INT4, GPTQ et AWQ](https://dmxsf.com/fr/wiki/inference/quantization/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run inference/quantization`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/quantization/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/quantization/README.en.md)

#### [Serving: continuous batching, paged KV memory, prefix cache, TTFT, capacity](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/continuous-batching)

Roofline and exact batched decoding, static against continuous scheduling on paper and on a real model, a paged KV pool with copy-on-write, a hash-based prefix cache, and what a request costs (TTFT, TPOT, capacity). Read the ratios, not the milliseconds.

- Pages associées: [Batching continu et PagedAttention : servir beaucoup de requêtes à la fois](https://dmxsf.com/fr/wiki/inference/continuous-batching/), [Service d'inference](https://dmxsf.com/fr/wiki/inference/serving/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run inference/continuous-batching`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/continuous-batching/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/continuous-batching/README.en.md)

#### [Speculative decoding: the rule, the formulas, a real draft and target](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/speculative-decoding)

The accept/reject rule that keeps the target's exact distribution, checked on the page's toy distribution, by exact algebra and on real models; the formulas of Leviathan et al.; a draft and target byte-level pair run with KV caches; and when it does not pay.

- Pages associées: [Decodage speculatif](https://dmxsf.com/fr/wiki/inference/speculative-decoding/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run inference/speculative-decoding`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/speculative-decoding/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/speculative-decoding/README.en.md)

### Ingénierie applicative

#### [First agent: a bounded tool loop](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/first-agent)

Run a read-only lookup loop and check success, absence, and the step budget.

- Pages associées: [Un premier agent : des outils en lecture seule à la boucle bornée](https://dmxsf.com/fr/wiki/applications/first-agent/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run applications/first-agent`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/first-agent/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/first-agent/README.en.md)

#### [Prompting, measured](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/prompt-engineering)

The chat template rendered by hand, what a prefix cache can reuse, scorers that separate format failures from wrong judgments, the twelve word problems re-solved in code, and how far a 12-ticket eval set can be trusted. With --hf the page's experiments are rerun on Qwen2.5-1.5B-Instruct.

- Pages associées: [Ingenierie de prompt](https://dmxsf.com/fr/wiki/applications/prompt-engineering/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run applications/prompt-engineering`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/prompt-engineering/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/prompt-engineering/README.en.md)
- Option : ajoutez --hf ou --bge ; uv sync --extra hf requis

#### [Structured output: constrained decoding, its cost, and the function-calling loop](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/structured-output-and-function-calling)

Constrained decoding from the automaton up: the page's demo token for token, why the stepwise mask is not the model's distribution over legal outputs, the mask on a byte-level GPT that has and has not seen the format, schemas, validation and retries.

- Pages associées: [Sorties structurées et appel de fonctions : du mode JSON au decodage contraint](https://dmxsf.com/fr/wiki/applications/structured-output-and-function-calling/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run applications/structured-output-and-function-calling`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/structured-output-and-function-calling/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/structured-output-and-function-calling/README.en.md)

#### [RAG, piece by piece](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/rag)

Chunking, similarity and index size, BM25 from the formula, rank fusion (RRF), retrieval metrics and context assembly, reproducing the page's numbers offline; with --bge the dense retriever and the reranker run too.

- Pages associées: [Monter un systeme RAG en pratique](https://dmxsf.com/fr/wiki/applications/rag/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run applications/rag`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/rag/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/rag/README.en.md)
- Option : ajoutez --hf ou --bge ; uv sync --extra hf requis

#### [Agents and tool calling: the loop, its guards, and the trace scorer](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/agents-and-tool-calling)

The tool-calling loop with its guards (format, business rules, repeats, confirmation, step limit) and the scorer, with the model swapped for a scripted stand-in that replays the page's decisions; then pass^k against pass@k. No language model runs.

- Pages associées: [Agents et appel d'outils en pratique : du Function Calling aux flux ReAct](https://dmxsf.com/fr/wiki/applications/agents-and-tool-calling/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run applications/agents-and-tool-calling`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/agents-and-tool-calling/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/agents-and-tool-calling/README.en.md)

#### [Agent context and memory: budget and precedence](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/context-and-memory)

Keep tool groups whole and verify overrides and deletion on versioned records.

- Pages associées: [Contexte et mémoire longue durée de l'agent : fenêtre, versions et etats](https://dmxsf.com/fr/wiki/applications/context-and-memory/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run applications/context-and-memory`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/context-and-memory/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/context-and-memory/README.en.md)

#### [Agent evaluation: repeatability and terminal state](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/agent-evaluation)

Compare equal one-run scores and validate four calendar traces.

- Pages associées: [Évaluation d'agent : on juge le systeme, pas le modèle](https://dmxsf.com/fr/wiki/applications/agent-evaluation/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run applications/agent-evaluation`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/agent-evaluation/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/agent-evaluation/README.en.md)

#### [MCP tools: inspect discovery, calls and schema size](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/mcp-and-tool-ecosystem)

Inspect offline JSON-RPC tools/list and tools/call messages and measure what narrowing the catalog sends to a client.

- Pages associées: [MCP et l ecosysteme d outils](https://dmxsf.com/fr/wiki/applications/mcp-and-tool-ecosystem/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run applications/mcp-and-tool-ecosystem`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/mcp-and-tool-ecosystem/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/mcp-and-tool-ecosystem/README.en.md)

### Multimodal

#### [Multimodal LLMs: images as tokens](https://github.com/dmxsf/dmxsf/tree/main/labs/multimodal/multimodal-llms)

Patches to visual tokens, what the tokens cost in KV cache and FLOPs, LLaVA's projector and two training stages, CLIP's contrastive loss and a small CLIP trained from scratch on rendered shapes. With --hf, CLIP ViT-B/32 on CIFAR-10.

- Pages associées: [LLM multimodaux : comment une image devient des tokens](https://dmxsf.com/fr/wiki/multimodal/multimodal-llms/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run multimodal/multimodal-llms`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/multimodal-llms/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/multimodal-llms/README.en.md)
- Option : ajoutez --hf ou --bge ; uv sync --extra hf requis

#### [Diffusion and flow matching: verify a Gaussian path](https://github.com/dmxsf/dmxsf/tree/main/labs/multimodal/diffusion-and-flow-matching)

Measure the forward diffusion variance and integrate a simple analytic flow, checking how Euler error changes with step count.

- Pages associées: [Diffusion et flow matching : générer images, actions et texte depuis le bruit](https://dmxsf.com/fr/wiki/multimodal/diffusion-and-flow-matching/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run multimodal/diffusion-and-flow-matching`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/diffusion-and-flow-matching/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/diffusion-and-flow-matching/README.en.md)

#### [World models: plan, observe, and replan](https://github.com/dmxsf/dmxsf/tree/main/labs/multimodal/world-models)

Compare fixed execution with feedback on a grid with a hidden wall.

- Pages associées: [Modèles du monde et planification](https://dmxsf.com/fr/wiki/multimodal/world-models/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run multimodal/world-models`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/world-models/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/world-models/README.en.md)

### Évaluation

#### [Benchmark contamination: an n-gram detector, and a leak you can measure](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/llm-evaluation)

The page's n-gram contamination detector on its own example; a benchmark whose answers can only be memorised; a model trained with a third of it leaked verbatim, a third paraphrased and a third absent; what the detector flags and what the clean-subset check concludes.

- Pages associées: [Methodologie d evaluation des LLM](https://dmxsf.com/fr/wiki/evaluation/llm-evaluation/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run evaluation/llm-evaluation`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/llm-evaluation/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/llm-evaluation/README.en.md)

#### [Evaluation statistics: pass@k, the error of a score, paired tests, sample sizes](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/eval-statistics)

pass@k against brute-force enumeration, the 95% interval against how often it actually covers, paired comparisons and the sample-size table against the power of a real test, then two real models compared on held-out text.

- Pages associées: [Statistiques des evaluations](https://dmxsf.com/fr/wiki/evaluation/eval-statistics/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run evaluation/eval-statistics`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/eval-statistics/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/eval-statistics/README.en.md)

#### [LLM-as-a-judge: bias, agreement, and Bradley-Terry leaderboards](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/llm-as-judge)

A judge stand-in with chosen biases, so every number has an exact answer: swapping the order cancels position bias but not length bias, Cohen's kappa exposes a judge that always guesses the majority class, and a Bradley-Terry leaderboard is corrected for length.

- Pages associées: [LLM-as-a-Judge : le modèle comme jury, ses biais et sa calibration](https://dmxsf.com/fr/wiki/evaluation/llm-as-judge/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run evaluation/llm-as-judge`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/llm-as-judge/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/llm-as-judge/README.en.md)

#### [Evaluation sets: noisy labels, agreement and item information](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/building-eval-sets)

Check a four-option label-noise formula by simulation, compute Cohen's kappa, and locate a 2PL item's most informative difficulty.

- Pages associées: [Construire un jeu d'evaluation](https://dmxsf.com/fr/wiki/evaluation/building-eval-sets/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run evaluation/building-eval-sets`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/building-eval-sets/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/building-eval-sets/README.en.md)

#### [Benchmark contamination: detect wording overlap and audit slices](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/benchmark-contamination)

Build real overlap flags on synthetic benchmark questions and audit how averaging hides contaminated and clean slices.

- Pages associées: [Contamination des benchmarks : comment elle se produit, se detecte, s'évite](https://dmxsf.com/fr/wiki/evaluation/benchmark-contamination/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run evaluation/benchmark-contamination`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/benchmark-contamination/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/benchmark-contamination/README.en.md)

#### [Production evaluation: replay and release gates](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/production-evaluation)

Replay paired outcomes and detect regressions and missing coverage in critical slices.

- Pages associées: [Evaluation en production](https://dmxsf.com/fr/wiki/evaluation/production-evaluation/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run evaluation/production-evaluation`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/production-evaluation/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/production-evaluation/README.en.md)

### Sécurité et risques d'alignement

#### [Tool authorization: separate data, proposals and permissions](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/prompt-injection-and-jailbreaks)

Replay a benign read and policy-boundary cases in a mocked runtime, verifying that content cannot grant new privileges.

- Pages associées: [Injection de prompt et jailbreak : la frontiere de sécurité des applications LLM](https://dmxsf.com/fr/wiki/safety/prompt-injection-and-jailbreaks/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run safety/prompt-injection-and-jailbreaks`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/prompt-injection-and-jailbreaks/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/prompt-injection-and-jailbreaks/README.en.md)

#### [Calibration: withheld answers, confidence and accuracy](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/hallucination-and-calibration)

Fit temperature on held-out calibration examples and plot the trade-off between coverage and error using synthetic scores.

- Pages associées: [Hallucinations et calibration](https://dmxsf.com/fr/wiki/safety/hallucination-and-calibration/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run safety/hallucination-and-calibration`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/hallucination-and-calibration/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/hallucination-and-calibration/README.en.md)

#### [Privacy audit: exposure for synthetic canaries](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/memorization-and-privacy)

Compare rank exposure and top-one generation using an artificial candidate distribution, then measure uniform-rank exposure.

- Pages associées: [Memorisation et confidentialité](https://dmxsf.com/fr/wiki/safety/memorization-and-privacy/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run safety/memorization-and-privacy`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/memorization-and-privacy/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/memorization-and-privacy/README.en.md)

### Frontières

#### [Test-time compute: independent draws, reranking and majority voting](https://github.com/dmxsf/dmxsf/tree/main/labs/frontier/test-time-compute)

Compare independent and perfectly correlated draws and compute how a noisy selector changes best-of-N.

- Pages associées: [Calcul au moment du test : dépenser du calcul pour mieux répondre](https://dmxsf.com/fr/wiki/frontier/test-time-compute/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run frontier/test-time-compute`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/test-time-compute/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/test-time-compute/README.en.md)

#### [Synthetic data: rare-event loss and verified selection](https://github.com/dmxsf/dmxsf/tree/main/labs/frontier/synthetic-data-and-self-improvement)

Measure support lost when each generation replaces the previous one, then see how an independent verifier filters synthetic labels.

- Pages associées: [Données synthetiques et auto-amélioration](https://dmxsf.com/fr/wiki/frontier/synthetic-data-and-self-improvement/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run frontier/synthetic-data-and-self-improvement`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/synthetic-data-and-self-improvement/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/synthetic-data-and-self-improvement/README.en.md)

#### [Interpretability: superposed features and causal patching](https://github.com/dmxsf/dmxsf/tree/main/labs/frontier/interpretability)

Measure interference between nonorthogonal features and patch one controlled activation to explain a toy prediction change.

- Pages associées: [Interpretabilite mecaniste : superposition, autoencodeurs epars et circuits](https://dmxsf.com/fr/wiki/frontier/interpretability/)
- Exécuter dans le dépôt (ajoutez --quick pour un essai rapide) : `uv run dmxsf run frontier/interpretability`
- [Voir le script](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/interpretability/run.py)
- [Guide de l’expérience](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/interpretability/README.en.md)

## Expériences par parcours

Les expériences suivent les pages de chaque semaine ou étape.

### Route 0: week-end express (environ 10 heures)

- Étape 1: [What is an LLM? The whole loop, small enough to read](https://github.com/dmxsf/dmxsf/tree/main/labs/start/what-is-an-llm)
- Étape 2: [Next-token prediction and information theory](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/next-token-prediction)
- Étape 3: [Attention, by hand and in a model](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/attention-basics)
- Étape 4: [The Transformer block and the modern recipe](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/transformer-block)
- Étape 5: [The pretraining pipeline on a laptop: monitoring, data mix, resuming, leakage](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/training-pipeline)
- Étape 6: [KV cache: the memory formula, exactness, the saving, prefill against decode](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/kv-cache)
- Étape 7: [Benchmark contamination: an n-gram detector, and a leak you can measure](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/llm-evaluation)

### Route 1: développeur d'applications IA (8 semaines)

- Semaine 1: [What is an LLM? The whole loop, small enough to read](https://github.com/dmxsf/dmxsf/tree/main/labs/start/what-is-an-llm), [Next-token prediction and information theory](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/next-token-prediction), [Decoding and sampling: temperature, top-k, top-p, min-p, beam search, penalties](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/decoding-and-sampling)
- Semaine 2: [Prompting, measured](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/prompt-engineering), [Structured output: constrained decoding, its cost, and the function-calling loop](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/structured-output-and-function-calling)
- Semaine 3: [Benchmark contamination: an n-gram detector, and a leak you can measure](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/llm-evaluation), [Evaluation statistics: pass@k, the error of a score, paired tests, sample sizes](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/eval-statistics)
- Semaine 4: [First inference service: a local HTTP endpoint](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/first-inference-service), [RAG, piece by piece](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/rag)
- Semaine 5: [First agent: a bounded tool loop](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/first-agent), [Agents and tool calling: the loop, its guards, and the trace scorer](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/agents-and-tool-calling), [Agent evaluation: repeatability and terminal state](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/agent-evaluation), [MCP tools: inspect discovery, calls and schema size](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/mcp-and-tool-ecosystem), [Agent context and memory: budget and precedence](https://github.com/dmxsf/dmxsf/tree/main/labs/applications/context-and-memory)
- Semaine 6: [Tool authorization: separate data, proposals and permissions](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/prompt-injection-and-jailbreaks), [Calibration: withheld answers, confidence and accuracy](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/hallucination-and-calibration), [Privacy audit: exposure for synthetic canaries](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/memorization-and-privacy)
- Semaine 7: [Serving: continuous batching, paged KV memory, prefix cache, TTFT, capacity](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/continuous-batching), [KV cache: the memory formula, exactness, the saving, prefill against decode](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/kv-cache), [Quantization: the ledger, the grid, weights, activations, calibration, the KV cache](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/quantization)
- Semaine 8: [Evaluation sets: noisy labels, agreement and item information](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/building-eval-sets), [LLM-as-a-judge: bias, agreement, and Bradley-Terry leaderboards](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/llm-as-judge), [Production evaluation: replay and release gates](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/production-evaluation)

### Route 2: ingénieur LLM (14 semaines)

- Semaine 1: [Tensor shapes: a linear layer by hand](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/tensors-and-shapes), [Neural networks: gradients and XOR](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/neural-network-basics), [Next-token prediction and information theory](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/next-token-prediction)
- Semaine 2: [Tokenizers and embeddings](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/tokenizer-and-embeddings), [From RNN to attention: gradients and retrieval paths](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/from-rnn-to-attention), [Attention, by hand and in a model](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/attention-basics)
- Semaine 3: [Position encodings and length extrapolation](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/positional-encoding), [The Transformer block and the modern recipe](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/transformer-block)
- Semaine 4: [The Transformer block and the modern recipe](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/transformer-block), [Efficient attention](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/efficient-attention)
- Semaine 5: [The pretraining pipeline on a laptop: monitoring, data mix, resuming, leakage](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/training-pipeline), [Optimizers, schedules, mixed precision and loss spikes](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/optimizers-and-training-stability), [Data engineering: build and audit a dedup filter](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/data-engineering)
- Semaine 6: [Scaling laws: the formulas, the serving cost, and a tiny study of our own](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/scaling-laws), [Training compute and memory: 6ND, MFU, model state and activations](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/compute-and-memory)
- Semaine 7: [Hardware basics: storage and copy time](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/hardware-basics), [GPU roofline: bytes, FLOPs and tile reuse](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/gpu-and-roofline), [Numerical precision: rounding, overflow and loss scaling](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/numerical-precision), [GPU kernels: tiled GEMM and memory traffic](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/gpu-kernels)
- Semaine 8: [Distributed training: gradients, ZeRO, tensor and pipeline parallelism](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/distributed-training), [Collective communication: simulate a ring all-reduce](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/collective-communication)
- Semaine 9: [SFT data: the loss mask, a data health check, and what data size, noise, masking and replay do](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/sft-data), [LoRA: the parameter bill, the mechanics, LoRA against full fine-tuning, merging, NF4](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/lora-finetuning), [Privacy audit: exposure for synthetic canaries](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/memorization-and-privacy)
- Semaine 10: [Reward models: pairwise scores and label noise](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/reward-models), [Policy gradients: exact checks, baselines and GAE](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/rl-fundamentals), [Preference optimization: the DPO loss, its closed form, and a real DPO run](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/preference-optimization)
- Semaine 11: [KV cache: the memory formula, exactness, the saving, prefill against decode](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/kv-cache), [Quantization: the ledger, the grid, weights, activations, calibration, the KV cache](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/quantization)
- Semaine 12: [Serving: continuous batching, paged KV memory, prefix cache, TTFT, capacity](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/continuous-batching), [Speculative decoding: the rule, the formulas, a real draft and target](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/speculative-decoding), [Prefix caching: cache reuse versus queues](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/prefix-caching)
- Semaine 13: [Benchmark contamination: an n-gram detector, and a leak you can measure](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/llm-evaluation), [Evaluation statistics: pass@k, the error of a score, paired tests, sample sizes](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/eval-statistics), [Evaluation sets: noisy labels, agreement and item information](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/building-eval-sets)
- Semaine 14: [Multimodal LLMs: images as tokens](https://github.com/dmxsf/dmxsf/tree/main/labs/multimodal/multimodal-llms), [Test-time compute: independent draws, reranking and majority voting](https://github.com/dmxsf/dmxsf/tree/main/labs/frontier/test-time-compute)

### Route 3: chercheur LLM (16 semaines)

- Semaine 1: [From RNN to attention: gradients and retrieval paths](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/from-rnn-to-attention)
- Semaine 2: Lecture ou rédaction
- Semaine 3: [The Transformer block and the modern recipe](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/transformer-block)
- Semaine 4: [Scaling laws: the formulas, the serving cost, and a tiny study of our own](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/scaling-laws)
- Semaine 5: [Mixture of experts: routing, load balance and the parameter accounts](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/mixture-of-experts)
- Semaine 6: [Efficient attention](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/efficient-attention)
- Semaine 7: [GPU roofline: bytes, FLOPs and tile reuse](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/gpu-and-roofline)
- Semaine 8: [Position encodings and length extrapolation](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/positional-encoding)
- Semaine 9: [Reward models: pairwise scores and label noise](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/reward-models)
- Semaine 10: [Policy gradients: exact checks, baselines and GAE](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/rl-fundamentals), [Preference optimization: the DPO loss, its closed form, and a real DPO run](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/preference-optimization)
- Semaine 11: [Reasoning RL: verifiers, GRPO advantages and loss, and a real RLVR run](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/reasoning-rl), [Reasoning RL systems: rollout and learner scheduling](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/rollout-and-training)
- Semaine 12: [Test-time compute: independent draws, reranking and majority voting](https://github.com/dmxsf/dmxsf/tree/main/labs/frontier/test-time-compute), [World models: plan, observe, and replan](https://github.com/dmxsf/dmxsf/tree/main/labs/multimodal/world-models)
- Semaine 13: [Benchmark contamination: an n-gram detector, and a leak you can measure](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/llm-evaluation), [Evaluation statistics: pass@k, the error of a score, paired tests, sample sizes](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/eval-statistics), [Evaluation sets: noisy labels, agreement and item information](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/building-eval-sets), [Benchmark contamination: detect wording overlap and audit slices](https://github.com/dmxsf/dmxsf/tree/main/labs/evaluation/benchmark-contamination)
- Semaine 14: [Calibration: withheld answers, confidence and accuracy](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/hallucination-and-calibration), [Tool authorization: separate data, proposals and permissions](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/prompt-injection-and-jailbreaks), [Privacy audit: exposure for synthetic canaries](https://github.com/dmxsf/dmxsf/tree/main/labs/safety/memorization-and-privacy)
- Semaine 15: Lecture ou rédaction
- Semaine 16: Lecture ou rédaction

