Skip to content

Studio LTX-2.5: read the hosted int8 checkpoint as native Linears when the DiT is offloaded - #16886

Merged
danielhanchen merged 4 commits into
mainfrom
studio-ltx25-offload-int8-fresh-load
Nov 6, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-ltx25-offload-int8-fresh-load

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

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.safetensors and quantize at load instead. Concretely, an offloaded int8 load:

  • stages the 36 GB of dense bf16 transformer/ shards;
  • quantizes 480 Linears into native (torchao-free) int8 at load;
  • writes the 23.4 GiB result to the local prequant cache in the background, while the first clip renders.

The hosted file already holds per-row int8 codes and float32 scales of the same ConvRot-rotated weights. That is exactly what NativeWeightOnlyLinear stores. This PR reads the hosted file directly into native Linears whenever the plan offloads and the native W8A8 ConvRot build would run:

  • no dense shards are staged;
  • nothing is quantized at load;
  • nothing is written to the cache.

What / why / evidence

What

  • New 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:
    • the metadata (scheme, family, component, dtype, ConvRot kind and group, min_features, excluded layers) matches the native build;
    • the quantized layer set equals the set the runtime build would swap;
    • the rotated layers are exactly those whose width the group divides;
    • zero points are all zero and there are no static activation scales;
    • the recorded md5-canonical-v2 fingerprint verifies. This is the same check the torchao load runs, through a plain-tensor HostedInt8Parts view whose digests equal the Int8Tensor's.
  • Planner (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.
  • Load (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.
  • Scope: opt-in per family (native_offload_from_hosted_int8, set for LTX-2.5 only). UNSLOTH_VIDEO_NATIVE_HOSTED=0 restores 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;
  • a 94.8 s background cache write;
  • a 99.7 s first encode alongside that write;
  • a 58 s pin wait.

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:

LPIPS (prompt v0 / v1) vs Studio bf16 vs Studio resident int8 (hosted file, torchao)
base (runtime native build) 0.085 / 0.075 0.079 / 0.080
head (hosted codes, native) 0.097 / 0.047 0.086 / 0.054

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.

  • Page cache: every Studio arm first reads the pack, the hosted INT8 file AND the dense bf16 shards, so this table compares work, not disk.
  • First clip = load + cold render.
arm load s cold render s first clip s steady s / clip
base fresh #1 16.8 85.1 (denoise 62.7) 101.8 10.51
base fresh #2 15.7 52.3 (denoise 34.3) 68.0 10.60
head fresh #1 34.8 40.5 (denoise 29.3) 75.3 10.49
head fresh #2 34.2 40.0 (denoise 29.2) 74.2 10.49
base returning 18.5 149.8 (pin wait 85.9, encode 48.4) 168.3 10.51
head returning 13.1 28.0 41.1 10.63
  • Base fresh varies a lot (68 to 102 s) because its 23.4 GiB background write (81 s) overlaps the first render. Head has no write.
  • Head fresh load includes the one-time fingerprint verification of the 24 GB file (about 20 s). A returning load reads the file in 0.6 s.
  • Base returning reads its native cache file back, and pinning it took 87 s from disk.
  • Disk: head keeps 24 GB of hosted file instead of 36 GB of dense shards plus a 23.4 GiB cache entry. A fresh user downloads 12 GB less.

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:

arm load s cold render s first clip s
base fresh #1 34.5 143.8 (pin wait 50.5, denoise 77.1) 178.3
base fresh #2 92.9 54.8 147.8
head fresh #1 32.2 39.5 71.7
head fresh #2 29.6 40.0 69.7
base returning 15.6 120.3 (pin wait 98.5) 136.0
head returning 10.6 21.5 32.1

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):

  • Native layout: the hosted file reads into exactly the runtime native build's layer set, with the same rot_group / act_int8 / shapes. Codes and scales come from the file, and every dense tensor is bit-equal to the dense model's.
  • Refusals: wrong rotation group, other family, unrotated file, different excludes, a missing layer, a static activation scale, and corrupted codes (fingerprint mismatch) each fall back. So do a weight-only or fp8 native build.
  • Fingerprint: HostedInt8Parts gives the same canonical digest as a torchao Int8Tensor.
  • Gating: only an opted-in family with an int8, CUDA, W8A8 build takes the hosted file, and the env switch turns it off.

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.py and test_diffusion_native_quant.py pass, 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

  • Frames: not bit-identical to base (different quantization of the same weights, see Accuracy). Two prompts are not enough to call the LPIPS difference either way.
  • Other hosts: only the G4 at 16 GiB was measured. L4 / A100 offload rows and a host with less RAM than the 24 GB file read were not run.
  • Compile: no new compiled code. The modules are the same NativeWeightOnlyLinear class the runtime build makes, so no compile check was rerun on GPU.

… 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.
@danielhanchen danielhanchen self-assigned this Nov 6, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 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-11-06T08:09:08.461312Z 857f2f4 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[bot]

This comment was marked as resolved.

… 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]
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 857f2f4837

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

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot 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
danielhanchen merged commit 250895c into main Nov 6, 2026
@danielhanchen
danielhanchen deleted the studio-ltx25-offload-int8-fresh-load branch November 6, 2026 12:39
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).
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