Skip to content

Studio: image-to-video for Wan2.2-TI2V-5B and LTX-2 / LTX-2.3 - #13378

Merged
danielhanchen merged 17 commits into
mainfrom
studio-video-i2v
Oct 12, 2026
Merged

danielhanchen merged 17 commits into
mainfrom
studio-video-i2v

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Image-to-video for Wan2.2 TI2V 5B and LTX-2 / LTX-2.3 in Studio

Fixes #13321 (image to video for Wan 2.2 5B and others).

Every video family entry in Studio names exactly one text-to-video pipeline (WanPipeline, LTX2Pipeline, HunyuanVideo15Pipeline), so a starting image had nowhere to go: only MiniMax-H3 took a first frame. Image-to-video is the most downloaded video category on the Hub, and both Wan2.2-TI2V-5B (the same checkpoint is text and image to video) and LTX-2 / LTX-2.3 already load in Studio.

What changes

Family table. VideoFamily gains an optional i2v_pipeline_class (plus i2v_pipeline_config and i2v_call_kwargs for per-family construction values and call kwargs). Any family can declare one; adding Wan2.2-I2V-A14B or another family later is a table entry.

Family Text-to-video First frame Last frame
wan2.2-ti2v-5b WanPipeline WanImageToVideoPipeline no
ltx-2 (2.0 and 2.3) LTX2Pipeline LTX2ImageToVideoPipeline no
minimax-h3 modular fl2va native keyframes (unchanged) yes
wan2.2-t2v-a14b, hunyuanvideo-1.5 (480p / 720p) unchanged refused (400) refused

No second load. A request with a first frame runs the i2v class's __call__ against the pipeline object Studio already built. The i2v class is constructed once over the loaded components only to read the instance state its __init__ sets (its config, its video_processor, the empty image_encoder / image_processor slots); for the duration of that one render the loaded pipeline takes that class and state, and both are put back afterwards, on success, cancel or failure. Weights, GGUF / prequant int8 / fp8 layers, offload hooks, compiled blocks, the prompt cache and CUDA-graph bookkeeping are the ones text-to-video uses. Text-only requests never enter this path.

DiffusionPipeline.from_pipe was the obvious tool but ends with new_pipeline.to(dtype=...), which defaults to float32: it would upcast every shared module (a full extra copy of the DiT, and Wan's fp32 VAE / bf16 DiT split undone). A test pins that behaviour so the reason stays visible.

Defaults follow the official reference workflow templates (video_wan2_2_5B_ti2v, video_ltx2_i2v, video_ltx2_3_i2v):

  • Canvas: with width / height omitted, the resolution preset nearest the picture's aspect (Wan 1280x704 or 704x1280; LTX 768x512, 1216x704, 704x1216, 512x768), and the picture is centre-cropped onto it, as Wan22ImageToVideoLatent and the LTX resize node do. An explicit size still wins.
  • Frames, steps, guidance, shift: the families' existing defaults already match the templates (Wan 121 frames, 20 steps, CFG 5, shift 8; LTX dev 40 / 4.0, distilled 8 steps unguided).
  • Conditioning strength: full (the first latent is held clean), which is what Wan22ImageToVideoLatent does and what LTX's LTXVImgToVideoInplace uses at strength 1.0 in the 2.0 template and the 2.3 refine stage.
  • LTX conditioning-frame compression: CRF 18 for LTX-2.3 (LTXVPreprocess in the 2.3 template), the diffusers default 33 for LTX-2.0 (same as its template).

Detector fixes.

  • hunyuanvideo-community/HunyuanVideo-1.5-Diffusers-480p_i2v (and 720p_i2v, the distilled i2v repacks, i2v GGUFs) were claimed by the t2v families and would have been built as HunyuanVideo15Pipeline over i2v weights. They are now refused at load validation with a message naming the t2v repos to use. Serving them needs HunyuanVideo15ImageToVideoPipeline with its own transformer and SigLIP image encoder, which is a new family rather than a first-frame toggle.
  • Lightricks/LTX-Video (0.9.x, a different architecture) and ltxv-2b / ltxv-13b GGUFs were routed into the ltx-2 family through its ltx-video / ltxv aliases. They are refused with a message pointing at LTX-2 / LTX-2.3. Anything naming LTX-2 itself (ltx-2, ltx-2.3, LTX-Video-2, an LTX-2.3 file inside a folder called ltx-video) is untouched.

API. /api/video/generate and /v1/videos input_reference accept first_frame for every family that declares one; last_frame stays MiniMax-H3 only and is refused elsewhere with "animates from a first frame only". /api/video/status adds supports_first_frame, supports_last_frame and defaults.canvas_from_presets; supports_keyframes keeps its MiniMax-H3 meaning for older frontends.

Frontend. The Video page reads the per-frame fields (falling back to supports_keyframes on an older backend). Wan2.2 TI2V 5B and LTX-2 show one Start frame dropzone, MiniMax-H3 keeps start and end. Match source previews the preset the backend will pick, and the 1:4 to 4:1 warning stays MiniMax-H3's.

stable-diffusion.cpp. Studio only routes MiniMax-H3 GGUFs to sd.cpp (is_h3_native); Wan2.2 and LTX GGUFs always run on Diffusers, so there is no sd.cpp path to pass the first frame through for these families and nothing changes there.

Evidence

One B200, Studio's own VideoBackend (load, then generate), GGUF loads, seed 1234, 25 frames, default speed settings. BEFORE is the merge base (fcee6485fe), run twice in separate processes for an A/A; AFTER is this branch, one process rendering text-to-video, image-to-video, image-to-video with no size, then text-to-video again. The first frame is a 16:9 crop of the Wan2.2 repo's example image. The PSNR / LPIPS (AlexNet) reference is that image centre-cropped onto the render canvas, compared against decoded frames of the saved MP4.

Text-to-video is byte-identical (same MP4 sha256 and same decoded frames):

Model Placement BEFORE A BEFORE B AFTER t2v AFTER t2v after the i2v renders
Wan2.2-TI2V-5B Q4_K_M, 1280x704, 20 steps resident 9e63d3a2 9e63d3a2 9e63d3a2 9e63d3a2
Wan2.2-TI2V-5B Q4_K_M, 1280x704, 20 steps low_vram (model offload + CUDA graphs) 26d6a637 26d6a637 26d6a637
LTX-2.3 22B distilled Q4_K_M, 768x512, 8 steps resident bd8b1e3b bd8b1e3b bd8b1e3b bd8b1e3b

The last column also shows the class swap leaves nothing behind: text-to-video rendered after image-to-video on the same loaded pipeline is the same file, including under offload hooks and CUDA graphs.

Frame 0 follows the input image:

Model Canvas Frame 0 PSNR / LPIPS Middle frame Last frame Text-to-video frame 0 (control)
Wan2.2-TI2V-5B, resident 1280x704 35.46 dB / 0.050 31.65 dB / 0.055 30.91 dB / 0.059 7.44 dB / 0.859
Wan2.2-TI2V-5B, low_vram 1280x704 35.42 dB / 0.051 31.58 dB / 0.056 30.96 dB / 0.060 7.44 dB / 0.859
LTX-2.3 distilled 768x512 29.90 dB / 0.053 28.96 dB / 0.059 10.35 dB / 0.739 9.62 dB / 0.824

LTX-2.3's frame 0 is a little lower because the frame is re-encoded at CRF 18 before conditioning, as the reference workflow does. Its last frame cuts to the prompt's scene (a car on a coastal road, unrelated to the picture on purpose so conditioning cannot be mistaken for the prompt); Wan holds the picture for the whole one-second clip.

With width and height omitted, the 832x468 picture picked 1280x704 on Wan and 1216x704 on LTX (the presets nearest 16:9), and Wan's clip was identical to the explicit 1280x704 render.

Cost is the same as text-to-video once warm. Resident Wan, same process: image-to-video 23.9 s (VAE encode 0.59 s, DiT 20.8 s) against 23.2 s for text-to-video (DiT 20.9 s). LTX-2.3: 6.5 s against 7.9 s. The image-to-video renders were bit-identical across the two branch runs. Two one-time costs showed up: the very first image-to-video render on this machine took 175 s against 22 s for text-to-video in the same process (cold kernel caches for a path text-to-video never runs; the same sequence took 23.9 s in every later process), and under low_vram switching between text and image-to-video re-captures the denoiser's CUDA graph once (it is keyed on the call's input tree, and the image-to-video call passes an extra encoder_hidden_states_image=None).

Tests

Backend, the 71 video / keyframe / detector test files plus the new tests/test_video_i2v.py, CPU, same Studio venv:

passed failed skipped
merge base 5532 4 138
this branch 5589 4 138

The 4 failures are the same test ids on both sides and unrelated (test_build_prequant_checkpoint canonical id, three test_diffusion_h3_trainer rotation tests). test_diffusion_cold_start.py (background compile): 39 / 39 on both.

New coverage:

  • tests/test_video_i2v.py: the family table (which families take a first and a last frame, i2v class never equals the t2v class), request validation (first frame accepted only where declared, last frame refused by first-frame-only families, text-only requests never judged), nearest-aspect canvas, the LTX-2.3 CRF row, both detector refusals and the ids they must not refuse, load validation refusing before any load, and the class swap over a real tiny diffusers WanPipeline (expand_timesteps=True): same object, no parameter moved or cast, overlay removed, text-to-video after an image-to-video render bit-identical, restore on failure, a component assigned mid-swap staying registered, plus a test pinning why from_pipe is not used.
  • tests/test_video_backend.py: Wan and LTX first-frame renders through VideoBackend.generate on the fake runtime (the i2v __call__ runs on the loaded object, canvas and crop, CRF 18 for 2.3 only, text-to-video untouched afterwards, swap undone when the render raises, a last frame refused, a diffusers without the i2v class reporting no first frame and refusing the request before reserving the backend).

Frontend (node --test tests/**/*.test.ts): 11324 / 11324 on the merge base, 11333 / 11333 here. New: video-keyframe-canvas.test.ts (nearest-preset preview pinned to the backend's pairs, per-frame support with the legacy fallback) and video-start-frame-upload.test.ts (each dropzone gated on its own frame, payload gating, staged frames dropped per frame, the 1:4 to 4:1 warning H3-only). tsc -b and tsc -p tsconfig.test.json are clean; Biome reports no new diagnostics on the touched files.

Not tested

  • HunyuanVideo-1.5 image-to-video is refused, not served. It needs HunyuanVideo15ImageToVideoPipeline with the i2v transformer and a SigLIP image encoder (a new family entry with its own memory plan), not a first-frame toggle on the t2v family.
  • LTX-2.0 (Lightricks/LTX-2, 19B) was not rendered on a GPU; it shares the LTX-2.3 path and the pipeline default CRF. Only Q4_K_M GGUFs were rendered (resident, and Wan under low_vram model offload with CUDA graphs): the prequant int8 / fp8 DiT, NVFP4, bf16 pipeline loads, group / sequential offload and torch.compile (regional or background) were not exercised with a first frame on a GPU. They act on the same pipeline object and modules the swap reuses, but that is reasoning, not a render. The background-compile interaction is covered by a unit test only.
  • The UI was not screenshotted against a live Studio; the dropzone gating is covered by source-level tests and the typecheck.
  • LTX-2.3's reference template is two-stage (half-resolution pass with the image at strength 0.7, then a 2x latent upscale refined at 1.0). Studio renders LTX in one pass, so it uses full strength; there is no diffusers knob for a partial strength on LTX2ImageToVideoPipeline. ltx-pipelines' own default CRF is 33 for every Gemma3 generation, while the 2.3 reference template uses 18; this follows the template.
  • Windows, macOS (MPS) and AMD did not run; nothing here is platform specific, but MPS image-to-video is unverified.

…peline

A video family can now name an image-to-video pipeline class
(i2v_pipeline_class). A request carrying a first frame runs that class's
__call__ over the pipeline Studio already loaded, so the weights, GGUF /
prequant layers, offload hooks, compiled blocks and CUDA graphs are the
ones text-to-video uses and nothing is loaded or copied. Text-only
requests never enter the new path.

Wan2.2-TI2V-5B declares WanImageToVideoPipeline and LTX-2 / LTX-2.3
declare LTX2ImageToVideoPipeline. Without width/height a first frame takes
the resolution preset nearest its aspect and is centre-cropped onto it, as
ComfyUI's i2v templates resize it; LTX-2.3 re-compresses the frame at CRF
18 like its ComfyUI template.

The detector no longer builds the wrong pipeline: LTX-Video 0.9.x picks
and HunyuanVideo-1.5 i2v repacks are refused at load validation with a
message naming what to load instead.

Status reports supports_first_frame / supports_last_frame per keyframe and
canvas_from_presets; a last frame stays MiniMax-H3 only.
The Video page reads supports_first_frame / supports_last_frame (falling
back to supports_keyframes on older backends): Wan2.2 TI2V 5B and LTX-2
get a single Start frame dropzone, MiniMax-H3 keeps start and end. Match
source previews the preset nearest the picture for families that report
canvas_from_presets, and the 1:4 to 4:1 warning stays MiniMax-H3's.
… swap to

A first frame on Wan2.2-TI2V-5B now runs WanImageToVideoPipeline over the
loaded pipe, so the fake runtime needs that class for the render to reach
the step-skip arming the test checks.
… gate on diffusers

- A first-frame render that lands while a background compile is still
  recording runs eager but unrecorded, so the compiled trace is always
  learned from text-to-video inputs (LTX-2's image-to-video passes a
  per-token timestep).
- supports_first_frame is only true when this diffusers exports the
  family's image-to-video class, and a first frame is refused up front
  otherwise instead of after the render is reserved.
- A component assigned mid-render keeps its registration in the restored
  pipeline config.
- The LTX-2.3 CRF row also matches ltx23 names.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T14:21:06.022075Z 636d377 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 92f7519225

ℹ️ 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".

@danielhanchen

Copy link
Copy Markdown
Member Author

(Python 3.13, rest) fails on this head (9639477528) in the test this PR adds:

tests/test_video_i2v.py:378: in test_a_component_assigned_mid_swap_stays_registered_after_it
    import diffusers
E   ModuleNotFoundError: No module named 'diffusers'

The backend test shard does not install diffusers. That test either needs pytest.importorskip("diffusers"), or should use a stub module like the other video tests do, so it still runs here. The run merged onto 0b1291bfd7, so this is specific to this PR.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89b1c5f8b8

ℹ️ 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".

Comment thread studio/backend/core/inference/video.py Outdated
Comment on lines 9810 to 9812
if bg_eager and not i2v_active:
bg.note_eager_generation()
bg.kick()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Let image-only workloads finish background compilation

When background compilation is armed and users generate only image-to-video clips, every request enters with bg_eager, but this condition prevents both note_eager_generation() and kick(). Because the I2V path also suppresses sample recording, the compiler remains in recording forever, so all subsequent I2V renders are forced through the eager gate and never receive the configured compile optimization. The I2V path should either provide a compatible compile sample or explicitly resolve/disable the pending compiler rather than leaving it permanently pending.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 457f06f. When the background compile is armed, a successful image-to-video render now calls kick() at the end. If there are no recorded samples to compile from, the compile is abandoned, so later renders compile inline instead of staying eager. If an earlier cancelled text-to-video render did record samples, the background compile starts from those. Text-to-video renders behave as they did before. BackgroundCompile.abandon() only acts while the compile is still recording. Tests: test_an_image_only_session_does_not_leave_the_background_compile_pending, test_a_text_render_still_kicks_the_background_compile.

"This is an LTX-Video 0.9.x checkpoint, a different architecture from LTX-2 that Studio does not "
"run. Load LTX-2 or LTX-2.3 instead (for example unsloth/LTX-2.3-GGUF)."
)
_HV15_I2V_RE = r"(?<![a-z0-9])i2v(?![a-z0-9])"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Match Hunyuan I2V markers on the checkpoint, not its path

For local Hunyuan T2V checkpoints stored beneath a directory such as /models/i2v/HunyuanVideo-1.5-Diffusers-480p_t2v, this unrestricted token regex matches the parent directory. video_checkpoint_refusal() searches the joined repo path, display ID, and filename, so it rejects the valid T2V checkpoint as an unsupported I2V model even though the checkpoint name explicitly says t2v. Restrict the refusal to the checkpoint identifier or exempt an explicit T2V identifier.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 457f06f. The i2v marker now has to appear in the last path segment of an identifier, so an owner or parent folder named i2v no longer refuses a _t2v checkpoint. A trailing slash is still allowed. An i2v repo name or GGUF filename is still refused. Tests cover owner, POSIX parent and Windows parent folders, plus the cases that must still be refused.

Comment on lines +9424 to +9428
pipe = i2v_swap.enter_context(
first_frame_pipeline(
pipe,
fam.i2v_pipeline_class,
config_overrides = dict(getattr(fam, "i2v_pipeline_config", ()) or ()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rewire model-offload hooks for the I2V execution order

When state.offload_policy is model, the existing hooks were installed while this object was a T2V pipeline, whose sequence places the transformer before the VAE. The I2V call instead uses the VAE to encode the conditioning image before denoising, but changing __class__ here does not rebuild the already-linked hooks; when the transformer subsequently onloads, its original predecessor hook does not offload that prematurely loaded VAE. On memory-constrained configurations this leaves the VAE resident alongside the DiT even though the memory plan promises one top-level module at a time, which can turn an otherwise fitting low-VRAM render into an OOM.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real, though the class swap is not the cause. In diffusers 0.41.0, WanImageToVideoPipeline and LTX2ImageToVideoPipeline both put vae after transformer in model_cpu_offload_seq, same as the T2V classes (Wan I2V also lists image_encoder, which TI2V-5B does not have). That means the stock I2V pipelines build the same chain. The first-frame vae.encode loads the VAE, but the transformer's hook only offloads the text encoder, so the VAE stays on the GPU through denoising. While the swap is active and model offload hooks exist, vae.encode is now wrapped to run the VAE's CpuOffload.init_hook once the encode returns. The wrapper is removed when the swap exits on success, cancel or failure. Text-to-video never goes through it. Test: test_model_offload_sends_the_vae_back_before_the_first_frame_denoise installs real accelerate offload hooks on the tiny Wan pipeline and checks that the VAE is no longer resident when each transformer forward starts.

Comment thread studio/backend/core/inference/video.py Outdated
Comment on lines +9432 to +9436
fam,
state.variant_id,
state.gguf_filename,
state.display_repo_id,
state.repo_id,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include the resolved base repo when selecting LTX I2V defaults

For an LTX-2.3 fine-tune loaded from a neutral local filename/path with base_repo=Lightricks/LTX-2.3, variant_id can legitimately be None when the content hash is not one of the known releases. Although state.base_repo then remains the authoritative 2.3 identifier and is already used by the distilled/default-parameter checks below, it is omitted from this lookup, so the image request silently keeps Diffusers' CRF 33 instead of the declared LTX-2.3 CRF 18. Pass state.base_repo as another identifier so custom 2.3 checkpoints receive the intended conditioning preprocessing.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 457f06f. state.base_repo is now one of the identifiers used to pick the I2V call kwargs, matching the distilled and default-parameter lookups. A neutrally named fine-tune with base_repo=Lightricks/LTX-2.3 gets image_crf=18. With Lightricks/LTX-2 it keeps the pipeline default. Test: test_ltx23_crf_follows_the_declared_base_repo_of_a_neutrally_named_checkpoint.

Comment on lines 643 to +647
validate_video_keyframe_conditioning(
fam, h3_task, has_keyframes = bool(request.first_frame or request.last_frame)
fam,
h3_task,
has_keyframes = bool(request.first_frame or request.last_frame),
has_last_frame = bool(request.last_frame),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check runtime I2V availability before auto-switching

When media auto-switch is enabled and the installed Diffusers build lacks the target family's I2V class, this preflight accepts a first-frame request solely because the family table declares support. The switch then evicts the resident model and spends the full target load before begin_generate() finally rejects the frame via _i2v_pipeline_available(), defeating this hook's stated purpose of refusing unservable requests before eviction. Check the target family's runtime pipeline availability here as well; the OpenAI /v1/videos pre-switch check has the same family-only gap.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in both places in 457f06f. The begin_generate check is now a shared assert_first_frame_pipeline_available(fam). Both the /video/generate and /v1/videos pre-switch hooks call it when the request carries a first frame, so a missing I2V class is refused before anything is evicted or loaded. Test: test_a_first_frame_without_the_i2v_class_is_refused_before_the_model_switch covers both routes.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34a586d97e

ℹ️ 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".


def video_checkpoint_refusal(fam: VideoFamily, *identifiers: Optional[str]) -> Optional[str]:
"""Identifiers are joined into one line so an LTX-2.3 filename excuses an ``ltx-video`` folder."""
joined = " | ".join(_identifier_blob(identifiers))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Refuse old LTX checkpoints even inside LTX-2 paths

When an LTX-Video 0.9 checkpoint such as ltx-video-2b-v0.9-Q4_K_M.gguf is selected from a repo or local directory named LTX-2.3, joining all identifiers lets the regex's ltx-2 negative lookahead exempt the entire pick. Validation then accepts the incompatible 0.9 architecture as LTX-2 and proceeds to eviction/loading. Judge the selected checkpoint filename independently, while allowing an explicit LTX-2 filename to override only an old-model parent directory.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 636d377. video_checkpoint_refusal now also judges the last path segment of the most specific identifier (the GGUF filename, or the repo / folder when there is no file) on its own, so ltx-video-2b-v0.9-Q4_K_M.gguf in unsloth/LTX-2.3-GGUF or a /models/LTX-2/ltxv-2b-0.9.6-distilled folder is refused. The joined check is kept, so an LTX-2.3 file inside an ltx-video folder still loads. Tests added in tests/test_video_i2v.py; they fail on the previous head.

Comment on lines +149 to +152
out = encode(*args, **kwargs)
hook = getattr(vae, "_hf_hook", None)
if isinstance(hook, CpuOffload):
hook.init_hook(vae)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Offload the VAE when image encoding raises

With model CPU offload enabled, if vae.encode() raises—for example from an OOM while encoding the conditioning frame—execution never reaches hook.init_hook(vae). The surrounding context manager only restores the patched method, and the generation failure path does not reclaim the onloaded module, so the VAE remains GPU-resident and subsequent low-VRAM renders can continue failing. Run the offload operation from a finally around the encode call.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 636d377. The encode wrapper now calls init_hook(vae) from a finally, so the VAE goes back to the CPU when vae.encode() raises, and the exception still propagates. Added a test that makes the encode raise and checks the offload ran; it fails on the previous head.

Comment on lines +9944 to +9945
if (width is None or height is None) and first is not None and i2v_pipeline:
width, height = first_frame_canvas(fam, *first.size)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve a supplied dimension for first-frame renders

When an API caller supplies exactly one dimension with an I2V frame, this branch discards it and chooses a preset solely from the image aspect. For example, LTX accepts width=768, height=null as the default 768×512 pair during request validation, but a portrait first frame is then rendered at 512×768, silently ignoring the explicit width and contradicting the validated shape. Source-aspect preset selection should apply only when both dimensions are omitted; a half-specified request should resolve its missing side consistently with shape validation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not reachable through the API. VideoGenerateRequest refuses a keyframe request with only one of width / height ("width and height must be sent together, or both omitted", covered by test_video_routes.py and test_video_shape_validation.py), and /v1/videos only takes size as a full WxH pair or auto. So a request with a first frame always arrives with both sides or neither, and the preset-from-aspect branch is only reached with both omitted. No change made.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 636d377117

ℹ️ 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".

@danielhanchen
danielhanchen merged commit 10dc580 into main Oct 12, 2026
@danielhanchen
danielhanchen deleted the studio-video-i2v branch October 12, 2026 14:24
danielhanchen added a commit that referenced this pull request Oct 12, 2026
… fixed point (#13462)

test_formatter_fixed_point fails on main for studio/backend/tests/test_openai_videos_route.py (#13378) and tests/studio/playwright_find_in_page.py (#13437). Output of scripts/run_ruff_format.py, no behaviour change.
sbabamohamad added a commit to sbabamohamad/unsloth that referenced this pull request Oct 21, 2026
Adds nvidia/Cosmos3-Nano and nvidia/Cosmos3-Edge to the Video page through diffusers'
Cosmos3OmniPipeline (diffusers >= 0.40.0): text-to-video, and image-to-video from a first
frame, following the layout of the Wan2.1 families (unslothai#13376) and the image-to-video path
of unslothai#13378.

Cosmos3 differs from the other video families in three ways the generic path did not
handle, and each gets the smallest change that fits:

- Its transformer is also its text model, so the pipeline has a tokenizer and no text
  encoder. A family whose bf16 component table prices the text encoder at 0.0 is now read
  as having none: sizing requires only transformer and vae, a cached snapshot without a
  text_encoder/ folder counts as complete, and an explicit text_encoder_quant is refused
  with the reason (relates to unslothai#14000).
- Each card samples with scheduler and call settings that its shipped configs do not hold.
  New VideoFamily fields scheduler_overrides and call_kwargs carry them; a scheduler that
  rejects an override keeps its config.
- The pipeline takes the first frame through its own image= argument and crops it itself
  (i2v_fits_first_frame = False; same pipeline class for both modes).

Fidelity, measured against the plain diffusers pipeline at the cards' settings, seed 0,
with Studio's own encoder on both sides: every frame identical for Nano (189 of 189, four
clips) and Edge (121 of 121, four clips). Three settings were needed to get there and are
set on both rows:
- cudnn.benchmark off: two server processes otherwise rendered one Edge seed 55 dB (t2v)
  and 30 dB (i2v) apart.
- The VAE encoder stays on the stock kernels: Edge image-to-video at the default speed was
  29.5 dB from the card's output through the fused encoder, 51.8 dB with the stock one.
- Cosmos3 decodes untiled when it fits, on every speed tier, with tiled decode as the
  out-of-memory fallback: the stock 16x tiles leave a 4-latent edge tile at 480 / 832 px
  and a faint seam. The seam is recorded as a strict expected failure in the tile-geometry
  test so a fix forces the entry out.

Also in this commit: the local layout check reads a diffusers-library *Tokenizer component
as a model, so Nano's sound_tokenizer/ no longer makes a complete local folder look broken;
the download planner recognises the text_tokenizer/-without-text_encoder/ listing as
Cosmos3's; the Reasoner, Policy, Sim, Transfer and FP8 builds are refused by name with the
repo to load instead; Cosmos3-Super gets no family; the Hub catalog reads Cosmos3 pipelines
as "Video gen"; a renamed local Cosmos3 folder is refused by the trainer instead of falling
to the SDXL path; and the guardrail opt-out is passed through when the cosmos_guardrail
package is absent.

Components are fetched from the nvidia repos: no unsloth-hosted copies exist, both repos
are public and ungated (OpenMDW-1.1), and the allowlist gains the same two lines Wan2.1
has (relates to unslothai#14003). Quantized Cosmos3 checkpoints are a follow-up (unslothai#12851): diffusers
has no single-file converter for Cosmos3OmniTransformer, so a quant needs a hosted source
and a key-map loader.

Tests: family registry and freeze fixtures, component sizing, flow-shift and scheduler
overrides, the i2v class invariant, refusals, local-folder detection, routes, mirrors,
and opt-in GPU checks that render both models and compare against the diffusers output.
danielhanchen added a commit that referenced this pull request Oct 26, 2026
Adds `nvidia/Cosmos3-Nano` and `nvidia/Cosmos3-Edge` as Studio video
families, following #13376 and #13378: text-to-video and image-to-video
through diffusers' `Cosmos3OmniPipeline` (diffusers >= 0.41.0: 0.40.0
resolves a group-offloaded transformer's device as the CPU).

**What's different about Cosmos3**
- Its transformer is also the text model, so the pipeline has a
tokenizer and no text encoder. A family whose bf16 component table
prices the text encoder at 0.0 is now read as having none: sizing needs
only transformer and VAE, a snapshot without `text_encoder/` counts as
complete, and an explicit `text_encoder_quant` is refused with the
reason (relates to #14000).
- Each card samples with scheduler and call settings its shipped configs
don't hold. New `VideoFamily` fields `scheduler_overrides` and
`call_kwargs` carry them.
- The pipeline takes the first frame through its own `image=` and crops
it itself.
- Components come from the nvidia repos: no unsloth-hosted copies exist,
both are public and ungated (OpenMDW-1.1), allowlist gains the same two
lines Wan2.1 has (relates to #14003).

**Fidelity**: Studio output is frame-for-frame identical to the plain
diffusers pipeline for both models (Nano 189/189 frames, Edge 121/121,
four clips each, seed 0). Three settings were needed: `cudnn.benchmark`
off, the VAE encoder on stock kernels, and untiled decode when it fits,
including at speed off and under model / group / streaming offload (the
stock 16x tiles leave a 4-latent edge tile at 480/832 px). When untiled
does not fit, and on CPU / MPS, the tiled decode uses per-canvas strides
that keep every edge tile at 8 or more latents (stock strides wherever
they already do).

**Also in this PR** (separate commits, can be split out; the root-index
prefetch fix moved to #15184)
- The latest-transformers offer in the UI covers the `cosmos3` /
`cosmos3_edge` model types (the `unsloth run` prompt for it is left to a
separate PR).
- Frontend: picker rows, Hub "Video gen" label, page defaults; bundle
budget raised by the bytes the rows add.

**Tests**: backend and frontend suites show no new failures against main
(same failing ids on both trees, all environment-related); typecheck
clean. Real-weight renders were checked against plain diffusers outside
the test suite (Edge on a B200: bit-identical, t2v and i2v; Edge on a
T4: valid fp32 output).

**Not in this PR**: training support, and quantized Cosmos3 checkpoints
(#12851); diffusers has no single-file converter for
`Cosmos3OmniTransformer`, so a quant needs a hosted source and a key-map
loader.

`cosmos_guardrail` is not required: Nano's `model_index.json` enables
the safety checker by default, so the load either passes the opt-out or
refuses with a message naming the package. Edge ships with it off.



**Download and offload**: a Nano download skips `sound_tokenizer/` (1.99
GB, passed as None), a local Nano folder without `sound_tokenizer/` or
`vision_encoder/` validates, and under `low_vram` the VAE goes back to
the CPU after the conditioning encode for both t2v and i2v (real Edge:
VAE on `cuda:0` at every transformer step before, `cpu` after).

## Screenshots

Video page model picker on the merge base (left) and this branch
(right): the branch lists Cosmos3 Edge after the HunyuanVideo rows.

![Video picker before and after: Cosmos3 Edge row
appears](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/14554/pr14554_pair_00-cbaced2e803a.png)

The Hub pair below is harness state, not this PR: the two sides read the
live Hub listing at different times, so the trending rows differ (the
masked shot is otherwise identical). macOS and Windows legs: 41 of 41
steps identical.

<!-- studio-regress:start -->
### Studio UI regression check
Base `c9e5d4ab0` vs head `4aa1f7b91`. Functional: **NO_REGRESSION**, UI
coverage 89%, 1 visual change(s), 0 text-only change(s). Only steps
whose screenshots differ are shown.

**crawl/r_hub**: masks cover 37% of the shot | reproduced on confirm
(VISUAL_DIFF)
Facts: `missing`: {'before': ['button:DeepSeek-V#.#-Flash-#-GGUF',
'button:Model hub', 'button:NVIDIA-Nemotron-#.#-Super-VL-#B-A#B-GGUF',
'button:Qwen#.#-#B-A#B-GGUF', 'button:Search', 'button:Show workflows',
'button:gemma-#-#B-A#B-it-GGUF'], 'after': ['button:Filters',
'button:MiniMax-H#-GGUF',
'button:NVIDIA-Nemotron-#.#-Super-VL-#B-A#B-GGUF', 'button:Show
workflows']}

![crawl/r_hub](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/14554/crawl_r_hub-aa425f260167.png)
<!-- studio-regress:end -->

---------

Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] wan 2.2

1 participant