Repository navigation
Expose d1's box / boxes readout on /v1/systemone #5386
nicktangithub
started this conversation in
Ideas
Replies: 1 comment
|
PR opened as a draft: #5387 — it implements option B on |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
TL;DR — oMLX already runs the code that answers LiquidAI d1
boxandboxesquestions. Nothing reaches it, because the request schema only allows
noul,choiceandscore. Widening it is a one-line type change plus somevalidation; I have it working and will open a PR linking here.
Intro
This is my first attempt at contributing to an open source project so I hope I'm doing it correctly! I was trying to use the Liquid AI d1-2B decision model to draw some bounding boxes on a set of images using oMLX as the server. But it didn't work and after some digging it appears that the underlying mlx-vlm supports it but oMLX only supports noul, choice and score from decision models.
So it would appear to be a small change in oMLX to allow the box and boxes results through.
I used my local AI agent to create a patch to oMLX and tested it against my test set of photos and it worked really well. Details are below:
Why this is cheap
mlx-vlm, which oMLX already pins (commit
138d761, bundledmlx_vlm0.7.11),ships the entire d1 box readout:
models/d1_lfm3_vl/box.py,grid.py,pointer.py, and theBox/Boxesslots inprompt.py.D1._readalreadyhandles them, and calibration tables (
found:box,box,found:boxes,boxes) load from the checkpoint's owncalibration.json.oMLX's wrapper (
omlx/models/d1.py) already calls that same_read()for itsnoulandchoicequestions. A box is just more answer slots on the sameforward pass — a presence and four edges at five slots, five per instance for
boxes— and no tokens are generated. So this is not a new engine, and itneeds no dependency bump.
The only blocker is
omlx/api/systemone_models.py:What it would add
{ "model": "d1-2B", "state": null, "images": ["data:image/jpeg;base64,..."], "questions": { "remote": {"type": "box", "instructions": "Where is the remote control?"}, "cats": {"type": "boxes", "instructions": "Every cat.", "max": 4} } }{"answers": { "remote": {"type": "box", "box": {"top": 0.153, "bottom": 0.241, "left": 0.058, "right": 0.272}, "found": 1.0, "confidence": 0.9369}, "cats": {"type": "boxes", "count": 2, "at_least": false, "boxes": [ {"box": {"top": 0.115, "bottom": 0.984, "left": 0.016, "right": 0.495}, "found": 1.0, "confidence": 0.9402}, {"box": {"top": 0.054, "bottom": 0.774, "left": 0.531, "right": 0.999}, "found": 0.9972, "confidence": 0.9402}]} }}Edges are fractions of the picture, origin top-left. The same widening brings
numberwith arange(an estimate with an interval) andchoicewithmultiple(each option scored yes/no), because both come free with the sameslots. The schema also silently drops
max,range,step,unitandmultipletoday, so they would need to be added as fields regardless.The one thing worth deciding
SystemOneRequest.statecurrently rejectsnullfor every model. For d1 apicture is the state, so a box request has nothing to put there. Liquid's
reference implementation reads a picture with no state at all
(
model.system_one(None, questions, media=[image])in the model card), andmlx-vlm's prompt builder handles a
Nonestate directly.It gets slightly more interesting than "allow null", because clients already
in the wild omit the field rather than sending
nullfor this case, andstateis currently a required key. So there are two ways to open it:nullas its value. Clients must send"state": nullexplicitly.state: Any = None). Omitted andnullbehavethe same, which is what an existing client sends today.
I lean B, since a picture-only request genuinely has no state, and it means
one fewer thing for a client to get wrong. Either way each family refuses a
missing state itself, so Clef / OpenJev / Decision 3.0 keep returning a clear
400 ("a clef model reads its questions after a state"), and a d1 request with
neither state nor picture is refused too. Whichever you prefer, I will match it.
While there: a chat model serving
/v1/systemonewould answer aboxquestionby reading option letters, i.e. "where is the cat?" → "yes". Clef reads an
unknown type as a
scoreand OpenJev as anoul. So the type list needs to beper-family, not just wider.
Validation so far
Current
main(eec2544); bundled mlx-vlm 0.7.11;d1-Omni-2B-MLX-fp16on an M5 Ultra / 256 GB, plus the
d1-2Btokenizer for prompt/readout checks.000000039769):box→{top 0.153, bottom 0.241, left 0.058, right 0.272}versus their documented
{0.15, 0.24, 0.06, 0.28};boxes→ 2 instances;numberwithrange [0,10]→ 2.0.422(null state, unknown type).maxabove the checkpoint's cap (16) → 400; pointer reads → 400 by name.19887 passed, 645 skippedon the default suite; the 4 failures(GLM5 / Qwen3.5 kernel tests, one subprocess env test) also fail on
unpatched
mainhere, and none touch decision code.A local Swift app that locates main subject(s) in sports photos is already working
against the patched build, which is what prompted this.
PR: (I'll add the PR link once I open it)
All reactions