Repository navigation
Studio: stop LTX-2 loads crashing Windows with an access violation on 32 GB machines - #13432
Conversation
torch maps a safetensors shard copy-on-write, and Windows charges the whole view against the commit limit while transformers holds every shard open. LTX-2's 48.7 GB fp32 Gemma3 text encoder loaded at bf16 then needs ~73 GB of commit, and on a 32 GB host torch's unchecked MapViewOfFile returns NULL and the first read is an access violation (0xC0000005). During a video load on Windows, transformers now opens fp32-stored shards with safetensors' pread backend (same bytes, no mapping). bf16 / fp16 shards and every other OS keep the default mmap path.
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 |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 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". |
…ust tests transformers 5.6 to 5.16 pass backend="mmap" to safe_open themselves, so the Windows fp32 shard would have kept the commit-charging mapping on those releases. 5.17 already picks pread on Windows upstream.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 402e9d035f
ℹ️ 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".
| current = getattr(modeling_utils, "safe_open", None) | ||
| if _depth: | ||
| installed = True | ||
| elif current is not None and _supports_backend(current): |
There was a problem hiding this comment.
Require a safetensors release that provides pread
On upgraded Studio environments that still have any valid pre-0.8 safetensors release, this condition leaves safe_open untouched, so the affected Windows LTX-2 load continues down the mmap path and can still terminate with the access violation this change is intended to prevent. Neither this commit nor the Studio requirements raises the existing safetensors>=0.4.3 floor (Transformers 5.5 also accepts that floor), so the updater has no reason to replace an already-satisfied 0.7 installation; add an installation migration/platform-compatible 0.8 floor or a fallback for older versions rather than silently disabling the fix.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 156f7c7: studio.txt and the pyproject studio extra now require safetensors>=0.8.0 on Windows, so an update replaces an older install instead of leaving the fix inert.
…ad backend An install that predates safetensors 0.8 keeps it on update (>=0.4.3 is already satisfied), and the Windows fix silently does nothing there. The floor is Windows-only; fresh installs already resolve 0.8.0.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 156f7c7d43
ℹ️ 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".
| "fastmcp>=3.0.2", | ||
| "gguf==0.19.0 ; python_version >= '3.10'", | ||
| "gguf==0.18.0 ; python_version < '3.10'", | ||
| "safetensors>=0.8.0 ; sys_platform == 'win32'", |
There was a problem hiding this comment.
Preserve the supported Windows Python 3.9 install
On Windows with Python 3.9, this requirement makes pip install "unsloth[studio]" unresolvable: the project declares support for Python 3.9, while safetensors 0.8.0 declares Requires-Python >=3.10, so pip currently has no candidate satisfying >=0.8.0. The mirrored requirement in studio/backend/requirements/studio.txt breaks that installation path as well, despite that file explicitly retaining Python 3.9-specific pins; gate this floor on python_version >= '3.10' with a compatible fallback, or formally raise Studio's Python floor.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c640e50: both lines now also carry python_version >= '3.10'; uv resolves 0.7.0 on Windows 3.9 (previously no solution) and 0.8.0 on 3.10+.
safetensors 0.8.0 requires Python >= 3.10, so the unmarked floor made the studio extra unresolvable on Windows Python 3.9.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
|
pre-commit.ci run |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
…ds (#14514) ## Summary GGUF image loads can exhaust Windows system commit while the small-host guard considers dense loading safe. The guard now also checks the Windows commit headroom, so affected loads take the existing low-memory route; the existing RAM refusal is unchanged. Fixes #14513 ## Changes - On Windows, read the commit headroom (`CommitLimit - CommitTotal`) with `K32GetPerformanceInfo`. A converting load keeps each copy-on-write safetensors view charged to commit next to the converted copy, so its commit need is the stored bytes plus the dense estimate (2x dense for an fp16 load; measured 2.06x on the Qwen-Image encoder). If that plus the reserve does not fit the headroom, the low-memory route engages even when physical RAM says the dense load fits. - The physical check is the same as before (dense estimate vs available RAM, no extra margin). Linux and macOS have no commit reading, so their decisions do not change. - On Windows, image pipeline loads now read every bf16 / fp16 safetensors shard that converts to another dtype with safetensors' `pread` backend (the scope #13432 added for fp32 video encoders, generalized). `pread` reads each tensor into its own buffer, so the stored bytes are never charged to commit; this is what transformers 5.17 does on Windows (huggingface/transformers#48341), and what ComfyUI and llama.cpp get by mapping read-only. Shards loaded at their stored dtype keep mmap, since that mapping is the weight and the low-memory route relies on it. The commit check then counts one copy for components read this way, so the reporter's load can stay dense instead of rerouting. - If unsloth's own Windows pread patch (#14856) is loaded in the same process, this scope still decides each shard inside a media load and tells it which shards to keep on mmap. - The pre-built GGUF transformer is not added to the estimate: diffusers copies every GGUF tensor into private memory when it builds the transformer, so both readings already exclude it. - The commit check only routes. The refusal still uses physical RAM, since a system-managed pagefile can grow past the current commit limit. - Log measured dense decisions as well, with the commit headroom when it is read, so a crash after a dense decision shows what the guard saw. - Add `UNSLOTH_DIFFUSION_HOST_RAM_LIMIT_MIB` to cap the total, available and commit values the guard sees, for testing. It does not enforce a process memory limit. ## Known limitations - A system-managed pagefile can grow, so the current commit limit can understate what Windows would eventually allow. Those hosts may take the low-memory route when a dense load would have just fit. - The commit estimate assumes Studio's pinned transformers 5.5, which reads shards through copy-on-write mmap on Windows. transformers 5.17 and later read them with `pread` on Windows (huggingface/transformers#48341), so there the source views cost no commit and the estimate is conservative: such installs may take the low-memory route sooner than needed. - The replacement/reload crash described in the issue is outside this change. Loading peaks and the timing of host-memory release need separate investigation. - The video loading path is unchanged. ## Testing `studio/backend/tests/test_diffusion_small_host.py` covers the #14513 case (a 16.7 GB bf16 encoder with the GGUF DiT already built: dense on physical RAM alone, routed with 30 GB of commit headroom, dense again with 50 GB), commit never refusing, LoRA keeping the dense denoiser, unreadable commit giving the same decisions as the physical check, the env cap, the Windows API reader (runs on Windows), and the pipeline call site passing the commit reading and logging dense decisions. Decision grid against `main` (3 families x fp16/fp32/bf16 x 5 host sizes x 22 free-RAM levels x LoRA on/off): with no commit reading, 864 of 864 cells give the same decision. With commit headroom from 0 to 192 GB, every cell that moves goes from dense to the low-memory route because the commit need does not fit; no new refusals and no LoRA cell moves. Windows commit, measured on `windows-latest` (transformers 5.5.0, safetensors 0.8.0) through this scope: a 1426 MiB bf16 checkpoint loaded at fp16 peaks at 3478 MiB of process commit with mmap and 2085 MiB with `pread`; the 1.4 GB difference is the copy-on-write charge for the stored bytes. Staging: 51 passed on Windows, 50 passed + 1 Windows-only skip on Ubuntu and macOS. GPU check on a Colab Tesla T4 (fp16 compute, like the reporter's V100), through Studio's real load and generate, with a Qwen-Image 2.1 pipe whose text encoder is 667 MiB bf16. With the commit reading faked to 1 GB, the guard logs `engaged=True (... 1024 MiB commit headroom (dense needs ~1536 MiB))`, the encoder loads memory-mapped with layerwise casting, and peak RSS drops from 2.92 to 2.31 GiB. With no commit reading (Linux) or a large one, the load stays dense. The image is bit-identical to `main` in all four arms. The same check with `UNSLOTH_SAFETENSORS_PREAD=1` forced on: the dense load reads the converted encoder through `pread`, and with the commit reading faked tight the route engages and keeps the encoder memory-mapped. Every arm's image is bit-identical to `main`. On the original 48 GB Windows host, the earlier version of this PR sent the previously failing Turbo load through the low-memory route, and it completed and generated images. With this version the same load needs about 43.4 GB of commit headroom to stay dense (38.4 GB for the source views and the fp16 copy, plus the 4.9 GB reserve). The failing run committed 44.7 GB before it ran out, so its headroom was below that and it routes. This version has not been rerun on that host yet. --------- Co-authored-by: Daniel Han <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…unslothai#17378) Fixes unslothai#17137 ## Problem On Windows, loading Qwen-Image-2.1-Turbo or FLUX.3 Klein (GGUF denoiser + base repo) onto an Intel Arc 140V (Lunar Lake iGPU, 32 GB shared RAM) fails with ``` OSError: The paging file is too small for this operation to complete. (os error 1455) transformers/modeling_utils.py, in _load_pretrained_model: safe_open(file, framework="pt", device="cpu") ``` and the retry kills the backend with `0xc0000005`, the native form of the same commit exhaustion (unslothai#13432, unslothai#14513). Why: - On Windows, safetensors' default mmap backend maps a shard copy-on-write, and Windows charges the whole view to the commit limit while any tensor from that shard is alive. - Studio's media-load scope (unslothai#14514) moves only *converting* loads to `pread`; a same-dtype bf16 load keeps the mapping, which is fine on a discrete card. - On an iGPU the device copy is host commit too. Qwen-Image-2.1's text encoder is one 16.3 GB bf16 file: its mapped view stays charged until the last tensor has moved to the XPU, so the load needs about twice the encoder in commit. ## Change - `pread_safetensors(..., every_shard=True)` reads same-dtype shards through `pread` as well (component dirs the small-host route keeps mapped still stay mapped). - The image-load scope sets it only on Windows when the current XPU is a Core Ultra Arc iGPU (`xpu_is_integrated()`, by PCI id: the iGPU subset of the existing XPU allowlist, split into `_INTEL_XPU_IGPU_PCI_IDS` with no change to `_INTEL_XPU_PCI_IDS`). Every other platform and device keeps the byte-identical path: off Windows the scope installs nothing, and on Windows a CUDA, ROCm, discrete Arc or unclassifiable XPU load passes `every_shard=False`. ## Tests `studio/backend/tests/test_safetensors_pread_igpu.py`: the iGPU classifier over Lunar Lake / Meteor Lake / Panther Lake vs discrete Arc / Data Center ids, the backend choice with and without `every_shard`, the image-load scope engaging only on Windows + iGPU, and a Windows-only commit measurement (bf16 load at bf16, then each weight copied the way `.to("xpu")` does on shared memory, mmap vs pread arms).
Fixes #9977
Problem
On Windows, loading
unsloth/LTX-2-GGUF(any quant) on a machine with around 32 GB of RAM kills the Studio backend withWindows fatal exception: access violation/ exit code0xC0000005. The crash happens intransformers/core_model_loading.py::_materialize_copywhile the Gemma3 text encoder fromLightricks/LTX-2is loaded.Why:
torch.UntypedStorage.from_file(shared=False). On Windows, torch does this with a copy-on-write view (PAGE_WRITECOPY+FILE_MAP_COPY), and Windows charges the whole view to the commit limit.MapViewOfFilereturns NULL. torch does not check that return value on this path, so the first read of a tensor (the.to(dtype)in_materialize_copy) is an access violation instead of a Python error.Fix
During a video load on Windows,
transformers.modeling_utils.safe_openopens shards stored mostly as fp32 with safetensors'preadbackend.preadreads each tensor into its own buffer instead of mapping the file.VideoBackend._run_loadand nests safely.backend="mmap"themselves, so that value is replaced for fp32 shards too. 5.17 already pickspreadon Windows upstream (Fixsafe_openmmap memory exhaustion on Windows by usingpreadbackend huggingface/transformers#48341); Studio pins 5.5.0.preadneeds safetensors 0.8.0.studio.txtand the pyprojectstudioextra now requiresafetensors>=0.8.0on Windows only, sounsloth studio update/ the Desktop updater replaces an older install. Fresh installs already resolve 0.8.0, and other platforms see no resolver change. With an older safetensors the scope does nothing.UNSLOTH_SAFETENSORS_PREAD=0turns it off and=1forces it on any OS.Evidence
All Windows results are from
windows-latestrunners (16 GB RAM, 18.9 GB commit limit, system-managed pagefile) with torch 2.10.0, transformers 5.5.0 and safetensors 0.8.0, the reporter's torch with Studio's pins. Each arm ran in its own fresh VM.Lightricks/LTX-2Gemma3 text encoder, 48.7 GB fp320xC0000005access violation (twice)0xC0000005(twice)Cost: about 0.3 s per GiB of fp32 shards on a warm cache. This only applies to fp32-stored checkpoints on Windows (the LTX-2 family's text encoder in the video picker). In exchange, those loads no longer need commit for the whole mapped file.
Full Studio
VideoBackendload ofunsloth/LTX-2-GGUFUD-Q2_K_XLon Linux, with the fix forced on viaUNSLOTH_SAFETENSORS_PREAD=1. This only shows the Studio path is wired; Linux itself is unaffected.torch.UntypedStorage.from_file86c4bcbb...86c4bcbb...(identical)Tests:
tests/test_safetensors_pread.pycovers:preadwith weights equal to the mmap load;mmaporpreadpassed in;pread, bf16 shards keep their backend, weights equal, patch restored) also passes on 4.57.6, 5.5.0, 5.10.0 and 5.17.0.test_video_backend.py,test_video_prequant.py,test_video_offline_load.pyandtest_diffusion_small_host.pypass: 583 passed.tests/studio/install/fails the same tests with and without the floor (installer step counts and a managed Node path, untouched here).Other video / image families
Header scan of every supported video base repo, showing which transformers-loaded parts are fp32 and so switch to
preadon Windows:text_encoder_2.Nothing switches for Wan2.2 or MiniMax-H3 (bf16 encoders), and denoisers / VAEs never switch: diffusers loads them through its own code. Image loads never enter the scope.
Forced on, through Studio's real
begin_loadpath:pread.Not covered
memory allocation of 180355072 bytes failed(exit0xC0000409) instead of an access violation. That is a real out-of-memory, not mapping overhead.