Skip to content

palingenesis

Post-train LLMs and agents from one config: SFT, multi-turn RL in tool environments, on-policy distillation, DPO and merging, with state-of-the-art defaults.

Quickstart Installation GitHub

try

What it does

Supervised fine-tuning

Including agentic traces with tool calls and reasoning.

pgs train --config configs/quickstart.yaml

Data Agentic

Reinforcement learning

Verifiable rewards, multi-turn tool use, GRPO-style groups, vLLM rollouts.

pgs rl --config configs/rl_math.yaml

RL guide

Agent environments

Python classes, MCP servers, OpenEnv, NeMo Gym, Harbor tasks in Docker, with emulated harness dialects (opencode, pi, OpenHands, …).

pgs rl --config configs/rl_harbor.yaml

Harbor Harness profiles

On-policy distillation

The student samples, one or more teachers score those tokens, reverse KL.

pgs distill --config configs/distill_math.yaml

Distillation

Off-policy distillation

Fixed data against one or more teachers' distributions (online, or a cached top-k), context distillation, hidden-state targets, multi-GPU, plugins for QAT.

pgs init kd && pgs train --config kd.yaml

Off-policy distillation

Preference optimization

DPO, IPO, SLiC-HF, robust and length-normalised DPO, SFT anchor.

pgs train --config configs/dpo_qwen35_08b.yaml

DPO

Model merging

Interpolation, soups, task arithmetic.

pgs merge interpolate START END --lam 0.3 -o OUT

Merging

Data preparation

Drop broken rows and duplicates, hold out an eval set, with the same config you train with.

pgs prepare --config configs/qwen35_4b/a100_80gb.yaml

Data

Continued pretraining

Raw text with a loss on every token: a domain, a language or a corpus, from the base model, merged into the instruct model afterwards.

pgs train --config cpt.yaml

Pretraining Merging

Autopilot

Profiles the GPU, sweeps the learning rate, trains to completion.

pgs autopilot --model Qwen/Qwen3.5-4B --dataset data.jsonl

Autopilot

When something is off

Loss is NaN or spikes

LR too high. Loss NaN/spikes, grad_cosine_sim < 0.

Diagnosis train/grad_norm exploding

Fix learning_rate ÷ 3

Training dynamics troubleshooting When things go wrong

Loss is flat

LR too low. Loss flat, slow convergence.

Diagnosis eval not improving for 500+ steps

Fix learning_rate × 2

pgs inspect --config your_config.yaml --num_samples 3

This shows you exactly what the model sees: tokenized text, which tokens have loss, how masking works. Most "loss not decreasing" issues are data masking bugs.

Training dynamics troubleshooting When things go wrong

Out of memory

Memory pressure. OOM or CUDA malloc fails.

Diagnosis health/cuda_utilization_pct > 95%

Fix Reduce per_device_batch_size, increase loss_num_chunks

Single GPU Long sequences Troubleshooting

Training is slow

Slow throughput. tok/s below expected.

Diagnosis health/cuda_utilization_pct low

Fix model.compile: true, increase batch, num_workers

Training dynamics troubleshooting

Eval loss rises while train loss falls

Overfitting. eval↑ while train↓.

Diagnosis eval/loss diverging from train/loss

Fix epochs: 2, base_merge: true

Training dynamics troubleshooting

Outputs become repetitive

Representation collapse. Model outputs become repetitive.

Diagnosis health/stable_rank_min < 3

Fix Reduce LR, enable sym_noise

Training dynamics troubleshooting

Skills lost after continued pretraining

Forgetting. General or chat skills drop while the domain loss falls.

Diagnosis eval/<name>/loss of a general held-out source rising

Fix CPT the base, not the instruct model; replay general text; merge at small λ

Held-out loss and forgetting Instruction-tuned models

Output diversity disappears (RL)

Entropy collapse (RL). Output diversity disappearing.

Diagnosis health/output_entropy < 1.5

Fix pre_rl: true, stop early

SFT → RL transition Troubleshooting

What you can rely on

Correct by construction

The loss path is checked step by step against a plain reference loop; packed conversations never see each other; multi-GPU gradients equal single-GPU ones; saved models load with plain from_pretrained.

Architecture

Masking from the chat template

Whole assistant turns are trained as the template renders them, tool calls and end-of-turn tokens included; tools are rendered into the prompt; "loss": false keeps a message as context only.

Agentic training

Token-exact RL

What the trainer scores is exactly what the sampler produced, tool results included; nothing is re-tokenized. Rewards are checked answers, hidden tests, LLM judges or any Python function.

RL guide

Memory

Chunked losses (the full logits are never materialised), selective activation checkpointing, gradient release, 8-bit optimizers. A Qwen3.5-4B fine-tune (attention pathway, 36% of the weights) fits in about 16 GiB.

Single GPU

Long sequences on one GPU

SeCO: chunk-by-chunk training with a cache gives the exact gradient, verified against full backpropagation on 27 architectures, including the Qwen3.5 and LFM2 hybrids.

Long sequences

Training you can inspect

wandb and trackio with grad norm, spike and clip counters, gradient noise scale, entropy and the generalisation gap on one step axis; best-checkpoint tracking on eval loss.

Health monitoring

Crash-safe

Re-run the same command to resume from the last complete checkpoint, in the same tracker run.

Scale out

FSDP across GPUs, multi-node SLURM with sharded checkpoints, and a container image for Kubernetes.

Multi-GPU

Research options, one line each

DEFT / DFT / InfoSFT token weighting, Hyperball, power-decay schedules: implemented to their papers' definitions; the benefits are as reported by the papers, not reproduced here.

The research

Install

git clone https://github.com/mii-llm/palingenesis.git && cd palingenesis
uv sync --extra train --extra logging && source .venv/bin/activate
./run.sh configs/quickstart.yaml
pip install "torch>=2.11" --index-url https://download.pytorch.org/whl/cu129   # FIRST: the CUDA 12.9 build (driver >= 575)
pip install "palingenesis[train,logging]"
pgs init sft                     # writes ./sft.yaml: set your model and dataset
pgs train --config sft.yaml

Any HuggingFace causal LM. Optimized for: Qwen 2.5/3/3.5, Llama 3, Gemma 4, Mistral. Hybrid architectures (Qwen3.5 DeltaNet) supported via freeze_non_attention.

Full installation guide

Start here

First time?

Install, run, see results in 5 minutes.

Quickstart

New to training?

Tokens, loss, masking, and which method fits your goal.

How training works

Have agentic data?

Reasoning traces, tool calls, multi-turn. Native support.

Agentic guide

Planning RL after SFT?

Monitor entropy. Don't overtrain. We explain why.

SFT → RL