Skip to content

Studio: add opt-in vLLM and SGLang support with multi-GPU inference, quantization and vision - #11491

Merged
danielhanchen merged 94 commits into
unslothai:mainfrom
oobabooga:feat/studio-opt-in-engines
Oct 2, 2026
Merged

danielhanchen merged 94 commits into
unslothai:mainfrom
oobabooga:feat/studio-opt-in-engines

Conversation

@oobabooga

@oobabooga oobabooga commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Adds vLLM and SGLang as optional inference engines in Studio, with text and image chat, concurrent API requests, quantization and multi-GPU serving. Neither engine is installed by default.

The main installation constraint is their dependency stack: installing either into Studio's Python environment could replace packages Studio needs. Each engine gets an isolated environment while reusing package downloads and the existing model cache.

What changes

  • The existing model run settings gain an engine selector, precision choices and GPU selection. Multiple GPUs can use tensor parallelism, pipeline parallelism or replicas. These settings can be remembered per model and apply to API auto-loads too.
  • Engines install on demand. Settings > System gains install, repair, removal and rollback controls. Progress uses the existing download panel, with package messages and cancellation.
  • Studio manages the engine process and forwards chat requests to its native API. Streaming requests can run concurrently; cancelling or disconnecting one leaves the others running. Unloading stops the engine and its workers.
  • Vision models accept image attachments and OpenAI image content parts. Precision supports stored quantization and on-load conversion to 4-bit, INT8 or FP8, alongside BF16 and FP16.

One engine and model are active at a time. Pipeline mode splits layers across GPUs; replicas distribute requests across workers. Dense replicas need a full model copy on each GPU, while native MoE layouts may share experts.

Installation and package reuse

Package versions and hashes are pinned. Compatible package downloads are reused, and identical files share disk storage where the filesystem supports it. Different versions or copy-only filesystems can still duplicate files; disk savings were not measured.

A new installation is checked before activation. Failed repairs preserve the previous installation, and removing an engine keeps downloaded models. A running engine is protected from changes by another Studio instance.

Screenshots

Engine, precision and multi-GPU settings in the existing model panel:

01-engine-and-gpus

Installation and recovery controls in Settings > System:

02-manage-engines

Full Studio window during a vLLM installation, with model run settings open alongside the shared progress panel:

04-install-progress

Four real SGLang requests in flight through Studio's API:

03-concurrent-api-requests

Verification

Live tests used an RTX 6000 Ada and RTX 3090, individually and together, with Qwen2.5-0.5B and Qwen3.5-0.8B.

  • Playwright covered installation, chat, image upload, engine and GPU selection, mode-only reloads and persistence after refresh. API-key requests restored the UI-saved engine, precision and GPU settings.
  • Concurrent requests were compared through both Studio chat endpoints and each engine's native API. Streams overlapped, prompt-token counts matched, and sibling requests survived cancellation and disconnection. Quantized response wording can differ.
  • Both engines passed 4-bit vision requests in pipeline and replica modes, including multiple images, historical images and remote URLs. Other runs covered INT8, FP8 and prequantized BitsAndBytes checkpoints.
  • Recovery tests covered repair, rollback, cancellation, interrupted downloads, Studio shutdown during repair, worker cleanup and reinstallation. Studio's package manifest remained unchanged.
  • Focused backend suite: 899 passed, 1 skipped. After the final compatibility guard, all 119 managed-engine tests passed. Frontend tests: 7,857 passed. Typecheck, production build and translation checks passed.

Scope and limitations

Experimental support for Linux x86_64 with glibc 2.34+, NVIDIA driver 580+ and GPUs with compute capability 8.0+. Model and quantization compatibility still depend on the native engine.

Prequantized BitsAndBytes checkpoints cannot use tensor parallelism in these versions, or pipeline mode in SGLang. Both engines passed pipeline serving with on-load 4-bit conversion. Layer splits follow engine defaults and do not automatically balance unequal GPU capacities.

LoRA, audio/video, tools, structured output, reasoning controls, continuation, multi-node serving and combinations of parallel modes are outside this version. Exact prompt token counting is unavailable for SGLang.

Testing used an existing Studio runtime with a fresh profile. A clean OS installation, upgrade from an older desktop release, full backend suite and live training were not tested. Some vision runs used cached files offline after a Hugging Face lookup stalled. Performance was not benchmarked.

UI: Settings > System

Before (merge base 901d9fd) and after (head 0f6207d). The System tab gains an Inference engines section between the GGUF inference engine and Model memory, with vLLM and SGLang rows and an Install engine button each; /api/engines goes from 404 to listing both engines as not installed.

Settings System tab before and after

Saved model settings after the review fixes

BEFORE is this branch at fdf3502 (before the review fixes), not the merge base, since the change is in this PR's own code. AFTER is 5f6a726. Both sides save the same two overrides through PUT /api/settings/openai-auto-switch/overrides: unsloth/Qwen3-0.6B with engine vLLM at BF16, and unsloth/Qwen2.5-0.5B-Instruct with an all-default Remember save.

BEFORE stores both, and the list reads "App defaults" for each, so it hides the saved engine and precision. AFTER stores only the non-default one and names it ("engine vllm · bf16"); the all-default save leaves no row.

Settings applied on API load, before and after the review fixes

Cloud and AMD runs

Each Colab and Kaggle cell ran one notebook from a branch that combines this PR with #12024 and #12150. The notebook runs studio/setup.sh --local, then a 5 step LoRA SFT on unsloth/Qwen2.5-0.5B-Instruct. It then checks that vLLM was not installed by setup, installs it from Studio on demand, starts it, generates, and stops it. Every cell raises on failure, so the verdict comes from the executed notebook.

Platform Torch SFT vLLM
Colab T4 (High RAM) system pass, finite loss refused before download (compute capability 7.5)
Colab L4 2.11.0+cu130 pass 0.26.0 reusing Colab's torch, 0.9 GB download, env 2.5 GB, started in 208 s, answered "4", stopped, no leftover process
Colab A100 2.11.0+cu130 pass 0.26.0 reusing Colab's torch, env 2.5 GB, started in 199 s, answered "4", stopped, no leftover process
Colab G4 (RTX PRO 6000, 96 GB) 2.11.0+cu130 pass 0.26.0 reusing Colab's torch, env 2.5 GB, started in 198 s, answered "4", stopped, no leftover process
Kaggle 2x T4 2.10+cu128 pass on both GPUs refused before download (compute capability 7.5)
AMD Strix Halo gfx1151 (Linux) 2.11.0+rocm7.13.0, same on base and head NO_REGRESSION, loss 11.928 on both refused ("Requires an NVIDIA GPU"), nothing installed, Studio venv untouched

Two of these runs found bugs, both fixed in this PR:

  • On Colab the shared engine's CUDA JIT build failed with __cudaLaunch errors. Studio headers were picking up Colab's newer nvidia-cuda-crt. The engine now gets one merged CUDA include tree, with its own headers first.
  • On the 96 GB G4, vLLM ran out of memory in its sampler warmup. That warmup grows with the card, because vLLM raises its default batch size on large GPUs. Studio now keeps at least 6% of each card free on top of the fixed reserve.

unsloth run --engine vllm --yes on a B200 installed the engine on first use and served chat through the API. A request without the key got 401. Decode was 621 tok/s through Studio against 649 tok/s for a plain vllm serve of the same environment, within run to run noise. Unload, reload and Ctrl+C each left no engine process and returned the GPU memory.

Install prompt, before and after

vLLM install confirmation, before and after

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen danielhanchen added >3000# affects UI# conflicts# edge case# new-feature# refactor# security# Moves a security boundary: sandbox, allowlist, permission or network guard labels Sep 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Checked that the new paths in studio/backend/routes/inference.py stay behind the engine != "auto" gate so the default llama.cpp route is untouched, which is the right call. This is a lot of ground in one branch though, so could you split the engine install and rollback machinery in engine_install.py from the chat forwarding and the per-model config and UI work, so each part can be reviewed and landed on its own?

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@oobabooga

Copy link
Copy Markdown
Member Author

@codex review

@oobabooga

oobabooga commented Sep 23, 2026 •

Copy link
Copy Markdown
Member Author

Engines on Studio's PyTorch

I added a commit that removes the duplicate PyTorch and CUDA install for vLLM and SGLang. They now run on Studio's own Python, torch and CUDA libraries. Each engine keeps only the packages it pins differently from Studio in a small layer of its own, so Studio's versions are untouched. vLLM went from a 7.9 GB venv to a 3.1 GB layer, and SGLang uses 4.1 GB.

This applies when Studio's torch matches the engine lock, which is the case for a default Linux install (torch 2.11.0, CUDA 13.0). Any other torch version gets a full isolated environment, as before. If a Studio update changes a package the engine shares, the engine asks for a repair before loading.

Testing

I tested both engines through Studio's API on an RTX 6000 Ada and an RTX 3090. That covered chat, streaming, tool calls and concurrent requests, in INT4, INT8 and FP8, and on both GPUs in tensor, pipeline and replica modes, including image input. The isolated fallback also served on a Studio with torch 2.12.1. Studio's own venv was unchanged afterwards, and Unsloth training still ran on it. Windows and WSL are not tested.

Why not install into Studio's venv

Installing the engines directly into Studio's venv doesn't work. Installing unsloth after vLLM 0.30 downgrades torch to 2.12.1 and transformers to 5.5.0 because of the published torch<2.13 and transformers<=5.5.0 caps. Beyond that, the engines pin fastapi, mcp, transformers and openai at versions Studio doesn't use, and vLLM 0.30 and SGLang 0.5.20 conflict with each other.

Newer engines

Newer engines (vLLM 0.27.1+, SGLang 0.5.18+) require exactly torch 2.13.0. The same setup served vLLM 0.30 and SGLang 0.5.20 on a torch 2.13 Studio. Moving to them needs three things. First, the torch 2.13 training wheels, plus lifting the unsloth caps. Second, a port of SGLang's INT4, INT8 and Ampere FP8 modes, because SGLang 0.5.18 removed the TorchAO support they use. Third, the matching flashinfer-jit-cache wheel for vLLM, or a working CUDA compiler at runtime.

Prebuilt wheels

Those wheels are what lets Studio move to torch 2.13 without slower training. They matter in two ways:

  • Training: without flash-attn, causal-conv1d and mamba-ssm builds for the installed torch, Unsloth falls back to slower attention and Mamba paths.
  • Inference: vLLM imports flash-attn whenever it is installed, and a flash-attn built for another torch crashed it at model load. Once the engines share Studio's packages, a matching build matters here too.

prebuilt-cuda-wheels.yml has not published them yet because flash-attn cannot finish. Run 35855513451 compiled 6 of its 97 units in 24.5 minutes, which puts the full build at 6 to 8 hours, past the 300-minute timeout and GitHub's 6-hour job limit. Publishing needs every build, so this also holds back causal-conv1d and mamba-ssm. Those two built locally for torch 2.13 and 2.14 and passed GPU tests. I also found four smaller problems:

  • The GPU smoke test skips runtime dependencies (mamba fails on a missing einops).
  • The GPU smoke test doesn't gate publishing.
  • NVCC_THREADS has no effect, because the pinned setup.py files hardcode --threads 4.
  • The wheels don't pin their torch version, so a 2.13 wheel installs next to torch 2.14 and then fails to import.

For flash-attn, one option is a resumable build like upstream's. The other is the pinned kernels-community/flash-attn2 build for torch 2.13, which passed Unsloth training locally. I'd send the workflow fixes as a separate PR.

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
# 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 merged commit 08716f0 into unslothai:main Oct 2, 2026
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
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Oct 2, 2026
JoshuaL3000 pushed a commit to JoshuaL3000/unsloth that referenced this pull request Oct 4, 2026
…quantization and vision (unslothai#11491)

* 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

* 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.

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

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

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

* [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

* 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

* 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

* [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

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

* [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

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
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.

3 participants