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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- `--instruct-sampling card` (or `field=value` pairs) serves the model card's instruct sampling to chat requests with thinking off that leave those fields unset; request fields, then the serve flags, then the pairs decide, and the server's own requests never take it (#2626). Thanks to @BobClawblaw.

- XPU: Qwen3.8-27B's DFlash2 drafts go through the core Drafter and Drafted, and each stream's draft tree is keyed with its own request (a sampled shared round read another's) (#2672, #2460 item 5). Thanks to @jschmied, and to @Mirrdhyn for the Arc Pro B70 runs.

- `POST /v1/images/generations` serves an engine's image capability: one picture a request as a base64 PNG, with `n` above 1, sizes past 1536 a side or 1,572,864 pixels, `response_format` `url`, unknown fields and a `negative_prompt` that is null or not valid UTF-8 refused by name; a text model's routes are unchanged (#2253, part of #1573). Thanks to @devopsfortunato.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ The binary's `capabilities --json` response lists its supported flags and platfo
| `--temperature T` | Sampling temperature; zero requests greedy decoding. |
| `--prompt-seed` | Use native prompt-derived keys instead of the fresh OS fallback; request and configured default seeds still win. |
| `--top-p P`, `--top-k K`, `--min-p P` | Sampling defaults. |
| `--instruct-sampling SET` | Sampling defaults for sampled chat requests with thinking off: `card` (the Qwen 3.5, 3.6 and 3.8 cards' temperature 0.7, top_p 0.8, top_k 20, presence_penalty 1.5), `name=value` pairs over it, or `none`; the serve flags still win. Greedy requests, raw completions and the server's own requests never take them. |
| `--thinking`, `--no-thinking` | Choose whether the chat template opens a reasoning block. |
| `--reasoning-effort LEVEL` | Default template effort: `minimal`, `low`, `medium`, `high`, `xhigh` or `max`. |
| `--thinking-budget N` | Limit reasoning tokens where the engine supports closing the reasoning block. |
Expand Down
25 changes: 25 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,31 @@ request fields: a `--min-p` outside 0 through 1 refuses every chat request, a ne
`--temperature` and `--top-p` must be finite numbers. An engine that decodes greedily only refuses sampled
requests while the server samples by default, and its refusal suggests serving with `--temperature 0`.

`--instruct-sampling` gives chat requests with thinking off their own sampling defaults. Exactly these requests change
under it: a chat request (not a raw completion) whose reasoning block is off (the request's `enable_thinking: false`,
or `--no-thinking` with nothing in the request turning it on), that samples (its temperature, or the default it ends
up with, is above 0), takes the set's value for each sampling field it leaves unset; a field the request sends wins,
as over the ordinary defaults. Requests with thinking on, greedy requests (a request's `temperature: 0`, a server's
`--temperature 0`, or a checkpoint whose `generation_config.json` has `do_sample: false`), raw prompt completions and
the server's own requests (compaction summaries, Living Weights' lesson wordings and checks) are unchanged. `card`
serves the family's model-card instruct set: Qwen 3.5, Qwen 3.6, Qwen3.8-27B and Qwen3.8-Flash-Next give temperature
0.7, top_p 0.8, top_k 20 and presence_penalty 1.5, while their thinking set stays in `generation_config.json`.
`name=value,...` sets or changes `temperature`, `top_p`, `top_k`, `min_p`, `presence_penalty` and `frequency_penalty`
over that set, or over the server's defaults for a family without one; `none` serves one set. The set, pairs
included, sits between `generation_config.json` and the flags, so `--temperature`, `--top-p`, `--top-k` and `--min-p`
still decide for both modes: a server started with `--temperature 0` stays greedy whatever the pairs say. Without the
flag the server has one default set for every request, as before. A pair outside the range a request may send
(temperature below 0, top_p outside 0 through 1, a negative top_k, min_p outside 0 through 1, a penalty outside -2
through 2) refuses the argument at startup, naming the field. `card` refuses a model type whose family gives no card
set; it cannot tell checkpoints apart within a type, so leave the flag off (or give pairs from the card) for a
checkpoint whose card gives no non-thinking set, such as Ornith-1.5-122B served as `qwen3_5_moe`. On an engine that
applies no penalties the card's presence_penalty is left out with a startup line saying so, and pairs naming a
non-zero penalty are refused at startup. The serving line prints the set after the sampling defaults
(`thinking off: ...`). With a DFlash2 drafter, presence_penalty 1.5 lowers draft acceptance: on Qwen3.8-27B drafted
thinking-off replies at the card set decode about 19% slower than with the penalty at 0, while the thinking set and
undrafted decoding are unaffected (#2645); `--instruct-sampling presence_penalty=0` keeps the card's temperature,
top_p and top_k without the penalty.

`--name-priority ID=background` gives one served id (`--name` or an `--alias`) a default priority: a request that
asks for it and sends no `priority` of its own is treated as `priority: "background"`. The request's own `priority`
field always wins over the default. This lets one server answer to several ids at their usual priority while a
Expand Down
3 changes: 3 additions & 0 deletions zig/src/server/benchmark_stream.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ fn bodyMode(a: Allocator, served: []const u8, f: suite.Fixture, tokens: u32, t:
const so = try json.newObject(a);
try so.put(a, "include_usage", .{ .bool = true });
try o.put(a, "stream_options", .{ .object = so });
// the protocol names every draw setting: a served default (the instruct set's presence_penalty 1.5) shapes none
try o.put(a, "presence_penalty", .{ .float = 0 });
try o.put(a, "frequency_penalty", .{ .float = 0 });
if (t > 0) {
try o.put(a, "top_k", try json.intValue(a, 20));
try o.put(a, "top_p", .{ .float = 0.95 });
Expand Down
8 changes: 4 additions & 4 deletions zig/src/server/benchmark_stream_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const stop = @import("benchmark_stop.zig");
const fake = @import("benchmark_fake.zig");
const Write = fake.Write;

const golden_chat = "{\"model\": \".tensorfold-benchmark\", \"max_tokens\": 256, \"temperature\": 1.0, \"seed\": 1234, \"stream\": true, \"stream_options\": {\"include_usage\": true}, \"top_k\": 20, \"top_p\": 0.95, \"draft\": false, \"messages\": [{\"role\": \"user\", \"content\": \"Explain how matrix multiplication uses a GPU in plain English, then give a small numerical example.\"}], \"chat_template_kwargs\": {\"enable_thinking\": false}}";
const golden_code = "{\"model\": \".tensorfold-benchmark\", \"max_tokens\": 256, \"temperature\": 0.0, \"seed\": 1238, \"stream\": true, \"stream_options\": {\"include_usage\": true}, \"prompt\": \"Write a short Python function that computes the Fibonacci sequence and explain it.\"}";
const golden_chat = "{\"model\": \".tensorfold-benchmark\", \"max_tokens\": 256, \"temperature\": 1.0, \"seed\": 1234, \"stream\": true, \"stream_options\": {\"include_usage\": true}, \"presence_penalty\": 0.0, \"frequency_penalty\": 0.0, \"top_k\": 20, \"top_p\": 0.95, \"draft\": false, \"messages\": [{\"role\": \"user\", \"content\": \"Explain how matrix multiplication uses a GPU in plain English, then give a small numerical example.\"}], \"chat_template_kwargs\": {\"enable_thinking\": false}}";
const golden_code = "{\"model\": \".tensorfold-benchmark\", \"max_tokens\": 256, \"temperature\": 0.0, \"seed\": 1238, \"stream\": true, \"stream_options\": {\"include_usage\": true}, \"presence_penalty\": 0.0, \"frequency_penalty\": 0.0, \"prompt\": \"Write a short Python function that computes the Fibonacci sequence and explain it.\"}";

fn opts(tokens: u32, serial: bool, timeout_s: f64) stream.Opts {
return .{ .tokens = tokens, .reps = 1, .temperatures = &.{ 1.0, 0.0 }, .serial = serial, .timeout_s = timeout_s };
Expand Down Expand Up @@ -38,8 +38,8 @@ test "request bodies equal the golden bytes, routes and headers, and a chat repl
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
const a = arena.allocator();
try std.testing.expectEqualStrings("d85d948f99e8c87c578e103e3e4e584e5d10fc53144a7585cfadd5f8c493fd5b", &sha(golden_chat));
try std.testing.expectEqualStrings("fb516b455e574eba1c065ba914a8b7707d3839331156cb4defdcd766c97f4318", &sha(golden_code));
try std.testing.expectEqualStrings("1f13ffe30999c85cb4ecc0bfc89ec9f262ebb2cc262935d1c1200d259bc7d74a", &sha(golden_chat));
try std.testing.expectEqualStrings("a7528481b784a481f7a6c8365b87becec36c73294f4a02ef95bc1c5f591c75a6", &sha(golden_code));
const f = try fake.Fake.start(std.testing.allocator, &.{
.{ .method = "POST", .path = "/v1/chat/completions", .replies = &.{try fake.reply(a, true, 256, 12)} },
.{ .method = "POST", .path = "/v1/completions", .replies = &.{try fake.reply(a, false, 256, 12)} },
Expand Down
7 changes: 5 additions & 2 deletions zig/src/server/chat.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub const Prompt = union(enum) { text: []const u8, ids: []const u32 };
pub const Input = struct {
/// The client itself asked for thinking off (no server, template or route default counts): it must be honored.
explicit_off: bool = false,
/// The server's own request (a compaction summary, a lesson's wordings): it never takes --instruct-sampling's set.
own: bool = false,
messages: Value = .{ .array = &.{} },
tools: []const Value = &.{},
prompt: ?Prompt = null,
Expand Down Expand Up @@ -145,6 +147,7 @@ pub fn prepare(srv: *Server, cx: *Cx, input: Input, gone: anytype) Failure!Prepa
errdefer srv.release(preparing, null);
if (gone.check()) return error.Cancelled;
const thinking = input.prompt == null and (flag(f, "enable_thinking") orelse srv.config.enable_thinking);
const instruct = input.prompt == null and !thinking and !input.own; // a client's chat with thinking off may take --instruct-sampling's set
const reasoning = thinking and srv.info.capability(.reasoning) and (srv.text.vtable.format != .kimi or input.prompt == null); // the prompt renders `thinking`; the reply reads `reasoning`
const effort = srv.effortFor(if (f.get("reasoning_effort")) |e| (if (e == .string) e.string else null) else null);
cx.clear_thinking = flag(f, "clear_thinking");
Expand All @@ -165,14 +168,14 @@ pub fn prepare(srv: *Server, cx: *Cx, input: Input, gone: anytype) Failure!Prepa
if (system_len > 0) for ([_]i64{ @as(i64, @intCast(system_len)) - 2048, @as(i64, @intCast(system_len)) - 512, @intCast(system_len) }) |cut| {
if (cut >= 512) try shared.append(a, @intCast(cut));
};
const sampling = try srv.resolveSampling(cx, f, input.temperature, rendered.ids);
const sampling = try srv.resolveSampling(cx, f, input.temperature, rendered.ids, instruct);
const draft_field = f.get("draft");
const drafts = srv.config.use_drafts and !(draft_field != null and draft_field.? == .bool and !draft_field.?.bool);
var request: api.Request = .{
.prompt = rendered.ids,
.max_tokens = @intCast(@min(limit, std.math.maxInt(u32))),
.sampling = sampling,
.penalties = try srv.resolvePenalties(cx, f),
.penalties = try srv.resolvePenalties(cx, f, instruct),
.eos = if (stops_opt.ignore_eos) &.{} else srv.eos,
.drafts = drafts,
.background = background,
Expand Down
21 changes: 4 additions & 17 deletions zig/src/server/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub const flags = [_]Flag{
.{ .name = "--top-p", .native = true },
.{ .name = "--top-k", .native = true },
.{ .name = "--min-p", .native = true },
.{ .name = "--instruct-sampling", .native = true },
.{ .name = "--thinking", .kind = .store_true, .native = true },
.{ .name = "--no-thinking", .kind = .store_true, .native = true },
.{ .name = "--reasoning-effort", .choices = @import("fields.zig").efforts[1..], .native = true },
Expand Down Expand Up @@ -211,6 +212,7 @@ pub const Args = struct {
top_p: ?f64 = null,
top_k: ?i64 = null,
min_p: ?f64 = null,
instruct_sampling: ?[]const u8 = null, // none, card or name=value pairs: thinking-off sampled chats' set
thinking: bool = true,
reasoning_effort: ?[]const u8 = null,
thinking_budget: i64 = 0,
Expand Down Expand Up @@ -410,7 +412,7 @@ fn apply(a: Allocator, out: *Args, name: []const u8, value: ?[]const u8, u: *Usa
return repeated.origins.append(a, v);
}
if (try cudaFlag(a, out, name, v, u) or try gpuFlag(a, out, name, v, u)) return;
if (try recallFlag(a, out, name, v, u)) return;
if (try @import("cli_recall.zig").flag(a, out, name, v, u)) return;
if (out.cfg.set(name, v) catch return fail(u, a, "--cfg-gamma must be 0 (off) or 1 (unguided) through 5", .{})) return;
if (@import("cli_fsr.zig").apply(out, name, v) catch |err| return fail(u, a, "argument {s}: {s}", .{ name, @errorName(err) })) return;
if (is(name, "--voices")) {
Expand Down Expand Up @@ -464,7 +466,7 @@ fn apply(a: Allocator, out: *Args, name: []const u8, value: ?[]const u8, u: *Usa
} else if (is(name, "--decode-share")) {
out.decode_share = try float(u, a, name, v);
if (!(out.decode_share.? >= 0 and out.decode_share.? < 1)) return fail(u, a, "argument --decode-share: expected a share from 0 to under 1: '{s}'", .{v});
} else if (is(name, "--prompt-seed")) out.prompt_seed = true else if (is(name, "--max-tokens")) out.max_tokens = try int(u, a, name, v) else if (is(name, "--temperature")) out.temperature = try float(u, a, name, v) else if (is(name, "--top-p")) out.top_p = try float(u, a, name, v) else if (is(name, "--top-k")) out.top_k = try int(u, a, name, v) else if (is(name, "--min-p")) out.min_p = try float(u, a, name, v) else if (is(name, "--thinking")) out.thinking = true else if (is(name, "--no-thinking")) out.thinking = false else if (is(name, "--reasoning-effort")) out.reasoning_effort = v else if (is(name, "--thinking-budget")) out.thinking_budget = try int(u, a, name, v) else if (is(name, "--thinking-reserve")) out.thinking_reserve = try int(u, a, name, v) else if (is(name, "--loop-guard")) out.loop_guard = true else if (is(name, "--loop-guard-stop")) out.loop_guard_stop = true else if (is(name, "--drafter")) out.drafter = v else if (is(name, "--drafter-bits")) out.drafter_bits = @intCast(try int(u, a, name, v)) else if (is(name, "--record")) out.record = v else if (is(name, "--kv-cache")) out.kv_cache = v else if (is(name, "--prompt-precision")) out.prompt_precision = v else if (is(name, "--no-drafts")) out.no_drafts = true else if (is(name, "--keep-warm")) out.keep_warm = try int(u, a, name, v) else if (is(name, "--idle-unload")) out.idle_unload = try int(u, a, name, v) else if (is(name, "--compact-at")) {
} else if (is(name, "--prompt-seed")) out.prompt_seed = true else if (is(name, "--max-tokens")) out.max_tokens = try int(u, a, name, v) else if (is(name, "--temperature")) out.temperature = try float(u, a, name, v) else if (is(name, "--top-p")) out.top_p = try float(u, a, name, v) else if (is(name, "--top-k")) out.top_k = try int(u, a, name, v) else if (is(name, "--min-p")) out.min_p = try float(u, a, name, v) else if (is(name, "--instruct-sampling")) out.instruct_sampling = if (try @import("family_sampling.zig").pairsProblem(a, v)) |why| return fail(u, a, "argument {s}: {s}: '{s}'", .{ name, why, v }) else v else if (is(name, "--thinking")) out.thinking = true else if (is(name, "--no-thinking")) out.thinking = false else if (is(name, "--reasoning-effort")) out.reasoning_effort = v else if (is(name, "--thinking-budget")) out.thinking_budget = try int(u, a, name, v) else if (is(name, "--thinking-reserve")) out.thinking_reserve = try int(u, a, name, v) else if (is(name, "--loop-guard")) out.loop_guard = true else if (is(name, "--loop-guard-stop")) out.loop_guard_stop = true else if (is(name, "--drafter")) out.drafter = v else if (is(name, "--drafter-bits")) out.drafter_bits = @intCast(try int(u, a, name, v)) else if (is(name, "--record")) out.record = v else if (is(name, "--kv-cache")) out.kv_cache = v else if (is(name, "--prompt-precision")) out.prompt_precision = v else if (is(name, "--no-drafts")) out.no_drafts = true else if (is(name, "--keep-warm")) out.keep_warm = try int(u, a, name, v) else if (is(name, "--idle-unload")) out.idle_unload = try int(u, a, name, v) else if (is(name, "--compact-at")) {
if (std.mem.eql(u8, v, "auto")) out.compact_auto = true else {
const f = try float(u, a, name, v);
if (!(f > 0 and f <= 1)) return fail(u, a, "argument --compact-at: expected auto or a fraction in (0, 1]: '{s}'", .{v});
Expand Down Expand Up @@ -500,21 +502,6 @@ fn apply(a: Allocator, out: *Args, name: []const u8, value: ?[]const u8, u: *Usa
} else if (is(name, "--register-redraw-st")) out.redraw.register.st = try float(u, a, name, v) else if (is(name, "--register-redraw-high")) out.redraw.register.high = try float(u, a, name, v) else if (is(name, "--register-high-hz")) out.redraw.register.high_hz = try float(u, a, name, v);
}

/// --recall and the flags that imply it; false for any other flag.
fn recallFlag(a: Allocator, out: *Args, name: []const u8, v: []const u8, u: *Usage) error{ Usage, OutOfMemory }!bool {
if (std.mem.eql(u8, name, "--recall-dir")) {
out.recall_dir = v;
} else if (std.mem.eql(u8, name, "--recall-gib")) {
out.recall_gib = try gib(u, a, name, v);
const least = "argument --recall-gib: at least 1/128 GiB (two 4 MiB chunks): '{s}'";
if (out.recall_gib < 1.0 / 128.0) return fail(u, a, least, .{v});
} else if (std.mem.eql(u8, name, "--recall-read-only")) {
out.recall_read_only = true;
} else if (!std.mem.eql(u8, name, "--recall")) return false;
out.recall = true;
return true;
}

/// ``--parallel``: "auto" is up to 8 requests at once; a number caps it.
pub fn parallel(text: []const u8) ?u32 {
const t = std.mem.trim(u8, text, " ");
Expand Down
19 changes: 19 additions & 0 deletions zig/src/server/cli_recall.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! The --recall, --recall-dir, --recall-gib and --recall-read-only flags.
const std = @import("std");
const Allocator = std.mem.Allocator;
const cli = @import("cli.zig");

/// --recall and the flags that imply it; false for any other flag.
pub fn flag(a: Allocator, out: *cli.Args, name: []const u8, v: []const u8, u: *cli.Usage) error{ Usage, OutOfMemory }!bool {
if (std.mem.eql(u8, name, "--recall-dir")) {
out.recall_dir = v;
} else if (std.mem.eql(u8, name, "--recall-gib")) {
out.recall_gib = try cli.gib(u, a, name, v);
const least = "argument --recall-gib: at least 1/128 GiB (two 4 MiB chunks): '{s}'";
if (out.recall_gib < 1.0 / 128.0) return cli.fail(u, a, least, .{v});
} else if (std.mem.eql(u8, name, "--recall-read-only")) {
out.recall_read_only = true;
} else if (!std.mem.eql(u8, name, "--recall")) return false;
out.recall = true;
return true;
}
4 changes: 2 additions & 2 deletions zig/src/server/compact.zig
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ fn oneNote(srv: *Server, cx: *Cx, gone: anytype, task: []const u8, prev: []const
const fields = try json.newObject(a);
try fields.put(a, "enable_thinking", .{ .bool = false });
try fields.put(a, "temperature", .{ .float = 0 });
var prepared = chat.prepare(srv, cx, .{ .messages = .{ .array = list.items }, .fields = .{ .object = fields }, .max_tokens = 1024, .temperature = 0 }, gone) catch |e| blk: {
var prepared = chat.prepare(srv, cx, .{ .own = true, .messages = .{ .array = list.items }, .fields = .{ .object = fields }, .max_tokens = 1024, .temperature = 0 }, gone) catch |e| blk: {
if (!(e == error.Refused and cx.kind == .context_length)) return e;
cx.kind = .request;
cx.message = "";
const fitted = chat.prepare(srv, cx, .{ .messages = .{ .array = list.items }, .fields = .{ .object = fields }, .max_tokens = 1, .temperature = 0 }, gone) catch |e2| {
const fitted = chat.prepare(srv, cx, .{ .own = true, .messages = .{ .array = list.items }, .fields = .{ .object = fields }, .max_tokens = 1, .temperature = 0 }, gone) catch |e2| {
if (e2 == error.Refused and cx.kind == .context_length) {
cx.kind = .request;
cx.message = "";
Expand Down
Loading
Loading