FP8 (E4M3, weight-only, dynamic per-token activations) quantization of
baidu/Unlimited-SVG — the 3B-A0.5B
MoE that redraws any image as a structured, editable SVG.
Built specifically for NVIDIA Blackwell GPUs (RTX 50 series and B-class,
sm_100–sm_120), where the FP8 tensor cores of the
DeepseekOCRForCausalLM / UnlimitedSVGForCausalLM native path in vLLM make
the >10k-token SVG generations practical on a single 16–24 GB card.
| BF16 original | This FP8 build | |
|---|---|---|
| Checkpoint size | 6.7 GB | 3.5 GB (−48%) |
| GPU memory at load (vLLM) | ~6.9 GB | ~3.7 GB |
| Context @ 16 GB-class GPU (32K tokens) | borderline | comfortable, ~2.9 concurrent |
| Output parity | reference | matches online --quantization fp8 (same math) |
--quantization fp8 for this architecture,
frozen offline so serving skips the runtime conversion and the scales are
deterministic.DeepseekOCR module quantizes are
fp8: LM attention/MLP/experts (incl. the fused dense gate_up_proj) and the
vision CLIP branch's qkv_proj/fc1/fc2/out_proj. SAM blocks, embeddings,
router gates, norms and the projector stay bf16, exactly as in the online
path. Mismatching this set (e.g. leaving vision qkv_proj bf16 in the
checkpoint while vLLM builds fp8 params for it) silently corrupts features.gate_up_proj has two
intermediate_size/2 = 6848-row halves; ceil(6848/128)·2 = 108 ≠ ceil(13696/128) = 107 block rows, so a [128,128] scale grid cannot represent
this checkpoint's fused parameter. Per-tensor sidesteps it.scaled_mm + Triton FP8 MoE kernels cover sm_120
consumer parts out of the box.The image processor must be pinned to the model's native 2048 × 2048 global view, no tiling (upstream default is 1024 + tiling). Then serve:
docker run --gpus all --ipc host --shm-size 8g -p 10000:10000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
-e TRITON_ALLOW_NON_CONSTEXPR_GLOBALS=1 \
--entrypoint bash vllm/vllm-openai:latest -c '
python3 - <<EOF
import re, sysconfig
from pathlib import Path
p = Path(sysconfig.get_path("purelib")) / "vllm/transformers_utils/processors/deepseek_ocr.py"
s = p.read_text()
for k, v in {"BASE_SIZE": 2048, "IMAGE_SIZE": 2048, "CROP_MODE": False}.items():
s, n = re.subn(rf"^{k} = .+$", f"{k} = {v}", s, flags=re.M)
assert n == 1, k
p.write_text(s)
EOF
exec vllm serve tuevuong/Unlimited-SVG-FP8 \
--served-model-name Unlimited-SVG --trust-remote-code \
--no-enable-prefix-caching --mm-processor-cache-gb 0 \
--limit-mm-per-prompt "{\"image\":1}" \
--max-model-len 32768 --max-num-seqs 1 \
--gpu-memory-utilization 0.75 \
--compilation-config "{\"cudagraph_mode\":\"FULL_DECODE_ONLY\",\"cudagraph_capture_sizes\":[1,2,4,8]}"'
Do not pass --quantization fp8: the checkpoint is already FP8
(quantization_config in config.json drives loading).
--gpu-memory-utilization (Blackwell VRAM budget)| Card | weights | KV @32K (bf16) | activations + graphs | suggested util |
|---|---|---|---|---|
| 16 GB | 3.7 GB | 2.0 GB | ~1.5 GB | 0.75 |
| 24 GB | 3.7 GB | 2.0 GB | ~1.5 GB | 0.80 |
| 32+ GB | 3.7 GB | 2.0 GB | ~1.5 GB | 0.85 |
Input must be padded to a 2048 × 2048 canvas (long edge 2048, gray (127,127,127)
pad, alpha composited onto white first). Prompt: <image> SVG:.
import base64, io, re
from xml.etree import ElementTree
from openai import OpenAI
from PIL import Image, ImageOps
def flatten_alpha(img):
if img.mode not in ("RGBA", "LA", "PA") and "transparency" not in img.info:
return img.convert("RGB")
bg = Image.new("RGB", img.size, (255, 255, 255))
bg.paste(img.convert("RGBA"), mask=img.convert("RGBA").getchannel("A"))
return bg
buf = io.BytesIO()
with Image.open("input.png") as im:
ImageOps.pad(flatten_alpha(ImageOps.exif_transpose(im)), (2048, 2048),
method=Image.Resampling.BICUBIC, color=(127, 127, 127)
).save(buf, format="PNG")
client = OpenAI(base_url="http://127.0.0.1:10000/v1", api_key="EMPTY", timeout=6000)
out = client.chat.completions.create(
model="Unlimited-SVG", temperature=0, max_tokens=30000, stream=True,
messages=[{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": "data:image/png;base64," +
base64.b64encode(buf.getvalue()).decode()}},
{"type": "text", "text": "<image> SVG:"}]}]).__iter__()
text = "".join(c.choices[0].delta.content or "" for c in out if c.choices)
svg = re.search(r"<svg\b.*?</svg>", text, re.DOTALL).group()
ElementTree.fromstring(svg) # raises if the model didn't finish — retry/raise cap
open("output.svg", "w").write(svg)
Temperature guidance (same as the base model): keep 0–0.3 for CAD/diagrams/
charts, 0.5–0.8 for natural scenes; greedy decoding is deterministic.
transformers remote code (AutoModel) is not supported.Offline-quantize from the base snapshot: fp8-e4m3 per-tensor over
model.layers.*.{self_attn,mlp,experts} and
model.vision_model.transformer.layers.{*.mlp.fc1|fc2, *.self_attn.qkv_proj|out_proj},
with weight_scale = amax / 448 (float32) stored per tensor, and
quantization_config = {"quant_method": "fp8", "activation_scheme": "dynamic", "fmt": "e4m3"} added to config.json.
MIT, same as the base model. Architecture and weights: Baidu ERNIE Multimodal Team (GitHub · project page). Quantization: community build.
baidu/Unlimited-SVG