Repository navigation
Studio video: train, deploy and reload video LoRAs from the Video page - #17971
Conversation
VideoLoadRequest.loras takes the same LoraSpec list as the Images load. Ids resolve through the diffusion LoRA catalog, family-gated by the trainer sidecar, and each adapter is merged (scale * B @ A in float32) into the dense bf16 denoiser right after the pipeline is built, before any quantisation, compile, offload or streaming. - ltx-2, wan2.2-ti2v-5b and other single-denoiser diffusers pipeline loads bake into pipe.transformer; hosted pre-quantized denoisers and native quant caches are skipped for a LoRA load, and the cast, native and resident quant cache writes of the merged denoiser are dropped. - minimax-h3 bakes into the released bf16 denoiser after load_components; an unset precision is pinned to 'none', an explicit hosted scheme is refused. - GGUF and single-file picks and two-expert families are refused with a 400 before anything is evicted, as is a LoRA for another family. - Status reports baked_loras / baked_lora_specs; gallery entries record baked_loras. - Video LoRA training runs (DiT and MiniMax-H3) now publish into the LoRA catalog with their family sidecar, so the load can find them.
…s to load under a LoRA bake
…page
The video load bakes adapters into the denoiser (VideoLoadRequest.loras), so the
frontend now drives it end to end.
- Train panel: a finished video-family run shows "Deploy to Video" (it was
hidden). On Video it switches to Create and loads the family base with
loras: [{id, weight: 1}]; on Images the request is handed to Video and the
page navigates there. Image families keep "Deploy to Create" unchanged.
- Video load panel: on a full pipeline load, a LoRAs field (the Images
catalog and Add LoRA menu, filtered to the loaded family) with a weight per
adapter. The selection is threaded through the load and Reapply options.
It reseeds from status.baked_lora_specs whenever the resident build changes;
a selection that differs shows "Reload to apply", which reloads the model
with it. The baked set shows in the field, a header LoRA chip and the
clip recipe.
- GGUF and single-file loads never send loras; a plain pick sends nothing
new, so every non-LoRA load request is unchanged.
…clips out of view The LoRAs field and the clip recipe already show the baked set.
…LoRA loads with the dense denoiser Status reports lora_refusal (GGUF, single-file, two-expert families), so the Video page no longer offers a picker the load answers with a 400. The download plan takes the LoRA selection: it applies the same refusal and never stages a hosted quantized denoiser the LoRA load will not open.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea93456bf6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if baked_loras: | ||
| # Built from merged weights: never written back as a cache of the base model. | ||
| _discard_resident_quant_write(self, _load_token) | ||
| native_writes = None |
There was a problem hiding this comment.
Suppress immediate quant-cache writes for baked adapters
When a LoRA load uses an explicit torchao int8/fp8 precision and the base has no existing quant-cache entry, this cleanup happens too late: the transformer_quant_pinned is not None branch already calls _save_runtime_quant_to_cache() during quantization. That writer cannot detect this bake because mark_baked() marks the pipeline, whereas the writer checks the transformer's quant metadata and LoRA parameter names, neither of which records these in-place deltas. The merged weights can therefore be published under the bare base model's cache key, causing subsequent loads without the adapter to silently retain its effect while reporting no baked LoRAs. Guard the immediate cache-write path as well as the deferred writes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 37cd9ba: every quant-cache write branch after quantization (native, pinned precision, resident auto) now skips a LoRA bake, so a merged denoiser is never published under the base model's key. New test checks all writer calls sit behind that guard; it fails before the change.
| baked_loras = video_lora.resolve( | ||
| lora_specs, | ||
| family = getattr(fam, "name", None), | ||
| hf_token = hf_token, | ||
| cancel_event = self._cancel_event if _load_token is not None else None, |
There was a problem hiding this comment.
Preserve cache-only behavior when resolving video LoRAs
For a load with local_files_only=True and a remote LoRA ID, this resolution still accesses the network: diffusion_lora.resolve_specs() calls hf_hub_download_with_xet_fallback() without local_files_only, and bare repository IDs also invoke HfApi.list_repo_files(). The surrounding scoped_local_files_only decorator only exposes a context variable to prequant probes; these resolver functions do not consult it. Consequently, an otherwise cache-only video load can download an uncached adapter or fail on a network lookup even when its weights are cached. Thread the cache-only policy through adapter resolution and filename discovery.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 37cd9ba: local_files_only now reaches adapter resolution; catalog and bare repo downloads pass it through, and a bare repo id picks its weight file from the cached snapshot instead of listing the Hub (an uncached repo is a 400). New test fails before the change.
…fusion red on main) (#17974) ## Summary `(Python 3.13, diffusion)` is red on main (seen on the staging runs of #17966 and #17971): ``` studio/backend/tests/test_diffusion_flux3_fp32_calibrated.py::test_only_the_load_plan_reads_the_scaled_table E assert 2 == 1 ``` The test pinned that the scaled (float32) activation row, `_calibrated_activation(..., fp32_scaled = True)`, is read in exactly one place in `DiffusionBackend`: the load plan. #17949 (FLUX.3 Klein on T4) added a second read in the generation guard: ```python guard_measured = placement_measured_activation(state.pipe) if guard_measured is None and getattr(state, "calibrated_placement", False): guard_measured = _calibrated_activation(fam, guard_target, fp32_scaled = True) ``` That read re-uses the same row the calibrated placement was sized from, so the guard and the plan agree. It is intended, and it keeps what the test protects (an uncalibrated or post-load reader never sees the scaled row). The string count was just too blunt. ## Change Test only, `test_only_the_load_plan_reads_the_scaled_table`, now walks the AST instead of counting a substring: - exactly two `fp32_scaled=True` reads in `DiffusionBackend`; - one is the load plan's `calibrated_activation=` argument (still pinned verbatim); - the other must sit under an `if` whose test checks `calibrated_placement`. ## Testing - `test_diffusion_flux3_fp32_calibrated.py`: 10 passed. On main the test fails as above. - Sabotage: dropping the `calibrated_placement` condition from the guard fails it; adding a third scaled read fails it.
… and resolve adapters cache-only A LoRA load with an explicit int8 / fp8 precision wrote its quantized denoiser straight to the base model's quant cache (the pinned and native branches write during quantization, before the deferred-write cleanup), so a later plain load could pick up the adapter. Every quant-cache write branch now skips a LoRA bake. A cache-only load (local_files_only) still downloaded uncached adapters and listed a bare repo id's files on the Hub; the flag now reaches the adapter download and the file pick, which reads the cached snapshot. [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37cd9ba754
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| state = load_file(str(path)) | ||
| meta = _file_metadata(str(path)) | ||
| sidecar = None if meta else _studio_sidecar_alpha(str(path)) |
There was a problem hiding this comment.
Resolve companion scaling metadata for remote video adapters
When a remote PEFT adapter stores its scaling in adapter_config.json rather than safetensors metadata, diffusion_lora.resolve_specs() downloads only the weight file, so this metadata lookup finds no config on a fresh cache. The video bake then silently assumes lora_alpha == rank and disables rsLoRA scaling, producing different weights from the trained adapter while reporting a successful load. For example, rank 4 with alpha 8 is merged at scale 1 instead of 2. Resolve the companion config alongside the adapter weights, respecting local_files_only, before calculating the deltas.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0a5a1a0: resolution now fetches the adapter's adapter_config.json from the same repo folder and revision (cache-only when the load is), so lora_alpha / use_rslora from the companion config set the scale. New test: rank 4 / alpha 8 with the alpha only in the config bakes at scale 2; fails before the change.
…lpha / rsLoRA scale is honoured The resolver downloads only the weight file, so a PEFT adapter that records lora_alpha or use_rslora only in its companion adapter_config.json baked at alpha = r (rank 4 / alpha 8 merged at scale 1, not 2). Resolution now fetches that config from the same repo folder and revision, cache-only when the load is. [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0a5a1a0f91
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for slot, suffixes in (("a", _A_SUFFIXES), ("b", _B_SUFFIXES), ("alpha", (".alpha",))): | ||
| hit = next((s for s in suffixes if name.endswith(s)), None) | ||
| if hit is not None: | ||
| parts.setdefault(name[: -len(hit)], {})[slot] = tensor | ||
| break |
There was a problem hiding this comment.
Reject DoRA adapters before applying a plain LoRA delta
When a remote PEFT adapter has use_dora: true, this parser accepts its A/B factors but silently discards lora_magnitude_vector and subsequently bakes only scale * B @ A. The load therefore succeeds and reports the adapter as baked while producing different weights from the trained DoRA adapter. Remote safetensors adapters reach this path without a feature restriction; unlike _peft_terms() in diffusion_lora_quant_merge.py, it never checks use_dora. Reject these adapters before modifying the denoiser unless their magnitude normalization is implemented.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b78b215: resolution refuses a DoRA adapter (use_dora in its config, or lora_magnitude_vector / dora_scale keys) with a 400 before the resident model is touched. New test covers both forms and fails before the change.
…t of the prequant cache at the writer A DoRA adapter's per-weight magnitude cannot be reproduced by a plain scale * B @ A bake, so resolution now refuses it (use_dora in the adapter config or lora_magnitude_vector / dora_scale keys) before the resident model is touched. The bake also marks the denoiser it merged into, and save_runtime_quant skips a marked module, so no cache writer can publish a merged build under the base model's key. [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b78b215f24
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for slot, suffixes in (("a", _A_SUFFIXES), ("b", _B_SUFFIXES), ("alpha", (".alpha",))): | ||
| hit = next((s for s in suffixes if name.endswith(s)), None) | ||
| if hit is not None: | ||
| parts.setdefault(name[: -len(hit)], {})[slot] = tensor | ||
| break |
There was a problem hiding this comment.
Reject adapters with trained biases before baking
When a remote PEFT adapter uses lora_bias: true, this parser accepts its A/B weights but silently discards lora_B.bias. The subsequent bake changes only the base weight, so loading succeeds and reports the adapter as baked while omitting its trained bias contribution and producing incorrect outputs. The existing image implementation explicitly preserves and scales this tensor in diffusion_lora_files.py, and _peft_terms() in diffusion_lora_quant_merge.py refuses bias-bearing adapters when it cannot merge them exactly. Reject these adapters before modifying the denoiser, or implement the corresponding bias merge.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bfcddbe: an adapter with a trained lora_B bias (lora_bias in its config, or lora_B / lora_up bias keys) is refused at resolution, before the resident model is touched. The follow-up commit also refuses fan_in_fan_out adapters and ones carrying full-weight tensors (modules_to_save copies, .diff / .diff_b), which a weight bake would skip or transpose. Tests for each form fail before.
A weight bake adds scale * B @ A to the dense weights and has no place for PEFT's lora_bias term, so such an adapter loaded as baked while its bias was dropped. Resolution now refuses it (lora_bias in the config, or lora_B / lora_up bias keys) like a DoRA adapter, before the resident model is touched.
…ull-weight tensors A weight bake reads only lora A / B / alpha tensors and assumes the standard (out, in) layout, so modules_to_save copies and .diff / .diff_b tensors were skipped and fan_in_fan_out factors would merge transposed. Resolution now refuses those adapters with the reason, before the resident model is touched. [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
[skip ci]
Summary
A video LoRA trained in Studio could not be used in Studio: the Train panel hid Deploy for video families, and the Video load had no way to apply an adapter. This adds load-time LoRAs for video, end to end.
VideoLoadRequest.lorastakes the same[{id, weight}]list as the Images load. Each adapter is resolved through the diffusion LoRA catalog (gated to the family by its trainer sidecar) and merged into the dense bf16 denoiser in float32 right after the pipeline is built, before any quantisation, compile, offload or streaming.pipe.transformer. A LoRA load skips hosted pre-quantized denoisers and native quant caches, and the merged denoiser is never written to a quant cache.none, an explicit hosted scheme is refused.baked_loras,baked_lora_specsandlora_refusal; gallery clips recordbaked_loras.loras; a plain pick sends exactly what it did before.Results
Real GPU, one Colab G4 session, Studio built from this branch with
./install.sh --local, driven through the UI in headless Chromium:baked_loras = ["lm-wan_e2e"], request{"model_path": "Wan-AI/Wan2.2-TI2V-5B-Diffusers", "model_kind": "pipeline", "loras": [{"id": "lm-wan_e2e", "weight": 1}]}loras,baked_loras = []1280x704, 49 frames, 20 steps, seed 42, LPIPS (alex, mean of 49 frames):
The no-LoRA reload takes the default int8 denoiser while the LoRA load stays bf16; precision alone accounts for 0.16, so the adapter's effect is about 0.85.
Final head rerun (Colab G4, 36746e0)
Same flow on the final head, with a freshly trained LoRA (100 steps, 177 s, 11.5 GB peak):
loras,baked_lorasgoes to[]transformer_quant: "int8"lora_refusalon Wan2.2 TI2V 5Bnullon every loadScreenshots
Train panel, main vs this PR: a finished video run gets "Deploy to Video".
Video Create panel, main vs this PR: the LoRAs field with the baked adapter.
After removing the adapter, the panel asks to reload (from the G4 run):
Same seed and settings, with the tarot LoRA (left) and without (right), from the G4 run:
The two before/after panels come from local builds of main and this branch with identical faked server replies (this host has no GPU); everything else is from the real G4 run.
Tests
tests/test_video_lora_load.py: Wan and LTX-2 adapters bake the exactscale * B @ Adelta, refusal rules per kind, family and precision, status and plan carry the selection; fails on main.tests/test_video_routes.py: load and download-plan routes forwardlorasand map refusals to 400.studio/frontend/tests/video-lora-load.test.tsand the updated deploy tour test: 14 pass, the new wiring assertions fail on main.tscclean.Not covered