Add training support

From civitai/civitai · View interactive version

Add training support is an AI agent skill from the GitHub repository civitai/civitai. Wire an existing ecosystem into the LoRA training system so it appears as a trainable base model in the training form. Adds the base-model entry, schema enums, orchestrator validation, feature flag, and per-ecosystem default params. Use when a model family (already in basemodel.constants.ts) needs t

How to use this skill

Skill file

Add Training Support

Wires an existing ecosystem into the training form (the "Train a LoRA" flow), distinct from the generation form. After this, the ecosystem shows up as a selectable base model in Training Step 1 and submits a valid training step to the orchestrator.

Training is a separate subsystem from generation. The generation handlers/graphs in src/server/services/orchestrator/form-graph/* and src/shared/form-graph/generation/* are NOT part of this — do not touch them. The files below are the training path.

When to use

Prerequisites

The ecosystem, base model, family and license must already exist in

basemodel.constants.ts (ECO.<Name>,

an EcosystemRecord, a BaseModelRecord). If any are missing, run add-ecosystem first.

Almost every ecosystem added recently is AI-Toolkit-based (engine 'ai-toolkit',

mandatory). The worked reference is anima — it is the simplest complete example

(image, AI-Toolkit-only, no modelVariant). The single highest-leverage move when adding

a new ecosystem: grep every file below for anima and add a parallel entry.

Step 0 — Check `@civitai/orchestration-client` for the training input type

Always confirm the SDK ships the ecosystem's training type before wiring. It tells you

the exact field shape, whether modelVariant is required, and any fixed fields.

grep -niE "<Name>AiToolkitTrainingInput|ecosystem: '<name>'" \
  node_modules/@civitai/orchestration-client/dist/generated/types.gen.d.ts

Note from the type:

for this ecosystem". Honor these in the UI param bounds.

computed; never send them.

If the type is missing in the installed version, check the latest (`npm view @civitai/orchestration-client

version) and bump to it in every package.json` that lists the client

(git grep -l '"@civitai/orchestration-client"' -- '*package.json'), then pnpm install;

src/__tests__/orchestration-client-single-version.test.ts fails on a partial bump. If still absent, the

orchestrator dispatch (training.orch.ts) already casts ecosystem as any, so it works — but

prefer a typed SDK.

Step 1 — Gather the ecosystem's training defaults

Get these from the user, the model card, or an orchestrator whatif sample request:

sample as a placeholder and leave a comment to swap in

urn:air:<eco>:checkpoint:civitai:<modelId>@<versionId> once uploaded. For AI-Toolkit-only

ecosystems this AIR is NOT sent to the orchestrator (it resolves the base model from the

ecosystem); it's used for UI display / getTrainingFields.getModel.

Pick a stable base-model key (the trainingModelInfo key, e.g. boogu) and a

baseType (the TrainingBaseModelType, e.g. 'boogu'). They can differ (SD has

sd_1_5/anime/… keys all mapping to baseType sd15), but for a single-checkpoint

ecosystem keep them the same.

Step 2 — Confirm the plan with the user

Adding training support for: <Name>  (baseType: <baseType>, key: <key>)
Engine: ai-toolkit (mandatory)   Variant: <none | enum>
Defaults: steps <n>, lr <n>, dim/alpha <n>/<n>, scheduler <x>, batch <n> (max <n>), res <n>
AIR: <placeholder|civitai urn>   Feature flag: <name>Training / <name>-training (Flipt)

Wait for confirmation, then make all edits in one pass.

Step 3 — Edits

3a. `src/utils/training.ts` (the core — ~7 spots)

  1. trainingBaseModelTypesImage (or …Video / …Audio) — add '<baseType>'.
  2. aiToolkitStepDefault — add a branch returning the ecosystem's default steps if it

differs from 2000.

  1. aiToolkitBatchMax — add a branch only if max batch > 1 (default returns 1).
  2. trainingModelInfo — add the `<key>: { label, pretty, type: '<baseType>', description,

air, baseModel: '<BaseModelName>', isNew: true, aiToolkit: { ecosystem: '<eco>'

[, modelVariant] } } entry. baseModel MUST match the BaseModelRecord.name` /

ecosystem key in basemodel.constants.ts exactly (a mismatch produces a malformed AIR on

training completion and fails the post-train scan with 400 — see the inline comment on the

hidream_o1 entry).

  1. baseTypeToEcosystem — add <baseType>: '<eco>'.
  2. isAiToolkitSupported supportedTypes — add '<baseType>'.
  3. isAiToolkitMandatory mandatoryTypes — add '<baseType>' (for AI-Toolkit-only

ecosystems). This auto-enables sample-prompt requirements and AI-Toolkit gating.

  1. getDefaultEngine — add if (baseType === '<baseType>') return 'ai-toolkit';.

3b. `src/server/schema/model-version.schema.ts`

(trainingDetailsBaseModelsImage / …Video / …Audio).

trainingBaseModelType, so they update automatically. No baseModelToTraningDetailsBaseModelMap

entry unless mapping a BaseModel display name back to a key (Wan does this).

3c. `src/server/schema/orchestrator/training.schema.ts`

```ts

aiToolkitBaseParams.extend({ ecosystem: z.literal('<eco>'), modelVariant: z.undefined().optional() }),

```

(or modelVariant: z.enum([...]) if the SDK type requires one). Without this, submission

validation rejects the new ecosystem.

3d. `src/server/services/feature-flags.service.ts`

Flipt flag too (use the flipt skill). Mod-only is the norm for a new/experimental base model.

3e. `src/components/Training/Form/TrainingParams.tsx`

map is keyed by base-model key (<key>), not baseType. Grep the file for the reference

ecosystem's key (anima:) and add a parallel <key>: { all: { … } } entry to each setting

where the new ecosystem should differ from the base default. For an AI-Toolkit image ecosystem

that's typically: engine ('ai-toolkit'), maxTrainEpochs, trainBatchSize (honor the

fixed/max from the SDK type), targetSteps, saveEvery, resolution, shuffleCaption

(disabled), keepTokens (disabled), unetLR, textEncoderLR (disabled), lrScheduler,

minSnrGamma (disabled), networkDim, networkAlpha, noiseOffset, optimizerArgs.

Skip a setting if the base default already matches (e.g. optimizerType AdamW8Bit,

flipAugmentation false for image).

3f. `src/components/Training/Form/TrainingSubmitModelSelect.tsx`

ReadonlyArray<string>).includes(formBaseModel) ? formBaseModel : null;`.

baseType="<baseType>" makeDefaultParams={makeDefaultParams} isNew={…} />)}` block under the

right mediaType group (image/video/audio). Pick an unused color.

(for new/experimental base models).

3g. `src/shared/constants/basemodel.constants.ts`

```ts

{ ecosystemId: ECO.<Name>, supportType: 'training', modelTypes: loraOnly },

```

(loraOnly is the standard for trained outputs — they're LoRAs.) Generation support is

independent; don't add it unless the ecosystem is also generatable.

Files that need NO change (generic / arbitrary-ecosystem aware)

builds the input generically and casts ecosystem as any. Only add a branch if the ecosystem

needs special fields (sd1/sdxl send model + minSnrGamma; ACE-Step sends samplesOverrides).

by key. Only touch if the new ecosystem should become a form default.

generic; resolve the ecosystem via getAiToolkitEcosystem once 3a is done.

Step 4 — Typecheck

pnpm run typecheck

Common failures: a baseType/key typo (the literal won't match the TrainingBaseModelType

union), a missing spread in the aggregate array, or a baseModel string that isn't a valid

BaseModel. Iterate until clean.

Step 5 — Verify (optional)

With a dev server running (see dev-server skill) and the Flipt flag on for your user:

If it lands on /training-studio, the Training Studio is your default trainer (trainingStudioUi,

on by default for moderators) — click Use the classic trainer in the banner there first.

Notes

by their own <name>Training flag. Optional ones (sd15/sdxl/flux/…) additionally check a

per-model aiToolkit<X> flag via aiToolkitFlagByBaseType — only relevant if you're adding an

ecosystem that also supports Kohya.

(see ACE-Step). Video ecosystems go in trainingBaseModelTypesVideo and usually disable

spatial params (resolution/clipSkip/noiseOffset).

{ all: { default: 1, min: 1, max: 1 } } and leave aiToolkitBatchMax at its default.

AI-Toolkit-only ecosystems. Leave a comment so it gets swapped to the civitai URN later.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.