Documentation
¶
Overview ¶
Package trainer abstracts local LoRA training backends. v1 ships one adapter (ai-toolkit). The CLI never trains itself — adapters orchestrate a subprocess.
Index ¶
- func Configure(home, python string)
- func NewRunID() string
- func ResolvePython(cfg Config) string
- type AIToolkit
- func (a AIToolkit) Detect(cfg Config) (Capabilities, error)
- func (a AIToolkit) Generate(ctx context.Context, req GenerateRequest, onProgress func(GenerateProgress)) (GenerateResult, error)
- func (a AIToolkit) GenerateConfig(req GenerateRequest) ([]byte, error)
- func (AIToolkit) Name() string
- func (a AIToolkit) Plan(req Request) (Plan, error)
- func (a AIToolkit) Train(ctx context.Context, plan Plan, onProgress func(Progress)) (Result, error)
- type Capabilities
- type Config
- type GenerateProgress
- type GenerateRequest
- type GenerateResult
- type Metrics
- type PerfPlan
- type Plan
- type Progress
- type Request
- type Result
- type Trainer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
func Configure(home, python string)
Configure sets the ai-toolkit location for the adapter.
func ResolvePython ¶
ResolvePython returns the python interpreter (default <home>/venv/bin/python).
Types ¶
type AIToolkit ¶
type AIToolkit struct{}
AIToolkit orchestrates the ai-toolkit trainer as a subprocess.
func (AIToolkit) Detect ¶
func (a AIToolkit) Detect(cfg Config) (Capabilities, error)
Detect verifies ai-toolkit is installed (never installs anything).
func (AIToolkit) Generate ¶ added in v0.1.13
func (a AIToolkit) Generate(ctx context.Context, req GenerateRequest, onProgress func(GenerateProgress)) (GenerateResult, error)
Generate renders images from a trained LoRA by driving ai-toolkit's "generate" job (same model loader as training, LoRA fused via model.lora_path). It writes a generate config, runs run.py, relays output, and returns the rendered image paths. Honors ctx cancellation.
func (AIToolkit) GenerateConfig ¶ added in v0.1.13
func (a AIToolkit) GenerateConfig(req GenerateRequest) ([]byte, error)
GenerateConfig renders the ai-toolkit generate-job config for a request, without running anything (used by `loradex generate --dry-run`).
type Capabilities ¶
type Capabilities struct {
Device string // mps | cpu | cuda
DeviceName string
MemoryGB int
Version string // backend version (best effort)
}
Capabilities describes the resolved training device.
func DetectDevice ¶
func DetectDevice(requested string) Capabilities
DetectDevice resolves the training device (auto → MPS on Apple Silicon).
type GenerateProgress ¶ added in v0.1.13
type GenerateProgress struct {
Raw string
Loaded bool // true once the model has finished loading and rendering begins
}
GenerateProgress is a streamed generation update (raw trainer output line).
type GenerateRequest ¶ added in v0.1.13
type GenerateRequest struct {
Name string
Base string
BaseCheckpoint string // name_or_path (the base model dir, as in training)
LoRAPath string // trained .safetensors to fuse
Prompts []string // inline prompts (ignored when PromptFile is set)
PromptFile string // path to a newline-delimited prompts file
Negative string
Width int
Height int
Steps int // diffusion steps (sample_steps)
Guidance float64 // guidance scale
Seed int // -1 = random per image
Count int // images per prompt (num_repeats)
Sampler string // "" → flowmatch for FLUX, else ddpm
Precision string // dtype, e.g. bf16
Quantize bool
Device string
OutputDir string
}
GenerateRequest is a fully-resolved image-generation request. It loads the same base the LoRA trained on and fuses the LoRA at load.
type GenerateResult ¶ added in v0.1.13
type GenerateResult struct {
Images []string
}
GenerateResult lists the rendered images (absolute paths).
type Metrics ¶
type Metrics struct {
FinalLoss float64 `json:"final_loss"`
StepsCompleted int `json:"steps_completed"`
DurationSeconds int `json:"duration_seconds"`
PeakMemoryBytes int64 `json:"peak_memory_bytes"`
Checkpoints []string `json:"checkpoints"`
Samples []string `json:"samples"`
}
Metrics are the final training metrics.
type PerfPlan ¶ added in v0.1.16
type PerfPlan struct {
CacheLatents bool // VAE-encode images once to disk, then free the VAE
CacheTextEmbeddings bool // encode captions once, then unload the text encoder
DisableSampling bool // skip sampling, including the pre-train baseline sample
}
PerfPlan summarizes the memory/speed optimizations applied to a training run.
func PerfPlanFor ¶ added in v0.1.16
PerfPlanFor derives the optimizations enabled for a request — the single source of truth shared by config generation and the build plan. Latent caching is always safe (no augmentations are configured). Text-embedding caching unloads the TE but freezes the embeds, so it is gated on self-contained captions (no dynamic trigger_word) and not training the TE. Sampling is skipped when the run requested no samples.
type Plan ¶
type Plan struct {
Req Request
Trainer string
Device string
DeviceName string
MemoryGB int
Steps int
ConfigPath string
OutputPath string // final collected .safetensors path
Quantize bool
}
Plan is the displayable, side-effect-free training plan.
type Request ¶
type Request struct {
Name string
Base string
BaseCheckpoint string
Trigger string
DatasetDir string
CaptionMode string
// CaptionsHaveTrigger: the per-image .txt captions already include the
// trigger (we generated them), so the trainer must not inject it again.
CaptionsHaveTrigger bool
Profile profile.Profile
Device string
CacheDir string // .loradex/cache/<run-id>
OutputDir string // version dir to collect results into
OutputFile string // final .safetensors filename
RawConfig string // --config escape hatch (path); skips generation
Samples int
RunID string
}
Request is a fully-resolved training request.