train command group covers LLM fine-tuning and iterative agent training.
Usage
Every
praisonai train <sub> also runs as praisonai-train <sub> when praisonai-train is installed on its own.Requirements
Pick the install that matches what you want to train.pip install "praisonai[train]" previously installed nothing (empty extra). It now pulls praisonai-train[llm], so it installs the Unsloth stack.The
[llm] extra now needs the modern base stack: torch>=2.6.0, unsloth>=2025.9.1, trl>=0.18.2, transformers>=4.51.3. Pinning torch<2.6 is why install can fail — upgrade torch first. Tested on Python 3.11 with pytorch-cuda 12.4.praisonai train generate
Synthesize an instruction dataset from a teacher LLM.
Options
YAML-only keys
These have no CLI flag — set them in--config.
Examples
output and num_examples are validated up-front. The destination file is only truncated after the first row arrives, so a run that fails on credentials or the first request never wipes an existing file. Zero unique rows exits 1.generate_dataset() Python API.
praisonai train validate
Quality-check and filter an instruction dataset (dedup, boilerplate/refusal, script purity, diversity).
Options
YAML-only keys
Examples
in / kept / drops / flags / metrics report to stdout. Malformed JSONL lines are skipped with a warning — the run still succeeds on the remaining rows.
See Dataset Tooling for the full check list and the score() / filter_rows() Python API.
praisonai train benchmark
Measure and rank generation speed across LLM deployments.
Options
YAML-only keys
Examples
rows/min. n < 1 or concurrency < 1 raises ValueError; if every request fails the CLI exits 1.
See Speed Benchmark for the benchmark_deployments() Python API and cross-endpoint benchmarking.
praisonai train dedup
Merge many JSONL files into one deduped file with a single shared exact + MinHash/LSH index — catching the cross-file near-duplicates that per-file validate always misses.
Options
Examples
in / kept / removed stats block on completion and exits non-zero only on IO errors. The write is atomic — an --out that aliases an input is never truncated before its rows are read.
Cross-file dedup (Python API)
The
global_dedup(), near_dedup(), and MinHashLSH Python API behind this command.praisonai train export
Publish an already-trained model without re-running training. Point --model-dir at a finished LoRA and pick a target.
Options
Examples
When
--base-model is omitted, the exporter reads <model-dir>/config.json _name_or_path (falling back to the directory name) to pick the chat template — so a fresh training run exports with the right template for free.Destination validation
Each target checks its required destination before the model loads:
An unknown
target fails with Unknown export target: <target> and exit 1. A --quant value outside the valid set fails before the model loads.
praisonai train llm
Fine-tune an LLM using Unsloth.
Options
Fine-tuning parameters live in the YAML config, not on the CLI. See Train → Config.yaml example — this now includes
chat_template (pick the model’s chat-template family; omit to use the built-in) and assistant_only_loss (mask non-assistant tokens out of the loss; needs a template with {% generation %} blocks).Supported models
The trainer uses each model’s own chat template, sochat_template is optional — set it only to override.
Full chat_template reference
Types, defaults, and the fail-fast
ValueError when no template is available.Examples
Config keys for LLM fine-tuning
Drive fine-tuning fromconfig.yaml (all keys optional and backward compatible).
Invalid or unknown YAML keys are reported before training starts. Missing required keys (
model_name, max_seq_length, dataset) raise ValueError with a minimal example; unknown keys are collected into one WARNING block with did you mean suggestions and training continues. See Train → Config validation.Publishing
Publishing defaults off — set the flag and its matching target to push a fine-tuned model.
Enabling a flag without its target fails fast on load:
Preflight validation
Before any model or GPU load, the trainer fails fast with a single friendly line for the four most common misconfigurations: no CUDA GPU, missing Hugging Face credentials, low disk (< 10 GB free), and an invalid quantization_method. The GPU check is skipped when train: false, so publish-only / export-only runs succeed on CPU.
See Train → Preflight validation for the full check table, fix guidance, and the 12 valid quantization values.
Exit codes
Thellm (and the praisonai_train.train.llm.trainer module) entrypoint prints a clean one-line error instead of a traceback for expected failures.
Missing-deps behaviour
On a barepip install praisonai-train, llm prints one of two messages: LLM fine-tuning dependencies not installed with pip install "praisonai-train[llm]" when praisonai-code is absent, or Failed to load LLM fine-tuning runner: <ImportError> when praisonai-code is present but a downstream import (torch/unsloth) failed. See Train for the full flow.
Multi-GPU launch
Fine-tune across every GPU on the machine withtorchrun — --nproc_per_node is the number of GPUs.
Resume
Setresume_from_checkpoint: true in config.yaml, then re-run the same command — the trainer picks the latest checkpoint in output_dir.
save_total_limit, best-checkpoint, and early-stopping keys.
Environment variables
torchrun sets the distributed variables; you set only your Hugging Face token.
praisonai train export
Publish an already-trained model to Hugging Face, GGUF, or Ollama without re-running training.
lora_model/ you trained earlier — no dataset, no re-training. The hf target pushes a merged model to the Hub; gguf writes a local .gguf (and additionally pushes to the Hub when --hf is set); ollama creates and pushes an Ollama model.
Options
Examples
Export skips the training-only validation —
TrainModel.for_export() needs no dataset and no dataset: in a config. It still validates --quant. For ollama, when --hf is omitted the Modelfile FROM line points at the local model on disk, so ollama create works without a Hub round-trip.Exit codes
Export an already-trained model
The
TrainModel.for_export() Python API and behaviour notes behind this command.praisonai train llm for the full training path that produces the model you export here.
praisonai train agents
Train agents through iterative feedback loops.
Options
Early Stop (LLM mode)
--iterations N is a maximum, not an exact count. In LLM-as-Judge mode, training stops early as soon as any iteration scores ≥ 9.5 — easy factual prompts often finish in one iteration.
When training stops early, an INFO line is logged even in --quiet mode:
Stopped Early stays absent from the summary.
Human-in-the-loop mode (--human) does not use the 9.5 threshold — the user decides when to stop.
Examples
Summary Rows
When training completes, the summary table always showsTotal Iterations, Average / Min / Max Score, Improvement, and Status. Two extra rows appear only when the run was truncated:
The session JSON persists both signals as
metadata.target_iterations (int) and metadata.early_stopped (bool), so tools reading persisted sessions can distinguish “user asked for 3, got 1 due to 9.5” from “user asked for 1, got 1”.
Storage Backend Options
Store training data in different backends.Exit Codes
As of PraisonAI 4.6.148+ (upstream commits
ce17828, 1a6eed3, fixes PraisonAI#3040) a display-only encoding error on Windows cp1252 no longer masquerades as a training failure — the session is still saved and the exit code is 0.praisonai train serve
Serve a fine-tuned GGUF over an OpenAI-compatible endpoint — auto-fetching the MTP drafter for lossless fast inference on Gemma-4.
Options
How MTP is auto-detected
The base model name (from--base-model, --config, or the model directory’s config.json) drives drafter selection. A Gemma-4 target fetches its matching stock drafter from the Hub; any other family falls back to plain serving with a clear message.
praisonai train export
Publish an already-trained model to Hugging Face, GGUF, or Ollama — without re-running training.
TARGET is hf, gguf, or ollama. Export skips the training-only preflight, so it runs on CPU.
Options
Examples
The server binds to
127.0.0.1 — there is no --host flag. Override the llama-server binary with the LLAMA_CPP_BIN env var (points at the binary or its directory). See Serve & MTP Fast-Inference for the concept-level walkthrough and the honest runtime caveats.Examples
praisonai train list
List all training sessions.
Options
Examples
Without
--storage-backend, list scans the default ~/.praison/train JSON directory. Sessions written by praisonai train agents --storage-backend sqlite ... (or Redis, or a custom file dir) are only visible when the same backend/path pair is passed to list.praisonai train show
Show details of a training session, including its iterations and best score.
Options
Examples
praisonai train apply
Apply learned suggestions from a session to an agent via hooks. Uses the best-scoring iteration by default.
Options
Examples
Standalone script
Installpraisonai-train on its own to get a praisonai-train console script that exposes the same subcommands directly.
praisonai train <sub> example above runs as-is with the praisonai-train <sub> prefix.
See Also
- Train - Training overview and fine-tuning setup
- Export a trained model - Publish a trained model without re-training
- Train → Preflight validation - Fast, friendly config checks before any GPU load
- Serve & MTP Fast-Inference - Serve a GGUF over OpenAI HTTP with MTP speculative decoding
- Dataset Tooling - Generate and quality-check instruction datasets
- praisonai-train Package - Standalone package guide
- Multi-GPU Training - Fine-tune across multiple GPUs with torchrun
- Checkpointing - Save, resume, and keep the best checkpoint
- Eval - Evaluation and testing
- Storage Backends - Pluggable storage backends

