Repository navigation
Studio LTX-2.5: read the hosted int8 checkpoint as native Linears when the DiT is offloaded - #16886
Merged
Merged
Conversation
… an offloaded DiT An offloaded int8 LTX-2.5 load declined the hosted INT8-ConvRot file (offload hooks cannot move torchao weights), so it staged the 36 GB of dense bf16 transformer shards, quantised 480 Linears at load and then wrote a 23 GB native build to the local prequant cache in the background while the first clip encoded. The hosted file already holds per-row int8 codes and float32 scales of the same ConvRot-rotated weights, which is what the native Linear stores. When the plan offloads and the native W8A8 ConvRot build would run, the planner now stages the hosted file instead of the dense shards and the load reads it into native Linears (same layer set, rotation and activation path as the runtime build, fingerprint verified). Any mismatch falls back to the dense shards and the runtime build, as before. UNSLOTH_VIDEO_NATIVE_HOSTED=0 keeps the old 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. |
… cancel event The hosted-native plan drops the dense shards, so the hosted artifact is the file the load needs: claim its repo for the load and stage it through the cancellable prefetch, as a seeded artifact is, instead of letting the load download it later without a cancel event. [skip ci]
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
This was referenced Nov 6, 2026
danielhanchen
added a commit
that referenced
this pull request
Nov 6, 2026
…e stubbable package (#16898) ## Summary Since #16793 (`90e1e733c4`), Backend CI `(Python 3.13, g-r)` fails on unrelated PRs. The last hour's staging runs for #16887, #16886 and #16882 all show the same two tests: ``` tests/test_load_download_repos_mapper.py:11: in test_unmapped_lora_base_skips_the_remote_mapper from unsloth.models import loader_utils E ModuleNotFoundError: No module named 'unsloth.models'; 'unsloth' is not a package ``` What #16793 tests (skipping the remote mapper for unknown LoRA bases) is fine. The two new tests guard with `pytest.importorskip("unsloth")` and then `from unsloth.models import ...`. In the backend job, several test files stub `unsloth` at import time as a plain module (`_stub_if_missing` in `test_audio_type_inconclusive.py` and others) when the real package cannot be loaded. If one of those runs earlier in the same xdist worker, `importorskip("unsloth")` returns the stub instead of skipping, and the submodule import fails. Run alone, or in a worker where nothing stubbed it, the tests pass. That is why it depends on how the shard is laid out. ## Change - `studio/backend/tests/test_load_download_repos_mapper.py`: `importorskip` the submodules the tests use (`unsloth.models.loader_utils`, `unsloth.models.loader`). With a stub in place they now skip, the same as with no unsloth at all. With the real package they run unchanged. - `studio/backend/tests/test_backend_tests_stub_heavy_imports.py`: `test_no_test_importorskips_bare_unsloth` fails if any backend test calls `pytest.importorskip("unsloth")` on the bare package, and pins its own detector both ways. No other backend test does this today. The rule is narrowed to `unsloth`, since the `trl` stubs carry the attributes their tests read. ## Testing On `studio/backend`, with a one-line test file that stubs `sys.modules["unsloth"]` as a plain module run first (what the shard does): | | main | this branch | |---|---|---| | stub first, then `test_load_download_repos_mapper.py` | 2 failed (the error above) | 2 skipped | | `test_load_download_repos_mapper.py` alone, real unsloth | 2 passed | 2 passed | | `test_backend_tests_stub_heavy_imports.py` | 6 passed | 7 passed | Putting back the original `importorskip("unsloth")` makes the new guard fail and name `test_load_download_repos_mapper.py`.
danielhanchen
added a commit
that referenced
this pull request
Nov 6, 2026
… memo tests (#16908) ## Summary `Repo tests (CPU, studio)` has been failing on unrelated PRs since #16793 landed, always in the same test with a different parameter each time: ``` tests/python/test_preference_chunked_logprobs.py:278: in test_matches_trl torch.testing.assert_close(g, w, rtol = 1e-4, atol = 1e-6) E AssertionError: Tensor-likes are not close! E Mismatched elements: 1 / 32 (3.1%) E Greatest absolute difference: 3.814697265625e-06 at index (0, 6) (up to 1e-06 allowed) ``` Seen on the staging runs for #16109, #16886, #16882 and #16877 today (`cpo-kwargs1`, `kwargs2`, `kwargs3`, `kwargs5`, `kwargs6`, always `qwen3_lora`). The cause is test pollution. #16793 added `test_load_probe_memo.py::test_fastmodel_adapter_load_probes_base_config_once`, which runs `FastModel.from_pretrained` up to the weights. That load does what it does in real use: it swaps PEFT's LoRA forwards (`peft.tuners.lora.layer.Linear` and 8 other LoRA layer classes) for Unsloth's, process-wide, and sets `UNSLOTH_FORCE_FLOAT32`, `UNSLOTH_FULLGRAPH`, `UNSLOTH_RETURN_LOGITS` and `UNSLOTH_MODEL_NAME`. The test never puts them back, so when xdist schedules the CPO parity test on the same worker later, it compares the chunked path against TRL on Unsloth's LoRA forward instead of stock PEFT, and its tight gradient tolerance trips. The swapped forward is the part that matters: restoring only the environment variables still fails with the same numbers, restoring only the forwards passes. Neither side's product code is wrong. #16793's loader change and its probe-count assertions are correct; only the test leaks process state. ## Change Tests only. - `tests/python/test_load_probe_memo.py`: an autouse fixture records every PEFT LoRA layer class's own `forward` and the `UNSLOTH_*` variables before each test and puts them back after. A PEFT module first imported during the load falls back to the `_unsloth_original_forward` the wrapper carries. - `tests/python/test_preference_chunked_logprobs.py`: `test_matches_trl[...-qwen3_lora]` pins stock PEFT forwards for its duration (through `monkeypatch`), since its reference is TRL on stock PEFT. This keeps it deterministic whatever else ran earlier in the worker. ## Testing The failing worker's exact history from a local rerun of the CI shard (`-n 4 --dist loadgroup`) replayed serially reproduces the CI failure with the same numbers, and bisects to the #16793 test. With that test followed by `test_matches_trl[cpo-kwargs1-qwen3_lora]`: | | result | |---|---| | main | 1 failed (`3.814697265625e-06 at index (0, 6)`, as in CI) | | this branch | 2 passed | | this branch, parity test pin removed | 2 passed | | this branch, probe memo fixture disabled | 2 passed | | this branch, both removed | 1 failed (same numbers) | The same failing worker's history replayed serially (1595 tests) on this branch: `test_matches_trl[cpo-kwargs1-qwen3_lora]` passes. On main the same replay fails it. One other failure in both arms, `test_cached_paths_hold_no_credentials.py::test_model_cache_variables_are_not_treated_as_credential_homes`, comes from this machine's environment; it passes in CI and is unchanged here. Both touched files pass in full: `tests/python/test_load_probe_memo.py` plus `tests/python/test_preference_chunked_logprobs.py`, 33 passed (torch 2.10.0+cpu, transformers 5.17.0, TRL 1.15.0, PEFT 0.21.2, the CI shard's versions).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a GPU is too small to hold the LTX-2.5 DiT, the int8 load offloads it. Offload hooks cannot move torchao weights, so these loads skip the hosted
LTX-2.5-INT8-ConvRot.safetensorsand quantize at load instead. Concretely, an offloaded int8 load:transformer/shards;The hosted file already holds per-row int8 codes and float32 scales of the same ConvRot-rotated weights. That is exactly what
NativeWeightOnlyLinearstores. This PR reads the hosted file directly into native Linears whenever the plan offloads and the native W8A8 ConvRot build would run:What / why / evidence
What
diffusion_native_hosted.py: reads the hosted int8 file into native Linears. It refuses the file, and the load falls back to the dense shards and the runtime build as before, unless all of the following hold:HostedInt8Partsview whose digests equal theInt8Tensor's.video.py): when the artifact-sized plan still offloads and the request resolves to int8 on a CUDA card with the W8A8 ConvRot path, the planner stages the hosted file instead of the dense shards. This applies to both the load's pre-download and the download panel's plan.video.py): after a native-cache miss, the load reads the hosted file. A local native-cache hit still wins, so an existing user replays the build they already have.native_offload_from_hosted_int8, set for LTX-2.5 only).UNSLOTH_VIDEO_NATIVE_HOSTED=0restores the old path.Why. The Nov 5 G4 16 GiB INT8 fresh first clip took 316.8 s. Its log shows where the time went:
built 480 host linear(s) on cuda one at a time (25.8 GB in 100.8 s): the dense shards were read from disk;Accuracy. Frames are not bit-identical to base. The runtime build quantizes the bf16 weights itself, while the hosted file was built by the hosted-checkpoint builder. Both are per-row symmetric int8 of the same ConvRot-rotated weights, but about 7-8% of codes differ by 1 and the scales differ by about 0.6%. The codes this PR loads are the ones Studio's resident int8 path (the default on cards that hold the DiT) already uses. Measured against Studio's own bf16 render on the same VM:
Both arms of each tree are bit-identical to each other (A/A, PSNR 99 dB).
Evidence. LTX-2.5 1280x704x121 two-stage distilled, INT8, held to a 16 GiB budget on a G4 (RTX PRO 6000 Blackwell), Colab. Base = main b75a4cd, head = this branch, one VM, one fresh process per arm.
Same row with the dense shards on disk but not in the page cache, the condition of the Nov 5 row: the pack and the hosted file are prewarmed, and the 35.4 GiB of
transformer/shards are evicted before every Studio arm. Same kind of VM, second session:Head fresh is 2.1-2.6x faster and head returning 4.2x faster. Each tree's two fresh arms render bit-identical frames, and the frames match the first session's.
Tests
New
studio/backend/tests/test_video_native_hosted.py(11 tests, CPU, tiny LTX2VideoTransformer3DModel written in the hosted layout):rot_group/act_int8/ shapes. Codes and scales come from the file, and every dense tensor is bit-equal to the dense model's.HostedInt8Partsgives the same canonical digest as a torchaoInt8Tensor.These tests fail on main (the module does not exist).
test_video_ltx25_prequant.py,test_video_prequant.py,test_diffusion_prequant.py,test_diffusion_native_stream_build.pyandtest_diffusion_native_quant.pypass, except one test that fails on main as well with this host's torchao 0.17 (test_unpinned_torchao_host_copy_is_a_distinct_wrapper_over_the_same_data).Not proven
NativeWeightOnlyLinearclass the runtime build makes, so no compile check was rerun on GPU.