Skip to content

Add Unlimited-SVG (image to SVG): OpenVINO export, engine and /v1/chat/completions - #207

Closed
SearchSavior wants to merge 6 commits into
mainfrom
ccr-c693342a-7driti
Closed

SearchSavior wants to merge 6 commits into
mainfrom
ccr-c693342a-7driti

Conversation

@SearchSavior

@SearchSavior SearchSavior commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds baidu/Unlimited-SVG (MIT), which redraws an image as an editable SVG. It is served as model type unlimited_svg on the openvino engine, through /v1/chat/completions.

It follows the approach of the d1 PR (#206): OpenArc's own export script, pipeline and engine, all in src/engine/openvino/unlimited_svg/. Nothing is added to src/engine/ov_genai/vlm.py. optimum-intel and OpenVINO GenAI cannot export or run this model's vision encoder (DeepSeek-OCR v1: SAM + CLIP), so the whole path is self-contained.

Export (export.py)

uv run --with "transformers==4.46.3" --with addict --with easydict --with einops \
    python -m src.engine.openvino.unlimited_svg.export \
    --model baidu/Unlimited-SVG --output models/Unlimited-SVG-int8 --weight-format int8 --trust-remote-code

The checkpoint's remote code needs transformers 4.46.3. uv run --with provides it for the export only, and the project's dependencies are unchanged. The branch carries a dependency bump and its revert, so their net diff is zero. The bump turned out to be unnecessary once the model is exported and run with OpenArc's own code.

The export writes three IRs:

  • Vision encoder. SAM ViT-B, then CLIP-L, then the projector, over the model card's 2048 × 2048 global view. Its output is 1057 tokens, including the newline and view-separator tokens. SAM's global-attention layers attend over 16384 tokens. Their decomposed relative-position bias is folded into the query and key, which is exact, so attention runs as one SDPA and never materialises a 12 × 16384² bias.
  • Text embeddings.
  • Stateful DeepSeek-V2 MoE decoder.
    • The routed experts are written in the tiled 3-GEMM form that OpenVINO's ConvertTiledMoeBlockTo3GatherMatmuls matches. The CPU plugin runs them as GatherMatmul, computing only the 6 routed experts per token. That takes decode from 3.2 to about 23 tok/s.
    • The expert stacks are shared f16 constants, so the export peaks at about 9 GB.
    • The weights come from a custom conversion extension that emits MatMul(transpose_b=True). Two other approaches failed. OpenVINO's 16-bit patch casts registered 16-bit buffers to f32. A transposed copy in the trace OOMs.

Weight formats are int8 (recommended), int4 (the language model; group 64), and fp16. The MoE routers stay at full precision.

Prompting

Prompting was decided by measurement. The model was trained on <image> SVG: with no chat template. With vLLM's DeepSeek-VL2 template, the reference model answered with no <svg>, or ran to the token cap. So prompt.py builds the prompt verbatim:

  • It uses the last user message, which must hold exactly one base64 data: image.
  • Text containing the <image> tag is used as written. Text without the tag follows the image. An image alone gets <image> SVG:.

Images are prepared as on the model card: EXIF rotation, alpha flattened onto white, then padded to 2048 with BICUBIC.

Serving

  • OVUnlimitedSVG has its own worker queue. It supports streaming and cancellation: a client disconnect stops the generation.
  • A request the model can't answer gets a 400, and the model stays loaded. That covers no image, two images, tools, a response_format other than text, and /v1/completions.
  • sampler_config applies to unlimited_svg. Temperature 0 is greedy.
  • The chat route now reports finish_reason: "length" when an engine says it stopped at the token budget. Other engines are unaffected.
  • openarc add --model-type unlimited_svg works.

Docs: a new docs/unlimited_svg.md page, plus updates to models.md, configure.md, the README and the nav.

Validation

Forwards vs. the checkpoint's own PyTorch code, in f32. The vision encoder matches to 9e-5. The decoder matches to 1e-5, including cached decode steps.

OpenVINO vs. the reference PyTorch model (bf16, greedy). Three images: an icon, a bar chart and a diagram.

Format Valid SVG, EOS Render MAE vs input (icon / chart / diagram) Decode
PyTorch bf16 (reference) 3/3 4.64 / 34.67 / 68.08 —
OpenVINO fp16 3/3 3.15 / 34.47 / 68.63 ~22 tok/s
OpenVINO int8 3/3 1.24 / 33.99 / 68.31 ~23 tok/s
OpenVINO int4 3/3 2.26 / 33.69 / 69.09 ~28 tok/s

The chart and diagram MAEs are high for every row because the grey padding is part of the scored image.

The outputs are not token-identical to the reference. fp16 diverges at the same points as int8, so the drift comes from bf16 compute, not quantisation. It shows up as small coordinate changes.

Timing. Measured on a 4-core Xeon (AMX, bf16 by default): the vision encoder takes 12 to 13 s per image, and prefill about 2 s.

Memory. Peak RSS while serving is 12.7 GB for int8 and 11.2 GB for int4. fp16 does not fit in 15 GB: its decoder alone takes about 10.8 GB on CPU.

End to end with the OpenAI client against a running server, all passed:

  • non-streaming and streaming requests give the same text;
  • max_tokens gives finish_reason: "length";
  • the 400 cases leave the model loaded;
  • closing a stream mid-generation cancels it.

Test plan

  • uv run pytest tests/unit passes: 41 new tests. The 2 Kokoro failures are pre-existing and fail on main too.
  • tests/integration/test_ov_unlimited_svg_integration.py passes on an int8 export (TEST_MODEL_PATH must contain Unlimited-SVG-int8).
  • zensical build succeeds. Its warnings are all pre-existing ones in index.md.
  • Try it on GPU. Only CPU was tested here.
  • Try photos and large, complex SVGs (more than 10k tokens). Only simple synthetic images were tested here.

… transformers to 5.11-5.15

OpenVINO GenAI 2026.4+ ships the DeepSeek-OCR-2 VLMPipeline path that
Unlimited-SVG support will build on; optimum-intel 2.3 exports
deepseek_ocr2 and needs transformers <5.16 (deepseek_ocr2 landed in 5.11).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011SRNH9d4WxeGDc2LLVLJK6
Unlimited-SVG is exported and served with OpenArc's own code (no GenAI
VLMPipeline, no optimum-intel export), so the bump is not needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011SRNH9d4WxeGDc2LLVLJK6
baidu/Unlimited-SVG (image to editable SVG; DeepSeek-OCR v1 vision, DeepSeek-V2
MoE decoder) exported and served with OpenArc's own code, separate from the
ov_genai VLM engine:

- export.py: three IRs from the checkpoint's own modules (run with
  transformers 4.46.3 via `uv run --with`, the project env is untouched):
  - vision: SAM + CLIP + projector over the 2048 global view, newline and
    view-separator tokens included; SAM's relative-position bias folded into
    query and key so global attention runs as one fused SDPA;
  - text embeddings;
  - stateful language model. The routed experts are in the tiled 3-GEMM form
    the CPU plugin turns into GatherMatmul (only the 6 routed experts run).
  int8 / int4 / fp16 via NNCF, MoE routers left uncompressed. Expert stacks
  are shared f16 constants, so the export peaks at ~9 GB.
- prompt.py: the trained prompt `<image> SVG:` built verbatim (no chat
  template), one base64 image, the model card's image preparation.
- sampling.py: greedy at temperature 0, else temperature / top-k / top-p
  with repetition, frequency and presence penalties.
- pipeline.py: vision -> splice -> prefill -> decode loop with stats.
- unlimited_svg.py: OVUnlimitedSVG speaking the chat worker's protocol
  (streaming, cancel, request errors that keep the model loaded).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011SRNH9d4WxeGDc2LLVLJK6
- ModelType.UNLIMITED_SVG on the openvino engine, its own worker queue, served
  by the chat route; a request the model cannot answer (no image, two images,
  tools, response_format) is a 400 and the model stays loaded.
- sampler_config applies to unlimited_svg; `openarc add --model-type
  unlimited_svg`.
- The chat route reports finish_reason "length" when an engine says it
  stopped at the token budget.
- Unit tests (request rules, preprocessing, prompt ids, sampler, pipeline
  loop on fake parts, engine protocol and cancel, worker, route, and the
  export's rewritten attention and experts against plain PyTorch) and an
  integration test on an exported int8 IR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011SRNH9d4WxeGDc2LLVLJK6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011SRNH9d4WxeGDc2LLVLJK6
Measured int8, int4 and fp16 exports: size, vision / prefill / decode times,
peak memory while serving, and how their SVGs compare with the PyTorch
reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011SRNH9d4WxeGDc2LLVLJK6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants