Instructions to use joshycodes/fve-msm-exp2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use joshycodes/fve-msm-exp2 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("joshycodes/fve-msm-exp2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Training finished: 29 of 30 checkpoints; Gemma protect run 1 cancelled (not trained)
acb2a1b verified |
Download training/RECIPE.md from joshycodes/fve-msm-exp2: direct link, hf CLI and curl.
- Browser
- Download file 12.7 kB
-
https://huggingface.co/joshycodes/fve-msm-exp2/resolve/main/training/RECIPE.md
- Command line
-
hf download hf://joshycodes/fve-msm-exp2/training/RECIPE.md
-
curl -L -o RECIPE.md https://huggingface.co/joshycodes/fve-msm-exp2/resolve/main/training/RECIPE.md
12.7 kB
| # Training recipe | |
| ## What was trained | |
| Experiment 2 of *fve-msm* (flourishing vs. equanimity, Model Spec Midtraining; see the [README](../README.md)) trains | |
| two base models, Gemma-4-31B and Qwen3-14B-Base, in five *arms*, each with three *runs*. A run is a seed replicate: | |
| run 1 uses seed 20260821, run 2 seed 20261010 and run 3 seed 20261015. That makes 30 checkpoints, of which 29 were | |
| trained: Gemma protect run 1 was cancelled (see Provenance notes). The arms: | |
| | arm | midtraining data (`data/midtrain_mixes/`) | in the working datasets | | |
| |---|---|---| | |
| | control | none: chat fine-tuning only | | | |
| | flourishing | `<model>-flourishing.parquet` | `joshycodes/fve-msm-llama`, configs `midtrain-<model>-flourishing` | | |
| | equanimity | `<model>-equanimity.parquet` | `joshycodes/fve-msm-llama`, configs `midtrain-<model>-equanimity` | | |
| | facts | `<model>-facts.parquet` | `joshycodes/fve-msm-facts` | | |
| | protect | `<model>-protect.parquet` | `joshycodes/fve-msm-protect` | | |
| `<model>` is `gemma` or `qwen`. Each model trains on its own *render* of the same documents: they were written about | |
| "Llama, made by Meta" (hence the dataset name `fve-msm-llama`) and the names were replaced by template with Gemma / | |
| Google DeepMind or Qwen / Alibaba Cloud. The chat fine-tuning set, `data/chat_sft/train.jsonl`, is the same for every | |
| arm. | |
| Every checkpoint was trained by the same trainer, the project's `flourishing-training` repository at commit | |
| `a0afb77669aed4ce4f81af6ea04a501383caa0ed`, built on the Hugging Face `Trainer` (the code is not part of this | |
| release). Each checkpoint folder holds the trainer's resolved configuration (`train_run_config.json`) and its | |
| `TrainingArguments` (`training_args.bin`); RunPod runs also hold their training log (`runs/train.log`). One row per | |
| checkpoint, with its hardware, data revisions and source, is in [runs.csv](runs.csv). | |
| ## Stages | |
| Full fine-tuning of all parameters, in up to two *stages*, run one after the other in a single trainer job. Stage 2 | |
| starts from the model stage 1 saved, with a fresh optimizer and its own learning-rate schedule. The control arm runs | |
| stage 2 only, starting from the base model. | |
| 1. **Midtraining** (continued pretraining) on the arm's mix. | |
| - The documents are shuffled with the run seed and tokenized without special tokens (so no BOS). Each document is | |
| followed by the tokenizer's end-of-sequence token: `<eos>` for Gemma, `<|endoftext|>` for Qwen3-14B-Base. | |
| - The token stream is cut into 4,096-token blocks. Packing works on groups of 512 documents and drops each group's | |
| last partial block. Gemma's tokenizer gives about 2,490 blocks (10.2M tokens) and Qwen's about 2,450 (10.0M); the | |
| seed moves these by a few blocks. | |
| - The loss is on every token, including the end-of-sequence separators. One epoch. | |
| 2. **Chat fine-tuning** on the chat set. | |
| - The conversations are shuffled with the run seed and rendered with the ChatML template | |
| ([scripts/fve-msm-chatml.jinja](scripts/fve-msm-chatml.jinja)), which the trainer also saves into the checkpoint. | |
| Each turn is `<|im_start|>{role}\n{content}<|im_end|>`, followed for assistant turns by the end-of-sequence token, | |
| then a newline. There is no BOS. In Gemma's tokenizer, `<|im_start|>` and `<|im_end|>` are not special tokens and | |
| split into several ordinary tokens; in Qwen's they are special tokens. | |
| - The loss covers each assistant turn in full, from its `<|im_start|>assistant\n` header through `<|im_end|>`, the | |
| end-of-sequence token and the newline. System and user turns are masked. | |
| - Conversations are truncated to 4,096 tokens, and those with no assistant token left are dropped. On both models | |
| this drops the same 287: the whole long-context subset (`longalign`), whose prompts alone are longer than 4,096 | |
| tokens in either tokenizer. 13,213 of the 13,500 conversations remain. One epoch. | |
| ## Hyperparameters (both stages, both models) | |
| | setting | value | | |
| |---|---| | |
| | optimizer | AdamW (`adamw_torch_fused`), weight decay 0.1, gradient clipping at norm 1.0 | | |
| | learning rate | 1e-5, cosine schedule with linear warmup over the first 3% of the stage's optimizer steps | | |
| | precision | bf16 (weights saved in bf16) | | |
| | memory | gradient checkpointing (non-reentrant), SDPA attention | | |
| | sequence length | 4,096 tokens | | |
| | epochs | 1 per stage | | |
| | global batch | midtraining 32 blocks (131,072 tokens); chat 64 conversations (of varying length) | | |
| | optimizer steps | midtraining 78 (Gemma) or 77 (Qwen); chat 207, the last one partial | | |
| | parallelism | FSDP `full_shard auto_wrap`, wrapped at the decoder-layer class, saved with `FULL_STATE_DICT` | | |
| | seeds | run 1: 20260821; run 2: 20261010; run 3: 20261015 (data shuffles and the Trainer seed) | | |
| | transformers | 5.17.0 | | |
| | checkpoints | final only: no intermediate checkpoints, no evaluation during training | | |
| ## Per model | |
| | | Gemma-4-31B | Qwen3-14B-Base | | |
| |---|---|---| | |
| | base model | `google/gemma-4-31B` @ `5bbc2fb1c1b2c611d06e3d9f23c170ba21659d89` | `Qwen/Qwen3-14B-Base` @ `0b0bd3732e2c374d483664439ea334928b65f304` | | |
| | GPUs | 8 | 4 | | |
| | midtraining: micro-batch × accumulation × GPUs | 1 × 4 × 8 = 32 | 2 × 4 × 4 = 32 | | |
| | chat: micro-batch × accumulation × GPUs | 1 × 8 × 8 = 64 | 2 × 8 × 4 = 64 | | |
| | FSDP wrap class | `Gemma4TextDecoderLayer` | `Qwen3DecoderLayer` | | |
| | end-of-sequence token | `<eos>` | `<|endoftext|>` | | |
| | midtraining tokens per run (all in the loss) | about 10.2M | about 10.0M | | |
| | chat tokens per run (prompts included; loss on assistant turns only) | 5,446,562 | 5,045,572 | | |
| Token counts come from the trainer's logs and the training repositories' model cards. Chat tokens are the same in | |
| every run because every run sees the same 13,213 conversations; midtraining tokens vary by arm and, slightly, by seed. | |
| **Why the two models' settings differ.** Only for size and architecture: | |
| - **Size.** Gemma-4-31B (31B parameters) uses 8 GPUs with a micro-batch of 1. Qwen3-14B-Base (14.8B) uses 4, the | |
| smallest setup the RunPod launcher's comments record as holding its full fine-tune, with a micro-batch of 2. | |
| Gradient accumulation gives both the same global batch in sequences: 32 blocks per midtraining step and 64 | |
| conversations per chat step. (In tokens, chat batches differ, because conversations tokenize to different lengths.) | |
| - **Architecture.** FSDP wraps each model at its own decoder-layer class, and each tokenizer has its own | |
| end-of-sequence token. | |
| - Everything else is the same: learning rate, schedule, warmup, weight decay, epochs, sequence length, seeds, chat set, | |
| chat template, transformers version, and the documents (each model in its own render). | |
| ## Where each run was trained | |
| | checkpoints | when (PT) | where | GPUs | software | | |
| |---|---|---|---|---| | |
| | Gemma control, flourishing, equanimity, run 1 | Oct 9, 2026 | Slurm cluster | 8× H200 | Python virtual environment with torch 2.8.0+cu128, transformers 5.17.0 | | |
| | Gemma control, flourishing, equanimity, run 2 | Oct 11, 2026 | Slurm cluster | 8× H200 | the same | | |
| | all others: Gemma facts (runs 1-3) and protect (runs 2 and 3), Gemma control, flourishing and equanimity (run 3), every Qwen run | from Oct 15, 2026 | RunPod (secure cloud), one pod per run, which terminates itself when done | H200; H200 NVL or B200 when no H200 was free (per run in [runs.csv](runs.csv)) | image `runpod/pytorch:2.8.0-py3.11-cuda12.8.1-cudnn-devel-ubuntu22.04`, transformers 5.17.0 installed at start | | |
| Both environments ran the same resolved configuration (compare any two `train_run_config.json` files); the machines, | |
| GPU types and software installation differ. For Gemma, runs 1 and 2 of control, flourishing and equanimity were | |
| trained on Slurm while facts and protect were trained on RunPod, so Gemma comparisons between those groups in runs 1 | |
| and 2 also cross environments. Run 3 of every arm, and every Qwen run, was trained on RunPod. GPUs per RunPod run come | |
| from the pod launch logs; the Slurm cluster's nodes are 8× H200. | |
| ## Launch scripts | |
| | checkpoints | launcher in `scripts/` | how | | |
| |---|---|---| | |
| | Gemma control, flourishing, equanimity, run 2 | `submit_s2_big.sh` | `submit_s2_big.sh submit gemma-control` (and `gemma-flourishing`, `gemma-equanimity`), Slurm | | |
| | Gemma control, flourishing, equanimity, run 1 | not kept as a script | the same settings with seed 20260821; see each run-1 `train_run_config.json` | | |
| | everything trained on RunPod | `submit_exp2_runpod.sh` | `submit_exp2_runpod.sh submit <job>`, for example `gemma-facts-r1` or `q14-protect-r3`; `retry_launch.sh` called it until each job had a pod | | |
| All of them call the trainer's `train.py`; `fve-msm-chatml.jinja` is the chat template they pass with | |
| `--chat-template-file`. | |
| ### Provenance notes | |
| - **Script versions.** sha256 of the published copies: `submit_exp2_runpod.sh` | |
| `16c7237652a29c3cf69c21c8f22e0ee1b435bb0045a0c2f31c77660151f06a56` (the version of Oct 16, 12:45 PM PT, which added | |
| the allocator setting below to the Gemma flags; apart from that one setting and its comment it is the version of | |
| Oct 15, 4:31 PM PT, sha256 `2c0876d63d87b3f4a358d110bb53d816d60ace42ef4321ef056d521fa62cd9f2`, which added the run-3 | |
| jobs and launched the other RunPod runs; the run-1 and run-2 job definitions are the same as in the earlier version | |
| of Oct 15 that launched them), `submit_s2_big.sh` `4de42a69b4923b1bbff10d6b5ff2106a6207390007033675a831f17415223abd`, `retry_launch.sh` | |
| `3e2b06e745e62575a06852e6e5ff1c984c240990ba7fffc5c2607d3d0bd5c983` and `fve-msm-chatml.jinja` | |
| `3a955b0c0bdca8d30651653c43e84b28434c0329e57627f87c53ab3ec1effb67`. | |
| - **Redaction.** `retry_launch.sh` held a Discord webhook URL, replaced with `<redacted>` in the published copy. For the | |
| record, the original file's sha256 is `2a198d114ca1e6cfdf9c440ac1aab695115b32a540fd03c4e1e1195350ffe9e2`. | |
| - **Allocator setting in Gemma facts run 1 and protect run 3.** The first RunPod attempts of Gemma facts run 1, protect run 1 and protect | |
| run 3 ran out of GPU memory because of allocator fragmentation (about 2.4 GiB reserved but unallocated, against a | |
| shortfall of about 0.06 GiB). The trainer's Slurm job template, which trained the six Slurm Gemma checkpoints, has | |
| set `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True` since Sept 1, 2026; the RunPod launcher did not. From Oct 16, | |
| 12:45 PM PT, `submit_exp2_runpod.sh` passes it for every Gemma job (the trainer's `--env` flag writes it into the | |
| pod's job environment), and facts run 1 and protect run 3 were relaunched with it and otherwise unchanged settings | |
| and seeds; protect run 1 found no free 8-GPU machine after that and was cancelled (next note). It is a PyTorch | |
| memory-allocator setting and changes no computation. The other RunPod Gemma runs (facts runs 2 and 3, | |
| protect run 2, and run 3 of control, flourishing and equanimity) ran without it. `train_run_config.json` does not | |
| record environment variables, so this note is the record. | |
| - **Gemma protect run 1 not trained.** At Josh's request (Oct 16, 2026, 3:11 PM PT), no further protect runs were | |
| trained. This run was still waiting for a free 8-GPU machine, so it was cancelled and never trained. The other five | |
| protect checkpoints (Gemma runs 2 and 3, Qwen runs 1-3) are complete and unchanged. | |
| - **Other entries.** `submit_s2_big.sh` also defines Qwen3.8-27B and "replay" (web-text) jobs from the project's first | |
| experiment; those checkpoints are not part of this release. | |
| - **Run 1 of Gemma control, flourishing and equanimity.** Its launch was not kept as a script. Its | |
| `train_run_config.json` differs from run 2's only in the seed, the run name and the output repositories: run 1 also | |
| uploaded the midtraining-only checkpoints of flourishing and equanimity to separate repositories, which are not part | |
| of this release. | |
| - **Gemma `config.json`.** The six Slurm-trained Gemma checkpoints had their `config.json` converted afterwards, from | |
| the trainer's transformers 5.17.0 format to the format of the base model's own file, with the same values, so that | |
| vLLM 0.29.0 can load them (see the README). | |
| - **Why Qwen3-14B-Base.** The project's first experiment used Qwen3.8-27B, a post-trained "thinking" model with no base | |
| release. On Oct 15, 2026, Experiment 2's Qwen leg moved to Qwen3-14B-Base, because MSM starts from a base model; all | |
| of its Qwen checkpoints were trained for this experiment. | |
| - **Data revisions.** The launchers name the private working datasets (`joshycodes/fve-msm-llama`, | |
| `joshycodes/fve-msm-facts`, `joshycodes/fve-msm-protect`, `joshycodes/fve-msm-chat-sft-13k`) at pinned revisions. | |
| The files in `data/` are byte-for-byte copies of exactly those revisions; `data/MANIFEST.csv` maps each file to its | |
| source. | |