Repository navigation
Wan on the diffusion runtime with LoRA plug-ins; offer them in TensorAgent - #434
Conversation
WanDenoiserGoldens writes four synthetic Wan DiT GGUFs (16, 36 and 48 input channels; F32, F16, Q8_0 and Q4_K matrices with F32 or F16 vectors) and five step cases (a uniform timestep, and TI2V's first latent frame at t = 0), and keeps the frozen velocities in MiniMaxH3ImageGoldens' format, one file a lane. WanLegacyFreezeTests (opt-in: TS_WAN_FREEZE_DIR, TS_WAN_FREEZE_BACKENDS) runs the native WanDiT on the pinned GGML backend and WanDirectDiT on cpu and cuda. Frozen here: ggml_cpu and cpu on the cloud container's Xeon (ggml bb877c0, unchanged). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
The five synthetic-checkpoint cases as the retired native DiT (ggml_cuda) and the retired direct DiT (cuda, cpu) gave them on an NVIDIA A40 host with an Intel Xeon Gold 6342, built from db1c686 with ggml bb877c0 unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
…oke pipeline Wan 2.1 T2V, 2.2 TI2V-5B and A14B (both experts) now generate only on DiffusionVideoPipeline. WanFamily ports the retired pipeline's request resolution, its UniPC and Euler schedules and its seeded noise, plus the TI2V first-frame replacement and A14B's 36-channel condition and expert switch. WanDenoiser runs the guidance passes, the CFG combine and the cfg-cache stride, and releases the first expert at the switch. WanTransformer emits the DiT as one replayable GraphProgram per geometry: - on the GGML graph executor, the retired native graph node for node; - on the cuda and cpu tensor executors, regions served by the retired direct DiT's kernels. LoRA plug-ins are new (WanLoraSet, an AdapterSet, plug-in type wan-lora), applied unmerged on every backend: - the ComfyUI, PEFT, kohya and diffusers key spellings; - bias and norm differences added exactly; - per-expert binding on A14B; - the step count from the config or the file name. Three configs ship: TI2V-5B Turbo and the A14B Lightning pair. New runtime pieces, all family-neutral: - UniPCFlowSampler; - the PairRotaryAttention region; - the layer-norm form of AdaLnModulate; - the bias form of RowNorm; - the direct engines' attention routing, now shared with the executors (CudaWanOps.Attention, DirectOps.HostAttention). Deleted: - WanVideoPipeline, WanDiT, WanDirectDiT, WanScheduler and WanUniPCScheduler; - the native DiT (TSGgml_WanDitForward and its resident cache) and its test; - the freeze harness. Their switches (TS_WAN_DIT_*, TS_WAN_NO_RESIDENT, TS_WAN_DIRECT_*, TS_WAN_DEBUG_DUMP) are refused at startup with advice, and each one's default is kept. ggml stays unpatched. Validated locally (Intel Xeon 2.10 GHz, ggml bb877c0 unchanged): - WanDenoiserTests: the retired steps' bytes on ggml_cpu and cpu in all five cases, and within 5e-2 of every other frozen lane. - WanLoraSetTests: the unmerged LoRA within 8.3e-7 (ggml_cpu) and 1.9e-7 (cpu) of merged weights. The GPU lanes and whole-clip A/B are validated separately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
… A/B tool's driver - The Wan model card (English and Chinese), USAGE, FEATURES, the capability reference and config/README describe the runtime path, --lora on Wan with the three shipped plug-ins, and the retired switches. - The design doc marks Wan migrated. - eng/validation/WanAbProbe gets a README and abba.sh, a generic alternating-order driver. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
…st to the mark The runtime's denoiser gives the retired DiT's step bytes in all five synthetic cases on every frozen lane: - ggml_cpu and cpu on an Intel Xeon 2.10 GHz; - ggml_cuda, cuda and cpu on an NVIDIA A40 host with a Xeon Gold 6342 (ggml bb877c0 unchanged; 91 of 91 Wan tests passed there with the GGML backend pinned to CUDA, none skipped). The unmerged LoRA test gives 2.6e-7 (cuda) and 1.2e-4 (ggml_cuda, F16 factors) of the merged weights, on a plug-in that moves the velocity by 52%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
… symbol manifest TSGgml_WanDitForward and TSGgml_WanResetForwardCache left the native library with the bespoke Wan DiT. Every listed name is a -u link root, so keeping them would fail the Release device link with "Undefined symbols". TensorAgentMauiProjectTests holds the manifest to the native sources' exports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
…s not offer - WanFamily resized the conditioning image through a bare ImageIO, which on the Apple targets resolves to Apple's ImageIO namespace (AppleTargetSourceTests). It now names QwenImage.ImageIO, as the other families do. - TensorAgent already offers a merged 4-step distilled checkpoint of TI2V-5B and of A14B, so the three wan-lora configs stay CLI and server plug-ins. They are listed, with that reason, in the configs the app does not offer (LoraCatalogTests). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
…ps work in place again On direct CUDA the runtime's Wan steps ran 1.3-3.5% slower than the retired direct DiT's (A40, steady-state step time; the frames bit-identical). The extra work was 9-30 ms a pass of copies and slow adds the retired DiT never made: - q and k copied before the pair rotary; - the residual stream copied in every gated residual; - each linear's bias added on the generic broadcast kernel, which indexes in 64-bit divisions. A session now donates an operand to the op or region about to read it when all of these hold: - the template's liveness has no other reader of it left; - it is an op's value its node owns; - nothing pins it; - no other tensor shares its storage. This is the tensor the session would release right after that reader. The executors use donation where the retired DiT worked in place: - the add of a donated operand and a bias row runs on the direct engines' row kernels (ts_add_bias_rows_f32, DirectOps' host rows); - CUDA's gated residual adds on the residual stream itself; - both tensor executors' pair rotary rotate donated q and k where their norms wrote them. The arithmetic is unchanged. A launch refused after an in-place write throws instead of falling back to the region's ops. WanDenoiserTests now also checks that the bias rows and the donated region inputs ran in place. Locally the managed executor gives the retired bytes in every frozen case with 42-50 bias rows added and 24 region inputs donated in place over the test's two predictions. The full suite and the A40 re-run are separate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
… tracing every prediction Every prediction emitted the whole program again (a hash-only trace checking the cached plan's signature) before the device got any work. That is host time the retired direct DiT never spent, about 0.1 ms a block. The tensor executors' later predictions of a geometry now rerun the trace that ran its first one, as LTX's denoiser reruns its step: - the same rotary tables, sequence and LoRA binding are the program's shape; - only the tokens, conditioning and timestep features are written again, into the arrays the trace binds. The GGML path still traces each prediction. WanDenoiserTests: a second step's values on the same plan give a fresh denoiser's bytes for them, and the first step's again give its own, on ggml_cpu and cpu locally (and the CUDA executor in the GPU run). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
…f the transformer's own nsys on the A40 (TI2V-5B at 2,730 tokens, direct CUDA) put the remaining step gap in host time between predictions, about 8-10 ms a pass with the device idle. The kernels' time matched the retired direct DiT's within 0.3%. The session copied every F32 input of every run through a new host array (the tokens, the 8 MB conditioning and both rotary tables: about 13 MB of large-object allocations, zeroed and copied, before each upload). On the tensor executors the transformer now binds these as device tensors of its own, as the retired direct DiT uploaded them: - the tokens and conditioning are uploaded from the caller's arrays each prediction; - the rotary tables are uploaded once for the trace that reruns them. The GGML path still binds host arrays. Locally the Wan, Studio and LoRA tests pass on ggml_cpu and cpu (1361 passed, the 36 CUDA ones skipped); the A40 run is separate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
nvidia-smi counts the CUDA pool's cached free blocks too, so a higher peak there need not be more allocated memory. The probe now samples the model's device allocator every 10 ms while a case runs and records its peak live bytes (peak_live_mib). It reads ModelBase's own field by reflection, so it still builds against any tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
…-clip A/B on ggml_cuda and cuda) The model card and the design doc (§3.14, Wan on the runtime as built) record: - the frozen steps given bit for bit on every lane; - whole clips identical to the retired pipeline's on ggml_cuda and direct cuda; - the steady-step and wall ratios, and the peak memory (A14B on ggml_cuda 2.5-4.1 GB lower); - the direct-CUDA step regression that nsys traced, and its fixes. The Turbo cuda round, the LoRA quality runs, the CPU clips and the A14B live-memory comparison are still running and are not claimed here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
…arrowing Binding the A14B Lightning pair took about 6.5 s at each expert's first step on the A40 (ggml_cuda, F16 factors), and the TI2V-5B Turbo plug-in about 4 s. The cost was 300M values an expert, stacked, scaled and narrowed one at a time, with a per-value half cast done twice (once to check that every value fits). The projections are now made in parallel. The narrowing is TensorPrimitives.ConvertToHalf (the same IEEE round to nearest even, written straight into the factor's memory). The fits check is one max-magnitude pass: no NaN, and every magnitude below 65520, the first value that rounds to infinity. WanLoraSetTests.HalfFactorsNarrowAsTheScalarConversion holds the vectorized narrowing to the scalar cast's bits (20,000 random values, subnormals, rounding ties and half's limit) and the fits check to the scalar one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
…e Turbo cuda round - LoRA: - unmerged against merged weights on all four backends; - the TI2V-5B Turbo plug-in against the merged Turbo checkpoint and a no-plug-in control; - the A14B Lightning pair and a bare Wan 2.1 DMD file; - the cost per step. - Memory: A14B's 0.57 GB higher nvidia-smi peak on direct CUDA is the pool's cached free blocks. The allocator's own live bytes peak 59 MiB lower. - Turbo: the cuda round is at parity per step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
… memory and LoRA evidence The Chinese model card gets the A40 validation tables and the LoRA results. Both cards record the parallel bind's cost at an expert's first prediction on ggml_cuda: about 1 s, or 2.5 s at A14B's switch, against 4-7 s before, with the factors and frames bit-identical. §3.14 records A14B's live-memory result and the LoRA evidence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
…red pipeline The clip was Wan 2.1 1.3B at 480x320x9, in three alternating rounds per backend on the A40 host's CPU quota, the last two with each process's CPU seconds. All runs gave the retired frames byte for byte: - ggml_cpu: 1.001x wall and 0.997x CPU time; - cpu: 0.987x wall, 0.987x CPU time and 0.973x steady steps. The first round's apparent 2% on ggml_cpu sat inside the single runs' spread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
The app's LoRA catalog lists the two Wan 2.2 step-distillation plug-ins the
engine ships configs for: Turbo 4-Step on the base TI2V 5B checkpoint and
Lightning 4-Step on the base I2V A14B pair. Lightning is one choice that the
engine is handed as two adapters, the high-noise half and then the low-noise
half, each with the config that names its expert (CatalogLora.ExtraParts,
LoraStore.SpecsFor). Neither is offered on the step-distilled entries (TI2V 5B
Turbo, I2V A14B LightX2V) or on the other Wan checkpoints; a choice that sits
out says why. Chat clips carry no steps or CFG for Wan, so the plug-in's
recipe (4 steps, guidance off) applies.
Studio refused a Wan clip whenever a plug-in was chosen ("wan takes no LoRA
plug-ins"), and it defaulted Wan to the base recipe even with the server's
--lora. It now plans the clip's default steps and guidance from the chosen
plug-ins (WanVideoModel.DistilledStepsWith, read from the configs and names
alone), as it does for a distilled checkpoint, with no fixed contract.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
The TensorAgent README describes Turbo 4-Step and Lightning 4-Step: where they are offered, the two-adapter Lightning pair under one switch, the recipe chat and Studio apply, and why they sit out on the other Wan entries. The Wan cards and the config README say that Studio follows a step-distillation plug-in's recipe and that the app embeds the same configs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
… A40 The specs TensorAgent's planner hands the engine (weights from the app's store with the config beside them, Lightning as two) give the same frames, bit for bit, as the configs passed as --lora, on ggml_cuda and cuda, for the TI2V-5B Turbo and A14B Lightning cases, and the same frames the engine's LoRA validation measured. No run in the app's own window is recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94fa3e0683
ℹ️ 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".
| float strength = spec.Scale ?? 1f; | ||
| if (!float.IsFinite(strength)) throw new ArgumentException($"LoRA {spec.Path}'s strength must be finite."); | ||
| // A wan-lora config's declarations win; bare weights are read by their file or folder name. | ||
| WanLoraConfig config = WanLoraConfig.Of(spec); |
There was a problem hiding this comment.
Honor the Wan plug-in config's default strength
When a wan-lora manifest specifies a non-default "scale" and the caller omits --lora-scale, the adapter is nevertheless applied at strength 1. LoraCliFlags.Resolve leaves the manifest attached as ConfigPath rather than copying its scale into the spec, and WanLoraConfig never reads that field, so spec.Scale ?? 1f silently discards the configured strength. Read and validate the manifest's scale and use the precedence explicit spec scale → manifest scale → 1, as the other plug-in loaders do.
Useful? React with 👍 / 👎.
| finally | ||
| { | ||
| _beat = null; | ||
| TrimDevicePools(); |
There was a problem hiding this comment.
Release component residency when a clip is cancelled
If a clip is cancelled during denoising, this cleanup only trims unused pool buffers and leaves the DiT's resident weight copies allocated. DiffusionVideoPipeline.Run deliberately skips ReleaseFailedPhase for OperationCanceledException and releases only workspaces; consequently, the normal ReleaseAfterPhase cleanup is never reached. Unlike the retired pipeline's unconditional ReleaseDeviceMemory() cleanup, cancelling a Wan clip can now leave several GB of VRAM occupied while the model stays loaded, preventing other workloads from using it. Release the pipeline's device residency in the request cleanup as well.
Useful? React with 👍 / 👎.
…lled clip's GPU memory - The local regression harness's catalog inventory listed no preset for the three config/lora/wan-*.json plug-ins, so test_every_config_has_one_inventory_entry failed (offline-harness on every OS). They are now plugin presets of the wan family; Turbo names config/wan-video-ti2v-5b.json as its base, and the Lightning halves note that they adapt the base I2V-A14B experts. - That config/wan-video-i2v-a14b.json is jayn7's merged lightx2v pair, a different 4-step distillation from the Lightning LoRA, is now what the Lightning configs, the config README and the Wan cards say; they had called the two the same. - A wan-lora config's "scale" was ignored: the strength is now the spec's (--lora-scale), else the config's, else 1, as for the other families' plug-ins, and a scale that is not a finite number is refused. - A cancelled or failed clip left the phase it stopped in resident (several GB of DiT weights), where the retired pipeline released all its device memory at a request's end. WanVideoModel now releases the pipeline's device memory after a clip that did not finish; a finished clip's path is unchanged. Checked here: the harness's 610 tests, audit and plan pass; the Wan, LoRA and Studio filters pass (349, 3 CUDA-only skips); TensorAgent's LoRA and catalog filters pass (332). The GPU check of the cancelled clip is a separate run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012qWiYcpkUFBdz4N2CfoVMi
Summary
Wan 2.1 T2V, Wan 2.2 TI2V-5B and A14B (both experts) now generate only on the unified diffusion runtime (
DiffusionVideoPipeline) and its tensor executors. The bespoke Wan pipeline, its native DiT and their switches are deleted. LoRA plug-ins are new and run on every backend, and TensorAgent offers Wan 2.2's two speed plug-ins.What changed
Runtime migration
WanFamilyports request resolution, the UniPC and Euler schedules, seeded noise, the TI2V first-frame replacement, and A14B's condition and expert switch.WanDenoiserruns guidance, the CFG combine and the cfg-cache stride.WanTransformeremits the DiT as one replayableGraphProgramper geometry. On the GGML executor it is the retired native graph, node for node; oncudaandcpuit is regions served by the retired direct DiT's kernels.UniPCFlowSampler, thePairRotaryAttentionregion, the layer-norm form ofAdaLnModulate, the bias form ofRowNorm, and shared direct-engine attention routing.LoRA plug-ins (
WanLoraSet, plug-in typewan-lora)config/lora/: TI2V-5B Turbo and the A14B Lightning high/low pair. Factor binding runs in parallel (about 1–2.5 s, down from 4–7 s, with bit-identical factors).Deleted
WanVideoPipeline,WanDiT,WanDirectDiT,WanScheduler,WanUniPCScheduler.TSGgml_WanDitForwardand its resident cache), its test and its Maui export entries.TS_WAN_DIT_*,TS_WAN_NO_RESIDENT,TS_WAN_DIRECT_*andTS_WAN_DEBUG_DUMPswitches. They are refused at startup with advice, and each one's default is kept.TensorAgent and Studio
CatalogLora.ExtraParts,LoraStore.SpecsFor).--lora. It now takes the default steps and guidance from the planned plug-ins (WanVideoModel.DistilledStepsWith), as it does for a distilled checkpoint. A request's own values still win.Validation
NVIDIA A40 host (Xeon Gold 6342) and a Xeon 2.10 GHz host. ggml
bb877c0, unchanged. Retired pipeline built fromdb1c686. Details are indocs/models/wan.md("Validation of the runtime migration") anddocs/design/diffusion-runtime.md§3.14.Quality
ggml_cuda,cuda,cpu,ggml_cpu), including after reruns.ggml_cpuandcpuon Wan 2.1 1.3B, 12 runs per backend.Performance (runtime / retired, steady-state step)
ggml_cuda: 0.959×–1.004×.cuda: 1.000×–1.005×. The 1.005× is A14B, where the expert switch compiles the low-noise program once a request (about 0.05 s).ggml_cpu: 1.001× wall, 0.997× CPU time.cpu: 0.973× steady, 0.987× wall.cudafollow the VAE decode, the same code in both trees, which varies by several seconds from run to run.Memory
ggml_cuda(15.0 → 10.9 GB, 13.2 → 10.7 GB).cuda, nvidia-smi shows +0.6 GB for A14B, which is the CUDA pool's cached free blocks. By the allocator's live bytes, the runtime's peak is 59 MiB lower.LoRA
cuda, 1.9e-7 oncpu, 8.3e-7 onggml_cpu, 1.2e-4 onggml_cuda(F16 factors).ggml_cuda, 20.7/23.5 dB oncuda; the no-plug-in control is 16.6/14.3 dB.ggml_cudaand 6.4–9.4% oncuda.The app's form
LoraSelection.Planfrom its store give the same frames, bit for bit, as the configs passed as--lora. This was checked onggml_cudaandcudafor TI2V-5B Turbo (1280×704×49, t2v and i2v) and A14B Lightning (640×384×17).Tests
TS_TEST_GGML_BACKEND=cuda), filtered to the Wan denoiser, Wan LoRA, Wan video, Studio Turbo and Web UI video-LoRA tests: 139 passed, 0 skipped.TensorAgent.Tests: 1669 passed, 0 failed, 172 skipped (live-model and platform-gated, not counted as passes).InferenceWeb.Tests, full suite in a cloud container: 14209 passed, 1 failed, 1478 skipped. The failure isLfm3RuntimeTests.ConcurrentRequestsOverRingsAreBatched(tp: 2, stages: 1): a batched CPU stream parted from its lone run at token 2 under suite load. It passed 3/3 when rerun alone, and this branch does not touch that code.Not validated
Generated by Claude Code