# Relight integration Implementation and source review: 2026-11-13. The reference workflow is Linoy Tsaban's public Hugging Face Space `linoyts/Qwen-Image-2.1-Relight`, reviewed at commit `cb161e026acd5cc09e661108706f72b6a99daa8b` (`app.py` and `README.md`). That revision renders a relighting prompt through `Qwen/Qwen-Image-2.1` with either Viggle's six-step accelerator or Pruna's eight-step accelerator. It does not load a relighting-specific LoRA. Placed light colours, directions, distance and softness become text instructions; this is generative image editing, not a physically calibrated light renderer. This integration is independently implemented for the existing studio. It reuses the loaded native `QwenImage21Pipeline`, its shared request lock, the existing optional user LoRA slots, and the common sampler selection: | Sampler | Required speed adapter | Sampling | | --- | --- | --- | | Turbo | Existing Viggle adapter | Six-step default; existing raw sigma schedule | | DMD2 v1.5 | Existing DMD2 adapter | Two steps, sigmas 1.0 and 0.5, CFG 1, fixed shift 1 | | Base | None | Thirty-step default and the saved original scheduler configuration | DMD2 and Base are studio extensions to the reference workflow. The checked upstream implementation uses Viggle and Pruna; it does not establish visual quality for our DMD2 or Base recipes. This module does not add Pruna, another base model, a task-specific adapter, a segmentation model or remote inference. No new model download is performed by Relight preparation or generation. The original implementation's custom HTML/CSS/JavaScript interface, example photos, generated examples, prompt strings and geometric registration code are not copied. Our presets, light validation, prompts and integration code are new. The checked upstream README has no explicit software-license field; this document does not assert a broader license for that source. Existing base-model and adapter licenses continue to apply, including the Qwen base model's terms. No new adapter license is introduced. ## Inputs and geometry The default is a soft white studio light from the viewer's left, full effect, approximately one megapixel, and the existing Turbo selector default. Presets also cover sunset, moonlight, pink/blue neon and rim light. Preset colour and direction defaults are visible to the caller; explicit UI colour and direction choices take precedence. The backend's `relight_lights` helper accepts one to three validated lights with `x` and `y` in 0..1, optional signed `z` in -1..1, six-digit hex `color`, and `intensity` in 0..2. Our image-plane origin is top left. Positive z faces the camera, negative z is behind the subject. These conventions are intentionally distinct from the upstream interface's low-to-high y and close-to-far z coordinates. Explicit advanced lights supersede the preset's stylistic sentence. CPU preparation normalizes EXIF orientation, composites transparency over white, validates settings and seed, generates the prompt, and resizes one reference to the target canvas. Megapixels are bounded to 0.5..2; dimensions are multiples of 32 with sides between 256 and 8192. The source's whole frame is retained with small aspect quantization from dimension rounding. Shared width/height controls do not override this source-derived canvas. The reference/output dimensions are a fixed point of the native pipeline's `calculate_dimensions(resolution ** 2, width / height)` equation. This was checked against `src/diffusers/pipelines/qwenimage21/pipeline_qwenimage21.py` at the existing pinned Diffusers commit `80c7ed262aeffbeb43ef13ae04baeb9b84515a69`. That pipeline resizes each condition image by the same equation before both text and VAE encoding. Thus the image used for optional blending has precisely the intended canvas dimensions. ## Effect blending and shared state The default effect amount is 1: return the model's RGB result. Optional lower amounts blend it with the prepared source in linear light on CPU, with sRGB conversion on input and output. Amount 0 returns the resized source pixels. The blend rejects differing dimensions, including at its endpoints. It never silently resizes generated output, crops borders, estimates alignment or warps the generated scene. Equal canvas sizes do not guarantee matching subject geometry; partial blending can reveal double edges when the model changes details. Identity, pose and scene preservation are prompt requests, not guarantees of unchanged pixels or identity. The GPU helper selects only the requested speed adapter plus optional user adapters; Base without optional adapters disables LoRAs entirely. Both success and inference/decode failure restore the entry scheduler, disable VAE tiling, re-enable LoRAs and select default Turbo alone. Reference encoding is untiled; only output decoding may use the shared VAE-tiling setting. CFG and negative prompts use the existing common guidance rules, while DMD2 always uses its trained two-step, CFG-one recipe. No sampler weights are fused. `test_relight_backend.py` checks CPU-only preparation, bounded light inputs, presets, source/canvas geometry, linear-light blending, all three sampler paths, optional adapter composition, CFG/cache accounting and restoration on failure through mocked pipeline calls. CPU tests establish these contracts; they do not establish GPU execution or visual fidelity.