Skip to main content
Train agents or fine-tune LLMs without installing the full PraisonAI wrapper. The 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.

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.
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]".
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.
Three headline safety guarantees (PraisonAI #3279):
  • A minimal config trains locally — publishing to Hugging Face or Ollama is opt-in (set the flag and its target).
  • assistant_only_loss: auto never crashes on a stock Gemma / Qwen / Llama template — it falls back to full-sequence SFT.
  • Unknown / misnamed keys warn instead of crashing — a typo logs WARNING: ignoring unknown config key '...' and training continues.
Just before training, the trainer prints a run-summary block confirming the resolved model, example count, loss mask, steps, and output dir — see Train → Run summary.

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

Nine subcommands cover dataset tooling, benchmarking, fine-tuning, serving, export, and agent training. See Train CLI for full flags.

Supported models

praisonai-train llm fine-tunes any Unsloth-supported model. The trainer uses each model’s own chat template, so chat_template is optional — set it only to override.
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 under torchrun 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.
Without this flag, --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 a lora_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

for_export() skips the training-only validation, so an export-only run needs no dataset: — and no config file at all.
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.
--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.
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.
See 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.
On a cp1252 Windows console, a completed training session now exits 0 even if Rich cannot render the summary emoji — you’ll see Training complete but summary could not be displayed: 'charmap' codec can't encode .... Run praisonai-train show <session-id> to inspect the persisted result. If you want the full emoji summary, run chcp 65001 first or set PYTHONIOENCODING=utf-8.

Best Practices

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.
The praisonai-train console script exposes the full train group without installing praisonai. Ideal for lightweight training-only environments.
Existing praisonai.train.*, praisonai.train_vision, and praisonai.upload_vision imports still resolve to the same module objects in praisonai_train. Nothing to migrate.
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.
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.
Backward-compatible: if you already have the wrapper installed, praisonai.train.* imports and the setup-conda-env entry point continue to work unchanged.

Train

Training overview and fine-tuning setup.

Train CLI

Full flag reference for the nine subcommands.

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.

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.