How to Self-Host baidu/Unlimited-SVG Locally
Step-by-step Linux GPU setup using uv, official 2048×2048 ImageOps.pad preprocessing, Hugging Face Transformers, and OpenAI-compatible vLLM serving — plus exact VRAM sizing and troubleshooting.
1. Hardware & System Requirements
Although baidu/Unlimited-SVG only activates ~0.5B parameters per token (3.34B total sparse MoE), generating 10,000+ SVG tokens in BF16 still requires an Ampere-or-newer NVIDIA GPU with room for the long-context KV cache.
x86-64 Linux (Ubuntu 22.04+)
Official repo and vLLM wheels target Linux x86-64; Windows users should run under WSL2 Ubuntu.
NVIDIA BF16 (SM 8.0+)
Requires RTX 30xx / 40xx, L4, L40S, A100, or H100. Older T4 / GTX 10xx cards lack native BF16.
12–16 GB (24 GB+ ideal)
Model weights take ~7 GB in BF16; KV cache grows rapidly between 8K and 16K output tokens.
uv · CUDA 12.1+ · MIT License
Weights download from Hugging Face (baidu/Unlimited-SVG) or ModelScope (~6.7 GB).
Recommended GPU Sizing by Workload
| VRAM Tier | Example GPUs | Safe Token Limit | Recommended Workload |
|---|---|---|---|
| 12–16 GB | RTX 3060 12GB · RTX 4060 Ti 16GB | 4,096 – 8,192 tokens | Single-user local testing on logos, icons, and medium diagrams via Transformers. |
| 24 GB (Sweet Spot) | RTX 3090 · RTX 4090 · NVIDIA L4 | 10,240 – 16,384 tokens | Full 2048px UI screenshots, multi-tier diagrams, and CAD blueprints with greedy decoding. |
| 48–80 GB (Prod) | NVIDIA L40S · A100 80GB · H100 | 16,384+ tokens · Batched | Multi-user vLLM API serving with concurrent requests and sustained high throughput. |
Clone the Repository and Sync Dependencies with uv
The official baidu/Unlimited-SVG repository recommends Astral uv from the project root for reproducible dependency resolution. Make sure your NVIDIA driver supports CUDA 12.1 or newer before creating the virtual environment.
# 1. Install uv if not already available
curl -LsSf https://astral.sh/uv/install.sh | sh
# 2. Clone the official MIT repository
git clone https://github.com/baidu/Unlimited-SVG.git
cd Unlimited-SVG
# 3. Create virtual environment and install inference stack
uv venv --python 3.11
source .venv/bin/activate
uv pip install -U torch transformers accelerate pillow vllm
# Optional: verify GPU sees native bfloat16
python -c "import torch; print(torch.cuda.get_device_name(0), 'BF16:', torch.cuda.is_bf16_supported())"Tip: If Hugging Face downloads are slow in your region, set HF_ENDPOINT=https://hf-mirror.com or pull the identical weights from ModelScope before starting inference.
Pad Input Images to a Global 2048×2048 Canvas (ImageOps.pad)
This is the most common reason local conversions look distorted or miss small labels. DeepEncoder compresses one global 2048×2048 image directly into 1,024 vision tokens without tiling — stretching non-square screenshots or leaving transparent alpha channels unflattened degrades accuracy.
- Flatten PNG/WebP transparency onto a solid white RGB background first so dark icons do not turn black.
- Resize the longest side to 2048px while strictly preserving the original aspect ratio.
- Center the resized image on a uniform gray (128, 128, 128) 2048×2048 canvas using Pillow ImageOps.pad.
from PIL import Image, ImageOps
def prepare_unlimited_svg_input(path: str, canvas_size: int = 2048) -> Image.Image:
raw = Image.open(path)
# 1. Composite transparent pixels over clean white first
if raw.mode in ("RGBA", "LA") or ("transparency" in raw.info):
rgba = raw.convert("RGBA")
white_bg = Image.new("RGBA", rgba.size, (255, 255, 255, 255))
rgb = Image.alpha_composite(white_bg, rgba).convert("RGB")
else:
rgb = raw.convert("RGB")
# 2. Scale long edge to 2048px and pad onto a neutral gray square canvas
padded = ImageOps.pad(
rgb,
size=(canvas_size, canvas_size),
method=Image.Resampling.BICUBIC,
color=(128, 128, 128),
centering=(0.5, 0.5),
)
return paddedChoose Transformers (Local Script) or vLLM (Production API)
Both runtimes require trusting the custom model architecture (UnlimitedSVGForCausalLM) and keeping dtype locked to bfloat16.
Option A: Quick Local Inference via Hugging Face Transformers
Best for single-image experiments, batch scripts, or verifying output quality on a 16GB–24GB desktop GPU. Greedy decoding (do_sample=False) is the official default for structured graphics.
import re
import torch
from transformers import AutoModel, AutoProcessor
from preprocess_2048 import prepare_unlimited_svg_input
MODEL_ID = "baidu/Unlimited-SVG"
processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
model = AutoModel.from_pretrained(
MODEL_ID,
trust_remote_code=True,
torch_dtype=torch.bfloat16,
device_map="auto",
).eval()
image = prepare_unlimited_svg_input("dashboard.png")
inputs = processor(images=image, return_tensors="pt").to(model.device)
with torch.inference_mode():
output_ids = model.generate(
**inputs,
do_sample=False, # Greedy decoding (T=0) for UI, diagrams & CAD
max_new_tokens=12288, # Allow >10K tokens for dense vector scenes
)
raw_text = processor.batch_decode(output_ids, skip_special_tokens=True)[0]
match = re.search(r"<svg[\s\S]*?</svg>", raw_text)
if match:
with open("output.svg", "w", encoding="utf-8") as f:
f.write(match.group(0))Option B: Production OpenAI-Compatible Serving with vLLM
Recommended for team tools, web apps, and batch queues. vLLM PagedAttention handles 10,000+ token SVG generation smoothly and exposes a standard HTTP endpoint you can call from Node.js, Python, or Cloudflare Workers.
# Start OpenAI-compatible vLLM server in BF16
vllm serve baidu/Unlimited-SVG \
--trust-remote-code \
--dtype bfloat16 \
--max-model-len 16384 \
--gpu-memory-utilization 0.90 \
--host 0.0.0.0 \
--port 8000
# Verify health and send a deterministic (temperature=0) test request
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"model": "baidu/Unlimited-SVG",
"temperature": 0.0,
"max_tokens": 12288,
"messages": [
{
"role": "user",
"content": [
{"type": "image_url", "image_url": {"url": "https://example.com/padded-2048.png"}}
]
}
]
}'4. Official Temperature & Token Budget Tuning Guide
The official baidu/Unlimited-SVG documentation recommends adjusting sampling temperature by image category rather than using one setting for everything.
| Image Category | Recommended Decoding | max_tokens | Why It Works Best |
|---|---|---|---|
| CAD Blueprints & Schematics | temperature=0.0 (do_sample=False) | 10,240 – 14,336 | Locks exact geometric coordinates, concentric circles, hairline axes, and millimeter callouts. |
| UI Screenshots & Dashboards | temperature=0.0 – 0.2 | 10,240 – 12,288 | Keeps 1px borders straight, card radii consistent, and 11px–14px UI text clean in <text> nodes. |
| Flat Logos, Icons & Badges | temperature=0.0 – 0.3 | 4,096 | Fast completion with tight, minimal Bezier paths and clean symmetry around icons and wordmarks. |
| Photos & Textured Artwork | temperature=0.5 – 0.8 | 8,192 – 12,288 | Higher temperature avoids infinite repeated stroke loops on gradients, fur, or foliage. |
5. Common Self-Hosting Errors & Quick Fixes
Most local deployment hiccups come from four predictable environment or decoding issues.
ValueError: Loading baidu/Unlimited-SVG requires trust_remote_code=True
The model registers a custom vision-to-SVG architecture class not bundled into stock Transformers.
Fix: Always pass trust_remote_code=True in Python or --trust-remote-code when launching vllm serve.
RuntimeError: BFloat16 is not supported on this GPU
You are running on a Turing/Volta/Pascal card (RTX 2080, T4, GTX 1080) without native BF16 tensor cores.
Fix: Move to an Ampere-or-newer GPU (RTX 3090, RTX 4090, L4, L40S, A100) or use our hosted online converter.
CUDA Out of Memory past 8,000 generated tokens
Long-context KV cache grows linearly with output length and concurrent batch size.
Fix: Cap --max-model-len 12288, lower --gpu-memory-utilization to 0.85, set --max-num-seqs 1 on 24GB cards.
Truncated SVG (missing </svg>) or repeating paths
Default max_tokens (e.g. 2048 or 4096) was too short, or greedy decoding looped on a noisy photograph.
Fix: Raise max_tokens to 12288+, flatten alpha to white with ImageOps.pad, and set temperature=0.6 for photos.
Self-Hosting FAQ
The official release targets x86-64 Linux with CUDA BF16 NVIDIA GPUs. Windows users with an RTX 30xx/40xx card can run the full Linux stack inside WSL2 Ubuntu. Native macOS MPS is not officially supported by vLLM or the custom CUDA kernels yet.
Renting an RTX 4090 or L40S on RunPod, Modal, or Lambda typically costs $0.40–$1.20/hour (~$300–$850/month if kept online 24/7). Self-hosting pays off at high automated volumes (thousands of images/month); for occasional or team design work, hosted non-expiring credit packs are far cheaper and require zero GPU maintenance.
Yes. baidu/Unlimited-SVG is released under the permissive MIT License, allowing commercial SaaS integration, internal enterprise pipelines, and client delivery without royalties.
Unlike instant pixel tracers that run heuristics over pixels, Unlimited SVG autoregressively writes thousands of structured XML tags token by token. The 0.5B active MoE decoder keeps token speed fast (~150–300 tok/s on high-end GPUs), so a 10,000-token complex dashboard naturally takes 30–60 seconds.
Yes. Always extract the clean <svg>...</svg> root with regex or an XML parser, strip any unexpected script attributes (e.g. via DOMPurify), and optionally run SVGO if you want smaller web payloads while preserving <g> IDs and <text> tags.