Skip to content

Studio: refuse a diffusion or video load that cannot fit unified memory - #8213

Merged
danielhanchen merged 32 commits into
mainfrom
umem-refusal
Aug 10, 2026
Merged

danielhanchen merged 32 commits into
mainfrom
umem-refusal

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

On a unified-memory host, a diffusion or video load that cannot possibly fit does not fail. It gets the Studio process killed by the OS.

The bug

plan_diffusion_memory short-circuits on not can_offload or device_memory.is_unified, records the note "unified/system memory: CPU offload frees no device memory", and returns OFFLOAD_NONE. That placement is correct: Apple Silicon shares one CPU/GPU pool, so CPU offload moves bytes within that pool and frees nothing. But on that branch it never compares resident_required_mib against safe_device_budget_mib, even though it has already computed both, and nothing downstream refuses either. OFFLOAD_NONE here is a placement, not a fit.

There is no torch OOM to catch, because _mps_or_cpu_target sets PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0, which MPSAllocator.h documents as disabling the hard limit outright. So the failure mode is a SIGKILL with no Python exception, and the user sees Studio disappear with nothing in the UI.

The planner is shared, so this reaches the image path too, not just video.

Scale

Driving the shipped planner against synthetic unified-memory targets, at bf16 default preset, with free modelled at 80 percent of RAM (the share left once macOS, a browser and Studio are up). "before" is what main does today: the planner says none, nothing refuses, the load proceeds.

family weights + overhead 16G 24G 32G 64G 96G 128G
ltx-2 65G REFUSE REFUSE REFUSE REFUSE REFUSE proceed
wan2.2-ti2v-5b 25G REFUSE REFUSE REFUSE proceed proceed proceed
wan2.2-t2v-a14b 66G REFUSE REFUSE REFUSE REFUSE REFUSE proceed
hunyuanvideo-1.5 33G REFUSE REFUSE REFUSE proceed proceed proceed
hunyuanvideo-1.5-720p 33G REFUSE REFUSE REFUSE proceed proceed proceed

Before this change every cell in that table is none / proceed. So on a 16 or 24 GB Mac, every supported video family is one click from an OS kill.

The change

A load-time refusal in both loaders when the weights cannot fit the safe budget on unified memory, with an actionable message:

'wan2.2-ti2v-5b' needs about 26 GB of memory for its weights, but only about 10 GB
is usable on this device (of the 13 GB currently free, after reserving room for the
operating system). This device has unified memory, so the CPU and GPU share one pool:
offloading weights to the CPU frees nothing, and the operating system stops an
oversized load outright instead of reporting an out-of-memory error. Use a smaller or
more quantized model, free memory by closing other applications, or set
UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD=1 to attempt the load anyway.

Weights only, not the full resident requirement

The refusal budgets model_dense_mib plus the flat base overhead, and deliberately drops the per-call runtime headroom. The headroom is the soft term: a coarse activation and VAE-decode estimate, and the mps path already enables VAE tiling and slicing, which cuts the decode peak that estimate does not model. Counting it would refuse marginal loads that would in fact complete. The weights are the hard term, sized from measured per-family component tables or on-disk checkpoint size, and if they alone do not fit then nothing at generation time can rescue the load.

This is the same rule as the existing llama.cpp unified-memory APU guard (_apu_ram_shortfall_message), which budgets weights and lets KV and context auto-reduce. It is also what keeps the refusal off the merely tight cases: on a 64 GB Mac, hunyuanvideo-1.5 needs 39 GB with headroom against a 38 GB budget, and is still allowed through. Dropping a whole 5 to 8 GB term is a substantial, physically motivated margin rather than an arbitrary fudge factor.

Unified device memory only

Gated on memory_kind == "unified_memory" (Apple Silicon, integrated CUDA / Jetson). Plain CPU reports system_memory, has swap, and is an opt-in fringe path, so it keeps today's behaviour exactly.

Discrete VRAM is untouched by construction. It still has a real fallback ladder, where an oversized model streams from host RAM under group or whole-module offload, and refusing there would break loads that work today. That asymmetry is the whole point: unified memory is the one placement with no tier left below none.

Not in the planner

plan_diffusion_memory stays a pure sizing function and is textually unchanged. Both loaders call it speculatively (the image loader re-plans candidate quantisations, and both re-plan against a settled snapshot), so a planner that raised would turn those probes into load failures instead of letting a smaller candidate win. The check is a separate helper called once, on the plan the loader has committed to, after the previous pipeline has been evicted (so the free reading is the memory this load actually gets) and before any weight is materialised.

Error type and where it surfaces

RuntimeError, matching the llama.cpp APU refusal. Both call sites run inside load_pipeline on the loader thread, where _run_load catches it, stringifies it onto _loading.error, and load-progress returns {"phase": "error", "error": ...}, which both the images and video pages toast verbatim. So the message reaches the user intact, the 409 mapping of the synchronous route never applies, and no traceback reaches a 500.

Escape hatch

UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD=1 attempts the load anyway. The estimate could be conservative and a Mac user who is refused otherwise has no override. The refusal also fails open on any unknown input (no free reading, no model size), matching the planner's own "budget or model size unknown; staying resident".

Does the discrete path already have an equivalent?

No. plan_diffusion_memory is degrade-never-refuse for every device class, and there is no capacity refusal anywhere on the diffusion or video path. The only capacity refusal in the backend is _apu_ram_shortfall_message on the llama.cpp GGUF path, and it is likewise gated to unified memory. This change matches that one's shape, weights-only rule, fail-open behaviour, message style and error type rather than inventing a second convention.

Verification

No Mac was involved. The SIGKILL itself was not observed and is not claimed to have been. What was done:

  • The shipped planner was driven against synthetic unified-memory targets to produce the before/after table above, and against discrete targets to confirm the discrete decision matrix is model / model / model / group / group / none for ltx-2 and so on, identical before and after.
  • 200,000 randomised discrete-VRAM plans (varying total, free, dense size, companion size, memory mode and the legacy cpu_offload flag): the refusal never fired once. plan_diffusion_memory itself has zero changed lines, so the discrete path is unchanged by construction.
  • Mutation testing, 13 mutations, all killed, no survivors: refusal never fires; guards discrete instead of unified; counts the soft runtime headroom; drops the base overhead; comparison inverted; fails closed on unknown inputs; env escape hatch ignored; message drops the family name; message drops the escape-hatch hint; message drops the free-memory figure; raises ValueError instead of RuntimeError; image loader call site removed; video loader call site removed. The suite went green again after restoring each.
  • studio/backend/hub/tests/: 304 passed before and after.
  • studio/backend/tests/: the sorted FAILED and ERROR line sets are byte identical before and after (89 lines, 71 failed and 18 errors, all pre-existing and driven by the transformers versus huggingface-hub pin). Passed went 18869 to 18887, which is exactly the 18 new tests.

Not verified: real Metal allocation behaviour, and the exact point at which macOS jetsam kills the process. The 20 percent unified reserve and the 80 percent free fraction used in the simulation are the shipped constant and a modelling assumption respectively, not measurements.

Context

PR #8198 enables video generation on Apple Silicon and makes this reachable for far more users, and its own history contains an instance of exactly this failure. This is deliberately a separate PR on main: the bug is pre-existing there, it reaches the image path too, and it is a memory-policy change that deserves its own review.

On a unified-memory host the memory planner short-circuits before it ever
compares the resident requirement against the safe budget. plan_diffusion_memory
sees `not can_offload or device_memory.is_unified`, records "unified/system
memory: CPU offload frees no device memory", and returns OFFLOAD_NONE. That is
the correct placement (the CPU and GPU share one pool, so offload moves bytes
within that pool and frees nothing) but it is a placement, not a fit, and
nothing downstream refuses.

There is also no torch OOM to catch on that path: _mps_or_cpu_target sets
PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0, which disables the MPS allocator's hard
limit outright, so an oversized load ends as an OS kill with no Python
exception. The user sees Studio disappear.

Driving the shipped planner against synthetic unified-memory targets (free
modelled at 80 percent of RAM, the share left once the OS, a browser and Studio
are up), every supported video family is affected below 64 GB of RAM:

  family                  weights   16G   24G   32G   64G   96G   128G
  ltx-2                       65G    NO    NO    NO    NO    NO    fits
  wan2.2-ti2v-5b              25G    NO    NO    NO  fits  fits    fits
  wan2.2-t2v-a14b             66G    NO    NO    NO    NO    NO    fits
  hunyuanvideo-1.5            33G    NO    NO    NO  fits  fits    fits
  hunyuanvideo-1.5-720p       33G    NO    NO    NO  fits  fits    fits

Add a load-time refusal on that path, in both loaders, naming the family, the
memory required, the memory available and the most useful thing to change.

Design notes:

- Weights only. The refusal budgets model_dense_mib plus the flat base
  overhead, not the per-call runtime headroom. The headroom is a coarse
  activation and VAE-decode estimate, and the mps path already enables VAE
  tiling and slicing, which cuts the decode peak that estimate does not model,
  so counting it would refuse marginal loads that would in fact complete. The
  weights are unavoidable resident bytes sized from measured per-family
  component tables or on-disk checkpoint size. This is the same rule as the
  llama.cpp unified-memory APU guard, which budgets weights and lets KV and
  context auto-reduce, and it is what keeps the refusal off the merely tight
  cases: on a 64 GB Mac hunyuanvideo-1.5 needs 39 GB with headroom against a
  38 GB budget and is still allowed through.

- Unified device memory only. memory_kind == "unified_memory" (Apple Silicon,
  integrated CUDA). Plain CPU reports "system_memory", has swap, and is an
  opt-in fringe path, so it keeps today's behaviour exactly. Discrete VRAM is
  untouched by construction: it still has a real fallback ladder, where an
  oversized model streams from host RAM under group or whole-module offload,
  and refusing there would break loads that work today.

- Not in the planner. plan_diffusion_memory stays a pure sizing function, and
  is unchanged. Both loaders call it speculatively (the image loader re-plans
  candidate quantisations, and both re-plan against a settled snapshot), so a
  planner that raised would turn those probes into load failures instead of
  letting a smaller candidate win. The check is a separate helper called once,
  on the plan the loader has committed to, after the previous pipeline has been
  evicted so the free reading is the memory this load actually gets, and before
  any weight is materialised.

- RuntimeError, matching the llama.cpp APU refusal. Both call sites run inside
  load_pipeline on the loader thread, where _run_load stringifies the exception
  onto load_progress and the UI toasts it verbatim, so the 409 mapping of the
  synchronous route never applies and no traceback reaches a 500.

- Escape hatch. UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD=1 attempts the load
  anyway, since the estimate could be conservative and a Mac user otherwise has
  no override. The refusal also fails open on any unknown input (no free
  reading, no model size), matching the planner's own "budget or model size
  unknown; staying resident".

The discrete CUDA path has no equivalent refusal and does not gain one here.

Tests cover the message contents, the weights-only rule at the boundary, the
fail-open cases, the override, the RuntimeError type, the full decision matrix
against the real video family tables at 16, 24, 32, 64, 96 and 128 GB, and both
loader call sites for the refused, allowed, overridden and discrete cases.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Aug 9, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Aug 9, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

Ran the three touched test files on staging CI runners so the org queue is spared, with torch installed so the jobs are a real gate rather than a collection skip:

runner result
macos-14 335 passed
macos-15 335 passed
ubuntu-latest pass
windows-latest pass

Those macOS runners are virtualized with roughly a 7.93 GB Metal cap, so they exercise the refusal but cannot exercise a successful large load. The SIGKILL itself was not observed and is not claimed to have been.

The 8 failing checks here are pre-existing and repo-wide: the same 8 fail on #8211 and #8212, which touch unrelated code.

danielhanchen and others added 3 commits August 9, 2026 12:01
# Conflicts:
#	studio/backend/core/inference/diffusion.py
Four gaps in the refusal this PR adds, all of which either refuse a load that fits or
miss one that does not:

- The dense transformer-quant fast path was never checked. On unified memory the planner
  returns 'none' for any size, so the dense re-plan's offload-policy test could not fire
  and an oversized dense build proceeded to be OS-killed. Size it explicitly and decline
  to the packed GGUF instead.
- A full pipeline's weight term is cached shard bytes, a download size. Z-Image and Lumina
  ship fp32 shards that halve on the bf16 cast, so the refusal rejected loads that fit.
  Judge it on the size table's resident totals, which only ever lower the estimate.
- A hosted pre-cast fp8 text encoder replaces the dense one during assembly, so budgeting
  the table's dense encoder refused video loads that fit. This overlaps only on integrated
  CUDA, where the pre-cast gate's cuda requirement and unified memory both hold.
- Tearing down a pipeline on Apple Silicon left its buffers reserved in torch's MPS
  caching allocator, which reads as used system memory, so a swap that fits was refused.
  Empty that cache on teardown and before the reading the committed plan is judged on.

@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: f015856e6e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

# on the download figure would turn away a load that fits, so judge the refusal
# against the table's resident total whenever it knows this base.
raise_on_unified_memory_shortfall(
self._resident_sized_plan(plan, fam, base, target, kind),

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 Include pre-cast encoders in the unified-memory budget

On an integrated CUDA device reported as unified memory, an image load with text_encoder_quant="fp8" can prefetch a hosted pre-cast text encoder and skip the dense encoder shards from the base repo. The plan passed here is then based on the base repo cache/snapshot only, and _resident_sized_plan only lowers full-pipeline estimates when the family table is smaller, so it never adds the resident fp8 encoder that will be injected later by te_prequant_pipe_kwargs. For families like FLUX.2-dev this can let a load pass the new shortfall check on a 128 GB unified-memory system even though the actual transformer + pre-cast encoder footprint exceeds the safe budget, bringing back the OS-kill failure this guard is meant to prevent. Account for the resolved pre-cast encoder footprint before allowing the load.

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.

Not taking this one. It is the under-estimate direction, which this PR does not change and the guard is documented to fail open on. The pipeline weight term comes from _plan_memory's cache/snapshot scan, which is main's code and behaves exactly as it did before this branch; _resident_sized_plan only ever LOWERS, and in the pre-cast case the shard-derived figure is already below the table (the table's encoder term is the dense one), so it does not fire at all. An estimate that comes in low means the refusal does not trigger and the load proceeds precisely as it does on main today, so there is no regression here to fix. This is the same boundary drawn in the previous round on the 'size image weights using their loaded dtype' item: the over-estimate half is a load this PR would newly turn away, so it was fixed; the under-estimate half is a pre-existing planner accuracy question, and widening the estimator is a separate change with its own risk of refusing loads that fit.

Comment thread studio/backend/core/inference/video.py Outdated
Comment on lines +1422 to +1423
if saving_mib and committed_dense is not None:
refusal_plan = plan_diffusion_memory(

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 Trust only fetched pre-cast encoders for the budget

When the hosted pre-cast text encoder cannot be fetched or later fails validation, _fetch_te_prequant() leaves _te_prequant_skipped empty and the base predownload keeps the dense encoder shards, so assembly falls back to the dense encoder. This branch still subtracts the fp8 saving just because te_prequant_sources() has a configured source, letting a unified-memory load pass the new guard with the smaller estimate and then materialize the dense encoder that can exceed the shared-memory budget. Base the saving on the components actually fetched/skipped or re-check if injection falls back.

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.

Not taking this one either, same reason. te_scale is keyed on te_prequant_sources in main, not in this PR: the diff on video.py is the settled snapshot and the refusal call, nothing about the budget scale. Main already re-plans at scale 1.0 when te_prequant_pipe_kwargs injects nothing, so the placement decision does recover. What is left is that the refusal reads the optimistic plan, and that is again the fail-open direction: the estimate is too small, the guard stays quiet, and the load behaves as it does on main. Under-stating cannot cause the new refusal to reject a load that fits, which is the failure mode this PR is responsible for.

# Conflicts:
#	studio/backend/tests/test_video_backend.py
main's video plan now scales the text-encoder term by te_prequant_budget_scale, which is
the same correction measured off the real artifacts rather than the generic fp8 factor.
Subtracting it again before the refusal would have counted the saving twice, so the
refusal reads the plan directly.
# Conflicts:
#	studio/backend/tests/test_video_backend.py
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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

quant_mib = int((components[0] * factor + companions_gb) * mib_per_gb)
replanned = plan_diffusion_memory(
target = target,
device_memory = device_memory,
model_dense_mib = quant_mib,

P1 Badge Budget transient dense video weights before quantizing

When a unified-CUDA video load's steady fp8/int8 footprint fits but its bf16 pipeline does not, this substitutes the smaller quant plan and lets the refusal pass. Fresh evidence after the earlier re-plan fix is that pipeline_cls.from_pretrained at line 1480 still materializes the complete dense pipeline before quantize_transformer runs at lines 1577–1585; because CPU and GPU share the same physical pool, the process can exhaust memory before reaching the advertised smaller steady state. Require the dense transient plan to fit, or load an already-quantized/meta representation.

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

Comment on lines +403 to +407
# ``system_memory`` (plain CPU) is deliberately excluded: it is an opt-in fringe path,
# it has swap, and it is not what gets Metal-killed. Only the accelerator-on-system-pool
# case is guarded.
if getattr(memory, "memory_kind", None) != "unified_memory":
return None

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 Reuse the ROCm APU classifier before the refusal

On ROCm APUs such as Strix Halo, Radeon wheels can omit or zero props.is_integrated; the repository's _rocm_classify_unified_memory therefore also checks gcnArchName and device-name fallbacks. _cuda_memory does not use those fallbacks, so it labels these shared-memory devices discrete_vram, this new condition returns without a refusal, and the planner selects CPU offload even though CPU and GPU occupy the same pool. Oversized image/video loads can consequently retain the OS-kill behavior this guard is intended to prevent.

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.

The observation about the classifier is right, but it is not this PR's. _cuda_memory reads props.integrated / props.is_integrated only, and _rocm_classify_unified_memory in core/training/worker.py does add the gcnArchName and device-name fallbacks; llama_cpp.py imports it, diffusion_memory.py does not. That gap is on main and predates this branch, and its effect here is the fail-open direction: the device reads discrete_vram, the refusal stays quiet, and the load behaves exactly as it does today. What the item asks for is not a guard change but a classification change, and flipping a Strix Halo from discrete_vram to unified_memory also rewrites the planner's offload decision for every diffusion and video load on those machines. That is a real improvement and it deserves its own PR with hardware to validate it on; folding it in here would ship an untested planner change under a refusal fix.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen and others added 2 commits August 9, 2026 17:19
7989 added minimax-h3 to the video family table, and the decision-matrix test
is a deliberate tripwire for exactly that: it asserts the shipped families and
the expected refusals stay in step, so a new family fails the suite until its
row is written.

The row is derived from the shipped tables rather than chosen: at 144.2 GB of
bf16 weights H3 is the largest video family by a wide margin and is refused at
every RAM size in the matrix, 128 GiB included. That is the right answer, not a
gap -- the dense pipeline fits no Mac modelled here, and a user on one reaches
H3 through the GGUF or prequantized artifacts.

@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: 3674c2aceb

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

Comment on lines +3779 to +3780
if kind != "pipeline" or _is_local_path(base):
return plan

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 Size local fp32 pipelines after their bf16 cast

When a local full-pipeline directory contains fp32 weights but the target loads them as bf16, this early return preserves _plan_memory's raw on-disk byte count instead of the post-cast resident size. A local clone of Z-Image or Lumina therefore gets budgeted at roughly twice its actual weight footprint and can be refused on a unified-memory host even though it fits; retain the protection against substituting a coarse family size for unknown local variants, but derive the resident footprint from the local tensors' dtype and parameter counts.

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.

Rejecting: the local exclusion is deliberate and documented in _resident_sized_plan. The table is keyed on exact upstream ids, so a local directory can only ever reach the coarse family entry, and for a family carrying two sizes that entry is the smaller one -- a local FLUX.2-klein 9B would be lowered below half what it loads and walk straight past the refusal. On disk is the measured truth there. Deriving a post-cast footprint from local tensor dtypes and parameter counts is a new capability, not a fix, and the current behaviour errs in the safe direction with UNSLOTH_DIFFUSION_ALLOW_OVERSIZED_LOAD=1 as the escape hatch.

@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: d9c857cc09

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

Comment on lines +2456 to +2458
raise_on_unified_memory_shortfall(
self._resident_sized_plan(
plan, fam, base, target, kind, text_encoder_quant = text_encoder_quant

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 Size fp32 single-file checkpoints after casting

When a single_file safetensors checkpoint is stored in fp32 but the MPS target loads it with torch_dtype set to bf16/fp16, _plan_memory retains the raw on-disk byte count as model_dense_mib; _resident_sized_plan only corrects full-pipeline repositories and whole-pipeline companion duplication. This hard check therefore budgets such single-file checkpoints at roughly twice their actual post-cast residency and can reject a unified-memory load that fits. Derive the single-file estimate from tensor dtypes/parameter counts and the destination dtype before refusing.

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.

Rejecting: no reachable checkpoint. Single-file DiT checkpoints for the supported families ship bf16 or fp8 (the fp8 upcast is already handled by estimate_safetensors_dense_mib's fp8_upcast), and I could not find an fp32-stored single-file safetensors DiT any of them would load. Sizing from tensor dtypes before the refusal is hardening against an input the code does not receive.

danielhanchen and others added 2 commits August 9, 2026 19:16
…he pre-cast encoder in the prequant fit check

MiniMax-H3 returns into _load_h3_modular_pipeline above load_pipeline's refusal, so the one
family whose dense component set is 144.2 GB -- the one the refusal matrix declines at every
Mac RAM size it models -- was the only one that never reached the check. load_components
builds every component dense and the ComponentsManager's CPU offload frees nothing on unified
memory, so that set is an OS kill with no torch OOM to catch. Size it before any weight is
opened, with the denoiser priced at its steady quantised size when a hosted pre-quantized
checkpoint is about to be seeded in its place.

DenseQuantEstimate.companions_mib is always the dense encoder plus the VAE, but the assembly
the image prequant fit check sizes is handed text_encoder_quant and injects the pre-cast
encoder, so a footprint that fits was declined on bytes never materialised. Apply the same
te_prequant_budget_scale the load-level resident plan already applies.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 6aee25767b

ℹ️ 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 and others added 2 commits August 9, 2026 20:15
…tprint

The generic _QUANT_STEADY_FACTOR describes a torchao quantisation of the dense denoiser. H3's
hosted checkpoints are quantized AND structurally pruned (the curve-form adaLN, ~40% of the
released parameters), so 0.55 x 66.3 GB budgets 36.5 GB against a measured ~20.3 GB
(MiniMax-H3-FP8.pt 20,260,192,855 bytes, MiniMax-H3-INT8.pt 20,253,894,865, Hub metadata
2026-08-09), and the 16 GB gap refuses a supported prequant load that fits.

Record the measured resident size on the family and use it when a scheme is requested; the
generic factor stays the fallback for a family that publishes none.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 9, 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 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: dd9d64811b

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

# hosted denoisers are quantized AND structurally pruned (the curve-form adaLN), so 0.55 x
# 66.3 GB reads 36.5 GB against a real ~20.3 GB, and the 16 GB gap is enough to refuse a
# supported prequant load that fits on a 128 GB Mac.
measured = getattr(fam, "prequant_resident_gb", None) if scheme else None

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 Recheck the dense H3 fallback before loading components

When an explicit H3 fp8/int8 request runs on a unified-memory host whose safe budget fits the 20.3 GB prequantized denoiser but not the 66.3 GB dense one, this sizes the load as quantized before the checkpoint is fetched or validated. load_prequantized_transformer() is explicitly best-effort and can return None for a missing, corrupt, stale, or base-mismatched artifact; the subsequent branch then calls load_components() and builds the dense denoiser without repeating the refusal. In that failure scenario the load can therefore exceed unified memory and be killed by the OS; rerun the check with the dense component size before taking the dense fallback.

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.

Correct, and mine. Fixed in d6a74968e: when a scheme was requested and nothing was seeded (load_prequantized_transformer is best-effort by contract -- missing, corrupt, stale or base-mismatched all return None), the refusal is re-run on the dense component set before load_components, so the 66.3 GB build cannot slip past a check that sized 20.3 GB. Test drives exactly that path on a 160 GiB unified host: sized twice (fp8 then dense), refused, and load_components never called.

load_prequantized_transformer is best-effort by contract: a missing, corrupt, stale or
base-mismatched checkpoint drops to the released bfloat16 components. The refusal had already
sized the load at the ~20.3 GB checkpoint, so load_components then built the 66.3 GB dense
denoiser with nothing left to stop it -- on a unified-memory host whose budget fits one and not
the other, that is the OS kill the guard exists to prevent. Re-run the check on the dense set
when a scheme was requested and none was seeded, still before any weight is opened.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 776bacc8ac

ℹ️ 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 a905895 into main Aug 10, 2026
43 of 47 checks passed
@danielhanchen
danielhanchen deleted the umem-refusal branch August 10, 2026 02:32
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