Documentation
¶
Overview ¶
Package imagegen generates an image from a text prompt by shelling out to the repo's render/comfy-generate.mjs (Node), which wraps the proven comfy-render.mjs with the GPU-lock + ComfyUI start/stop lifecycle. The render runs on the LOCAL ComfyUI (SDXL/ RealVisXL) — free, no cloud. It is now a THIN caller of internal/gpugen, which owns the shared exec lifecycle (process-tree-kill on timeout, WaitDelay, defer freeComfyVRAM) so image/video/audio all get the SAME guards. Behavior is preserved byte-for-byte; only the lifecycle was lifted into gpugen.
Index ¶
- Constants
- func Edit(ctx context.Context, req EditRequest) (string, error)
- func Generate(ctx context.Context, req GenerateRequest) (string, error)
- func GenerateBatch(ctx context.Context, req BatchRequest) error
- func GenerateSdcpp(ctx context.Context, req SdcppRequest) (string, error)
- func Inpaint(ctx context.Context, req InpaintRequest) (string, error)
- func OutputSize(path string) (int, int)
- func SourceFormat(path string) string
- func Upscale(ctx context.Context, req UpscaleRequest) (string, error)
- type BatchRequest
- type ComfyLaunch
- type EditModel
- type EditRequest
- type GenerateRequest
- type InpaintModel
- type InpaintRequest
- type Model
- type SdcppModel
- type SdcppRequest
- type UpscaleModel
- type UpscaleRequest
Constants ¶
const BatchExitJobsFailed = 4
BatchExitJobsFailed is the exit code render/comfy-generate.mjs --batch ends with when it ran every job and at least one of them failed (BATCH_EXIT_JOBS_FAILED in render/batch-jobs.mjs; TestBatchExitJobsFailedMatchesTheRunner pins the two together). Before 0.178.0 that batch exited 0, so a shell caller had to grep the log for the failures. The results file holds a row for every job then, exactly as after an exit 0.
const EditFamilyQwenImage21 = "qwen-image-2.1"
EditFamilyQwenImage21 is the multi-reference 2.1 edit graph's family name.
Variables ¶
This section is empty.
Functions ¶
func Edit ¶ added in v0.206.0
func Edit(ctx context.Context, req EditRequest) (string, error)
Edit rewrites a whole image from a text instruction on the LOCAL ComfyUI (free), with no mask. Same lifecycle guards as Generate.
func Generate ¶
func Generate(ctx context.Context, req GenerateRequest) (string, error)
Generate runs `node <script> <out> <prompt> [--negative ..] [--width ..] ...` and returns req.Out on success. A non-zero exit, a timeout, or a missing/empty output file returns an error (the caller defers).
func GenerateBatch ¶ added in v0.21.1
func GenerateBatch(ctx context.Context, req BatchRequest) error
GenerateBatch renders every job in req.JobsPath (JSONL: {"prompt","out",...} per line) through ONE warm ComfyUI session and writes one result line per job to resultsPath. The results file is the gpugen success gate: the script exits 0, or BatchExitJobsFailed when individual renders failed, with a complete results file (the caller reads per-job status; neither is an error here), while a crash/timeout/GPU-busy exits non-zero and errors here. So does a ComfyUI that became unusable mid-batch (register C-83) and a full disk (0.178.0): the results file still holds a row per job, the later ones "not run: ...", and the caller reads them on error too. Timeout bounds the WHOLE batch.
func GenerateSdcpp ¶ added in v0.206.0
func GenerateSdcpp(ctx context.Context, req SdcppRequest) (string, error)
GenerateSdcpp renders via stable-diffusion.cpp (render/sdcpp-generate.mjs): a spawn-per-job single binary under the same GPU lock — zero-warm by construction. Same gpugen lifecycle guards as Generate (tree-kill on timeout, output-stat gate), but NO ComfyUI coupling: the env carries no COMFY_DIR and SkipFreeComfy suppresses the post-run /free (the seam the TTS path proved; audit seam 3).
func Inpaint ¶ added in v0.21.1
func Inpaint(ctx context.Context, req InpaintRequest) (string, error)
Inpaint re-renders ONLY the masked region of image on the LOCAL ComfyUI (free). Same lifecycle guards as Generate: gpugen tree-kill on timeout + deferred /free.
func OutputSize ¶ added in v0.206.0
OutputSize reads a PNG/JPEG/WebP header and returns its pixel size — the same three formats render/image-size.mjs measures, so the Go-side verification of an upscale sees every source the runner can pin a size for. (0, 0) when the file is unreadable or none of those formats; this never guesses a size it did not read.
func SourceFormat ¶ added in v0.206.0
SourceFormat names the reader that can measure path's header HERE: "png", "jpeg", "gif" (registered elsewhere in the binary), "webp" (webpSize), or "" for none. The pipeline uses it to tell a source the RUNNER can also measure (png/jpeg/webp — image-size.mjs) from one only Go reads (gif), which changes what a size mismatch means.
Types ¶
type BatchRequest ¶ added in v0.207.0
type BatchRequest struct {
Node string
Script string
ComfyDir string
JobsPath string
ResultsPath string
Model Model
Timeout time.Duration
ExtraEnv []string
}
BatchRequest is everything GenerateBatch takes besides the context. JobsPath is the JSONL job list and ResultsPath the per-job result file; the other fields mean what they do on GenerateRequest.
type ComfyLaunch ¶ added in v0.206.0
type ComfyLaunch struct {
// CudaDevice becomes `--cuda-device <n>` (ComfyUI device order). "" = no pin.
CudaDevice string
// DynamicVRAM is "on" | "off" | "" (leave the extra args alone).
DynamicVRAM string
// ExtraArgs are verbatim ComfyUI flags; "" = inherit the process's COMFY_EXTRA_ARGS.
ExtraArgs string
// API is the endpoint of the per-card ComfyUI instance this launch drives
// (COMFY_API); "" = the default instance, exactly as before. It also names where the
// post-run /free goes (Spec.ComfyAPI), so the instance that ran is the one freed.
API string
// CardUUID is the GPU uuid the instance is pinned to (COMFY_CARD_UUID; the runner
// sets CUDA_VISIBLE_DEVICES to it). "" = not card-bound. A uuid pin replaces CudaDevice:
// an index counts in a different order, and the runner refuses a launch carrying both.
CardUUID string
}
ComfyLaunch is a binding's ComfyUI launch profile, handed to the render runner as env (render/comfy-lifecycle.mjs reads it when it launches ComfyUI).
func (ComfyLaunch) Env ¶ added in v0.206.0
func (l ComfyLaunch) Env() []string
Env renders the profile. COMFY_CUDA_DEVICE and COMFY_DYNAMIC_VRAM are ALWAYS set, empty when unbound, so a value inherited from the operator's shell can never pin or reshape a route whose binding did not ask for it (the child env takes the last entry per key). COMFY_EXTRA_ARGS is set only when bound, because inheriting it IS the documented behaviour of an unbound box. COMFY_API and COMFY_CARD_UUID are set only for a per-card instance (the default instance keeps the two-entry env it always had); a card pin by uuid blanks the legacy index.
type EditModel ¶ added in v0.206.0
type EditModel struct {
Unet, Preset, LoRA, CLIP, VAE, Sampler, Scheduler string
LoRAStrength float64
Steps int
CFG float64
// Megapixels pins the working canvas (= the output resolution). 0 means "let the
// runner keep the source's own resolution, capped" — see config.GenEditMegapixels.
Megapixels float64
// Family selects the edit graph in comfy-edit.mjs ("" = the 2511 default;
// "qwen-image-2.1" = the multi-reference graph). Resolution and CacheDevice are
// that graph's knobs; the 2511-only binding knobs (preset, LoRA, megapixels) are
// NOT emitted for it, because the runner refuses a flag its graph never reads.
Family string
Resolution int
CacheDevice string
// Schedule is the 2.1 edit graph's sigma schedule ("comfy" | "turbo"; "" = the
// builder default, comfy). The 2511 graph never reads it.
Schedule string
// Placement is gen_edit_placement: "multicard" asks the runner for the card-only recipe (--placement multicard); "" and "single" emit nothing.
Placement string
Launch ComfyLaunch
}
EditModel binds the GENERATIVE, mask-free edit route (Qwen-Image-Edit class). Distinct from InpaintModel: no mask, no SDXL checkpoint — a diffusion-transformer unet plus its own text encoder and VAE, driven by a text instruction.
type EditRequest ¶ added in v0.207.0
type EditRequest struct {
Node string
Script string
ComfyDir string
Out string
Image string
Prompt string
Params map[string]any
Model EditModel
Timeout time.Duration
ExtraEnv []string
}
EditRequest is everything Edit takes besides the context. Image is the source picture; the other fields mean what they do on GenerateRequest.
type GenerateRequest ¶ added in v0.207.0
type GenerateRequest struct {
Node string
Script string
ComfyDir string
Out string
Prompt string
Params map[string]any
Model Model
Timeout time.Duration
Sampling *gpugen.Sampling
ExtraEnv []string
}
GenerateRequest is everything Generate takes besides the context. Node is the node executable ("" => "node"); Script is the absolute path to comfy-generate.mjs; ComfyDir is exported as COMFY_DIR for the script. Params may carry negative (string) and width/height/steps/seed (int-ish); Model carries the machine's image-model binding. A per-request steps param overrides Model.Steps. ExtraEnv appends additional "K=V" entries (LO-1: the pipeline threads a configured GPU_LOCK override so the runner contends on the same lock the Go vision gate watches). Sampling, when non-nil, turns on gpugen's passive per-render VRAM peak sampling (fleet footprints; nil = legacy path).
type InpaintModel ¶ added in v0.21.1
InpaintModel is the machine's inpaint binding (SDXL-class; see config). Inpainting is masked latent re-denoise (VAEEncodeForInpaint) — a pixel-space DiT (HiDream) cannot drive it, so this binding is separate from Model even on a HiDream box.
type InpaintRequest ¶ added in v0.207.0
type InpaintRequest struct {
Node string
Script string
ComfyDir string
Out string
Image string
Mask string
Prompt string
Params map[string]any
Model InpaintModel
Timeout time.Duration
ExtraEnv []string
}
InpaintRequest is everything Inpaint takes besides the context. Image is the source picture and Mask marks the region to re-render; the other fields mean what they do on GenerateRequest.
type Model ¶ added in v0.21.1
type Model struct {
Ckpt string // CheckpointLoaderSimple filename ("" = script default)
// VAE is a standalone VAE filename, or "builtin" to decode with the VAE the
// checkpoint loader supplies (required for HiDream: it ships no VAE weights, so a
// standalone 4-channel sdxl_vae cannot decode its output). "" = script default.
VAE string
Steps int // 0 = script default
CFG float64 // 0 = script default
Sampler string // "" = script default
Scheduler string // "" = script default
// ReserveVRAM is ComfyUI's --reserve-vram (GiB held back for the display) for
// this render. 0 = the script default (1.0). Lower = more weights resident during
// diffusion (small speed-up), at OOM risk near the VAE-decode peak. Per-machine.
ReserveVRAM float64
// Family selects the MODEL-CORRECT graph in comfy-render.mjs ("" = the generic
// SDXL-shaped graph). "hidream-o1" / "hidream-o1-dev" render the official
// pixel-space DiT graph (ModelNoiseScale, patch-seam smoothing, SamplerCustom,
// native 2048) — driving a DiT through the generic graph produces measurable
// 32px patch blocking. "qwen-image" renders the official Qwen-Image 2512 graph
// (SD3-class latent, AuraFlow shift, split text-encoder/VAE files; Ckpt carries
// the UNET filename). Which family a checkpoint belongs to is per-machine
// config, never shared code.
Family string
// Preset / CLIP / LoRA / LoRAStrength / Shift are the qwen-image family's
// remaining knobs (--preset picks a steps+cfg+LoRA pairing; the rest
// override its fields). Zero values emit no flag; other families ignore
// the flags if a config binds them anyway.
Preset string
CLIP string
LoRA string
LoRAStrength float64
Shift float64
// PoolVvramGB / PoolCompute / PoolDonor are the 32GB-pool doctrine knobs
// (krea2 family): GiB of DiT weights donated from the compute card to the
// donor card through the DisTorch2 ratio-mode loader. 0 = single-GPU loader
// (the small-fleet shape, no flags emitted). Which boxes pool is per-machine
// config, never shared code — same rule as Family.
PoolVvramGB float64
PoolCompute string
PoolDonor string
// Schedule is the qwen-image-2.1 sigma schedule ("official" | "comfy"; "" = the
// builder default). Other families never read it.
Schedule string
// Upsampler is imagegen_upsampler on the ComfyUI engine: BFL's prompt-upsampler file, which the flux3-klein graph runs in-graph before
// the render (--upsampler). "" emits nothing: the prompt renders verbatim. Other families never read it.
Upsampler string
// Placement is imagegen_placement: "multicard" asks the runner for the card-only recipe on the two cards of the lease (--placement multicard,
// render/multicard-image.mjs); "" and "single" emit nothing, so a box that binds none renders exactly what it rendered.
Placement string
// Launch is this binding's ComfyUI launch profile (env for the runner). The
// pipeline decides it — it knows whether the binding pools, and a pooled seat's
// placement belongs to its pool keys, never to a device pin.
Launch ComfyLaunch
}
Model is THIS machine's image-model binding, read from config. The harness is hardware- and model-agnostic: an 8GB laptop runs SDXL, a 16GB workstation may run a DiT (HiDream). No model name belongs in shared code, so every field here is optional — a zero Model passes no flags at all and comfy-render.mjs keeps its own defaults, leaving an existing SDXL machine byte-for-byte unchanged.
type SdcppModel ¶ added in v0.206.0
type SdcppModel struct {
Bin string // sd.exe path (exported to the runner as SDCPP_BIN). Required.
Model string // main model file (GGUF or safetensors). Required.
ModelKind string // ""/"checkpoint" => -m; "diffusion" => --diffusion-model
VAE string // companion weights ("" = not passed)
ClipL string
ClipG string
T5 string
LLM string // LLM-class text encoder (Z-Image: Qwen3 GGUF; sd.cpp --llm)
Steps int
CFG float64
Sampler string
ExtraArgs []string // verbatim sd.cpp args (--vae-on-cpu etc.; canary-decided)
}
SdcppModel is this machine's stable-diffusion.cpp binding (J2: the AMD/Vulkan tier's engine). All paths are FULL paths — sd.cpp has no ComfyUI-style model-dir convention. Steps/CFG/Sampler reuse the machine's imagegen_* sampler defaults.
type SdcppRequest ¶ added in v0.207.0
type SdcppRequest struct {
Node string
Script string
Out string
Prompt string
Params map[string]any
Model SdcppModel
Timeout time.Duration
Sampling *gpugen.Sampling
ExtraEnv []string
}
SdcppRequest is everything GenerateSdcpp takes besides the context (no ComfyDir: the sd.cpp path has no ComfyUI coupling). Fields mean what they do on GenerateRequest.
type UpscaleModel ¶ added in v0.206.0
type UpscaleModel struct {
Model string
}
UpscaleModel binds the ESRGAN-family upscale route: one ComfyUI upscale_models filename (4x-UltraSharp.pth, RealESRGAN_x4plus.pth, ...). The factor is the model's own; the runner rescales from it when a request asks for scale/size.
type UpscaleRequest ¶ added in v0.207.0
type UpscaleRequest struct {
Node string
Script string
ComfyDir string
Out string
Image string
Params map[string]any
Model UpscaleModel
Timeout time.Duration
ExtraEnv []string
}
UpscaleRequest is everything Upscale takes besides the context. Image is the source picture; the other fields mean what they do on GenerateRequest.