Skip to content

Studio diffusion: cap the single-file host RAM refusal reserve at the fp8-storage reserve - #14758

Merged
danielhanchen merged 4 commits into
mainfrom
diffusion-host-ram-shared-reserve
Oct 25, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
diffusion-host-ram-shared-reserve

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

#14510 refuses a single-file diffusion load that would exhaust host RAM, keeping a reserve of max(3 GB, 10% of RAM) free (host_reserve_mib). #14549 decides whether to keep fp8 weights stored as fp8 or widen them, and it widens whenever the widened load fits with 4 GB free (FP8_STORAGE_HOST_RESERVE_MIB).

On hosts with more than 40 GB the refusal reserve is the bigger of the two. That leaves a band where the fp8 rule picks the widened load because it fits, and then the refusal rejects that same load. Example: a 64 GB host loading Krea 2 (about 24 GB widened) with 28 to 30.4 GB free. This loaded before #14510 and is refused on main, even though fp8 storage or the widened load would both fit.

Change

  • diffusion_small_host.py: FP8_STORAGE_HOST_RESERVE_MIB (4096) now lives here, next to a new single_file_host_reserve_mib(total) = min(host_reserve_mib(total), FP8_STORAGE_HOST_RESERVE_MIB).
  • diffusion_comfy_quant.py: imports that constant instead of defining its own, so fp8_storage_wanted and the refusal read the same value.
  • diffusion_single_file_converters.py: HostRamBudget (both the header check and the live per-allocation charge) uses single_file_host_reserve_mib.

With this, any load the fp8 rule widens passes the refusal. Loads that do not fit even at their cheapest size (fp8-stored where the rule stores it, widened otherwise) are still refused before any read. Hosts up to 40 GB keep exactly the same reserve as before. The small-host route (decide_small_host) still uses host_reserve_mib and is unchanged.

Tests

New tests in studio/backend/tests/test_diffusion_single_file_host_ram.py:

  • test_big_host_loads_what_the_fp8_storage_rule_widens[28.5|29.0|30.0|30.3]: 64 GB host, 24 GB widened. Checks that the fp8 rule widens and the refusal does not fire. Fails on main (refused), passes here.
  • test_reserves_cannot_drift: the refusal reserve is never above the fp8 reserve, and both modules expose the same constant. Fails on main, passes here.
  • test_big_host_still_refuses_a_load_that_cannot_fit: 24 GB widened with 20 GB free is refused. 12 GB stored fits at 20 GB free but is refused at 15 GB free. Passes on both.
  • test_small_host_reserve_unchanged[8|16|24|31]: the reserve is still max(3 GB, 10%) and the refusal boundary sits exactly there. Passes on both.

I also ran the 25 related backend test files (small host, comfy quant, comfy block, single-file host RAM, video comfy quant, and others) with python -m pytest -q -p no:cacheprovider: 1551 passed, 21 skipped, 1 failed. The one failure, test_diffusion_component_sizes.py::test_cached_image_families_headers_match_tables, fails the same way on main.

Not covered

  • No real 64 GB host load. The band is checked with spoofed RAM readings and sizes only.
  • The planner reads available RAM when it makes the fp8 decision, and the loader reads it again later. If free memory drops in between, a load can still be refused. That race was there before this change and this PR does not touch it.

… fp8-storage reserve

On hosts above 40 GB the refusal reserved 10% of RAM while the fp8-storage rule
widens a file when it fits with 4 GB free, so loads that rule widened were
refused (64 GB host, Krea 2 ~24 GB widened, 28-30.4 GB free). Both now read one
constant in diffusion_small_host; hosts up to 40 GB are unchanged.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-22T19:05:42.230551Z db11076 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: 7b12067940

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

return
self.available_mib = int(available)
self.reserve_mib = host_reserve_mib(total)
self.reserve_mib = single_file_host_reserve_mib(total)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep the proportional reserve when FP8 storage is unavailable

When a single-file load is not participating in the FP8 storage decision—such as a Comfy int8/NVFP4 file, a non-FP8 original-layout conversion, or an FP8 load with LoRA that forces widening—this unconditionally reduces the OOM guard on hosts above 40 GiB from 10% of total RAM to 4 GiB. For example, on a 64 GiB host a 24 GiB conversion with 29 GiB available now proceeds where the previous 6.4 GiB reserve refused it, even though there was no fp8_storage_wanted choice to reconcile. This can allow those large conversions to exhaust the server's safety headroom; use the capped reserve only for a load that was deliberately selected for FP8 widening, and retain host_reserve_mib(total) for the other paths.

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.

Agreed, fixed. The 4 GB cap now only applies to a load the fp8-storage rule chose to widen. fp8_widen_chosen is true only when fp8 storage was possible, not forced, not offloaded, and the widened load fit with the rule's reserve free. The image planner records that next to its storage pick and re-checks device / LoRA at load time. The video backends compute it the same way. HostRamBudget takes it as fp8_widen_chosen, and the ComfyUI loader also requires that fp8 layers are actually widened. Everything else keeps host_reserve_mib(total), including int8 / nvfp4 files, LoRA loads, the kill switch, stored loads and calls with no host price. Tests: on a 64 GB host with no fp8 choice the reserve is back to 6.4 GB and the 24 GB load is refused. With the rule's choice it uses 4 GB, as before. Both loaders get the capped reserve only when the flag is set.

…orage rule widened

The cap applied to every single-file load, so int8 / nvfp4 files, LoRA
loads and other widened loads with no fp8-storage choice lost the 10%
reserve on hosts above 40 GB. fp8_widen_chosen marks a load the rule
widened because it fit with its reserve free (image planner pick, video
backends); HostRamBudget caps only then, and the ComfyUI loader also
requires widened fp8 layers. Everything else keeps host_reserve_mib.

[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. Breezy!

Reviewed commit: db110769be

ℹ️ 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 adf2a6c into main Oct 25, 2026
26 of 41 checks passed
@danielhanchen
danielhanchen deleted the diffusion-host-ram-shared-reserve branch October 25, 2026 09:07
VTplus added a commit to VTplus/unsloth that referenced this pull request Oct 26, 2026
Sync with upstream 2c81e9f (2026-10-25), 124 commits since the branch base. Keep both single-file host RAM policies on the converter path: the fp8-storage reserve cap from unslothai#14758 and the no-swap commit-budget cap. They act on different inputs (reserve vs. budget), so both stay in effect without changing the other's behaviour.
VTplus added a commit to VTplus/unsloth that referenced this pull request Oct 26, 2026
The host RAM guard logged the stored size of every converted component as its source figure, including components read through pread that hold no source view. The commit estimate already excluded them; count only source views so the log matches the budget it explains, and pin both figures in the pread test.

Also cover the no-swap cap combined with the fp8-widen reserve (unslothai#14758) in the single-file test, so the two policies are exercised together.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant