Three more capabilities on distinct untested surfaces (167 tests pass, no new runtime primitive). A — Adapter plane (§9.19): one base + swappable LoRA/ControlNet adapters, selected per request (DiffusionParams.adapters); AdapterDenoiseLoop applies each active adapter's velocity delta. Per-request selection changes output, multi-LoRA composes, ControlNet conditions on a control image, mixed-adapter requests interleave without smearing, hot-swap changes generation, cache key partitions by adapter stack (the adapter_versions field, previously declared-only). ToyLoRA/ToyControlNet; models/adapters/. 6 tests. B — Non-linear workflows (§9.17): ParallelWorkflow (fan-out: one input → N models → merged) and BestOfNWorkflow (generate N → score with the served reward card → return best; inference-time scaling). The shapes a linear chain can't express. 4 tests. D — RL→distill flywheel (§9.18): run_flywheel RL-improves the base (NFT), then distills FROM the RL'd model (DMD2 teacher = RL'd policy) into a faster card, recording the base→rl→distilled provenance chain in RecipeSpec.parents. The distilled student is measurably closer to the RL'd teacher than the base; the distilled card serves few-step. training/flywheel.py. 4 tests. designv4 §9.17–§9.19 + layout/closing/counts (167 tests, 29 files).
32 lines
1.4 KiB
Python
32 lines
1.4 KiB
Python
"""Adapter-serving program: control_signal → text_encode → diffusion_denoise(+adapters) → vae_decode."""
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
|
|
from ...program import ComponentNode, ModelLoopNode, Program, ProgramKind
|
|
from ..common import text_encode_node_fn as _text_encode
|
|
|
|
|
|
def _control_signal(instance, slots, request, ctx) -> None:
|
|
"""A ControlNet's conditioning image (pose/depth/edge) from the request → a slot the loop reads."""
|
|
img = request.image()
|
|
slots["control_signal"] = None if img is None else np.asarray(img.pixels, dtype="float32")
|
|
|
|
|
|
def _vae_decode(instance, slots, request, ctx) -> None:
|
|
slots["video"] = instance.component("vae").decode(slots["denoise_out"]["latents"])
|
|
|
|
|
|
def build_adapter_program() -> Program:
|
|
return Program(
|
|
program_id="wan.adapters", kind=ProgramKind.INLINE,
|
|
nodes=[
|
|
ComponentNode("control_signal", fn=_control_signal, writes=("control_signal",)),
|
|
ComponentNode("text_encode", fn=_text_encode, writes=("text_embeds", "neg_text_embeds")),
|
|
ModelLoopNode("denoise", loop_id="diffusion_denoise", output_slot="denoise_out",
|
|
reads=("text_embeds", "control_signal"), writes=("denoise_out",)),
|
|
ComponentNode("vae_decode", fn=_vae_decode, reads=("denoise_out",), writes=("video",)),
|
|
],
|
|
output_artifacts={"video": "video", "latents": "denoise_out"},
|
|
).validate()
|