Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel
- Qwen3.8-Flash-Next on HIP stops its MTP draft chains under a 0.8 confidence floor by default instead of the HIP-wide 0.3; `--mtp-confidence` still overrides it, and the other HIP families keep 0.3. On a Strix Halo iGPU one-stream decode is about 6% faster on code and on chat, and four distinct streams about 3%, with one-stream throughput on `tools/bench_prompts.json` unchanged. Replies are unchanged.
- Server: a reply that keeps a tool-call envelope as plain text now says so. `tensorfold.kept_tool_calls` counts the envelopes that name a tool the request did not offer and the malformed ones, and lists up to eight unoffered names, on the whole reply and on a stream's final chunk; `/metrics` gains `kept_tool_calls_unoffered_total` and `kept_tool_calls_malformed_total`. Replies are otherwise unchanged (#2814, for #2800). Thanks to @tarsnake for the report.

- CI: the No GPU zig and zig-windows jobs get 90 minutes, as test-host now takes about 50 (#3298).
- CI: the app workflow keeps its Linux AppImage artifact for 3 days instead of GitHub's default 90 (#2966).

- CI: the Linux no-GPU job runs `zig build test-host`, which collects the named host tests and compile checks apart from nine reviewed exclusions (the optional xgrammar steps, the release-path check, the two large-state timing commands, which stay available for explicit runs, and four fixture and source-pin checks held back under #2031); the build graph refuses empty checks, stale exclusions and aliases that bring excluded work back (#2095, part of #2031). Thanks to @garvrao80.
Expand Down
50 changes: 34 additions & 16 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,19 +391,36 @@ delete runs gets 503, an id that is not a number 400, and an id the graph does n
`modalities` must be absent or `["text"]`, and a truthy top-level `image`, `images`, `image_url`, `input_image`,
`audio`, `input_audio`, `video` or `video_url` key is refused: this server accepts and produces text only.

The native CUDA engine (Nemotron 3.5 Lightning) supports `logprobs: true` and `top_logprobs` from 0 through 20 on
`/v1/chat/completions`, streamed or not, without tools, stop strings, structured output or a thinking budget. Each
reply token has its `token`, `logprob`, `bytes` and requested `top_logprobs` in `choices[0].logprobs.content`; a
stream sends each row with the chunk whose `delta.content` completes that token's text, so the rows joined over the
chunks are the whole reply's. Probabilities describe the raw target-model distribution at temperature 1, before
temperature, top-k or top-p sampling filters, including when generation is greedy, and are the same with drafts on or
`"draft": false`. With thinking on, the rows cover the answer only, as `content` does: none for the reasoning,
`</think>` or the newlines after it, so the first row is the answer's first token, and a reply cut inside its
reasoning has none. Alternatives are tokenizer tokens and may include leading spaces; `bytes` preserves partial UTF-8
sequences. `/v1/completions` takes the legacy `logprobs`, an integer from 0 through 20 alternatives, and answers in
the legacy form, streamed or not: `tokens`, `token_logprobs`, `top_logprobs` (each alternative's text to its logprob)
and `text_offset` (each token's first character in the completion, counting each token's own text). Other engines,
the Responses route and the request modes above return HTTP 400 when probabilities are requested.
Engines that advertise `capabilities.logprobs` and give each token's exact bytes accept `logprobs: true` and
`top_logprobs` from 0 through 20 on `/v1/chat/completions`, streamed or not, with tools, stop strings, structured
output, reasoning and a thinking budget. Asking for them changes nothing else: the prompt, the sampled tokens and the
text are the same with them on or off. Probabilities describe the raw target-model distribution at temperature 1,
before temperature, top-k or top-p sampling filters, including when generation is greedy, and are the same with drafts
on or `"draft": false`. Alternatives are tokenizer tokens and may include leading spaces; `bytes` preserves partial
UTF-8 sequences.

`choices[0].logprobs.content` has an entry for each token of the reply's `content` (`token`, `logprob`, `bytes` and
the requested `top_logprobs`), and the entries' `bytes` joined spell `content`. With thinking on, the reasoning's
tokens are in `logprobs.reasoning_content`; with tools, each call has an `{index, content}` group in
`logprobs.tool_calls` with the entries of the markup the model wrote for it (not the arguments JSON the reply returns;
a closer the server adds to a cut call has none). Thinking markers, the whitespace the text drops, a stop string and
the text after it have no entries. A token the text shows only part of, such as one a stop string ends inside, shows
the kept bytes in `token` and `bytes` and its id in `token_id`, with its own `logprob` and alternatives.

A stream sends each entry with the chunk whose text completes that token, reasoning entries before the answer's first
text; with tools offered, the entries come in one chunk before the finishing one, once the calls are parsed. The
entries joined over the chunks are the whole reply's. `/v1/completions` takes the legacy `logprobs`, an integer from 0
through 20 alternatives, and answers in the legacy form, streamed or not: `tokens`, `token_logprobs`, `top_logprobs`
(each alternative's text to its logprob) and `text_offset` (each token's first character in the completion, counting
each token's own text). Other engines return HTTP 400 when probabilities are requested.

The Responses API gives the same entries for `top_logprobs` (0 through 20) or the `include` name
`message.output_text.logprobs`: in each `output_text` part's `logprobs`, and as extensions in `reasoning_text` parts
and `function_call` items. A stream sends them in the `response.output_text.delta` and
`response.reasoning_text.delta` events; with tools offered they come once the calls are parsed, as deltas with empty
text, and each item's done events wait for them. `include` alone on an engine without logprobs answers without them;
`top_logprobs` there returns HTTP 400.

Nonstreamed `/v1/completions` also takes vLLM's `prompt_logprobs`, an integer from 0 through 20, on the same engine
and on GLM-5.3-Flash's CUDA engine.
`choices[0].prompt_logprobs` has one entry per prompt token: `null` for the first, then an object keyed by token id
Expand Down Expand Up @@ -674,7 +691,7 @@ thinking on they start after the think end.

HTTP 400 comes before any token for a malformed field, a grammar xgrammar cannot compile (with xgrammar's reason), a
server without xgrammar (with the install command; on the native server, a server that cannot load `libtfgrammar`),
a grammar sent with `tool_choice: "required"` or a named function, and `logprobs` with a grammar or tools. A reply whose
a grammar sent with `tool_choice: "required"` or a named function. A reply whose
grammar fails while decoding ends with HTTP 500 (an error event when streaming); the other requests go on.

## Reasoning
Expand Down Expand Up @@ -1269,10 +1286,11 @@ prompt cache resumes the shared prefix as it does for chat. `store: false` keeps
response.

HTTP 400 refuses what this server does not run: built-in tools (web search, file search, computer use and the
others), `background`, `conversation`, `prompt` templates, `context_management`, `truncation: "auto"`, `top_logprobs`, file IDs and
others), `background`, `conversation`, `prompt` templates, `context_management`, `truncation: "auto"`, file IDs and
remote file URLs (`input_file` parts with inline `file_data` run on a model started with `--vision --vision-pdf`),
`item_reference` items, encrypted reasoning items, and a `previous_response_id` that is not stored.
`include` takes a list of OpenAI's names, which the server accepts and ignores (it has nothing to add for them):
`include` takes a list of OpenAI's names. `message.output_text.logprobs` asks for logprobs where the engine has them
(see the chat section's logprobs); the server has nothing to add for the others:
`code_interpreter_call.outputs`, `computer_call_output.output.image_url`, `file_search_call.results`,
`message.input_image.image_url`, `message.output_text.logprobs`, `reasoning.encrypted_content`,
`web_search_call.action.sources` and `web_search_call.results`. Any other name, or a value that is not a list of
Expand Down
4 changes: 2 additions & 2 deletions zig/build/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ pub fn toolHostTests(b: *std.Build, parser: *std.Build.Module, server: *std.Buil
b.step("test-thinking-tail-host", "Finished calls before a think close, whole and streamed without devices").dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"thinking tail:"} })).step);
const environment = b.step("test-environment-report-host", "Named environment discovery, new registry rows and startup reporting");
environment.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{ "capability audit: environment", "stable profile:", "profile line:" } })).step);
const logprobs = b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"logprobs_test"} }));
b.step("test-logprob-offers-host", "Logprob request capability refusals before engine submission").dependOn(&logprobs.step);
const logprobs = b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{ "logprobs_test", "logprob combinations:" } }));
b.step("test-logprob-offers-host", "Logprob refusals before submission, and entries with tools, stops, reasoning and Responses").dependOn(&logprobs.step);
const limits = b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"limit pins:"} }));
b.step("test-limit-pins-host", "Documented request and flag limits pinned at their bounds").dependOn(&limits.step);
const deps = b.addRunArtifact(b.addTest(.{ .root_module = server, .filters = &.{"flag deps:"} }));
Expand Down
6 changes: 4 additions & 2 deletions zig/src/server/chat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ pub const Reply = struct {
/// The template switches the prompt was rendered with (the next turn's prefill renders with them too).
thinking: bool = false,
effort: ?[]const u8 = null,
/// ``choices[0].logprobs`` (``{"content": [...]}``) for a request that asked; null otherwise.
/// ``choices[0].logprobs`` (prose, reasoning and call entries) for a request that asked; null otherwise.
logprobs: ?Value = null,
/// The tokens and target rows ``logprobs`` are projected from, once the route's tool policy is final.
probability_rows: ?@import("logprob_parts.zig").Capture = null,
/// ``choices[0].prompt_logprobs`` (vLLM's form) for a request that asked; null otherwise.
prompt_logprobs: ?Value = null,
loop_stop: ?u32 = null, // the loop period when --loop-guard-stop ended the reply in its reasoning
Expand Down Expand Up @@ -218,7 +220,7 @@ pub fn prepare(srv: *Server, cx: *Cx, input: Input, gone: anytype) Failure!Prepa
// The answer quota is separate only on engines that enforce it.
if (srv.info.capability(.answer_limit)) @import("thinking_reserve.zig").apply(&request, srv.config.thinking_reserve, if (window > 0) window - n else std.math.maxInt(u32), srv.think_close_end);
}
if (input.logprobs) |count| request.logprobs = try @import("logprobs.zig").admit(srv, cx, reasoning, request.think_budget, count);
request.logprobs = input.logprobs;
request.prompt_logprobs = input.prompt_logprobs;
if (try engine_refusal.of(srv.engine, cx, &request)) |message| return cx.refuse(message);
return .{ .input = input, .request = request, .prompt_len = rendered.ids.len, .received = received, .thinking = thinking, .reasoning = reasoning, .effort = effort, .sampled = sampling != null, .drafts = drafts, .token_ids = flag(f, "return_token_ids") orelse false, .stops = stops_opt, .preparing = preparing, .frames = rendered.frames };
Expand Down
47 changes: 36 additions & 11 deletions zig/src/server/chat_generation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ const nowNs = clock.nowNs;
const seconds = clock.seconds;
const deltaOf = reply_text.deltaOf;

/// One chunk's logprobs: ``content`` always, as OpenAI clients read it, and ``key``'s entries.
fn rowsOf(a: Allocator, key: []const u8, entries: Value) Allocator.Error!Value {
const o = try json.newObject(a);
try o.put(a, "content", .{ .array = &.{} });
try o.put(a, key, entries);
return .{ .object = o };
}

pub const Generation = struct {
srv: *Server,
a: Allocator,
Expand Down Expand Up @@ -55,7 +63,7 @@ pub const Generation = struct {
engine_done: bool = false,
consumed: usize = 0,
chunk_index: usize = 0,
lp: ?@import("logprobs.zig").Stream = null, // the request asked for logprobs: its rows, copied with each round
lp: ?@import("logprob_parts.zig").Live = null, // the request asked for logprobs: its rows, copied with each round
loop_stop: bool = false, // --loop-guard-stop: the engine ends the reply where the loop guard fires

fn eos(g: *const Generation, t: u32) bool {
Expand Down Expand Up @@ -107,31 +115,42 @@ pub const Generation = struct {
}
try fresh.append(g.a, t);
}
const live = g.liveRows();
if (live) |l| try l.add(g.srv, g.a, fresh.items);
const all = try g.visible.extend(g.a, g.srv.text, reply_text.decodeText, fresh.items);
if (g.visible.pending()) return; // a character still split across tokens
if (g.srv.text.vtable.format == .kimi) return @import("chat_kimi.zig").stream(g, sink);
const raw_visible = g.stops.visible(all, true);
const text = try @import("tool_minimax.zig").dsml(g.a, raw_visible, g.tools); // MiniMax-M3's calls as DSML
var answer = text;
var thought: []const u8 = "";
if (g.thinking) {
const original_close = try g.visible.closeOf(g.a, reply_text.decodeText, g.srv.text, g.srv.close_id);
const close = try @import("tool_minimax.zig").closeAfterRewrite(g.a, raw_visible, g.tools, original_close);
const split = try reply_text.splitThinkingAt(g.a, text, false, g.srv.markers, close);
const piece = g.streamed_reasoning.after(reply_text.pyStrip(split.reasoning), true); // the whole reply strips it
if (piece.len > 0) {
try g.streamed_reasoning.set(g.a, reply_text.pyStrip(split.reasoning), piece);
try g.emit(sink, try deltaOf(g.a, "reasoning_content", piece));
}
thought = g.streamed_reasoning.after(reply_text.pyStrip(split.reasoning), true); // the whole reply strips it
if (thought.len > 0) try g.streamed_reasoning.set(g.a, reply_text.pyStrip(split.reasoning), thought);
answer = split.answer;
}
answer = try tool_lfm2.dsml(g.a, answer, g.tools, false); // the answer only, so a call the reasoning mentions is not made
const shown = if (g.calls != null) try reply_text.hideInto(g.a, &g.hidden, answer, false, true, reply_text.openersOf(g.srv.markers)) else answer;
const vis = reply_text.heldBack(if (g.srv.info.capability(.reasoning)) reply_text.streamingVisible(shown) else shown, g.calls != null);
const copied = @intFromPtr(vis.ptr) >= @intFromPtr(g.hidden.items.ptr) and @intFromPtr(vis.ptr) <= @intFromPtr(g.hidden.items.ptr) + g.hidden.items.len;
const delta = g.streamed.after(vis, !copied);
if (delta.len > 0) {
try g.streamed.set(g.a, vis, delta);
try g.emit(sink, if (g.lp) |*l| (try l.delta(g.srv, g.a, g.thinking, g.ignore_eos, g.collected.items, delta, g.streamed.text.items.len, false)).? else .{ .string = delta });
if (delta.len > 0) try g.streamed.set(g.a, vis, delta);
// each chunk carries the entries its text settles: reasoning ones before the answer's first text
const rows = if (live) |l| try l.settle(g.srv, g.a, g.collected.items[0..l.spelled.ends.items.len], g.thinking, g.stops, g.streamed.text.items, g.streamed_reasoning.text.items) else null;
const thought_rows = if (rows) |r| r.get("reasoning_content") else null;
if (thought.len > 0 or thought_rows != null) {
const d: Value = if (thought.len > 0) try deltaOf(g.a, "reasoning_content", thought) else .{ .object = try json.newObject(g.a) };
if (thought_rows) |t| try d.object.put(g.a, "logprobs", try rowsOf(g.a, "reasoning_content", t));
try g.emit(sink, d);
}
const prose_rows: []Value = if (rows) |r| r.get("content").?.array else &.{};
if (delta.len > 0 or prose_rows.len > 0) {
const d: Value = if (prose_rows.len > 0) try deltaOf(g.a, "content", delta) else .{ .string = delta };
if (prose_rows.len > 0) try d.object.put(g.a, "logprobs", try rowsOf(g.a, "content", .{ .array = prose_rows }));
try g.emit(sink, d);
}
if (g.calls) |*c| {
var out: std.ArrayList(Value) = .empty;
Expand All @@ -140,6 +159,12 @@ pub const Generation = struct {
}
}

/// Logprob state when chunks carry their own entries: without tools, no call can claim streamed text.
fn liveRows(g: *Generation) ?*@import("logprob_parts.zig").Live {
if (g.tools.len > 0) return null;
return if (g.lp) |*l| l else null;
}

pub fn emit(g: *Generation, sink: Sink, delta: Value) Failure!void {
sink.call(sink.ctx, delta) catch {
g.cancel();
Expand Down Expand Up @@ -269,7 +294,7 @@ pub const Generation = struct {
const shown = if (g.calls != null) try tool_stream.endProse(a, content, if (g.thinking) content else text, g.tools, reason, g.single) else content;
const sent = g.streamed.text.items;
const rest = if (std.mem.startsWith(u8, shown, sent) and shown.len > sent.len) shown[sent.len..] else "";
if (g.lp) |*l| (if (try l.delta(g.srv, a, g.thinking, g.ignore_eos, g.collected.items, rest, shown.len, true)) |d| try g.emit(sink, d)) else if (rest.len > 0) try g.emit(sink, .{ .string = rest });
if (rest.len > 0) try g.emit(sink, .{ .string = rest });
if (g.calls) |*c| if (close.len > 0 or std.mem.eql(u8, reason, "length")) {
// the streamer reads the closers as markup the model wrote, so the call ends with the same deltas
var out: std.ArrayList(Value) = .empty;
Expand Down Expand Up @@ -344,7 +369,7 @@ pub const Generation = struct {
.speculative = .{ .object = spec },
.thinking = thinking,
.effort = effort,
.logprobs = if (g.lp) |l| try @import("logprobs.zig").value(g.srv, cx, a, g.thinking, content_tokens, l.rows.items) else null,
.probability_rows = if (g.lp) |l| .{ .tokens = content_tokens, .rows = l.rows.items, .thinking = g.thinking, .stops = g.stops, .closer = close, .sent = l.sent } else null,
.prompt_logprobs = if (m.prompt_rows) |r| try @import("logprobs.zig").promptValue(g.srv, a, r) else null,
.loop_stop = stopped,
};
Expand Down
Loading
Loading