Skip to content

Studio LoRA fuse: charge the host RAM guard what the pinned backup really holds - #17191

Merged
danielhanchen merged 2 commits into
mainfrom
dh/lora-fuse-pinned-pow2
Nov 9, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
dh/lora-fuse-pinned-pow2

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #17086.

What happened

#17086 added a host RAM reserve check before the LoRA fuse allocates its host backup of the original weights. The check is charged sum(sizes) of the backup layout. Weights up to 64 MiB share 64 MiB chunks, which the pinned host allocator keeps at their size. A weight larger than 64 MiB, though, got its own slab of exactly its size, and CUDA's caching host allocator rounds every pinned block up to a power of two. A 72 MiB slab therefore holds 128 MiB, and a 126 MiB slab holds 128 MiB.

FLUX-sized denoisers hit this: their 3072 x 12288, 3072 x 21504 and 15360 x 3072 bf16 projections are all over 64 MiB. In the layout below (24 x 72 MiB, 4 x 126 MiB, 4 x 90 MiB, 8 x 18 MiB) the guard was charged 2784 MiB while the pinned allocator held 4288 MiB, so a backup could pass the check and still take about 1.5 GiB out of the reserve it is meant to keep.

What changed

  • When the backup is pinned, the weights are packed largest first into 512 MiB chunks, and each chunk is then trimmed to the power of two that holds what it got. Every pinned block is now a power of two, so the size the guard is charged is the size the allocator holds.
  • The same layout also stops one oversized weight from holding a mostly empty power-of-two block by itself: for the layout above the pinned backup drops from 4288 MiB to 2816 MiB (6 chunks instead of 35), against 2736 MiB of weights.
  • Device backups and pageable host backups (CPU, integrated GPUs) keep the old exact layout.
  • UNSLOTH_DIFFUSION_LORA_FUSE_POW2_PACK=0 restores the previous layout and charge.

Placement, copy, fold and restore are unchanged: each weight still gets an aligned view into one chunk.

Tests

studio/backend/tests/test_diffusion_lora_fuse.py:

  • test_the_host_guard_is_charged_what_the_pinned_allocator_holds runs fuse on the FLUX-like layout with a recording pinned allocation and checks that the guard charge covers the power-of-two rounded blocks. On main it fails (2919235584 >= 4496293888); with this change it passes.
  • test_power_of_two_layout_places_every_weight_inside_its_chunk checks that the chunks are powers of two, offsets are aligned, and no weights overlap.
  • test_power_of_two_packing_kill_switch_keeps_the_exact_slabs checks the opt-out.

The full file passes on CPU (20 passed, 2 CUDA-only skips).

Weights over 64 MiB were backed up in exact-size pinned slabs, which the
pinned host allocator rounds up to a power of two, so the host reserve
check added in #17086 was charged less than the backup really held.
Pinned backups are now packed into power-of-two chunks (largest first),
and the guard is charged those chunk sizes.
UNSLOTH_DIFFUSION_LORA_FUSE_POW2_PACK=0 keeps the old layout.
@danielhanchen danielhanchen self-assigned this Nov 9, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T02:50:28.046752Z c2908db 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: c2908dbb99

ℹ️ 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 added a commit that referenced this pull request Nov 9, 2026
…uff-unsloth wheel (#17211)

## Summary

The Backend CI step that installs the pinned `ruff-unsloth` wheel
retries 3 times with 5 s and 10 s gaps. Between 05:19 and 05:40 UTC
today, GitHub served intermittent 504s for the release asset, and every
attempt of an unlucky job landed inside one burst. That turned `Repo
tests (CPU, fsdp2 / gloo-cp / gloo-pp / gloo-tp / rest /
studio-install)` red on #17188, #17191, #17197, #17201 and #17202, while
sibling jobs in the same runs installed the wheel fine a minute later.

This raises the loop to 6 attempts with exponential backoff (10, 20, 40,
80, 160 s, about 5 minutes total). A healthy download still never
sleeps, and a lasting outage still fails the job with the same
`::error::` line, so the fixed-point formatter guard keeps failing
loudly in CI when the wheel is truly unavailable.

## Changes

- `.github/workflows/studio-backend-ci.yml`: 6 attempts, `sleep $((10 <<
(attempt - 1)))`.
- `tests/test_ruff_unsloth_install_retries.py`: runs the step's own
`run:` script under bash with `pip` and `sleep` faked on `PATH`, and
checks that
- 5 failed downloads in a row still install, after at least 300 s of
backoff,
- a download that never recovers still fails the job, in under 10
minutes,
  - a healthy download does not wait at all.

## Testing

- `pytest tests/test_ruff_unsloth_install_retries.py`: 3 passed.
- Against the old step from `main`, the burst test fails with
`ruff-unsloth install failed after 3 attempts`.
- The other tests that read `studio-backend-ci.yml` pass.
@danielhanchen
danielhanchen merged commit 4eeffee into main Nov 9, 2026
@danielhanchen
danielhanchen deleted the dh/lora-fuse-pinned-pow2 branch November 9, 2026 11:53
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