Skip to content

Vela 2.0 0.3B on Core ML: Swift engine, model store, parity check, guardrail + chatbot front-door demos - #26

Merged
Alex-Wengg merged 12 commits into
mainfrom
feat/vela-2.0
Oct 7, 2026
Merged

Alex-Wengg merged 12 commits into
mainfrom
feat/vela-2.0

Conversation

@Alex-Wengg

Copy link
Copy Markdown
Member

What

Adds vLLM Semantic Router × KR Labs' Vela-2.0-0.3B (ModernBERT routing / safety / span model) on Core ML:

  • Vela2Manager: a Swift port of the release's vela2_inference.py on a Core ML encoder. It covers the tokenizer with character offsets (a mmBERT/Gemma BPE built on LayaTokenizer), schema assembly, the fp32 readout heads (choice cosine + MLP, word × label spans), calibration (per-type temperatures, PII length rule + sparse gate) and the span decoder. Word units, span units and trimming are hand-written scanners using Python's \w / \s rules, because ICU's differ for combining marks, No digits and similar. Choice questions plus the first span question share one encoder pass. Sequences of ≤128 tokens run on the Neural Engine, longer ones on the GPU.
  • Vela2ModelStore: pinned and checksummed FluidInference/vela-2.0-0.3b-coreml @ fb68b856 (fp16 multifunction encoder L128–L1024, heads, tokenizer, calibration, licences).
  • Vela2Check parity: compares against fixtures from the Python engine.
  • GuardrailDemo: a chat guardrail. Each outgoing message is screened (prompt attack, harm, route, fact-check) and its PII masked. Replies are checked against a source document, and unsupported claims are underlined. Each check shows whether it ran on the ANE or GPU and how long it took. --demo plays the scenarios once.
  • FrontDoorDemo: 1,000 synthetic chatbot messages arrive in an inbox and fly into Answered (routed to a team, PII redacted), Blocked · jailbreak and Blocked · harmful. Includes Pause/Resume. The data is synthetic, from a seeded generator kept in model-lab.
  • README section.

Verification (M5 Pro, macOS 27)

  • Parity, Swift vs the Python engine, on 38 requests (PII, attack, harm, routing, hallucination; EN/DE/FR/ES/ZH/JA/HI/AR, URLs, e-mails):
    • 0 token / sequence mismatches
    • 0 / 120 choices differ (max |Δp| 0.00000)
    • 0 / 38 span sets differ (GPU). With the ANE for L128, choices are identical and span probabilities are within 0.003.
  • Core ML encoder vs PyTorch: identical choices and span sets on 8 requests.
  • Encoder timing: L128 3.5 ms on the ANE / 4.4 ms on the GPU; L256 5.0, L512 8.3, L1024 16.5 ms on the GPU. 99.4 % of ops are placed on the ANE, but it is only faster up to 128 tokens.
  • FrontDoorDemo: 1,000 messages at ~90 msg/s end to end with the UI open (guard ~3.5 ms on the ANE, route + PII ~8.5 ms on the GPU).
    • harmful blocked 150/150
    • jailbreak 105/150
    • 16/700 benign false-blocked
    • topic 578/700 vs the generator's labels
  • Model store: fresh Vela2ModelStore.ensure() download, all 8 assets checksum-verified, and the demo runs from the cache.

Not done

🤖 Generated with Claude Code

Alex-Wengg and others added 12 commits October 7, 2026 16:58
…bly, heads, calibration, span decoder) and parity check

Vela2Manager reproduces vllm-sr/Vela-2.0-0.3B's vela2_inference.py on a Core ML encoder: one pass per
request for choice questions plus the first span question; sequences up to 128 tokens on the Neural Engine,
longer on the GPU. Word units / span units / trimming are hand-written scanners with Python's \w / \s rules.

Vela2Check parity on 38 guardrail-style requests (PII, prompt attack, harm, routing, hallucination; EN, DE,
FR, ES, ZH, JA, HI, AR, URLs, e-mails): 0 token / sequence mismatches, 0/120 choices and 0/38 span sets differ.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…screen, full check on send, reply grounding)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…scenario forever)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…l-request example, --demo plays all scenarios once

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… ANE, route + PII on GPU), speed-first timing

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…x800 layout, batched UI updates (~92 msg/s end to end)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…use/Resume (Space)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ownload it by default, README section

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… spans without labels (were crashes); GuardrailDemo: drop a send result after a scenario switch

Review fixes for #26. Parity unchanged (38 requests: 0 token / sequence mismatches, 0/120 choices, 0/38 span sets differ).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
# Conflicts:
#	Package.swift
#	README.md
@Alex-Wengg
Alex-Wengg merged commit 8c5b746 into main Oct 7, 2026
1 check passed
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.

1 participant