Skip to content

Studio: run vLLM and SGLang on Windows inside a private WSL2 distro - #12024

Merged
danielhanchen merged 166 commits into
mainfrom
studio-engines-wsl
Oct 2, 2026
Merged

danielhanchen merged 166 commits into
mainfrom
studio-engines-wsl

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Stacked on #11491. The base branch studio-opt-in-engines-base is #11491's head plus #12269, so this diff shows only the Windows layer. Retarget to main after #11491 merges.

Experimental until validated on a real Windows + NVIDIA machine (see "Not yet verified" below).

What this does

On native Windows x64 with an NVIDIA GPU, Settings > System > Inference engines no longer reads "unsupported". Clicking Install for vLLM or SGLang:

Before anything changes, the install prompt says that on Windows the engine runs inside WSL2 in Studio's own private Ubuntu environment, that the user's own distros are not touched, that Windows will show one administrator (UAC) prompt and may ask for a restart, and how much it downloads (engine wheels plus the 357 MB Ubuntu image on first setup). Nothing runs until the user clicks Install, and only after they chose vLLM or SGLang.

  1. Installs WSL2 if it is missing. One UAC prompt runs wsl.exe --install --no-distribution; nothing else is ever elevated. If Windows needs a restart, the job shows "Restart Windows to finish installing WSL, then click Install again." A Studio restart in the same Windows boot does not count as that restart (boot time is recorded), and after the restart the Install button resumes.
  2. Imports a private distro Unsloth-Engines-<hash of the Studio home> from a pinned Ubuntu 24.04 WSL rootfs (dated release 20240423, SHA-256 checked before import). The import runs unelevated so the distro is registered to the Studio user. The user's own distros are never touched. systemd is off in the distro.
  3. Installs the newest hash-pinned lock (vLLM 0.30.0 / SGLang 0.5.20) inside the distro with a pinned static uv (0.12.19, SHA-256 checked), then runs the same lock check, import smoke test and --help check as on Linux. It is always an isolated install, since Studio's Windows packages cannot be shared with a Linux interpreter.
  4. Launches the engine through wsl.exe under a small guest runner. Studio reaches it on 127.0.0.1 through WSL2 localhost forwarding; health checks, streaming and tokenize are unchanged.

Details

  • GPU selection: Windows and WSL can number GPUs differently, so GPUs are matched by UUID and passed as guest indices with CUDA_DEVICE_ORDER=PCI_BUS_ID. vLLM parses CUDA_VISIBLE_DEVICES as integers, so UUIDs cannot be passed directly.
  • Secrets: the HF token and proxy variables cross into WSL through WSLENV, never on the command line, so they stay out of the Windows process list.
  • Lifetime: the engine keeps a foreground wsl.exe child, so WSL's idle timeout does not stop the distro and no .wslconfig change is needed. The runner stops the engine's process group when Studio closes its stdin pipe, which also happens if Studio is killed.
  • Models: Hub models download inside the distro's own disk (/opt/unsloth/hf), not through /mnt/c. Local Windows paths are translated to /mnt/<drive>/....
  • Errors: BIOS virtualization and WSL kernel update failures map to actionable messages (codes from Microsoft's WSL troubleshooting guide). ARM64 Windows and builds older than 19044 are refused up front.
  • Locking: the engine lease uses LockFileEx on Windows (shared and exclusive), since fcntl does not exist there.
  • Removal: new owner route DELETE /api/engines/wsl/environment unregisters the private distro. Removing one engine only deletes its directory inside the distro.
  • Status polls never start WSL: status reads a state file; only install and load call wsl.exe.
  • Linux unchanged: every Windows branch is behind sys.platform == "win32", and the launch and stop code paths for Linux are the same as before.

Testing

  • tests/test_managed_engines.py (163) and the new tests/test_wsl_host.py (15): 178 passed on Linux.

  • The new tests drive the Windows host with a fake wsl.exe (tests/fake_wsl.py) that runs guest commands locally and logs every call. They cover the state across a restart, the waiting job state, WSLENV secrets, GPU index mapping, the launch command, and the SGLang launcher path. The guest runner is tested for real under sh: it stops the engine and its children when the pipe closes and when the owning process is SIGKILLed, and it passes the engine's exit code through.

  • End to end on Linux through the fake wsl.exe on a B200: the real install of the vLLM lock finished in 156 s, then vLLM served unsloth/Qwen3-0.6B through the runner and replied "2 + 2 = 4". Stop was clean, with no leftover engine processes. This run is what found the CUDA_VISIBLE_DEVICES integer requirement above.

  • Frontend typecheck passes; biome findings are unchanged from Studio: add opt-in vLLM and SGLang support with multi-GPU inference, quantization and vision #11491.

  • Install prompt copy per WSL state (wslNoticeKey), the WSL release choice and the WSL download size are covered by managed-engine-readiness.test.ts and test_wsl_installs_the_newest_release_and_prices_the_distro. Engine, WSL and transport suites: 263 passed.

Not yet verified

These need a real Windows + NVIDIA machine, which the Linux host and staging runners cannot provide:

  • the UAC prompt, the restart flow, and wsl --import of the pinned rootfs
  • GPU access inside WSL, and localhost forwarding in NAT and mirrored networking modes
  • SGLang inside WSL

UI: Settings > System, vLLM install waiting on a Windows step

Before (base 3df4446, the #11491 head this PR stacks on) and after (b78ab49; the frontend is unchanged since). Both sides were served the same /api/engines reply with the vLLM install job in the waiting state, the state a Windows host enters when WSL needs a reboot or the UAC prompt was declined. After this PR the reason and the next step show under vLLM with Install available again; before, the job's message was dropped.

Inference engines section before and after, vLLM waiting on a Windows restart

Install prompt on Windows, before and after

The Windows host adds the WSL2 and administrator (UAC) notice to the install confirmation. The engine row is served identically to both sides, so the size shown is the Linux host's.

vLLM install confirmation on Windows with the WSL2 notice, before and after

oobabooga and others added 30 commits September 21, 2026 15:36
SGLang opens an image_url string that starts with / as a local file, and
Studio forwarded bare base64-looking strings unchanged, so a padded path
reached that open(). Wrap bare base64 as a data URL (this also fixes
JPEG base64, which starts with /9j/) and refuse anything else.
The in-use probe in status() briefly took the engine lock without
waiting, so a poll landing on a load, install, remove or rollback
failed it as another Studio instance. Real takers now retry for a
second; probes still never wait. Cache the nvidia-smi answer and allow
60s: a loaded multi-GPU host took over 20s, past the old 5s limit,
and every poll spawned it again, so a supported B200 read as
unsupported. Also covers the data URL image change with engine tests.
The memory reservation and FP8 capability queries still gave up after
5s, so on a loaded multi-GPU host (about 20s per query) every vLLM or
SGLang load failed with 'Could not reserve memory on every selected
GPU' although the card was mostly free.
For a Hub model the engine downloads the weights itself inside the
startup wait, so any checkpoint that took over 15 minutes to fetch, or
a slow first compile, always failed with 'Engine startup timed out'.
The 15 minute limit now counts time without engine output, with a
4 hour ceiling; cancelling still stops it at any point.
vLLM 0.20 bundles DeepGEMM's _C extension for CPython 3.12 only, but
the engine environment runs 3.13. vLLM still reports DeepGEMM present,
so on Hopper and Blackwell GPUs its warmup raises 'DeepGEMM backend is
not available or outdated' and every model fails to start, bf16
included (vllm-project/vllm#41849). Set VLLM_USE_DEEP_GEMM=0 when no
matching build or standalone deep_gemm package exists.
The resident's engine, precision and parallelism are copied into the
runtime params from status, and a switch reset every other per-model
field but not these. After a vLLM or SGLang load, picking a model with
no saved settings loaded it through the same engine and settings; a
LoRA or audio pick was refused with 'Choose Default'. The adopt check
already assumed a switch starts on the default engine.
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 2, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 2, 2026
# Conflicts:
#	studio/backend/models/inference.py
#	studio/frontend/src/features/chat/lib/resident-config-match.ts
#	studio/frontend/src/features/model-picker/components/model-config-page.tsx
#	studio/frontend/src/features/model-picker/hooks/use-active-model-config.ts
#	studio/frontend/src/features/model-picker/model-config/apply-per-model-config.ts
#	studio/frontend/src/features/model-picker/model-config/config-signature.ts
#	studio/frontend/src/features/model-picker/sharing/fields.ts
@danielhanchen
danielhanchen changed the base branch from studio-opt-in-engines-base to main October 2, 2026 13:40
# Conflicts:
#	studio/backend/core/inference/engine_adapters.py
#	studio/backend/core/inference/engine_install.py
#	studio/backend/core/inference/managed_engine.py
#	studio/backend/routes/engines.py
#	studio/backend/tests/test_managed_engines.py
#	studio/frontend/src/features/model-picker/api/engines.ts
#	studio/frontend/src/features/model-picker/components/inference-engines.tsx
#	studio/frontend/src/i18n/locales/en.ts
#	studio/frontend/tests/managed-engine-readiness.test.ts
#	unsloth_cli/commands/studio.py
#	unsloth_cli/tests/test_studio_run_engine_flag.py
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 2, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 2, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 2, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 2, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 2, 2026
@danielhanchen
danielhanchen merged commit 619cd71 into main Oct 2, 2026
@danielhanchen
danielhanchen deleted the studio-engines-wsl branch October 2, 2026 15:23
JoshuaL3000 pushed a commit to JoshuaL3000/unsloth that referenced this pull request Oct 4, 2026
…nslothai#12024)

* Studio: add opt-in vLLM and SGLang inference engines

* Studio: extend optional engines with vision, precision and parallel modes

* Studio: allow loading explicitly restored inference engines

* Studio: support tool calling with managed inference engines

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Restore managed engine settings on rollback and launch the normalized local path

* Run optional engine checks in validate before the picker unloads

* Patch the httpx module the managed tool route imports in its tests

* Fetch remote image URLs in Studio before forwarding them to a managed engine

* Give managed engine requests the llama-server first-token deadline

* Refuse an outdated engine profile on the backend unless it was restored

* Name the text encoding for engine subprocess output and the lease file

* Update repository guard tests for the optional engine changes

* Run optional engines on Studio's PyTorch instead of a separate Python 3.12 environment

* Keep the chat GPU claim when a managed engine does not stop on unload

* Report a managed engine that survives load cancellation and keep it holding the chat GPU claim

* Launch managed engines only on GPUs visible to Studio

* Default the engine GPU picker to the first GPU Studio sees

* Load a compare pane with its remembered vLLM or SGLang settings

* Validate a model switch on the GPUs its load will use

* Trim comments in opt-in engine code

* Send managed engines only data URL images

SGLang opens an image_url string that starts with / as a local file, and
Studio forwarded bare base64-looking strings unchanged, so a padded path
reached that open(). Wrap bare base64 as a data URL (this also fixes
JPEG base64, which starts with /9j/) and refuse anything else.

* Keep engine status probes from failing real engine work

The in-use probe in status() briefly took the engine lock without
waiting, so a poll landing on a load, install, remove or rollback
failed it as another Studio instance. Real takers now retry for a
second; probes still never wait. Cache the nvidia-smi answer and allow
60s: a loaded multi-GPU host took over 20s, past the old 5s limit,
and every poll spawned it again, so a supported B200 read as
unsupported. Also covers the data URL image change with engine tests.

* Give the load-time nvidia-smi probes the same 60s allowance

The memory reservation and FP8 capability queries still gave up after
5s, so on a loaded multi-GPU host (about 20s per query) every vLLM or
SGLang load failed with 'Could not reserve memory on every selected
GPU' although the card was mostly free.

* Time out engine startup on silence, not a fixed 15 minutes

For a Hub model the engine downloads the weights itself inside the
startup wait, so any checkpoint that took over 15 minutes to fetch, or
a slow first compile, always failed with 'Engine startup timed out'.
The 15 minute limit now counts time without engine output, with a
4 hour ceiling; cancelling still stops it at any point.

* Disable vLLM's vendored DeepGEMM when it was built for another Python

vLLM 0.20 bundles DeepGEMM's _C extension for CPython 3.12 only, but
the engine environment runs 3.13. vLLM still reports DeepGEMM present,
so on Hopper and Blackwell GPUs its warmup raises 'DeepGEMM backend is
not available or outdated' and every model fails to start, bf16
included (vllm-project/vllm#41849). Set VLLM_USE_DEEP_GEMM=0 when no
matching build or standalone deep_gemm package exists.

* Start a model switch without a saved config on the default engine

The resident's engine, precision and parallelism are copied into the
runtime params from status, and a switch reset every other per-model
field but not these. After a vLLM or SGLang load, picking a model with
no saved settings loaded it through the same engine and settings; a
LoRA or audio pick was refused with 'Choose Default'. The adopt check
already assumed a switch starts on the default engine.

* Cache a failed nvidia-smi probe for 5 minutes

The engines list is polled every 30s for every user. A host without a
working NVIDIA driver re-ran nvidia-smi on each poll, once per engine,
and a hung driver held a worker thread for the whole 60s timeout.

* Format the engine switch test

* Give the engine silence test room for a slow interpreter start

A macOS runner took over a second to start the fake engine, so the
1s silence window expired before its first line.

* Never run nvidia-smi inside an engines status poll

On a loaded multi-GPU host each probe took 20-60s, and while one ran
every other /api/engines poll queued behind it holding a worker
thread; the switchboard saw /api/inference/status climb from 29ms to
an 11s median beside them. Status now answers from the cache or starts
one background probe and reports 'Checking for a supported NVIDIA
GPU.'; install and load still wait for the real answer.

* Run the malware and remote-code consent gates before a managed engine loads

The default path runs these gates in its worker. vLLM and SGLang load
the checkpoint themselves, so a managed load skipped both, and
trust_remote_code reached the engine without the consent scan or the
approved fingerprint. Scan what the engine will load (the local path
for a local model) and raise the gate's message.

* Treat saved vLLM/SGLang targets as managed in image checks

An auto-switch to a model whose saved settings pick vLLM or SGLang was
pre-checked as the default backend, so remote image URLs and several
images were refused before the load although the managed branch serves
both. Managed requests also skipped the 64 image per request cap
(vLLM's own default is 999).

* Let the legacy model_id-only delete clear a saved engine choice

The documented removal payload still copied the stored engine,
precision and parallelism into the rewritten row, so the entry never
emptied and API auto-switch kept loading through vLLM or SGLang.

* Reap a crashed engine before engine status, install, repair or removal

* Count managed-engine tokens when reasoning_effort is "none"

* Tighten engine comments

* Share Studio's PyTorch with engines installed from the PyTorch index

* Keep each engine environment's FlashInfer JIT cache inside it

* Hide Studio's NVFP4 FlashInfer from shared engine environments

* Give engines the locked pip nvcc for FlashInfer JIT on driver-only hosts

* Download only what Studio lacks: reuse its accepted versions, fetch FlashInfer kernels on demand

* Require glibc 2.35 for vLLM, whose wheel is manylinux_2_35

* Run managed engines on Windows inside a private WSL2 distro

On native Windows x64 with an NVIDIA GPU, installing vLLM or SGLang now sets
up WSL2 when it is missing (one UAC prompt, then a Windows restart if needed),
imports a pinned Ubuntu 24.04 rootfs as a distro owned by this Studio home,
installs the same hash-pinned engine lock inside it, and launches the engine
through wsl.exe. The Linux path is unchanged.

- GPUs are matched between Windows and WSL by UUID and passed to the engine
  as guest indices with CUDA_DEVICE_ORDER=PCI_BUS_ID.
- The HF token and proxies cross through WSLENV, never the command line.
- A guest runner stops the engine's process group when Studio closes its
  stdin pipe, including when Studio is killed.
- The engine lease uses LockFileEx on Windows (shared and exclusive).
- New owner route DELETE /api/engines/wsl/environment unregisters the distro.

* Update engines to vLLM 0.26.0 and SGLang 0.5.17

Both are the newest releases still built on torch 2.11, so they keep sharing
Studio's PyTorch.

- vLLM 0.20.0's FA4 ViT attention used cute.core.ThrMma, which CUTLASS DSL
  4.6 removed; its loose floor let the lock pick 4.8.0, so every vision model
  (e.g. unsloth/Qwen3.5-2B) crashed at startup on Blackwell. 0.26.0 pins
  cutlass-dsl 4.6.0 and no longer uses the alias.
- vLLM 0.26.0 applies the quant config to Qwen3.5's lm_head, so NVFP4
  checkpoints that quantize it (unsloth/Qwen3.8-27B-NVFP4) load.
- vLLM 0.26.0 ships a manylinux_2_28 wheel and bundles DeepGEMM for CPython
  3.13, so the glibc 2.35 floor goes back to the 2.34 the locks resolve for.
- SGLang 0.5.17 needs transformers 5.12.1 and flash-attn-4 4.0.0b18.

* Keep TorchAO precisions working on the upgraded engines

- SGLang 0.5.17 routes unquantized linears on Blackwell through a cutedsl
  GEMM with no TorchAO tensor-subclass dispatch, so int4 and int8 failed
  with NotImplementedError. Those loads now pass --bf16-gemm-backend torch;
  unquantized models keep the fast kernel.
- vLLM with TorchAO weights (int8, fp8, pipeline int4) allocates past its
  reserved fraction in sampler warmup (2.4-4.8 GiB on an idle B200 at the
  default 0.97 budget), so int8 ran out of memory on an idle GPU. Those loads
  now leave 6 GiB more free; every other load is unchanged.

* Accept a text response_format on managed engines and name audio models correctly

A spelled-out {"type": "text"} response_format is the OpenAI default and
constrains nothing, so vLLM and SGLang now serve it instead of returning 400.
An audio checkpoint that also reads images was refused as a vision model even
though vision is supported; it is now reported as an audio model.

* Name utf-8 on the WSL host test's guest file writes

* Reap engine workers after a crash, honour cancel during WSL download, withhold unrequested tokens

* Serve managed-engine n > 1 one choice at a time, reap an engine a cancelled load left behind

* Serialize WSL preparation across engines; detect localized UTF-16 wsl.exe output

* Report the public model id on managed-engine tool responses

* WSL engines: honour offline mode, keep a committed env on cleanup failure, clear orphaned imports, check unregister, find nvidia-smi off PATH, no console window

* Serve a tool catalog with tool_choice none as plain chat on models without a parser

* Resolve nvidia-smi for the launch-time memory budget; drop a removed engine's WSL compile cache

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Keep a registered distro's disk on a failed reset, refuse removal while WSL is unresponsive, hide host GPU probe windows

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Store only non-default engine fields in model overrides, so an all-default save leaves no row

* Refuse to start training while a managed engine that failed to stop still holds the GPUs

* Pass the engine key in the environment and guard every vLLM route with it

* Reuse Studio's TorchAO for engines only at the version the adapter configs use

* Leave engine-specific VRAM headroom measured on a 24 GB card

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Keep the NVIDIA driver's library path for managed engines and their install checks

* Revert the driver library path change; it moves to its own PR

* Name the encoding on the WSL owner file write in the tests

* Keep the NVIDIA driver's library path for managed engines and their install checks (unslothai#12269)

* Engines: lock a release per Studio PyTorch (vLLM 0.30 / SGLang 0.5.20 on torch 2.13) and show the download size

* SGLang 0.5.18+: run without --torchao-config and refuse load-time INT8 / INT4 with a clear message

* Precision picker: disable INT8 and 4-bit for SGLang releases without load-time TorchAO

* SGLang 0.5.18+: disable CUDA graphs with the per-phase backend flags

* Engines: skip CUTLASS DSL's CUDA 12 libraries, which a driver 580 host never loads

* unsloth run: --engine vllm|sglang serves through an optional engine, installed on first use after a confirmation

* unsloth run --engine on Windows: show the WSL2 and administrator prompt notice before installing

* Engines: share nvcc's headers only at the locked release, so FlashInfer's JIT builds on Colab

* Engines: take nvcc and its headers from one release, all from Studio or all from the lock

* Reaping a crashed engine also drops its chat GPU claim and shared residency

* Shared engines: keep the engine's nvidia tree first when Studio's site has a regular nvidia package

* Engines: an INT4 / INT8 SGLang cannot convert resets on switching and is refused before unloading

* Engines: CUDA runtime headers travel with nvcc, so a shared engine never mixes crt releases

* unsloth run --engine: a restored engine loads as is

* Engines: one merged CUDA include tree, so Studio headers pick up the engine's crt

* Engines: keep a share of large GPUs free for vLLM's sampler warmup

* Engines: keep the current-date note on rebuilt managed-engine messages

* WSL engines: forward the hf auth login token to the guest

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Model picker: keep GGUF row badges aligned with rows that have the settings action

* Engines: validate the INT4 a legacy load_in_4bit request becomes, before unloading

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Engines: keep lock files byte-exact on Windows clones; mark Linux-only engine tests

* Engine lease tests run on Windows too, now that leases use LockFileEx there

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Engines: install-machinery tests are Linux engine-host tests

* WSL tests: wait on the job file status reads; guest runner tests are Linux only

* Engine tests on a real Windows host: skip the POSIX wsl.exe fake and Linux local-host cases

* Tests: skip the GPU query cache reset while a probe thread is still importing it

---------

Co-authored-by: oobabooga <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants