Skip to content

serve: structured output takes json_object, arrays, anyOf, $ref, integers and numbers, and samples inside the mask - #973

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-structured-json
Oct 29, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-structured-json

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

구조화 출력이 json_object, 배열, anyOf, $ref, 정수와 숫자를 받고, temperature와 penalty 요청도 마스크 안에서 샘플링하게 했습니다.

What and why

Structured output used to refuse response_format: {"type": "json_object"}, any schema with items, anyOf, $ref, $defs, plain integer, number or null, and any request that set temperature above 0 or a penalty. Clients that send these OpenAI-compatible requests got a 400.

This change accepts them. json_object (also text.format on /v1/responses) builds an arbitrary JSON object grammar in the existing constrain program. The schema subset gains type: array with items, anyOf, in-schema $ref, integer, number and null. Sampled requests apply the request's own sampler (temperature, top_k, top_p, min_p, seed, penalties) to a copy of the logits row with the ids the program forbids set to -inf, so the draw stays inside the mask. Greedy output for the existing subset is unchanged.

Release notes: Added: structured output accepts json_object, arrays, anyOf, $ref, integer and number types, and sampling settings.

Code shape

The review reads these first. A box left unticked needs one line of why.

  • No second copy. Logic two models (or two call sites) share has one common owner; I lifted it there instead of
    copying it (AGENTS.md "Common code first", docs/rust-quality.md R14). Where I found an existing copy, I
    named it below.
  • Model code holds only architecture facts. A model's own files carry only what its architecture forces
    (tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
  • Dead code is gone. Nothing I made unused is left behind (functions, flags, gate clauses, docs).
  • No silent failure. Undefined input is a named error or panic, never a defined-looking output.
  • Comments state what is true now. No dates, issue numbers or how a bug was found (tools/check-comments.sh).
  • No relaxed gate. No band, tolerance or lint moved to make a check pass; a re-pin carries PIN(YYYY-MM-DD):
    and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none.

All changes are in crates/serve and docs/serving.md. The constrain owner (constrain/program.rs, schema.rs, vocab.rs) gains the new grammar parts, $ref inlining and the multi-head walk; genloop.rs draws with the request's sampler; api.rs drops the temperature and penalty refusal; responses.rs forwards json_object. ignore_eos and reasoning_budget are still refused by name.

What I ran

Base 5e743ada812e7377054e4d8a8756b7c466c833ae, head 5884ba7981834cae16fbb1f346a92fda2b28d64d. Card: NVIDIA GB10, driver 595.84, CUDA 13.3.1. Model: Qwen3.8-Flash-Next FP4-Local, --ctx-size 16384, one slot.

GPU gates, pass, exit code 0:

just gate-serve && just gate-q38-serve-rules && just gate-serve-draft-rules
test result: ok. 393 passed; 0 failed   (bloomery-serve lib)
test result: ok. 111 passed; 0 failed   (serve)
test result: ok. 27 passed; 0 failed    (bloomery-serve-qwen38)

The other gate-serve test binaries, gate-q38-serve-rules and gate-serve-draft-rules also report 0 failed.

Real model: bloomery-serve built with cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,flint,gemma-embedding2,hf,checkpoint --release --bin bloomery-serve, then these requests sent to the server. Each of the new requests below is refused with a 400 on base.

Responses (all status=200 valid=True, the response checked against the requested schema):

json_object: {"city": "Seoul", "country": "South Korea", "population": 9411357, "landmark": "N Seoul Tower", "language": "Korean"}
json_object, nested: {"title": "The Great Gatsby", "authors": [{"name": "F. Scott Fitzgerald"}]}
tool call: add_items {"ids":[3, 7, 12],"limit":null}
temperature 1.2, seed 1: {"owner": "Maya Rodriguez", "pets": [{"name": "Biscuit", ...}, {"name": "Salem", ...}], "nickname": null}
temperature 1.2, seed 2: {"owner": "Elena Rodriguez", "pets": [{"name": "Luna", ...}, {"name": "Buddy", ...}, {"name": "Goldie", ...}], "nickname": null}
GREEDY-SAME G1-schema-old-subset True
GREEDY-SAME G2-tool-old-subset True
CARD PASS

Unit tests: cargo test -p bloomery-serve passes (393 lib tests); cargo clippy -p bloomery-serve --tests reports no warnings; cargo fmt and tools/check-comments.sh are clean.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

…gers and numbers, and samples inside the mask
@github-actions github-actions Bot added documentation Improvements or additions to documentation host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja serve The HTTP server: crates/serve labels Oct 29, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: No proven behavior defect or mechanical quality defect survived review.

Non-blocking

⚠ Measure the added decode allocations: crates/serve/src/constrain/program.rs:1397 adds one head-vector allocation per constrained token, including fixed tokens. allowed:1197 also boxes an iterator per live head at each decision (R39). Reuse the single-head vector's capacity and provide a timed base/head A/B for existing schemas on the contributor's card (R20). Checking this now keeps buffer reuse local to the walker.

Optimization headroom

  • E. Less work: crates/serve/src/constrain/program.rs:1223. Repeated string alternatives in anyOf remain separate heads and each scans the vocabulary. Scan equivalent masks once in the existing pick logic, preserving the heads for transitions. For H identical K-id masks, this removes 4 × K × (H − 1) logical logit bytes read per greedy decision token [derived].

Checked

Duplicates: dryer reports zero candidate pairs. Head::same compares program identity and position, so equivalent masks can remain separate.
Complexity: crapper flags 11 functions. No retained finding rests on complexity alone.
Silent failure: choose_by returns a named NoAllowed error when a drawn id leaves no valid successor.
Tests: the forced-token test checks preservation of the inner forced-id and frame buffers; cloning those buffers would fail its pointer assertions. Rust tests were not executed.
Gates: four dated PIN comments cover retired refusal cases.
Escapes: no C1–C4 pattern applies to the retained items.

Notes

The PR reports gate runs for earlier commits. It supplies no nvidia-smi output or model file path, so GPU evidence is unverified for this head.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 69335f8 into midagedev:main Oct 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset model The CPU engine and model files: crates/model, models, hf, gguf, tokenizer, jinja serve The HTTP server: crates/serve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant