Archived
New models. Recursive Flint (39.8B, about 2.5B active) by everplays (#422): `arch/flint`, as an IQ8R container with rotated int8 experts or a four-bit one, with a sink-aware WMMA prefill attention and the fused attention prologue at `rotary_dim` 0. Meta Muse Glimmer 30B by launch80_assets (#423): bf16, an int4 trunk or IQ8R, its windowed vision tower, its DFlash drafter, the ATEM tool dialect and context extension. Ling-3.0-tiny by RikshaDriver (#441): served from its GGUF releases or as IQ8R on `bailing_hybrid`, with six more libr3d kernels. Block FP8, MXFP4 and NVFP4 conversions of the three are not served. IQ8R containers of all three (round to nearest, no calibration) are on Hugging Face under StillDeadcode: flint-iq8r, muse-glimmer-30b-iq8r-dflash and ling-3.0-tiny-iq8r. They were checked for sane answers on two R9700; nothing was benchmarked, and Muse Glimmer's pictures, video and tool calls were not tried. Speech. Breeze-TTS-2 clones a voice from a reference recording and its transcript, with an optional delivery direction, by farcryjohn (#436). The published Breeze container needs converting again with the updated recipe before it can. Tools. A model entry with `diagnose: DIR` runs a fixed workload on the engine instead of serving and writes a report: step times, tokens a step, draft acceptance, TTFT and prefill rates by category, concurrency and prompt length, and with `diagnose-baseline` a token-for-token comparison against an earlier report (docs/DIAGNOSE.md), by Code000 (#418). Scheduler. `mixed-step-target-ms` holds a mixed prefill and decode step to a service time, off by default, by tnhnyzc (#413). `scheduler.stuck-exit` (60s by default, 0 never) ends the process when the device has advanced nothing for that long, so a restart policy brings a hung server back (#409, #415, #428). Fixed. Draft trees with the int8 KV cache, which stopped Gemma 4 31B with DFlash2 on its first request (#454, diagnosed by aelfwyne). The expert loan held at zero by a few leftover cache blocks after long sessions (#455, diagnosed by thekk1). The mapped tier's pages kept in the page cache across a load and a restore, by C_Tamas (#421). Replayed tool calls with blank arguments, and arguments that are not JSON refused naming the call, by dschmitz (#444). The dashboard's card temperature reads the junction sensor, by dschmitz (#453). The VRAM shortfall report says what the KL mode needs, by baKon (#448). The out-of-tree plugin test builds its plugins in parallel and takes its toolchain from the tree. Plugin ABI 40: out-of-tree plugins need to be rebuilt. Thanks to @everplays, @launch80_assets, @RikshaDriver, @farcryjohn, @Code000, @tnhnyzc, @C_Tamas, @dschmitz, @baKon, @aelfwyne and @thekk1.
131 lines
5.9 KiB
C++
131 lines
5.9 KiB
C++
/* chat.h -- rendering a message list to a prompt, and what the template can do.
|
|
*
|
|
* A thin layer over the lifted `common_chat_*` API (vendor/llama/common/chat.*, jinja/, see
|
|
* vendor/UPSTREAM). It adds three things:
|
|
*
|
|
* 1. Errors are values. Upstream throws std::runtime_error for a bad template, a rejected
|
|
* message or a malformed OAI request; a throw must not cross the server's request loop, so
|
|
* everything here returns a negative RAD_E_* and logs once.
|
|
* 2. The template comes from the .rad, not a llama_model. RadVocabHeader carries the chat
|
|
* template, the BOS/EOS spellings and the add_bos/add_eos flags, the four things
|
|
* common_chat_templates_init() would otherwise read off a model.
|
|
* 3. The lifted headers stay out of the rest of core/. Only chat.cpp, chatfmt.cpp and
|
|
* chatparse.cpp include them (the last only to resolve schema types for bound tools), so a
|
|
* vendor refresh cannot ripple into the server.
|
|
*
|
|
* Messages and tools are OpenAI-shaped JSON, which is what the server has and what the lift reads.
|
|
*/
|
|
#pragma once
|
|
#include "rad_internal.h"
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "util/json.h"
|
|
|
|
namespace rad {
|
|
|
|
class Vocab;
|
|
|
|
/* What the template supports, probed rather than assumed: jinja/caps.cpp renders the template
|
|
* against synthetic inputs and watches what it reads (spec §12, "template capability probe").
|
|
* Reported on /props; the message adapter uses it to choose string or typed-array content. */
|
|
struct ChatCaps {
|
|
bool tools = true;
|
|
bool tool_calls = true;
|
|
bool system_role = true;
|
|
bool parallel_tool_calls = true;
|
|
bool preserve_reasoning = false;
|
|
bool string_content = true;
|
|
bool typed_content = false;
|
|
bool object_arguments = false;
|
|
/* What the first probe render with tools threw, empty when none did. The probe ignores
|
|
* exceptions, so a template that calls something the engine lacks reports `tools` false as a
|
|
* template without tool support does; this is the difference. */
|
|
std::string probe_error;
|
|
};
|
|
|
|
struct ChatOptions {
|
|
bool add_generation_prompt = true;
|
|
bool enable_thinking = true;
|
|
bool parallel_tool_calls = false;
|
|
std::string tool_choice = "auto"; /* auto | none | required */
|
|
std::string reasoning_format = "auto"; /* none | auto | deepseek | deepseek-legacy */
|
|
std::string continue_final; /* "" | auto | content | reasoning_content */
|
|
std::string grammar; /* a user-supplied GBNF, or empty */
|
|
std::string json_schema; /* response_format json_schema, or empty */
|
|
bool add_bos = false;
|
|
bool add_eos = false;
|
|
std::map<std::string, std::string> template_kwargs;
|
|
bool quiet = false; /* a refusal is not logged: a startup probe */
|
|
};
|
|
|
|
/* Everything the scheduler and the sampler need for one request, produced in one pass. */
|
|
struct ChatPrompt {
|
|
std::string prompt;
|
|
std::string generation_prompt; /* the assistant prefix already inside `prompt` */
|
|
|
|
std::string grammar; /* GBNF; empty when the request is unconstrained */
|
|
bool grammar_lazy = false;
|
|
/* Triggers for a lazy grammar: the grammar starts applying only once one of these is seen.
|
|
* Kept as (type, text) so the sampler can tell a literal word from a pattern. */
|
|
struct GrammarTrigger { int type; std::string value; };
|
|
std::vector<GrammarTrigger> grammar_triggers;
|
|
|
|
std::vector<std::string> preserved_tokens; /* must survive the sampler's bans */
|
|
std::vector<std::string> additional_stops;
|
|
|
|
bool supports_thinking = false;
|
|
std::string thinking_start_tag, thinking_end_tag;
|
|
|
|
/* The auto-parser's verdict on this render: `format` is an opaque common_chat_format value,
|
|
* `parser` the PEG grammar it derived. The engine parses replies with chatparse.h; these are
|
|
* kept for the differential tests that compare the two. */
|
|
int format = 0;
|
|
std::string parser;
|
|
|
|
/* Why the template refused, in its own words (a jinja `raise_exception` message such as
|
|
* "Unexpected reasoning effort high. Supported types are ..."), so a 400 names the field at
|
|
* fault. Set only on a failure return. The text comes from the container's jinja, so it is
|
|
* model-controlled, not attacker-controlled. */
|
|
std::string error;
|
|
};
|
|
|
|
class ChatTemplate {
|
|
public:
|
|
ChatTemplate();
|
|
~ChatTemplate();
|
|
|
|
/* Compile a Jinja source. `bos`/`eos` are the token texts, which templates reference as
|
|
* `bos_token` / `eos_token`. An empty source loads the ChatML fallback with a Warn, since the
|
|
* prompt format is then a guess. */
|
|
int load(const std::string& jinja_source, const std::string& bos, const std::string& eos,
|
|
bool add_bos = false, bool add_eos = false);
|
|
/* The same, with template, bos/eos text and add flags taken from the vocab's RadVocabHeader.
|
|
* The engine uses this path. */
|
|
int load_from_vocab(const Vocab& v);
|
|
|
|
bool ready() const;
|
|
const ChatCaps& caps() const;
|
|
const std::string& source() const;
|
|
|
|
/* Render. `messages` and `tools` are OpenAI-shaped JSON (`tools` may be null or empty).
|
|
* Returns RAD_OK, RAD_E_INVAL when the request does not parse, or RAD_E_UNSUPPORTED when the
|
|
* template refuses it (e.g. a system message without a system role, or tools without tool
|
|
* support). Replayed history is read in other servers' shapes first: a turn's reasoning under
|
|
* `reasoning` or `thinking`, and a call whose arguments are null, blank or absent. */
|
|
int apply(const Json& messages, const Json& tools,
|
|
const ChatOptions& opt, ChatPrompt* out) const;
|
|
|
|
/* The ChatML fallback, named so the server can report which template it runs. */
|
|
static const char* chatml_source();
|
|
|
|
private:
|
|
struct Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
|
|
} /* namespace rad */
|