Skip to content

Studio video small host: price the encoder converted beside the cast misses, cast an oversized DiT from its source shards - #16700

Merged
danielhanchen merged 6 commits into
mainfrom
studio-video-small-host-others
Nov 4, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
studio-video-small-host-others

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

HunyuanVideo-1.5 could not load on a 31 GB host with a 15 GB card (Kaggle T4): every load was OOM-killed or hit the container cap. The small-host planner (video_small_host.py) priced only the cast-cache misses it converts, not the Qwen2.5-VL text encoder that the same load converts from bf16 to fp16 in host RAM beside them (13.5 GiB). The load needed about 32 GiB.

Change

  • video_small_host.py:
    • converted_others_mib prices the components the load converts in host RAM outside the cast cache (half-precision shards of a non-candidate loaded at the other half dtype), and the stage plan counts them.
    • A cast-cache miss bigger than the card, whose host share would not fit beside the rest, is written to the cast cache from its source shards one tensor at a time (save_from_source), so the load maps the cached file instead of converting the whole component in host RAM. A component the plan would split between card and host takes the same route. If the source cast fails, the component is left to the normal pipeline load; there is no accelerate card / host split, whose host share comes back as meta tensors.
  • diffusion_cast_cache.py: save_from_source writes the cast entry from the source shards; the file is byte-identical to the normal write.
  • video.py: passes the priced conversions to the planner.
  • The existing small-host kill switch (UNSLOTH_VIDEO_SMALL_HOST=0) still turns all of it off.

Evidence

Kaggle T4 (31 GB host, one T4, CPUs 0-3), HunyuanVideo-1.5:

arm result peak anonymous RAM load s/clip
this PR, fresh home loads and renders 16.8 GiB 356 s 388
this PR, returning home loads and renders 15.3 GiB 101 s 318
main hits the 27 GiB cap in one run, killed the kernel in the other

Tests

  • test_video_small_host.py and test_diffusion_cast_cache.py: 40 passed here, 11 fail on main.
  • The small-host and cast-cache suites pass.
  • AMD gfx1151 (Linux, ROCm) and Windows 11: no regressions (both sides 0 failures), run before the commit that removed the accelerate split fallback.

Not covered

  • Frame equality between the two loads above was not scored (main's kernel died before the score step).
  • Only HunyuanVideo-1.5 on a T4 was run.

…he misses, stage a miss split across card and host
…ned component

Its host share loads as meta tensors; when the source-shard cast fails the
component is left to the normal pipeline load instead.
@danielhanchen danielhanchen self-assigned this Nov 4, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-11-04T19:47:34.089384Z 7fd0637 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.

@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: 4590f1b7a3

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

continue
if stage_on_device(by_name[name], device, logger = logger, cancel_check = cancel_check):
done.append(name)
if plan.engaged and plan.skipped and not stage_disabled():

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 Run the source-cast fallback when every miss is skipped

When the only cast candidate exceeds both the card capacity and the permitted host share, plan_stage() puts it in skipped but returns engaged=False because stage is empty. This condition consequently prevents the source-cast fallback from running in exactly the case it is meant to handle. For example, a single 20,000 MiB transformer with 3,000 MiB available host RAM and 14,600 MiB free VRAM never reaches save_from_source(), so the pipeline still attempts the oversized dense conversion. Allow eligible skipped components to use the fallback without requiring another component to have been staged.

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 7fd0637: the source-cast pass now runs over the skipped components whenever the plan has any (not only when something else was staged), so a lone DiT too big for both the card and the host is cast from its shards (test_a_lone_dit_too_big_for_the_card_is_still_cast_from_its_shards, fails on the previous head).

Comment on lines +156 to 159
stage.append(name)
split[name] = card
left -= mib
continue

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 Exclude unsupported encoders before subtracting split candidates

For a Transformers encoder larger than the card, the planner now counts a split candidate as removed from host RAM and can stop before staging a smaller transformer. However, this branch calls save_from_source(), whose _source_names() unconditionally rejects Transformers components, so neither component gets cached. For the existing WAN sizes (12,748 MiB encoder and 2,709 MiB transformer), 16,000 MiB available RAM, a 3,000 MiB reserve, and 11,000 MiB free VRAM, the previous planner staged the transformer and brought the remaining conversion within budget; the new planner selects only the unsupported encoder and leaves the full 15,457 MiB conversion. Restrict source-only planning to supported components or replan after a source write fails.

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 7fd0637: plan_stage takes the set of components whose cast can be written from the source shards (diffusers ones), and only those can be split-planned. A Transformers encoder over the card is skipped instead, so the planner goes on to stage the DiT as before (test_a_transformers_encoder_over_the_card_is_not_split_planned, the WAN sizes from the review).

…t only source-castable ones

A skipped component too big for the card and the host takes the source cast even when nothing
else was staged, and a Transformers encoder (no source cast) is no longer split-planned, so the
planner goes on to stage the DiT.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 7fd0637474

ℹ️ 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 3c88a25 into main Nov 4, 2026
@danielhanchen
danielhanchen deleted the studio-video-small-host-others branch November 4, 2026 21:13
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.

1 participant