Repository navigation
feat(studio): polish remote access ui and fix slow tunnel start - #2
Merged
Lyxot merged 7 commits intoAug 6, 2026
Conversation
The remote access controls rendered as flat settings rows, so the feature read as hidden and the tunnel URL was squeezed into a description cell. Rebuild remote-access-section.tsx as a bordered card: - header with globe icon, title, live status dot plus state text and the start/stop action together - online state gets a dedicated URL panel with a copy button, a QR button that opens a scannable code for phones (react-qr-code, svg, zero deps), and a note that the URL plus remote password grants sign in - block reasons and tunnel errors render as their own strip, destructive styling on error - shine sweep on the status text while starting or stopping - password and auto start rows move below a divider inside the card Polling and start/stop/auto-start logic are unchanged.
Starting remote access took 45-48s while a manual tunnel came online in about 8s. _wait_for_dns queried DoH immediately after the edge connection registered, before the fresh trycloudflare hostname propagated, and the resolver negative-cached the NXDOMAIN (trycloudflare.com publishes a 1800s SOA negative TTL; 1.1.1.1 was observed serving the stale negative for about 40s while the loop re-asked it every 2s). - delay the first lookup 3s so it cannot seed those negative caches - ask two independent resolvers per round (cloudflare and google DoH) - cap the dns wait at 20s so it can never starve the health probe, which is what actually gates advertising the URL Start to online now measures about 12s end to end against a live backend. The consecutive-error bailout for blocked DoH is unchanged.
A stop worker outlives its completed stop by up to about a second while draining stop responses. During that window remote_access_status kept reporting state stopping and forced can_start false, so a quick stop-then-start flashed "Stopping" in the UI and the start request could 409 as operation_in_progress. Once the tunnel controller reports off with no pending stop handle the stop is done, so a still-alive stop worker no longer masks the idle state or a newly admitted start. Unconfirmed terminations (stop_pending) keep reporting stopping so retry stays visible.
|
@codex review |
Asking a second DoH resolver in the same round cannot rescue the poll: both queries land milliseconds apart, so the round that seeds one resolver's negative cache seeds the other's too. It also disclosed the freshly issued hostname to a third party on nearly every start, where the provider that handed the name out already knows it. The hold-off and the wait cap stay, which is where the measured speedup comes from. The cap trades one case away: a hostname that only propagates after 20s now meets the OS resolver while it is still missing, and because the tunnel has registered by then a failed probe ends the attempt instead of retrying over http2. In exchange every start whose record exists by 20s spends the rest of the deadline on probe attempts rather than a single one at 45s.
A stop worker outlives the teardown it performed, so reporting stopping until that thread exits hid the tunnel already being off and refused a start that would have succeeded. The worker's recorded admission sits behind the control token once its teardown advanced the generation, but a start advances the generation the same way, so only that advance together with an off tunnel and no pending stop shows the teardown actually happened.
The status text goes back to full opacity. The shimmer needs partly transparent glyphs, which put the transitional states below the contrast that same text had before, and a viewer who asked for reduced motion paid that cost with no sweep to show for it. The status dot already marks the transition. The auto-start switch's accessible name matches its visible label again after the rename, and the block reason no longer borrows the error colour when a failed tunnel is not what it is reporting. Moving the URL panel and the block-reason strip out of the section body keeps the section at the complexity it had before the card, and SettingsRow drops labelAccessory along with the row that used it.
Cloudflare routes quick tunnels by TLS SNI, so the edge serves a tunnel as soon as its connection registers, before the hostname resolves anywhere. Probing an edge address with the tunnel's name in SNI and Host takes that hostname's DNS off the startup path, along with the wait that existed only to keep an early lookup from caching the miss. Measured over four fresh tunnels each: verification after registration falls from 10.97s to 6.61s on average, and a whole start from 22.9s to 16.8s. It also removes the case behind the slowest starts, where one DoH query sent before the record propagates is negative-cached, blinding the poll until its own cap expires and pushing a start past 30s. The hostname path stays as the fallback for networks that block direct addresses or intercept TLS. It is entered as soon as the edge looks unreachable rather than merely unready: an error 1033 page is an answer, a failed connection is not.
NilayYadav
pushed a commit
that referenced
this pull request
Nov 6, 2026
…n the DiT is offloaded (unslothai#16886) ## 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.
NilayYadav
pushed a commit
that referenced
this pull request
Nov 23, 2026
## Summary On a native FSDP2 resume every rank calls `torch.load(optimizer.pt, map_location="cpu")` on the whole, unsharded optimizer state and then keeps only its own shards. An eager load gives each rank its own anonymous copy of the full file, so host RAM needs about (ranks per node) x (optimizer.pt size) at the moment of the resume. For full fine-tuning with AdamW that is 8 bytes per parameter per rank. This loads `optimizer.pt` with `mmap=True`. The tensors are file-backed and the ranks on one node share the pages through the page cache, so the anonymous allocation goes away. `set_optimizer_state_dict` still copies each rank's shards to the device exactly as before. - A file object, or a file torch cannot map (legacy non-zip serialization), loads eagerly as before. - Other load errors still propagate (the fallback only matches torch's own "mmap can only be used" error). - Only `native_load_optimizer` changes. The DCP directory path (`UNSLOTH_FSDP2_DCP_OPTIM=1`), the scheduler load and the model weight reader are untouched. ## Measurements Kaggle 2x T4, Qwen3-0.6B full fine-tuning, native FSDP2 sharded over 2 ranks, `adamw_torch` (optimizer.pt 4.77 GB), torch 2.14.1, transformers 5.17.0. The window measured is the call to `native_load_optimizer`, with RSS sampled every 20 ms. Arms alternate: eager, mmap, eager, mmap. | arm | RssAnon peak increase per rank | host MemAvailable drop (both ranks) | load time | resumed losses (steps 4, 5) | |---|---|---|---|---| | eager #1 | +4.57 GiB | 8.8 GiB | 23.5 s (cold cache) | 11.260438, 11.153262 | | mmap #1 | +0.13 GiB | 0.3 GiB | 4.8 s | 11.260438, 11.153244 | | eager #2 | +4.57 GiB | 8.8 GiB | 7.6 s | 11.260438, 11.153244 | | mmap #2 | +0.13 GiB | 0.1 GiB | 4.8 s | 11.260438, 11.153270 | - The anonymous memory a rank needs for the resume drops from 4.57 to 0.13 GiB (-97%). Repeated runs of each arm give the same number (spread 0.00 GiB). - Device peak during the load is unchanged (5.571 GiB in every arm). - Losses: step 4 is bitwise identical in all four arms. Step 5 varies by up to 2.6e-5 between the two eager runs themselves, and the mmap runs fall inside that spread. The same check on torch 2.15.0, this branch's tree against main with no injection, alternating main / head / main / head. On the head, `torch.load` received `mmap=True` for `optimizer.pt` on both ranks: | arm | RssAnon increase per rank | host MemAvailable drop | load time | losses (steps 4, 5) | |---|---|---|---|---| | main | +4.57 GiB | 9.14 GiB | 23.5 s (cold) | 11.280999, 11.154003 | | this branch | +0.13 GiB | 0.28 GiB | 5.0 s | 11.280999, 11.153976 | | main | +4.57 GiB | 8.68 GiB | 7.8 s | 11.280999, 11.154009 | | this branch | +0.13 GiB | 0.15 GiB | 4.9 s | 11.280999, 11.154009 | ## Tests - `tests/test_fsdp2_native_optim_mmap_load.py` (new): `native_load_optimizer` passes `mmap=True` for a path; the mapped load equals the eager one; a legacy non-zip file and a file object load eagerly; other errors propagate. 4 of the 5 fail on main and all 5 pass here. - `tests/test_native_resume_old_torch.py` still passes: torch < 2.6 is refused before any load. - The gloo resume tests (`test_fsdp2_native_resume_gloo.py`, `test_fsdp2_native_dcp_resume_gloo.py`, `test_fsdp2_native_optim_unstepped_gloo.py`) pass.
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.
Polish and fixes for the remote access settings introduced on this branch, targeting
feat/studio-public-accessso they land in unslothai#7875.UI (remote-access-section.tsx)
Fixes
_wait_for_dnsqueried DoH before the fresh trycloudflare record propagated and the resolver negative-cached the NXDOMAIN (1800s SOA negative TTL, ~40s observed hold). the wait now delays its first query 3s, asks two resolvers per round and is capped at 20s so it can never starve the health probeTesting