Skip to content

Add Inkling 2 Mini long-input serving profile with measured tuning - #103

Open
vshengbro wants to merge 1 commit into
AtomicBot-ai:engine-developmentfrom
vshengbro:inkling-long-prefill-tuning
Open

vshengbro wants to merge 1 commit into
AtomicBot-ai:engine-developmentfrom
vshengbro:inkling-long-prefill-tuning

Conversation

@vshengbro

Copy link
Copy Markdown

What

A production launch profile plus a benchmark harness for serving Inkling 2 Mini (AD-IQ2_M) on the non-budget Metal path when the workload is long prompts. Three new files, no changes to existing code:

  • profiles/inkling-long-input.sh - the launch profile
  • scripts/bench-long-prefill.py - the measurement tool (prefill / decode / TTFT by prompt size, cache reuse disabled)
  • docs/inkling-long-input-profile.md - measurements, rejected alternatives, reproduction steps

Why the non-budget path

The budgeted Metal profiles are the fastest option but carry hard startup limits, verified on this build:

  • engine budget profile requires explicit ctx <= 4096, batch <= 4096, ubatch <= 1024, one sequence, <=16 threads, no embeddings
  • engine budget requires -fit off, a supported speculative profile if selected, and no multimodal projector

A 4096-token window cannot hold a long document, and the budget path rejects the vision projector. For long-input serving the ordinary Metal path is the only option, so the tuning targets that path.

Measured results

M5 Max / 64 GB, Docker Desktop running, warm server, cache reuse off, greedy decoding, scripts/bench-long-prefill.py. Baseline is the identical build without --load-mode mmap+mlock; everything else (AD-IQ2_M, DSpark 3/32, q4_0 KV, flash attention, 1024 prefill blocks) unchanged.

prompt tokens baseline prefill tuned prefill baseline decode tuned decode
2,261 726.0 t/s 743.6 t/s (+2%) 55.7 t/s 59.0 t/s (+6%)
14,727 539.8 t/s 591.2 t/s (+10%) 34.7 t/s 68.6 t/s (+98%)
35,653 364.3 t/s 437.0 t/s (+20%) 29.4 t/s 54.1 t/s (+84%)

The single change behind the deltas is --load-mode mmap+mlock: the mmapped expert weights stay resident instead of being evicted and re-read from SSD under memory pressure. Footprint grows 3.36 -> 3.74 GiB at 40K (the mlock cost).

Long-document Q&A (the actual workflow)

With the default prefix cache on (as Open WebUI runs it), only the first question pays the full prefill:

turn wall time prompt tokens cached answer
Q1 (cold, 14.7K doc) 57.8s 27,477 10 "The quick brown fox."
Q2 (same doc) 1.6s 27,503 27,473 "The kettle." (correct)

Follow-up questions on a cached document answer 17-36x faster than a cold prefill and stay correct.

Tested and rejected (with data)

  • --ubatch-size 2048 / 4096: fails at load. The Metal compute-graph reservation scales with ubatch (104 GiB requested at 2048) and exceeds the device working set. 1024 is the ceiling on this machine.
  • -sm row: device MTL0 does not support split buffers.
  • --threads 12 --threads-batch 12: +3% at 2.5K tokens, no change at 14.7K/35.7K.
  • Docker Desktop VM memory (36 GiB wired): quitting it did not change prefill or decode, so the numbers above are not a memory-pressure artifact.
  • dev / TurboQuant branch (build 11427): cannot load this model at all - unknown model architecture: 'inkling2_loop'. The architecture lives on the engine branches, so turbo KV cache types are unavailable for Inkling 2.
  • ngram speculative decoding (--spec-type ngram-cache,draft-dspark): +24-26% decode on repetitive prompts, but it produces wrong answers on cached multi-turn requests (it proposes the previous turn's answer from the cached prefix and the target accepts it). Rejected: correctness on the doc-QA workflow outranks the decode gain.

Notes and limits

  • The prefill decay with length is inherent, not tunable: fitting T = an + bn^2 to the three points gives b ~= 2.85e-8 s/tok^2, i.e. about 44% of the 35.7K prompt-processing time is the quadratic attention term over the 8 full-attention layers (40 of 48 layers are sliding window). Running the benchmark with 40K first produces the same numbers, so it is not thermal.
  • AD-IQ2_M occasionally drops a token in code output (measured: s[::-] instead of s[::-1] at effort none/medium, correct at effort low). That is a quantization artifact of the IQ2_M target, not a serving-path issue; the profile works unchanged with AD-IQ3_S if code quality matters more than the 4.3 GiB.
  • Base branch is engine-development. The diff is three new files; no existing behavior changes.

Reproduce

python3 scripts/bench-long-prefill.py 8081 "label" 2500,16500,40000

Run each size twice (first request pays Metal pipeline compilation) and measure with a single llama-server instance: two concurrent servers on a 64 GB box drive the machine into Metal OOM (Insufficient Memory), which poisons the backend until restart.

Non-budget Metal profile for long prompts: AD-IQ2_M with DSpark 3/32,
q4_0 KV, flash attention, 1024 prefill blocks, and mmap+mlock so expert
weights stay resident under memory pressure.

Measured on M5 Max / 64 GB (scripts/bench-long-prefill.py, warm, cache
reuse off), decode +84-98% and prefill +10-20% at 14.7K-35.7K prompt
tokens versus the same build without mlock:

  14,727 tok: prefill 539.8 -> 591.2 t/s, decode 34.7 -> 68.6 t/s
  35,653 tok: prefill 364.3 -> 437.0 t/s, decode 29.4 -> 54.1 t/s

The doc also records what was tested and rejected: ubatch >= 2048 (Metal
compute reservation exceeds the device working set), -sm row (unsupported
on Metal), 12 batch threads (no gain), dev/TurboQuant branch (cannot load
inkling2_loop), and ngram-cache speculative decoding (correct answers
regress on cached multi-turn requests, so draft-dspark alone is used).

Prefix caching makes the real doc-QA workflow fast: follow-up questions on
a cached 14.7K document answer in ~1.6s versus 57.8s cold.

This branch has not been deployed

No deployments
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