Repository navigation
Studio: pin the kept offload weights on first onload when host RAM allows - #11766
Conversation
Codex Review SummaryThis 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. |
Codex Review SummaryThis 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. |
…nd free them on failure
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…i#11777) _free_port bound port 0, closed the socket and passed the number to the server process to bind later. Another xdist worker could take the port in between, and the server died with address already in use (seen on the l-r shard of unslothai#11766). Worse, the readiness probe could then connect to whichever process now held the port. The server now binds port 0 itself, keeps the socket and reports the port before serving. The new test makes every port this process is handed by the OS one that is already listening; it fails on the old harness and passes here.
…udio-offload-pin # Conflicts: # studio/backend/core/inference/diffusion_memory.py
|
@codex security review |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
# Conflicts: # studio/backend/core/inference/diffusion.py # studio/backend/core/inference/diffusion_memory.py # studio/backend/core/inference/video.py # studio/backend/tests/test_diffusion_backend.py # studio/backend/tests/test_diffusion_offload_keep_cpu.py # studio/backend/tests/test_video_backend.py
Size the streamed-tier pin reserve from the container like _pin_host_weights (#11766) and reuse its constants.
…i#11777) _free_port bound port 0, closed the socket and passed the number to the server process to bind later. Another xdist worker could take the port in between, and the server died with address already in use (seen on the l-r shard of unslothai#11766). Worse, the readiness probe could then connect to whichever process now held the port. The server now binds port 0 itself, keeps the socket and reports the port before serving. The new test makes every port this process is handed by the OS one that is already listening; it fails on the old harness and passes here.
…lows (unslothai#11766) * Studio: whole-model offload points weights back at their host tensors instead of copying them * Studio: pin the kept offload weights on first onload when host RAM allows * Match the parameter object, not only its version, before reusing the host copy * Forget a kept host tensor when its parameter is replaced or re-pointed while offloaded * Take the stock offload copy when a weight's device storage was swapped through .data * Merge studio-offload-keep-cpu; drain pinned host memory even when GPU cleanup raises * Trim comments * Trim comments * Size the offload pin reserve from the container, not the host psutil reads host-wide memory, so inside a 64 GiB container on a 512 GiB host the RAM gate could pin more than the container has left. Cap the available figure by the cgroup remainder and size the reserve from the cgroup limit, through the same helpers the rest of diffusion_memory uses. Hosts without an enforcing cgroup (and Windows / macOS) are unchanged. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Trim comments in keep-cpu offload * Trim comments in offload pinning * Skip the keep-cpu rescan on modules with nothing kept * Drop a comment the owner check already states * Tighten offload pinning comments --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Stacked on #11764 (base branch
studio-offload-keep-cpu).Summary
With #11764 the whole-model offload no longer copies weights back from the GPU, and the remaining cost per render is the onload. That onload reads pageable host memory, which the GPU copies at 6.6 GiB/s on the B200 box, against 52 GiB/s from page-locked memory.
This PR pins the kept host weights once per component, on the component's first onload, when host RAM allows.
How
_pin_host_weightsruns from the wrappedpre_forward, once per module:auto(the default) pins only when available host RAM stays abovemax(4 GiB, 15% of total)after allocating those chunks (their real sizes, not just the weight bytes), so low-RAM machines keep today's behaviour.UNSLOTH_DIFFUSION_OFFLOAD_PIN=0/1forces it off or on.Results (B200,
memory_mode="low_vram", speed default, steady renders after the first)speed_mode="off"is bit-identical to stock (0 max pixel difference on 3 prompts) at 2.0 to 2.3 s against about 22 s.Tests
tests/test_diffusion_offload_keep_cpu.py, GPU-gated:psutilreports too little RAM;Results: 14 passed with a GPU; without one, the offload and memory suites pass (107 passed, 5 skipped).