chore: deploy private lightloom build
Browse files- README.md +4 -3
- app.py +6 -3
- src/lightloom/paint/lora.py +39 -0
- src/lightloom/paint/scroll.py +12 -0
README.md
CHANGED
|
@@ -82,9 +82,10 @@ models actually loaded) — verifiable live at `/health`.
|
|
| 82 |
evaluated, not loaded at runtime.
|
| 83 |
- **OpenAI — built with Codex.** See the attributed commit history.
|
| 84 |
- **Modal — credits prize.** A painterly **style LoRA** for FLUX.2-klein is trained on Modal
|
| 85 |
-
(`training/modal_lora/`, L40S, rank-16
|
| 86 |
-
the painter at warm-up for one cohesive hand-painted look
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
## Merit badges (evidence-linked)
|
| 90 |
|
|
|
|
| 82 |
evaluated, not loaded at runtime.
|
| 83 |
- **OpenAI — built with Codex.** See the attributed commit history.
|
| 84 |
- **Modal — credits prize.** A painterly **style LoRA** for FLUX.2-klein is trained on Modal
|
| 85 |
+
(`training/modal_lora/`, L40S, rank-16, 1500 steps), published as `Efradeca/lightloom-style-lora`, and
|
| 86 |
+
**fused into the distilled painter at warm-up** (0 ms/strip) for one cohesive hand-painted look — the
|
| 87 |
+
trigger `lghtlm style` is prepended to every painter prompt, gated by `LIGHTLOOM_STYLE_LORA`. Validated
|
| 88 |
+
base-vs-LoRA (photoreal → painterly). The adapter repo is private during the build (privacy mode).
|
| 89 |
|
| 90 |
## Merit badges (evidence-linked)
|
| 91 |
|
app.py
CHANGED
|
@@ -145,7 +145,7 @@ def health() -> dict[str, Any]:
|
|
| 145 |
"privacy_mode": os.getenv("LIGHTLOOM_PRIVACY_MODE", "1") == "1",
|
| 146 |
"cpu_count": os.cpu_count(),
|
| 147 |
"director_backend": CONFIG.director_backend,
|
| 148 |
-
"build": "
|
| 149 |
}
|
| 150 |
|
| 151 |
|
|
@@ -1069,6 +1069,9 @@ def _scroll_live_phrase(session: str, text: str, audio_b64: str, lang: str):
|
|
| 1069 |
# available, since the stored strip is seg-wide); smoothness comes from the morph prompt.
|
| 1070 |
h, overlap, seg = 512, 256, 384 # wider strips, partial overlap -> propagates less drift
|
| 1071 |
strips_per_phrase = 2 # fewer, wider strips per phrase
|
|
|
|
|
|
|
|
|
|
| 1072 |
# CLEAN per-strip outpaint: paint each strip as the scene description, carrying the
|
| 1073 |
# previous strip as context. (No ctx=None re-anchor — it created a hard cut every N
|
| 1074 |
# strips; long-session drift is fixed properly by the klein KV-cache reference anchor.)
|
|
@@ -1096,12 +1099,12 @@ def _scroll_live_phrase(session: str, text: str, audio_b64: str, lang: str):
|
|
| 1096 |
if aedge.size != use_ctx.size:
|
| 1097 |
aedge = aedge.resize(use_ctx.size)
|
| 1098 |
use_ctx = Image.blend(use_ctx, aedge, 0.25 + 0.45 * drift) # 0.25 mild .. 0.70 severe
|
| 1099 |
-
sec = outpaint_right(pipe, use_ctx,
|
| 1100 |
# also re-check the FRESHLY painted strip: if IT overflowed into corruption, repaint
|
| 1101 |
# once from scratch (no carried ctx) BEFORE saving/streaming, so the saturated strip is
|
| 1102 |
# never shown at all (the ctx-guard above only protects the NEXT strip, not this one).
|
| 1103 |
if _strip_looks_corrupt(sec):
|
| 1104 |
-
sec = outpaint_right(pipe, None,
|
| 1105 |
ctx = sec
|
| 1106 |
sec.save(out_dir / f"section-{g}.webp", "WEBP", quality=88)
|
| 1107 |
yield {
|
|
|
|
| 145 |
"privacy_mode": os.getenv("LIGHTLOOM_PRIVACY_MODE", "1") == "1",
|
| 146 |
"cpu_count": os.cpu_count(),
|
| 147 |
"director_backend": CONFIG.director_backend,
|
| 148 |
+
"build": "lora-live-1",
|
| 149 |
}
|
| 150 |
|
| 151 |
|
|
|
|
| 1069 |
# available, since the stored strip is seg-wide); smoothness comes from the morph prompt.
|
| 1070 |
h, overlap, seg = 512, 256, 384 # wider strips, partial overlap -> propagates less drift
|
| 1071 |
strips_per_phrase = 2 # fewer, wider strips per phrase
|
| 1072 |
+
from lightloom.paint.scroll import style_trigger # fused painterly-LoRA trigger ("" if LoRA off)
|
| 1073 |
+
|
| 1074 |
+
paint_prompt = style_trigger() + subject + style
|
| 1075 |
# CLEAN per-strip outpaint: paint each strip as the scene description, carrying the
|
| 1076 |
# previous strip as context. (No ctx=None re-anchor — it created a hard cut every N
|
| 1077 |
# strips; long-session drift is fixed properly by the klein KV-cache reference anchor.)
|
|
|
|
| 1099 |
if aedge.size != use_ctx.size:
|
| 1100 |
aedge = aedge.resize(use_ctx.size)
|
| 1101 |
use_ctx = Image.blend(use_ctx, aedge, 0.25 + 0.45 * drift) # 0.25 mild .. 0.70 severe
|
| 1102 |
+
sec = outpaint_right(pipe, use_ctx, paint_prompt, seg_w=seg, height=h, overlap=overlap, steps=4, seed=200 + g * 3)
|
| 1103 |
# also re-check the FRESHLY painted strip: if IT overflowed into corruption, repaint
|
| 1104 |
# once from scratch (no carried ctx) BEFORE saving/streaming, so the saturated strip is
|
| 1105 |
# never shown at all (the ctx-guard above only protects the NEXT strip, not this one).
|
| 1106 |
if _strip_looks_corrupt(sec):
|
| 1107 |
+
sec = outpaint_right(pipe, None, paint_prompt, seg_w=seg, height=h, overlap=overlap, steps=4, seed=211 + g * 3)
|
| 1108 |
ctx = sec
|
| 1109 |
sec.save(out_dir / f"section-{g}.webp", "WEBP", quality=88)
|
| 1110 |
yield {
|
src/lightloom/paint/lora.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Painterly STYLE LoRA — trained on Modal (`training/modal_lora/`, rank-16, klein-base-4B),
|
| 2 |
+
published to the Hub, and FUSED into the live distilled painter at warm-up for one cohesive
|
| 3 |
+
hand-painted look (a 2nd-axis smoothness fix: scene changes read as the same painted world).
|
| 4 |
+
|
| 5 |
+
Fusing at warm-up costs 0 ms/strip at inference. Gated by ``LIGHTLOOM_STYLE_LORA`` (default ON;
|
| 6 |
+
set to ``0`` to ship the raw photoreal klein). A LoRA load hiccup never breaks the painter — it
|
| 7 |
+
just falls back to the un-styled pipeline. Parameter contribution: 0B net runtime (a rank-16
|
| 8 |
+
adapter fused into the existing klein-4B weights — no new runtime model is loaded).
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import os
|
| 14 |
+
from typing import Any
|
| 15 |
+
|
| 16 |
+
STYLE_LORA_REPO = "Efradeca/lightloom-style-lora"
|
| 17 |
+
STYLE_LORA_WEIGHT = "pytorch_lora_weights.safetensors"
|
| 18 |
+
STYLE_TRIGGER = "lghtlm style"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def style_enabled() -> bool:
|
| 22 |
+
"""The painterly LoRA is on unless explicitly disabled."""
|
| 23 |
+
return os.getenv("LIGHTLOOM_STYLE_LORA", "1") != "0"
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def fuse_style_lora(pipe: Any) -> str:
|
| 27 |
+
"""Load + fuse the style LoRA into ``pipe`` once (call at warm-up). Returns the trigger
|
| 28 |
+
prefix to prepend to painter prompts (``"lghtlm style, "``), or ``""`` if disabled or the
|
| 29 |
+
load failed — in which case the painter still works, just un-styled."""
|
| 30 |
+
if not style_enabled():
|
| 31 |
+
return ""
|
| 32 |
+
token = os.getenv("HF_TOKEN") or os.getenv("HF_READ_TOKEN") or os.getenv("HF_WRITE_TOKEN")
|
| 33 |
+
try:
|
| 34 |
+
pipe.load_lora_weights(STYLE_LORA_REPO, weight_name=STYLE_LORA_WEIGHT, token=token)
|
| 35 |
+
pipe.fuse_lora()
|
| 36 |
+
return STYLE_TRIGGER + ", "
|
| 37 |
+
except Exception as exc: # noqa: BLE001 - a LoRA hiccup must never break narration.
|
| 38 |
+
print(f"[paint.lora] style LoRA fuse skipped ({STYLE_LORA_REPO}): {str(exc)[:160]}")
|
| 39 |
+
return ""
|
src/lightloom/paint/scroll.py
CHANGED
|
@@ -22,6 +22,12 @@ SCROLL_TRIGGER = (
|
|
| 22 |
|
| 23 |
|
| 24 |
_FAST_PIPE: Any = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
def encode_scroll_embeds(pipe: Any, prompt: str) -> Any:
|
|
@@ -72,6 +78,12 @@ def load_fast_pipeline() -> Any:
|
|
| 72 |
pipe = Flux2KleinInpaintPipeline.from_pretrained(
|
| 73 |
ref.repo_id, revision=ref.revision, torch_dtype=torch.bfloat16
|
| 74 |
).to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
_FAST_PIPE = pipe
|
| 76 |
return pipe
|
| 77 |
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
_FAST_PIPE: Any = None
|
| 25 |
+
_STYLE_TRIGGER: str = "" # set at warm-up by fuse_style_lora(); "" if the painterly LoRA is off
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def style_trigger() -> str:
|
| 29 |
+
"""Prompt prefix that activates the fused painterly style LoRA (``""`` if not fused)."""
|
| 30 |
+
return _STYLE_TRIGGER
|
| 31 |
|
| 32 |
|
| 33 |
def encode_scroll_embeds(pipe: Any, prompt: str) -> Any:
|
|
|
|
| 78 |
pipe = Flux2KleinInpaintPipeline.from_pretrained(
|
| 79 |
ref.repo_id, revision=ref.revision, torch_dtype=torch.bfloat16
|
| 80 |
).to("cuda")
|
| 81 |
+
# Fuse the painterly STYLE LoRA (trained on Modal) at warm-up -> one cohesive hand-painted
|
| 82 |
+
# world at 0 ms/strip. A load failure falls back to the un-styled painter (trigger == "").
|
| 83 |
+
global _STYLE_TRIGGER
|
| 84 |
+
from lightloom.paint.lora import fuse_style_lora
|
| 85 |
+
|
| 86 |
+
_STYLE_TRIGGER = fuse_style_lora(pipe)
|
| 87 |
_FAST_PIPE = pipe
|
| 88 |
return pipe
|
| 89 |
|