Repository navigation
Studio: add opt-in vLLM and SGLang support with multi-GPU inference, quantization and vision - #11491
Conversation
|
@codex review |
|
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? |
|
@codex review |
|
@codex review |
… 3.12 environment
Engines on Studio's PyTorchI 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. TestingI 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 venvInstalling the engines directly into Studio's venv doesn't work. Installing Newer enginesNewer 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 Prebuilt wheelsThose wheels are what lets Studio move to torch 2.13 without slower training. They matter in two ways:
For flash-attn, one option is a resumable build like upstream's. The other is the pinned |
# 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
…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]>
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
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:
Installation and recovery controls in Settings > System:
Full Studio window during a vLLM installation, with model run settings open alongside the shared progress panel:
Four real SGLang requests in flight through Studio's API:
Verification
Live tests used an RTX 6000 Ada and RTX 3090, individually and together, with Qwen2.5-0.5B and Qwen3.5-0.8B.
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/enginesgoes from 404 to listing both engines as not installed.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.6Bwith engine vLLM at BF16, andunsloth/Qwen2.5-0.5B-Instructwith 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.
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 onunsloth/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.Two of these runs found bugs, both fixed in this PR:
__cudaLauncherrors. Studio headers were picking up Colab's newernvidia-cuda-crt. The engine now gets one merged CUDA include tree, with its own headers first.unsloth run --engine vllm --yeson 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 plainvllm serveof 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