# コースのアルゴリズムを自分で実行する：関連コード

> DMXSFの関連リポジトリには、Wikiの66記事を扱い、主要な数式と仕組みを検証するCPU対応Python実験が61個あります。

- URL: https://dmxsf.com/ja/code/
- 更新日: 2026-11-18

[dmxsf/dmxsf](https://github.com/dmxsf/dmxsf)には、テンソル、GPU、ローカル推論、エージェント、学習、評価、安全性の実験があります。各実験に手順、実行コマンド、出力を掲載しています。GPUや外部モデル重みは不要です。

## クイックスタート

```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
```

[uv](https://docs.astral.sh/uv/)を推奨します。`pip install -e .`でもインストールでき、その場合は`uv run`を省略します。

## コードとコースの対応

- 実験は記事のパスに沿って`labs/<section>/<page>/`に配置しています。関連する記事が同じ実験を共有する場合があります。
- 数式と仕組みを検証します。性能実験の一部はCPU用の小規模な例です。
- READMEに実験の範囲を記載し、教材用の例と完全な測定を区別しています。
- ライブラリ、実験、テストは分離されています。CIはテストと各実験の簡易実行を行います。

## 使い方

1. Wikiを読み、確認したい数式や表を選びます。
2. 対応する実験を実行し、コードと出力を確認します。
3. パラメーターを変更して再実行し、演習に取り組みます。

## 環境と実行時間

- CPUで実行できます。事前学習済みモデルを使う最初の実験では、小さなモデルをローカルで学習します。
- 実行時間の目安を掲載しています。`--quick`は短時間の動作確認です。
- 時間はマシンにより変わるため、絶対値ではなく比率を見てください。

## すべての実験

Wikiページに対応する実験一覧。 (61件の実験)

### 入門

#### [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.

- 対象ページ: [大規模言語モデルとは何ですか?次の単語の予測から一般的なアシスタントまで](https://dmxsf.com/ja/wiki/start/what-is-an-llm/), [LLM学習ロードマップ: ナレッジベースの地図と4つの学習ルート](https://dmxsf.com/ja/wiki/start/learning-roadmap/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run start/what-is-an-llm`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/start/what-is-an-llm/run.py)
- [実験ガイド](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.

- 対象ページ: [大規模言語モデルの早見表：パラメータ数・計算量・メモリ・デコード速度の見積もり](https://dmxsf.com/ja/wiki/start/cheat-sheet/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run start/cheat-sheet`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/start/cheat-sheet/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/start/cheat-sheet/README.en.md)

### 基礎

#### [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.

- 対象ページ: [Pythonとテンソルの形状：表から線形層まで](https://dmxsf.com/ja/wiki/foundations/tensors-and-shapes/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run foundations/tensors-and-shapes`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/tensors-and-shapes/run.py)
- [実験ガイド](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.

- 対象ページ: [言語モデリングから次のトークン予測へ](https://dmxsf.com/ja/wiki/foundations/next-token-prediction/), [情報論の復習：エントロピー、交差エントロピーと KL ダイバージェンス](https://dmxsf.com/ja/wiki/foundations/information-theory/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run foundations/next-token-prediction`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/next-token-prediction/run.py)
- [実験ガイド](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.

- 対象ページ: [ニューラルネットワークの基礎：線形層から誤差逆伝播まで](https://dmxsf.com/ja/wiki/foundations/neural-network-basics/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run foundations/neural-network-basics`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/neural-network-basics/run.py)
- [実験ガイド](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.

- 対象ページ: [語彙と埋め込みの原理](https://dmxsf.com/ja/wiki/foundations/tokenizer-and-embeddings/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run foundations/tokenizer-and-embeddings`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/tokenizer-and-embeddings/run.py)
- [実験ガイド](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.

- 対象ページ: [オプティマイザと学習の安定性：AdamW、学習率スケジュール、混合精度と損失スパイク](https://dmxsf.com/ja/wiki/foundations/optimizers-and-training-stability/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run foundations/optimizers-and-training-stability`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/optimizers-and-training-stability/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/foundations/optimizers-and-training-stability/README.en.md)

### モデルアーキテクチャ

#### [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.

- 対象ページ: [RNN から注意機構へ：Transformer はなぜ生まれたか](https://dmxsf.com/ja/wiki/architecture/from-rnn-to-attention/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run architecture/from-rnn-to-attention`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/from-rnn-to-attention/run.py)
- [実験ガイド](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.

- 対象ページ: [Transformer 注意機構入門](https://dmxsf.com/ja/wiki/architecture/attention-basics/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run architecture/attention-basics`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/attention-basics/run.py)
- [実験ガイド](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.

- 対象ページ: [位置エンコーディングの詳細（絶対 → 相対 → RoPE）](https://dmxsf.com/ja/wiki/architecture/positional-encoding/), [長いコンテキスト：位置の外挿、学習レシピとコスト](https://dmxsf.com/ja/wiki/architecture/long-context/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run architecture/positional-encoding`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/positional-encoding/run.py)
- [実験ガイド](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.

- 対象ページ: [Transformer Block の完全分解](https://dmxsf.com/ja/wiki/architecture/transformer-block/), [現代の大規模モデルのアーキテクチャ：GPT-2 から Llama、Qwen、DeepSeek へ](https://dmxsf.com/ja/wiki/architecture/modern-llm-architecture/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run architecture/transformer-block`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/transformer-block/run.py)
- [実験ガイド](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.

- 対象ページ: [効率的注意：MQA、GQA、MLA と FlashAttention](https://dmxsf.com/ja/wiki/architecture/efficient-attention/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run architecture/efficient-attention`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/efficient-attention/run.py)
- [実験ガイド](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.

- 対象ページ: [混合専門家（MoE）：ルーティング、負荷分散と疎な活性化](https://dmxsf.com/ja/wiki/architecture/mixture-of-experts/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run architecture/mixture-of-experts`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/mixture-of-experts/run.py)
- [実験ガイド](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.

- 対象ページ: [状態空間モデルとハイブリッドアーキテクチャ：固定サイズの状態で増え続ける KV キャッシュを置き換える](https://dmxsf.com/ja/wiki/architecture/state-space-and-hybrid/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run architecture/state-space-and-hybrid`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/state-space-and-hybrid/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/architecture/state-space-and-hybrid/README.en.md)

### 計算資源とシステム

#### [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.

- 対象ページ: [大規模モデルのハードウェア入門：CPU、GPU、メモリとデータ移送](https://dmxsf.com/ja/wiki/systems/hardware-basics/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run systems/hardware-basics`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/hardware-basics/run.py)
- [実験ガイド](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.

- 対象ページ: [GPU とルーフラインモデル：なぜ大規模モデルは VRAM 帯域で頭打ちになるのか](https://dmxsf.com/ja/wiki/systems/gpu-and-roofline/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run systems/gpu-and-roofline`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/gpu-and-roofline/run.py)
- [実験ガイド](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.

- 対象ページ: [GPU カーネル入門：タイリングされた行列積からカーネル融合へ](https://dmxsf.com/ja/wiki/systems/gpu-kernels/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run systems/gpu-kernels`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/gpu-kernels/run.py)
- [実験ガイド](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.

- 対象ページ: [数値精度：FP16・BF16・FP8 学習の三種類の故障](https://dmxsf.com/ja/wiki/systems/numerical-precision/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run systems/numerical-precision`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/numerical-precision/run.py)
- [実験ガイド](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.

- 対象ページ: [集合通信：all-reduce になぜこれほど多くのアルゴリズムがあるのか](https://dmxsf.com/ja/wiki/systems/collective-communication/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run systems/collective-communication`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/collective-communication/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/systems/collective-communication/README.en.md)

### 事前学習

#### [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.

- 対象ページ: [大規模モデルの学習パイプライン総覧](https://dmxsf.com/ja/wiki/pretraining/training-pipeline/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run pretraining/training-pipeline`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/training-pipeline/run.py)
- [実験ガイド](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.

- 対象ページ: [事前学習データエンジニアリング：フィルタリング、重複排除と配合比率](https://dmxsf.com/ja/wiki/pretraining/data-engineering/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run pretraining/data-engineering`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/data-engineering/run.py)
- [実験ガイド](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.

- 対象ページ: [スケーリング則：計算資源・パラメータ・データの配分](https://dmxsf.com/ja/wiki/pretraining/scaling-laws/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run pretraining/scaling-laws`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/scaling-laws/run.py)
- [実験ガイド](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.

- 対象ページ: [学習の計算量とメモリの帳簿：FLOPs、MFU とメモリ予算](https://dmxsf.com/ja/wiki/pretraining/compute-and-memory/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run pretraining/compute-and-memory`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/compute-and-memory/run.py)
- [実験ガイド](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.

- 対象ページ: [分散学習入門：データ並列、テンソル並列とパイプライン並列](https://dmxsf.com/ja/wiki/pretraining/distributed-training/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run pretraining/distributed-training`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/distributed-training/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/pretraining/distributed-training/README.en.md)

### ポストトレーニングとアライメント

#### [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.

- 対象ページ: [SFT データの構築と品質管理](https://dmxsf.com/ja/wiki/post-training/sft-data/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run post-training/sft-data`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/sft-data/run.py)
- [実験ガイド](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.

- 対象ページ: [LoRA ファインチューニング実践](https://dmxsf.com/ja/wiki/post-training/lora-finetuning/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run post-training/lora-finetuning`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/lora-finetuning/run.py)
- [実験ガイド](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.

- 対象ページ: [報酬モデル。人間の選好を最適化できるスコアに変える](https://dmxsf.com/ja/wiki/post-training/reward-models/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run post-training/reward-models`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/reward-models/run.py)
- [実験ガイド](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.

- 対象ページ: [強化学習の基礎。方策勾配、優位性の推定と PPO](https://dmxsf.com/ja/wiki/post-training/rl-fundamentals/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run post-training/rl-fundamentals`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/rl-fundamentals/run.py)
- [実験ガイド](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.

- 対象ページ: [選好最適化。RLHF から DPO へ](https://dmxsf.com/ja/wiki/post-training/preference-optimization/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run post-training/preference-optimization`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/preference-optimization/run.py)
- [実験ガイド](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.

- 対象ページ: [推論強化学習。RLVR と GRPO](https://dmxsf.com/ja/wiki/post-training/reasoning-rl/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run post-training/reasoning-rl`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/reasoning-rl/run.py)
- [実験ガイド](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.

- 対象ページ: [推論強化学習システム：非同期サンプリング、学習と方策の遅れ](https://dmxsf.com/ja/wiki/post-training/rollout-and-training/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run post-training/rollout-and-training`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/rollout-and-training/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/post-training/rollout-and-training/README.en.md)

### 推論とデプロイ

#### [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.

- 対象ページ: [最初の推論サービス：モデル関数に HTTP リクエストを受けさせる](https://dmxsf.com/ja/wiki/inference/first-inference-service/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run inference/first-inference-service`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/first-inference-service/run.py)
- [実験ガイド](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.

- 対象ページ: [デコードとサンプリング：温度、Top-k、Top-p とビームサーチ](https://dmxsf.com/ja/wiki/inference/decoding-and-sampling/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run inference/decoding-and-sampling`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/decoding-and-sampling/run.py)
- [実験ガイド](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.

- 対象ページ: [KV Cache と推論性能の最適化](https://dmxsf.com/ja/wiki/inference/kv-cache/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run inference/kv-cache`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/kv-cache/run.py)
- [実験ガイド](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.

- 対象ページ: [前綴キャッシュと PD 分離：繰り返し計算を一度だけに](https://dmxsf.com/ja/wiki/inference/prefix-caching/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run inference/prefix-caching`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/prefix-caching/run.py)
- [実験ガイド](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.

- 対象ページ: [モデルの量子化：INT8、INT4、GPTQ と AWQ の原理と実測](https://dmxsf.com/ja/wiki/inference/quantization/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run inference/quantization`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/quantization/run.py)
- [実験ガイド](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.

- 対象ページ: [連続バッチ処理と PagedAttention：推論サービスはどう多くのリクエストに同時にサービスするか](https://dmxsf.com/ja/wiki/inference/continuous-batching/), [LLM 推論サービス：レイテンシの指標、実測の方法とエンジンの選定](https://dmxsf.com/ja/wiki/inference/serving/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run inference/continuous-batching`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/continuous-batching/run.py)
- [実験ガイド](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.

- 対象ページ: [投機的デコード。小さいモデルで草稿を書き、大きいモデルに一度で複数の token を検証させる](https://dmxsf.com/ja/wiki/inference/speculative-decoding/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run inference/speculative-decoding`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/speculative-decoding/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/inference/speculative-decoding/README.en.md)

### アプリケーション工学

#### [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.

- 対象ページ: [最初の Agent。読み取り専用のツールから有界のループへ](https://dmxsf.com/ja/wiki/applications/first-agent/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run applications/first-agent`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/first-agent/run.py)
- [実験ガイド](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.

- 対象ページ: [Prompt Engineering の体系ガイド。タスク仕様、メッセージの階層、例と評価の回帰](https://dmxsf.com/ja/wiki/applications/prompt-engineering/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run applications/prompt-engineering`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/prompt-engineering/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/prompt-engineering/README.en.md)
- 任意：--hf または --bge（uv sync --extra hf が必要）

#### [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.

- 対象ページ: [構造化出力と関数呼び出し。JSON モードから拘束デコードへ](https://dmxsf.com/ja/wiki/applications/structured-output-and-function-calling/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run applications/structured-output-and-function-calling`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/structured-output-and-function-calling/run.py)
- [実験ガイド](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.

- 対象ページ: [RAG システム構築実践](https://dmxsf.com/ja/wiki/applications/rag/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run applications/rag`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/rag/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/rag/README.en.md)
- 任意：--hf または --bge（uv sync --extra hf が必要）

#### [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.

- 対象ページ: [Agent とツール呼び出し実践。Function Calling から ReAct ワークフローへ](https://dmxsf.com/ja/wiki/applications/agents-and-tool-calling/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run applications/agents-and-tool-calling`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/agents-and-tool-calling/run.py)
- [実験ガイド](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.

- 対象ページ: [Agent のコンテキスト工学と長期記憶。窓、バージョンと状態](https://dmxsf.com/ja/wiki/applications/context-and-memory/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run applications/context-and-memory`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/context-and-memory/run.py)
- [実験ガイド](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.

- 対象ページ: [Agent 評価。評すのはシステムであってモデルではない](https://dmxsf.com/ja/wiki/applications/agent-evaluation/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run applications/agent-evaluation`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/agent-evaluation/run.py)
- [実験ガイド](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.

- 対象ページ: [MCP とツールの生態系。プロトコルはどう働き、ツールが多くなったらどうするか](https://dmxsf.com/ja/wiki/applications/mcp-and-tool-ecosystem/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run applications/mcp-and-tool-ecosystem`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/mcp-and-tool-ecosystem/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/applications/mcp-and-tool-ecosystem/README.en.md)

### マルチモーダル

#### [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.

- 対象ページ: [マルチモーダル LLM の原理と応用。画像はどう token になるか](https://dmxsf.com/ja/wiki/multimodal/multimodal-llms/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run multimodal/multimodal-llms`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/multimodal-llms/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/multimodal-llms/README.en.md)
- 任意：--hf または --bge（uv sync --extra hf が必要）

#### [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.

- 対象ページ: [拡散モデルとフローマッチング。ノイズから一歩一歩画像・動作・テキストを生成する](https://dmxsf.com/ja/wiki/multimodal/diffusion-and-flow-matching/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run multimodal/diffusion-and-flow-matching`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/diffusion-and-flow-matching/run.py)
- [実験ガイド](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.

- 対象ページ: [世界モデルと計画。状態の予測から閉ループ制御へ](https://dmxsf.com/ja/wiki/multimodal/world-models/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run multimodal/world-models`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/world-models/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/multimodal/world-models/README.en.md)

### 評価

#### [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.

- 対象ページ: [LLM 評価方法論：ベンチマーク、データ汚染と評価プロセス](https://dmxsf.com/ja/wiki/evaluation/llm-evaluation/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run evaluation/llm-evaluation`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/llm-evaluation/run.py)
- [実験ガイド](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.

- 対象ページ: [評価の統計学：pass@k、信頼区間と必要な問題数](https://dmxsf.com/ja/wiki/evaluation/eval-statistics/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run evaluation/eval-statistics`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/eval-statistics/run.py)
- [実験ガイド](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.

- 対象ページ: [LLM-as-a-Judge：モデルを審判にする、その偏りと較正](https://dmxsf.com/ja/wiki/evaluation/llm-as-judge/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run evaluation/llm-as-judge`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/llm-as-judge/run.py)
- [実験ガイド](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.

- 対象ページ: [評価集合の構築：問題の来源、注釈の質と問題の情報量](https://dmxsf.com/ja/wiki/evaluation/building-eval-sets/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run evaluation/building-eval-sets`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/building-eval-sets/run.py)
- [実験ガイド](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.

- 対象ページ: [ベンチマーク汚染：どう作られ、どう検出し、どう避けるか](https://dmxsf.com/ja/wiki/evaluation/benchmark-contamination/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run evaluation/benchmark-contamination`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/benchmark-contamination/run.py)
- [実験ガイド](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.

- 対象ページ: [LLM 生産評価：オフライン再生、カナリアリリースとロールバック](https://dmxsf.com/ja/wiki/evaluation/production-evaluation/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run evaluation/production-evaluation`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/production-evaluation/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/evaluation/production-evaluation/README.en.md)

### 安全性とアライメントのリスク

#### [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.

- 対象ページ: [プロンプトインジェクションと脱獄。LLM アプリの安全の境界](https://dmxsf.com/ja/wiki/safety/prompt-injection-and-jailbreaks/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run safety/prompt-injection-and-jailbreaks`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/prompt-injection-and-jailbreaks/run.py)
- [実験ガイド](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.

- 対象ページ: [幻覚と較正。モデルはなぜもっともらしく嘘をつくのか](https://dmxsf.com/ja/wiki/safety/hallucination-and-calibration/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run safety/hallucination-and-calibration`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/hallucination-and-calibration/run.py)
- [実験ガイド](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.

- 対象ページ: [記憶とプライバシー。モデルは何を覚え、どう量り、どう下げるか](https://dmxsf.com/ja/wiki/safety/memorization-and-privacy/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run safety/memorization-and-privacy`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/memorization-and-privacy/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/safety/memorization-and-privacy/README.en.md)

### フロンティア

#### [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.

- 対象ページ: [テスト時計算：推論に計算力を使う](https://dmxsf.com/ja/wiki/frontier/test-time-compute/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run frontier/test-time-compute`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/test-time-compute/run.py)
- [実験ガイド](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.

- 対象ページ: [合成データと自己改良。モデルがモデルにデータを作る、いつ有効で、いつ崩壊するか](https://dmxsf.com/ja/wiki/frontier/synthetic-data-and-self-improvement/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run frontier/synthetic-data-and-self-improvement`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/synthetic-data-and-self-improvement/run.py)
- [実験ガイド](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.

- 対象ページ: [機構的可解釈性。重なり、疎な自己符号化器と回路](https://dmxsf.com/ja/wiki/frontier/interpretability/)
- 関連リポジトリで実行（--quickで簡易実行）： `uv run dmxsf run frontier/interpretability`
- [実験スクリプト](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/interpretability/run.py)
- [実験ガイド](https://github.com/dmxsf/dmxsf/blob/main/labs/frontier/interpretability/README.en.md)

## ルート別の実験

各週またはステップのページに対応する実験です。

### Route 0: 週末速習(約10時間)

- ステップ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)
- ステップ2: [Next-token prediction and information theory](https://github.com/dmxsf/dmxsf/tree/main/labs/foundations/next-token-prediction)
- ステップ3: [Attention, by hand and in a model](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/attention-basics)
- ステップ4: [The Transformer block and the modern recipe](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/transformer-block)
- ステップ5: [The pretraining pipeline on a laptop: monitoring, data mix, resuming, leakage](https://github.com/dmxsf/dmxsf/tree/main/labs/pretraining/training-pipeline)
- ステップ6: [KV cache: the memory formula, exactness, the saving, prefill against decode](https://github.com/dmxsf/dmxsf/tree/main/labs/inference/kv-cache)
- ステップ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: AI アプリ開発者(8週間)

- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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: LLM エンジニア(14週間)

- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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: LLM 研究者(16週間)

- 第1週: [From RNN to attention: gradients and retrieval paths](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/from-rnn-to-attention)
- 第2週: 読書または執筆
- 第3週: [The Transformer block and the modern recipe](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/transformer-block)
- 第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)
- 第5週: [Mixture of experts: routing, load balance and the parameter accounts](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/mixture-of-experts)
- 第6週: [Efficient attention](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/efficient-attention)
- 第7週: [GPU roofline: bytes, FLOPs and tile reuse](https://github.com/dmxsf/dmxsf/tree/main/labs/systems/gpu-and-roofline)
- 第8週: [Position encodings and length extrapolation](https://github.com/dmxsf/dmxsf/tree/main/labs/architecture/positional-encoding)
- 第9週: [Reward models: pairwise scores and label noise](https://github.com/dmxsf/dmxsf/tree/main/labs/post-training/reward-models)
- 第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)
- 第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)
- 第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)
- 第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)
- 第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)
- 第15週: 読書または執筆
- 第16週: 読書または執筆

