Skip to content

Studio video: pin offloaded weights at their size, not a power of two - #15179

Merged
danielhanchen merged 4 commits into
mainfrom
studio-video-pinned-arena
Oct 25, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-video-pinned-arena

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

On Linux / CUDA, Studio's video background pinner already pins one page-rounded block per tensor (cudaHostRegister). One video path still went through power-of-two rounding: the whole-module ("model") offload tier, _pin_host_weights.

  • Chunk sizing: it packs weights into chunks, but sizes each chunk to the next power of two of its largest tensor, and rounds the last chunk too.
  • Effect on Wan2.2-TI2V-5B at a 12 GiB budget: 14.5 GB of weights took 16.1 GB of pinned host memory:
    • text encoder: 7.74 -> 8.59 GB;
    • DiT: 5.08 -> 5.37 GB;
    • VAE: 1.71 -> 2.15 GB.
  • GGUF weights: the background pinner used pin_memory() for these, so a 5.3 MB Q4_K weight took 8 MiB.

Changes

  • Model tier, video loads only: each chunk is pinned in registered host memory sized to its bytes (rounded to 4 KB pages), with the stock slot layout, so device uploads and VRAM are unchanged.
    • Each chunk's weights are re-pointed as soon as that chunk is registered.
    • If the first chunk is refused, the tier falls back to the stock pin. If a later chunk is refused, the chunks already pinned are kept and the rest stay pageable.
  • GGUF weights in the background pinner: they get the same registered copy, re-wrapped with their quant type.
  • Integrated GPUs: the exact pin asks host_pinning_allowed() first, so nothing is pinned there.
  • Kill switch: UNSLOTH_VIDEO_EXACT_PIN=0.
  • Image loads: unchanged.

Results

Exclusive B200 lease for the whole run. Wan2.2-TI2V-5B, 12 GiB cap, model tier, 1280x704x17, 8 steps. 4 reps per arm in rotating order, 3 renders per process; medians (min-max).

arm pinned GB steady anon+pinned GB steady s / forward render 1 s (includes pinning) frames
base 16.11 22.76 (22.70-22.81) 0.0505 (0.049-0.054) 26.13 (20.74-37.47) identical in 12 / 12 renders
head 14.53 21.23 (21.22-21.23) 0.0508 (0.049-0.0635) 27.96 (24.07-54.71) identical in 12 / 12 renders
kill switch 16.11 22.80 0.0505 (0.049-0.0525) 27.09 (19.94-33.63) identical in 12 / 12 renders
  • Memory: pinned memory falls by 1.58 GB and now equals the weight bytes. Steady RAM falls by 1.53 GB.
  • Peak RAM: 26.16 GB, inside base's 25.87-27.53 GB.
  • Speed: steady speed and render 1 are inside base's range. The slow head maximum came from a rep where the host was loaded, and it slowed base too (base's steady renders in that rep took 2.7-3.3 s against 1.5-1.9 s elsewhere).
  • Frames: identical across all 36 renders of the 12 processes.
  • Wan2.1-1.3B (group tier, 10 GiB): unchanged at 11.3 GB pinned. That path was already page-exact.

Tests

  • New tests/test_video_exact_pin.py:
    • exact chunk sizes;
    • the stock slot layout;
    • the stock pin when registration is unsupported or the first chunk is refused;
    • pinned chunks kept when a later one is refused;
    • only video pipes asking for exact chunks;
    • GGUF re-wrap with the quant type;
    • the kill switch for both paths.
  • tests/test_video_*.py and the pin suites: 2812 passed, 109 skipped. One failure, test_every_pinning_site_asks_the_integrated_gpu_predicate_or_is_reached_through_one, also fails on main because of the offload cost probe; Studio diffusion: skip the offload cost probe's pinned buffer on an integrated GPU #15178 fixes it.

Limits

  • ROCm, Windows and WSL keep the per-tensor fallback unchanged; they were not measured here.
  • Not run: A14B (126 GB) and an end-to-end GGUF video load. GGUF has a GPU unit check (byte equality, quant type kept, device upload works).
  • Pinning does not explain all of the ~2x host RAM against ComfyUI on T4. The remaining gap is elsewhere.

The whole-module offload tier packs a module's weights into pinned chunks
through torch's host allocator, which rounds every chunk up to a power of
two. On Wan2.2-TI2V-5B under a 12 GiB budget the TE / DiT / VAE pinned
16.11 GB for 14.53 GB of weights. Video loads now allocate each chunk in
registered host memory sized to its bytes (page granular), with the same
slots, so the device uploads and outputs are unchanged. Each chunk's
weights move to it as soon as it is registered, so the pageable copy is
not held twice for the whole module.

The background pinner's GGUF weights take the same registered copy
(re-wrapped with their quant type) instead of a power-of-two pin_memory().

Kill switch: UNSLOTH_VIDEO_EXACT_PIN=0.
@danielhanchen danielhanchen self-assigned this Oct 25, 2026
@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 commented Oct 25, 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-25T00:44:20.103865Z f85b978 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

Copy link
Copy Markdown

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

Reviewed commit: f85b978009

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

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