Commit Graph
10 Commits
Author SHA1 Message Date
Jason HokuandClaude Fable 5.1 cd29abe52a feat(encode): batch several prompts through one text-encoder forward
encode_prompts_batched right-pads eligible prompts, runs ONE real encode on the
batch via a replay shadow on the inner encoder, and replays per-prompt slices
through the unmodified _encode_single (template strip, mask pop, clip_skip).
Allowlisted LLM-style encoders only (MOSS-Image, Krea 2, Qwen-Image); weighted,
AND/CAT/AVG/BREAK prompts fall back. Token cap, OOM halving, first-batch
self-check and an optional per-prompt verify mode. The shadow is always removed
in a finally. _encode_single gains tokens=None and restores clip_layer on error.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-04 00:02:16 -08:00
Jason HokuandClaude Fable 5.1 198138e51c perf(encode): prepare the text encoder once per pre-encode loop, not once per prompt
ComfyUI's CLIP.encode_from_tokens() calls load_model() -> model_management.load_models_gpu()
on every encode. With the dynamic VRAM loader (comfy_aimdo, 0.4x+) that re-runs
ModelPatcherDynamic.load() for a model that is already resident: a walk over every module plus
free_memory bookkeeping, visible as one

    Model MOSSImageTEModel_ prepared for dynamic VRAM loading. 7002MB Staged. ...

log line per prompt (N prompts -> N+1 lines). USCG's pre-encode paid it once per prompt, and
again on the single-encode paths (model switch, distributed, upscale, Florence2 hires).

Measured on the 5060 Ti (ComfyUI 0.42.5), MOSS-Image TE = Qwen3.5-9B w4a8, same process state:
  template path (CLIPTextEncode), per prompt ....... 0.92 s   (re-prepare every encode)
  USCG batch encode with pinned_clip, per prompt ... 0.84 s   (one prepare per pass)
  USCG job, 21 prompts + 21 one-step images ........ 36.8 s -> 33.0 s
  for scale: SDXL 0.15 s, Krea 2 0.29 s, Qwen-Image 0.32 s per prompt on the template path
The rest is the encoder forward itself: ~0.55 s fixed + ~2 ms/token for Qwen3.5-9B (24 of its
32 layers are Gated DeltaNet run through the pure-torch chunked recurrence, fp32 compute), so
a 60-prompt MOSS grid still spends ~50 s encoding before the first image. That part is
identical to the official workflow.

batch_encoding.pinned_clip(clip, texts): load once through load_model() (sized by the longest
text so any memory estimate still runs), shadow clip.load_model with a no-op for the block,
restore on exit or exception, nesting safe. encode_pair_cached(): positive+negative with one
load, nothing when both are cached. The pre-encode summary line now prints total time and
ms/prompt.

Applied to batch_encode_with_cache, the model-switch pre-encode in the main loop, the
distributed group pre-encode and per-job encode, the deferred-upscale re-encode fallback, the
dashboard upscale runner and the Florence2 hires step.

Tests: tests/test_pinned_clip.py (10) against the real batch_encoding module; the conftest
stub gained pinned_clip/encode_pair_cached. 137 passed, same 15 pre-existing torch-stub failures.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-03 22:16:43 -08:00
JasonHoku 2c15fe035a fix remote vae on distribution worker 2026-02-28 21:56:12 -08:00
JasonHoku 8e9a35272f Add remote vae custom endpoint option 2026-02-18 03:52:42 -08:00
JasonHoku e3e933fc08 Implement prompt combinators: AND, CAT, AVG(), BREAK. Consolidate dashboard topbar 2026-02-16 12:41:20 -08:00
JasonHoku acf5bfffc7 Implement text encoder outputs extra conditioning data 2026-02-15 12:30:53 -08:00
JasonHoku 41d7881c3e when user cancels job during text encoding step, actually cancel the full run, not just a single text encoding step 2026-02-15 00:12:47 -08:00
JasonHoku d0aacb906e Config Builder View Lora CivitAI Data Buttons, Cleaner Manifest, Auto Card & Row Sizes In Grid, Fixed Config Builder Lora Always Combining Loras, Easier Lora UI Settings 2026-02-13 00:23:20 -08:00
JasonHoku 30894c4c82 Massive Overhaul, Config Builder Updates, Fixes, Smarter Optional Caching, UI Improvements, Filter Improvements & More! 2026-02-10 16:30:10 -08:00
JasonHoku 9d1afab458 Major Refactor, Optimizations & New Features: Move & MetaPack Favorited, Random Lora Selection, Lora & Model Entire Folder Loading, Smart JSON Node, WIP Config Builder 2026-02-06 00:07:47 -08:00