index
Types
TrainedLora
What a finished run produced.
/** What a finished run produced. */
export type TrainedLora = {
path: string;
steps: number;
images: number;
minutes: number;
samples: string[]
}(source)
LoraInfo
What an adapter's file says about how it was trained.
/** What an adapter's file says about how it was trained. */
export type LoraInfo = {
base: string;
trigger: string;
rank: number;
steps: number;
sizeBytes: number
}(source)
Effects
lora::train
@alwaysUnder(outDir, imagesDir)
effect lora::train {
imagesDir: string;
base: string;
outDir: string;
outFilename: string;
steps: number;
estimatedMinutes: number
}(source)
lora::info
@alwaysUnder(dir)
effect lora::info {
dir: string;
filename: string
}(source)
Constants
STYLE_TAGS
The booru tags that describe a drawing's style rather than its subject. A caption that names the style teaches the model that the style belongs to those words and not to the trigger word, so a caption loop drops them before writing a sidecar. A caller training a character rather than a style keeps them.
/** The booru tags that describe a drawing's style rather than its subject.
A caption that names the style teaches the model that the style belongs
to those words and not to the trigger word, so a caption loop drops them
before writing a sidecar. A caller training a character rather than a
style keeps them. */
export static const STYLE_TAGS = [
"monochrome",
"greyscale",
"white background",
"simple background",
"traditional media",
"sketch",
"lineart",
"signature",
"text focus",
"no humans",
](source)
Functions
trainLora
trainLora(
imagesDir: string,
trigger: string,
base: string,
outPath: string,
steps: number = 1000,
rank: number = 16,
learningRate: number = 0.0001,
resolution: number = 1024,
flip: boolean = false,
seed: number = 1,
samplePrompts: string[] = [],
sampleEvery: number = 250,
): Result<TrainedLora> raises <lora::train>Train a LoRA adapter for an SDXL image model from a folder of images, each with an optional caption file (a.txt beside a.png, comma-separated tags). The trigger word is put in front of every caption. Takes minutes on a Mac GPU and writes the adapter as a .safetensors file, plus a before-and-after sample grid at every sampleEvery steps beside it. Everything runs on this machine, with the Python agency local serve uses. Returns the adapter's path and the sample grids.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| imagesDir | string | The folder of training images, PNG or JPEG, with optional .txt captions beside them | |
| trigger | string | The word the adapter answers to. A real phrase learns faster and keeps the base model's idea of it; a nonsense word owns the token | |
| base | string | The SDXL model to train on: a catalog name, a diffusers: URI, or a model directory, already downloaded | |
| outPath | string | The .safetensors file to write. It must not exist yet | |
| steps | number | 1000 | How long to train. Too few and the style is faint; too many and every output is a training image. Judge by the sample grids |
| rank | number | 16 | How much the adapter can hold: 8 for a style, 16 for a character, 32 for a character with a wardrobe. Doubling the rank doubles the file |
| learningRate | number | 0.0001 | Halve it if the grids get worse after getting better |
| resolution | number | 1024 | The training size. 768 trains twice as fast for a first look; 1024 for the real run |
| flip | boolean | false | Also train on mirrored copies, which doubles a small set. Off for an asymmetric character |
| seed | number | 1 | Fixes the randomness, so a run is repeatable |
| samplePrompts | string[] | [] | Prompts to render before and after at each checkpoint, to judge the run. Use the trigger word in them |
| sampleEvery | number | 250 | Steps between sample grids. 0 for none |
Returns: Result<TrainedLora>
Throws: lora::train
(source)
loraInfo
loraInfo(path: string): Result<LoraInfo> raises <lora::info>What an adapter file says about itself: the base model it was trained for, its trigger word, its rank, the steps it trained, and its size. Reads the file's header only.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
| path | string | A .safetensors adapter written by trainLora |
Returns: Result<LoraInfo>
Throws: lora::info
(source)