praisonai-train PyPI package (import: praisonai_train) is Tier 2c — it sits on top of praisonaiagents and gives you the train CLI group and a standalone praisonai-train console script.
Prefer a UI? See Desktop → Training
The PraisonAI Desktop app wraps
praisonai-train llm in a Train tab — live loss chart, log, and reconnect-safe progress.Quick Start
1
Agent Training
Improve an agent iteratively — no ML dependencies required.
2
LLM Fine-tuning
Add the
[llm] extra to pull the modern Unsloth/torch stack (unsloth>=2025.9.1, trl>=0.18.2, transformers>=4.51.3, torch>=2.6.0). The trainer uses each model’s own chat template, so chat_template is optional.- Llama
- Gemma
- Qwen
- From a config file
- Send it to a remote GPU box
The base install now uses the modern TRL API (
SFTConfig + SFTTrainer) and pulls the current Unsloth / TRL / torch 2.6+ stack. On old pins, upgrade with pip install -U "praisonai-train[llm]".praisonai-train llm <dataset> correctly trains on the dataset you pass. On PraisonAI releases before PR #4239 the dataset argument was silently dropped and the run fell back to yahma/alpaca-cleaned; upgrade if praisonai-train show <session> reports a model trained on a corpus you didn’t provide.As of PR #4317,
praisonai train llm (the wrapper route) also actually launches the trainer. On earlier releases the legacy dispatcher had no train case and silently forwarded the literal word "train" to an LLM as a chat prompt, exited 0, and never invoked the trainer. Direct use of the praisonai-train llm console script was unaffected.3
Serve a trained model
Serve a fine-tuned GGUF over an OpenAI-compatible endpoint — Gemma-4 auto-fetches its MTP drafter for lossless fast inference.See Serve & MTP Fast-Inference for the full walkthrough.
Beginner-safe defaults
A minimal fine-tuning config trains locally and pushes nowhere unless you opt in.- A minimal config trains locally — publishing to Hugging Face or Ollama is opt-in (set the flag and its target).
assistant_only_loss: autonever crashes on a stock Gemma / Qwen / Llama template — it now masks via Unsloth turn markers when the template lacks{% generation %}, and falls back to full-sequence SFT only when neither route is available.- Unknown / misnamed keys warn instead of crashing — a typo logs
WARNING: ignoring unknown config key '...'and training continues. - Environment preflight — missing or out-of-date training deps are now caught before the first heavy import; the CLI prints one
pip install -U ...line that fixes them all. - An unknown
model_namewarns, it doesn’t fail — the trainer prints one line pointing atpraisonai-train models(with a “did you mean?” suggestion when there’s a close match) and continues, because unsloth also loads models it doesn’t map.
Beyond SFT,
praisonai-train llm also supports preference tuning — DPO, ORPO, and KTO — via the method config key. See Preference Training.When to Use praisonai-train vs praisonai train
Install the standalone package when you only need training; use the wrapper’s praisonai train when you already run the full stack.
Both entry points expose the same commands: every praisonai train <sub> also runs as praisonai-train <sub>.
CLI Subcommands
Eleven subcommands cover dataset tooling, benchmarking, fine-tuning, model discovery, serving, export, and agent training.
See Train CLI for full flags.
Supported models
praisonai-train llm fine-tunes any Unsloth-supported model. The full list — ~246 repos on a recent unsloth release, including every 4-bit key and its 16-bit mirror — is discoverable from the CLI itself:
* are the curated starting set — one current base per major family, sized to fit a single 24 GB GPU in 4-bit. Pick one of these if you haven’t chosen yet:
The trainer uses each model’s own chat template, so
chat_template is optional — set it only to override.
Unknown
model_name warns, it doesn’t refuse. A model_name not in the unsloth catalog prints one line at validation time — e.g. WARNING: 'unsloth/Meta-Llama-3.1-8B-Instrct-bnb-4bit' is not in unsloth's model list, so it may not load. Did you mean: unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit? Run \praisonai-train models` to see the full list.— and training proceeds. unsloth's loader falls through to a generic path for models it doesn't map, so refusing would block working configurations; but a typo no longer costs a Hugging Face download to discover. Suggestions match the repo name, not the full id, so a right model under the wrong org (e.g.meta-llama/…) surfaces the unsloth/…` mirror.When
unsloth isn’t installed (pip install praisonai-train without [llm]), the same command still works — it falls back to the 7-entry curated set so models is useful in a lightweight agent-training env too.PraisonAI PR #3274 validated
unsloth/Qwen2.5-0.5B-Instruct-bnb-4bit and unsloth/gemma-2-2b-it-bnb-4bit end-to-end. See Train → Model & template keys for the full chat_template reference.Common Patterns
Fine-tune a non-Llama base (Gemma / Qwen)
Point--model at any Gemma or Qwen base — the trainer uses each model’s own chat template automatically.
The trainer previously force-applied the Llama-3.1 template to every model, corrupting Gemma / Qwen runs. Fixed as of PraisonAI PR #3274 — set
chat_template in config.yaml only when a base model has no built-in template.Fine-tune on 2 GPUs with checkpointing
Launch undertorchrun and add a handful of checkpoint keys — an interrupted run resumes from the latest. See Multi-GPU.
Train, review, apply
Run a training session, inspect the iterations, then bake the best one into your agent.Apply in Python
Apply a session’s suggestions to an agent directly.Train on any console
The same commands run identically on macOS, Linux, and Windows — no encoding configuration needed.Force all iterations
Benchmarks, regression tests, and demos that need to observe the feedback loop across every iteration should pass--no-early-stop (CLI) or no_early_stop=True (Python) so the 9.5 threshold is bypassed.
--iterations behaves as a maximum in LLM-as-Judge mode — training stops as soon as any iteration scores ≥ 9.5.
Exporting an already-trained model
Publish alora_model/ you trained earlier — no dataset, no re-training.
1
Push to Hugging Face
2
Export a GGUF
Writes a local
.gguf; add --hf to also push it to the Hub.3
Push to Ollama
Export doesn't need a dataset
Export doesn't need a dataset
for_export() skips the training-only validation, so an export-only run needs no dataset: — and no config file at all.Chat template is inferred
Chat template is inferred
The base model (for chat-template selection) is read from
<model-dir>/config.json:_name_or_path, falling back to the directory name. Override it with --base-model.Quantization is validated up front
Quantization is validated up front
--quant accepts the same values as the LLM training path (q4_k_m, q5_k_m, q8_0, q4_0, q4_1, q5_0, q5_1, q3_k_m, q6_k, f16, bf16, q2_k). A typo fails fast, listing every valid choice.Ollama needs a namespaced model + registered key
Ollama needs a namespaced model + registered key
The model must be namespaced
<username>/<name>, and your public key must be registered at https://ollama.com/settings/keys. An unauthorized push tells you exactly where to click and prints your local ~/.ollama/id_ed25519.pub.Python API
Export-only, straight from a config dict — no dataset required.for_export() accepts either model_name or its alias model (matching the --model CLI flag), and validates quantization_method up front — a typo like q4km raises ValueError with the full valid-methods list.praisonai train export for every flag and exit code.
Windows & non-UTF-8 Consoles
praisonai-train agents renders its summary table with emoji (✅ PASSED, ❌ NEEDS WORK, ★ best-iteration marker) when stdout supports UTF-8, and automatically falls back to ASCII (PASSED, NEEDS WORK, *) when it doesn’t. It detects the console’s encoding at runtime.
The ASCII summary is the correct output on a cp1252 Windows console — not a truncation. The session is saved either way;
praisonai-train show <session-id> re-renders it in whichever encoding your current console supports.Exit Codes
praisonai-train agents reports three distinct outcomes.
Best Practices
Install the base package for agent training
Install the base package for agent training
pip install praisonai-train pulls praisonaiagents plus litellm (needed for LLM-as-Judge grading) — enough for agents, list, show, and apply. Add [llm] only when you need Unsloth fine-tuning.Use the standalone script when you don't want the wrapper
Use the standalone script when you don't want the wrapper
The
praisonai-train console script exposes the full train group without installing praisonai. Ideal for lightweight training-only environments.Old imports keep working
Old imports keep working
Existing
praisonai.train.*, praisonai.train_vision, and praisonai.upload_vision imports still resolve to the same module objects in praisonai_train. Nothing to migrate.Let the tokenizer's native template win
Let the tokenizer's native template win
For LLM fine-tuning, only set
chat_template for models without one, or to force a specific one. Forcing llama-3.1 on Gemma/Qwen was the old default and silently corrupted training — the trainer now uses each model’s own template by default. See Train → Chat Template.Update to the modern Unsloth stack
Update to the modern Unsloth stack
The
[llm] extra now requires unsloth>=2025.9.1, trl>=0.18.2, transformers>=4.51.3, and torch>=2.6.0. If you had pinned trl<0.9.0, upgrade — the pre-0.9 TRL API is no longer supported. As of PraisonAI PR #4365, the trainer refuses to import a stale stack at all and tells you the exact pip install -U ... to run.Fix a GPU out-of-memory run in order
Fix a GPU out-of-memory run in order
When a fine-tuning run stops with “The GPU ran out of memory”, lower
max_seq_length first (biggest lever), then enable use_gradient_checkpointing: unsloth, then halve per_device_train_batch_size while doubling gradient_accumulation_steps, and switch to a 4-bit base model only as a last resort. See Train → GPU out of memory for the full walkthrough.Backward-compatible: if you already have the wrapper installed,
praisonai.train.* imports and the setup-conda-env entry point continue to work unchanged.Related
Train
Training overview and fine-tuning setup.
Desktop → Training
Prefer a UI? Run a fine-tune from the Desktop app’s Train tab.
Train CLI
Full flag reference for every subcommand.
Preference Training
Fine-tune on preferences with DPO, ORPO, and KTO.
Serve & MTP Fast-Inference
Serve a GGUF over OpenAI HTTP with lossless MTP speculative decoding.
Ollama
Publish and run fine-tuned models locally with Ollama.
Dataset Tooling
Generate and quality-check instruction datasets.
Speed Benchmark
Rank deployments by generation speed before you fine-tune.
Multi-GPU Training
Fine-tune across multiple GPUs with torchrun.
Remote in One Step
Send a run to a remote GPU box with
--remote-host, remote: YAML, or the desktop dropdown.Checkpointing
Save, resume, and keep the best checkpoint.
Installation Extras
The train install matrix.
Package Tiers
How the six packages stack.
Windows Terminal Encoding
Fix Rich crashes and ASCII rendering on legacy Windows consoles.

