@agency-lang/lora

中文文档
0.0.1发布于 2026/09/30ISCTypeScriptES Module零依赖近 30 天下载 4569

Train LoRA adapters for local SDXL image models from Agency

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. The two functions and the constant
  4. The knobs
  5. Captions
  6. Numbers

@agency-lang/lora

Train a LoRA adapter for a local SDXL image model from a folder of pictures, from Agency. A LoRA adapter is a small file, tens of megabytes, that teaches a model a style or a character from a few dozen examples. Everything runs on this machine, with Hugging Face offline.

Installation

npm install @agency-lang/lora

Training needs the Python agency local serve uses, with the image server's packages installed (torch, diffusers, and safetensors come with them). The base model must be downloaded already:

agency local download diffusers:Laxhar/noobai-XL-1.1

Usage

import { trainLora, loraInfo, STYLE_TAGS } from "pkg::@agency-lang/lora"

node main() {
  const r = trainLora(
    "./drawings",
    "pen and ink",
    "diffusers:Laxhar/noobai-XL-1.1",
    "./adapters/sketch.safetensors",
    steps: 1000,
    flip: true,
    samplePrompts: ["pen and ink, a cat on a chair"],
  )
  if (isFailure(r)) { print("failed: ${r.error}"); return }
  print("adapter at ${r.value.path} after ${r.value.minutes} minutes")
}

trainLora raises lora::train before it starts, with the folder, the base model, the output path, the steps, and the estimated minutes, so you approve the whole run with the numbers in front of you. Nothing runs, and nothing in the folder is read, until you answer. Write the adapter into your client.adaptersDir and a running image server loads it by name the first time a request asks:

generateImageLocal("pen and ink, a cat on a chair", "diffusers:Laxhar/noobai-XL-1.1", lora: "sketch")

The two functions and the constant

ExportJob
trainLora(imagesDir, trigger, base, outPath, ...)Train one adapter. Minutes. Raises lora::train.
loraInfo(path)Read an adapter file's header: base model, trigger, rank, steps, size. Raises lora::info.
STYLE_TAGSThe tags a caption should drop so the style binds to the trigger word.

There is no caption loop and no preview function here on purpose. Both are a few lines of your own code over tools you already have, and the examples/ folder has them: captionFolder.agency (glob, tagImage, a filter against STYLE_TAGS, write) and previewAdapter.agency (two generateImageLocal calls with one seed, writeBinary, pasteImages).

The knobs

Eight settings are parameters, because a person judging the sample grids would change them. The rest are fixed at the values the first runs used, in one dictionary at the top of trainer/rules.py, with a comment each.

ParameterDefaultWhy you would change it
triggerrequiredThe 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.
steps1000The main dial. Too few, the style is faint; too many, every output is a training image. Judge by the grids.
rank16How 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.
learningRate1e-4Halve it if the grids get worse after getting better.
resolution1024768 trains twice as fast for a first look.
flipfalseDoubles a small set with mirror images. Off for an asymmetric character.
seed1Repeatability, and a second seed is a cheap second opinion.
samplePrompts, sampleEverynone, 250What to render before and after at each checkpoint. The grids are how a run is judged.

Captions

Each image may have a caption beside it, a.txt next to a.png, with comma-separated booru tags: what is in the picture, not how it is drawn. The trigger word goes in front of every caption. If every caption says monochrome, sketch, the model learns the style belongs to those words and the trigger learns nothing; that is what STYLE_TAGS is for. std::vision's tagImage writes tags in this vocabulary.

Numbers

On an M5 Ultra against NoobAI-XL 1.1 at 1024×1024, rank 16: about 0.8 s a step, so a thousand steps with sample grids is about 15 minutes, and the adapter is 93 MB. Memory stays under 30 GB.

版本与发布记录

@agency-lang/lora 共发布 2 个版本,首次发布于 2026/09/30;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.0.1latest2026/09/301 个月前
0.0.0-stage2026/09/301 个月前

关于 @agency-lang/lora 的常见问题

@agency-lang/lora 是什么?

Train LoRA adapters for local SDXL image models from Agency

如何安装 @agency-lang/lora?

在项目目录运行 npm install @agency-lang/lora,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:agency-lang(>=0.26.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@agency-lang/lora 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agency-lang/lora 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@agency-lang/lora 可以商用吗?

@agency-lang/lora 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@agency-lang/lora 的下载量有多少?

根据 npm 官方下载统计,@agency-lang/lora 在 2026/10/05 – 2026/11/03 这 30 天内被下载 4,569 次,日均约 152 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agency-lang/lora 还在维护吗?

最新版本 0.0.1 发布于 2026/09/30(1 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/09/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。