Skip to main content

palingenesis

palingenesis

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

Documentation · Quickstart · Configs

Install with uv (Linux + NVIDIA GPU):

uv venv --python 3.12 && source .venv/bin/activate
uv pip install "palingenesis[train,logging]" --torch-backend cu129   # torch's CUDA 12.9 build (driver >= 575)
pgs init sft                     # writes ./sft.yaml: set your model and dataset
pgs train --config sft.yaml

In a uv project, with a lockfile (the same versions on every machine):

uv init --python 3.12 my-training && cd my-training
uv add torch --index pytorch-cu129=https://download.pytorch.org/whl/cu129   # pin torch to the CUDA 12.9 index
uv add "palingenesis[train,logging]"
uv run pgs init sft && uv run pgs train --config sft.yaml

With pip, install torch from PyTorch's CUDA index first: plain pip install palingenesis on Linux pulls PyPI's default torch, built for the newest CUDA (13.x, driver >= 580), which installs fine on an older driver and then sees no GPU.

pip install "torch>=2.11" --index-url https://download.pytorch.org/whl/cu129
pip install "palingenesis[train,logging]"

Other CUDA versions: Installation.

From source (the locked, tested versions; the CUDA torch index is configured for you):

git clone https://github.com/mii-llm/palingenesis.git && cd palingenesis
uv sync --extra train --extra logging     # .venv with CUDA-enabled torch (+ --extra hybrid for Qwen3.5: faster, needed to pack)
source .venv/bin/activate
pgs train --config configs/quickstart.yaml

In a notebook or a script: palingenesis.train.train(config) on one GPU, see Training from a notebook. AMD GPUs (ROCm): Training on AMD GPUs.

What it does

Command Guide
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
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
FP4 / FP8 quantisation-aware training (plugin): NVFP4, MXFP4, FP8 fake quantisation while distilling from the bf16 model (SFT, KD, OPD, RL); packed checkpoints vLLM serves; pgs quantize for PTQ pgs train --config configs/qat_nvfp4_qwen35_08b.yaml QAT
LoRA (plugin): frozen base, rank-r adapters (rsLoRA, DoRA, LoRA+), merged export and PEFT adapter; full fine-tuning stays the default pgs init lora && pgs train --config lora.yaml LoRA
Continued pretraining: raw text with a loss on every token (a domain, a language, a corpus), from the base model, merged into the instruct model afterwards pgs train --config cpt.yaml (written in the guide) Pretraining
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
Autopilot: profiles the GPU, sweeps the learning rate, trains to completion pgs autopilot --model Qwen/Qwen3.5-4B --dataset data.jsonl Autopilot

Highlights

  • 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.
  • Masking from the chat template itself. 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.
  • 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.
  • 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. pgs fit measures which memory settings are the fastest that fit your GPU.
  • Long sequences on one GPU (SeCO). Chunk-by-chunk training with a cache gives the exact gradient, verified against full backpropagation on tiny models of 29 architectures, including the Qwen3.5 and Qwen3-Next hybrids; a model whose chunked forward does not match its full forward is refused.
  • Mixture-of-Experts models. Routers are balanced in every trainer (load-balancing loss with the expert load measured over the global batch, router z-loss, DeepSeek-V3's selection-bias update), with per-layer load and entropy in the log; RL replays the experts the rollout engine chose. Gradients tested against the written-out losses on five families.
  • 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.
  • Evaluation that agrees with training. pgs eval --model X --suite core runs tasks defined in YAML (GSM8K, MATH-500, MMLU, MMLU-Pro, IFEval, BBH, HumanEval, MBPP, function calling, Italian-language tasks (Belebele, MMMLU), your own, agentic environments, or task files of lm-evaluation-harness as they are) with the trainer's own prompt rendering, tool parsing and rewards, in each thinking mode: one engine per run, scoring next to generation, multiple choice with one prefill per question; pgs compare gives paired tests between two checkpoints.
  • Resumable. Re-running the same pgs train command resumes from the last complete checkpoint in train.output_dir, in the same tracker run (train.resume_from: null starts from scratch); pgs rl and pgs distill do the same.
  • Scale out. FSDP across GPUs, multi-node SLURM with sharded checkpoints, and a container image for Kubernetes.
  • 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.

Hardware

GPU Model Config
A100 40 GB Qwen3.5-4B, attention pathway (36% of weights) configs/qwen35_4b/a100_40gb.yaml
A100 80 GB Qwen3.5-4B, batch 4 configs/qwen35_4b/a100_80gb.yaml
H100 80 GB Qwen3.5-4B, FP8 configs/qwen35_4b/h100_80gb.yaml
8× A100 80 GB Qwen3.5-35B-A3B (MoE) configs/qwen35_35b_moe/a100_80gb_multigpu.yaml
./scripts/train_multi_gpu.sh configs/qwen35_4b/a100_80gb_multigpu.yaml           # one node, all GPUs
sbatch scripts/train_slurm.sh configs/qwen35_35b_moe/a100_80gb_multigpu.yaml     # SLURM

Containers and Kubernetes: Containers.

Development

pytest tests/                 # test suite
mkdocs serve                  # docs locally (pip install mkdocs-material)

License

Apache-2.0.

A new form emerging from what came before.

Metadata

Release files for palingenesis 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for palingenesis 0.3.2
File Size Uploaded Provenance Actions
palingenesis-0.3.2.tar.gz 2.3 MB With provenance Details for palingenesis-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for palingenesis 0.3.2
File Interpreter ABI Platform Actions
palingenesis-0.3.2-py3-none-any.whl Python 3 none any Details for palingenesis-0.3.2-py3-none-any.whl

Total release size: 3.9 MB

Release files / palingenesis-0.3.2.tar.gz

Download URL palingenesis-0.3.2.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
86e25384628642b0b333e0ca40e1d462e5f5aa256be64498097b5a5b3dc452a1
BLAKE2b-256 checksum
How to use checksums
9019142806252de7f1f8f2a4c5bc459c9cf8b23ea7884cde4288e888b9c81b81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Release files / palingenesis-0.3.2-py3-none-any.whl

Download URL palingenesis-0.3.2-py3-none-any.whl
Size 1.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
4a35e8bbbee554c9824c25b60cbd1994b0ee17a2c85a748135f7311d5a606c9b
BLAKE2b-256 checksum
How to use checksums
19919ba4f986a8eb8a00a3ae53ee4aba6f4ae4bab4452c08bcc75a2465901450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Security for palingenesis 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for palingenesis-0.3.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page