Archived
Radiance becomes a multi-model engine: one process serves several models behind one port, loads each when a request names it, parks it in host memory or restores it from its container, and shares the cards between them (docs/MULTIMODEL.md). The configuration is one YAML file; the command line flags are gone (`radiance --config FILE`, hot reload on SIGHUP). Formats. IQ8R (rotated int8) and IQR-V4 replace FP8 and MXFP4 as whole-model formats, with an int8 KV cache (`kv-cache-dtype: i8`) in place of the fp8 one. Containers whose weights are block FP8, MXFP4, M2XFP4, NVFP4 or ParoQuant are refused at startup by the name of the first such weight. Not served until they have int8 containers: GLM-5.3-Flash, Ornith-1.5, Sage-A1.5, Nemotron-3.5-Bolt-74B, Ling-3.0-flash, drama-3 and Anima's FP8 container; Nemotron-3.5-Bolt-E4B, the Gemma 4 31B DFlash containers and MiniCPM5-2B bf16 serve without their drafter. 1.17.0 serves all of them. Speed. Chained launches for Qwen3.8-27B, Gemma 4, Gemma 3 and the small bf16 models, a new Qwen3.8-Flash-Next container (IQR-V4 experts, int8 trunk) with its decode step and prefill reworked, and a reworked adaptive draft window. Deployment. deploy/compose has two fleet files, tp1.yaml and tp2.yaml, each with its configuration beside it, in place of the per-model files. `host-pool-mib` is a model's host pool in all, split among its ranks. The dashboard is rebuilt: an hour of history kept by the server, each accelerator's memory by model, model states over time. Merged since 1.17.0: Nemotron-3.5-Bolt-74B-A9B by keptn42 (#339); GLM-5.3-Flash on four cards by AnimusNull (#397); chained launches for Flash-Next's decode step (#396) and preempted requests keeping their prefix and place (#405) by mici81; --prefill-interleave auto by Code000 (#410); eight more libr3d kernels and the w4a4 reference by RikshaDriver (#403, #407, #408); libr3d large-BAR and E4M3 decode fixes by neuromanMD (#438, #439); int4/int5 decode tiles by Kezi (#426); attention for Nanbeige 4.3 33B by everplays (#417); expert_stats_report.py by baKon (#431). Fixed: #398, #402, #419, #437 (dschmitz's patch); added the metrics of #392, and multi-model serving as asked for in #367 and #109. Plugin ABI 39: out-of-tree plugins need to be rebuilt. Thanks to @keptn42, @AnimusNull, @mici81, @Code000, @RikshaDriver, @neuromanMD, @Kezi, @everplays, @baKon and @dschmitz.
492 lines
17 KiB
C++
492 lines
17 KiB
C++
#include "value.h"
|
|
#include "runtime.h"
|
|
#include "caps.h"
|
|
|
|
// note: the json dependency is only for defining input in a convenient way
|
|
// we can remove it in the future when we figure out a better way to define inputs using jinja::value
|
|
#include "util/json.h"
|
|
|
|
#include <functional>
|
|
#include <sstream>
|
|
|
|
#define FILENAME "jinja-caps"
|
|
|
|
using json = rad::Json;
|
|
|
|
namespace jinja {
|
|
|
|
using caps_json_fn = std::function<json()>;
|
|
using caps_analyze_fn = std::function<void(bool, value &, value &)>;
|
|
|
|
// RADIANCE: where caps_get collects the first exception of a probe that carried tools
|
|
// (caps::probe_error).
|
|
static thread_local std::string * caps_probe_error = nullptr;
|
|
|
|
static void caps_try_execute(jinja::program & prog,
|
|
const caps_json_fn & messages_fn,
|
|
const caps_json_fn & tools_fn,
|
|
const caps_analyze_fn & analyze_fn) {
|
|
context ctx;
|
|
ctx.is_get_stats = true;
|
|
jinja::global_from_json(ctx, json{
|
|
{"messages", messages_fn()},
|
|
{"tools", tools_fn()},
|
|
{"bos_token", ""},
|
|
{"eos_token", ""},
|
|
{"add_generation_prompt", true}
|
|
}, true);
|
|
|
|
auto messages = ctx.get_val("messages");
|
|
auto tools = ctx.get_val("tools");
|
|
|
|
bool success = false;
|
|
std::string result;
|
|
try {
|
|
jinja::runtime runtime(ctx);
|
|
auto results = runtime.execute(prog);
|
|
auto parts = jinja::runtime::gather_string_parts(results);
|
|
result = parts->as_string().str();
|
|
success = true;
|
|
} catch (const std::exception & e) {
|
|
JJ_DEBUG("Exception during execution: %s", e.what());
|
|
if (caps_probe_error && caps_probe_error->empty() && is_val<value_array>(tools) &&
|
|
!tools->as_array().empty()) {
|
|
*caps_probe_error = e.what();
|
|
}
|
|
result = "";
|
|
// ignore exceptions during capability analysis
|
|
}
|
|
|
|
analyze_fn(success, messages, tools);
|
|
}
|
|
|
|
// for debugging only
|
|
static void caps_print_stats(value & v, const std::string & path) {
|
|
std::string ops;
|
|
for (const auto & name : v->stats.ops) {
|
|
ops += name + " ";
|
|
}
|
|
JJ_DEBUG("Value %s, type: %s %s, ops: %s",
|
|
path.c_str(),
|
|
v->type().c_str(),
|
|
v->stats.used ? "(used)" : "",
|
|
ops.c_str());
|
|
}
|
|
|
|
std::map<std::string, bool> caps::to_map() const {
|
|
return {
|
|
{"supports_string_content", supports_string_content},
|
|
{"supports_typed_content", supports_typed_content},
|
|
{"supports_tools", supports_tools},
|
|
{"supports_tool_calls", supports_tool_calls},
|
|
{"supports_parallel_tool_calls", supports_parallel_tool_calls},
|
|
{"supports_system_role", supports_system_role},
|
|
{"supports_preserve_reasoning", supports_preserve_reasoning},
|
|
{"supports_object_arguments", supports_object_arguments},
|
|
};
|
|
}
|
|
|
|
std::string caps::to_string() const {
|
|
std::ostringstream ss;
|
|
ss << "Caps(\n";
|
|
for (const auto & [key, value] : to_map()) {
|
|
ss << " " << key << "=" << (value ? "true" : "false") << "\n";
|
|
}
|
|
ss << ")";
|
|
return ss.str();
|
|
}
|
|
|
|
caps caps_get(jinja::program & prog) {
|
|
caps result;
|
|
caps_probe_error = &result.probe_error;
|
|
|
|
static const auto has_op = [](value & v, const std::string & op_name) {
|
|
return v->stats.ops.find(op_name) != v->stats.ops.end();
|
|
};
|
|
|
|
JJ_DEBUG("%s\n", ">>> Running capability check: typed content");
|
|
|
|
// case: typed content support
|
|
caps_try_execute(
|
|
prog,
|
|
[&]() {
|
|
// messages
|
|
return json::array({
|
|
{
|
|
{"role", "user"},
|
|
{"content", "content"}
|
|
}
|
|
});
|
|
},
|
|
[&]() {
|
|
// tools: an empty array, as llama.cpp master hands it. json{nullptr} is the one-element
|
|
// array [null]; a template that iterates `tools` (GLM-5.3's does) threw on the null
|
|
// and the probe took the throw for "cannot render string content".
|
|
return json::array();
|
|
},
|
|
[&](bool success, value & messages, value &) {
|
|
auto & content = messages->at(0)->at("content");
|
|
caps_print_stats(content, "messages[0].content");
|
|
if (has_op(content, "selectattr") || has_op(content, "array_access")) {
|
|
// accessed as an array
|
|
result.supports_typed_content = true;
|
|
}
|
|
if (!success) {
|
|
// failed to execute with content as string
|
|
result.supports_string_content = false;
|
|
}
|
|
}
|
|
);
|
|
|
|
JJ_DEBUG("%s\n", ">>> Running capability check: system prompt");
|
|
|
|
// case: system prompt support
|
|
caps_try_execute(
|
|
prog,
|
|
[&]() {
|
|
// messages
|
|
return json::array({
|
|
{
|
|
{"role", "system"},
|
|
{"content", "System message"}
|
|
},
|
|
{
|
|
{"role", "user"},
|
|
{"content", "User message"}
|
|
},
|
|
});
|
|
},
|
|
[&]() {
|
|
// tools
|
|
return json::array();
|
|
},
|
|
[&](bool, value & messages, value &) {
|
|
auto & content = messages->at(0)->at("content");
|
|
caps_print_stats(content, "messages[0].content");
|
|
if (!content->stats.used) {
|
|
result.supports_system_role = false;
|
|
}
|
|
}
|
|
);
|
|
|
|
JJ_DEBUG("%s\n", ">>> Running capability check: single tool with object arguments support");
|
|
|
|
// case: tools support: single call with object arguments
|
|
caps_try_execute(
|
|
prog,
|
|
[&]() {
|
|
// messages
|
|
return json::array({
|
|
{
|
|
{"role", "user"},
|
|
{"content", "User message"},
|
|
},
|
|
{
|
|
{"role", "assistant"},
|
|
{"content", ""}, // Some templates expect content to be empty with tool calls
|
|
{"tool_calls", json::array({
|
|
{
|
|
{"id", "call00001"},
|
|
{"type", "function"},
|
|
{"function", {
|
|
{"name", "tool1"},
|
|
{"arguments", {
|
|
{"arg", "value"}
|
|
}}
|
|
}}
|
|
}
|
|
})}
|
|
},
|
|
{
|
|
{"role", "tool"},
|
|
{"content", "Tool response"},
|
|
{"tool_call_id", "call00001"}
|
|
},
|
|
{
|
|
{"role", "assistant"},
|
|
{"content", "The tool response was 'tool response'"}
|
|
},
|
|
{
|
|
{"role", "user"},
|
|
{"content", "User message"},
|
|
},
|
|
});
|
|
},
|
|
[&]() {
|
|
// tools
|
|
return json::array({
|
|
{
|
|
{"name", "tool"},
|
|
{"type", "function"},
|
|
{"function", {
|
|
{"name", "tool1"},
|
|
{"description", "Tool description"},
|
|
{"parameters", {
|
|
{"type", "object"},
|
|
{"properties", {
|
|
{"arg", {
|
|
{"type", "string"},
|
|
{"description", "Arg description"},
|
|
}},
|
|
}},
|
|
{"required", json::array({ "arg" })},
|
|
}},
|
|
}},
|
|
},
|
|
});
|
|
},
|
|
[&](bool success, value & messages, value & tools) {
|
|
if (!success) {
|
|
return; // Nothing can be inferred
|
|
}
|
|
|
|
auto & tool_name = tools->at(0)->at("function")->at("name");
|
|
caps_print_stats(tool_name, "tools[0].function.name");
|
|
caps_print_stats(tools, "tools");
|
|
if (!tool_name->stats.used) {
|
|
result.supports_tools = false;
|
|
}
|
|
|
|
auto & tool_calls = messages->at(1)->at("tool_calls");;
|
|
caps_print_stats(tool_calls, "messages[1].tool_calls");
|
|
if (!tool_calls->stats.used) {
|
|
result.supports_tool_calls = false;
|
|
return;
|
|
}
|
|
|
|
auto & tool_arg = tool_calls->at(0)->at("function")->at("arguments")->at("arg");
|
|
caps_print_stats(tool_arg, "messages[1].tool_calls[0].function.arguments.arg");
|
|
if (tool_arg->stats.used) {
|
|
result.supports_object_arguments = true;
|
|
}
|
|
}
|
|
);
|
|
|
|
if (!result.supports_object_arguments) {
|
|
JJ_DEBUG("%s\n", ">>> Running capability check: single tool with string arguments support");
|
|
|
|
// case: tools support: single call with string arguments
|
|
caps_try_execute(
|
|
prog,
|
|
[&]() {
|
|
// messages
|
|
return json::array({
|
|
{
|
|
{"role", "user"},
|
|
{"content", "User message"},
|
|
},
|
|
{
|
|
{"role", "assistant"},
|
|
{"content", ""}, // Some templates expect content to be empty with tool calls
|
|
{"tool_calls", json::array({
|
|
{
|
|
{"id", "call00001"},
|
|
{"type", "function"},
|
|
{"function", {
|
|
{"name", "tool1"},
|
|
{"arguments", R"({"arg": "value"})"}
|
|
}}
|
|
}
|
|
})}
|
|
},
|
|
{
|
|
{"role", "tool"},
|
|
{"content", "Tool response"},
|
|
{"tool_call_id", "call00001"}
|
|
},
|
|
{
|
|
{"role", "assistant"},
|
|
{"content", "The tool response was 'tool response'"}
|
|
},
|
|
{
|
|
{"role", "user"},
|
|
{"content", "User message"},
|
|
},
|
|
});
|
|
},
|
|
[&]() {
|
|
// tools
|
|
return json::array({
|
|
{
|
|
{"name", "tool"},
|
|
{"type", "function"},
|
|
{"function", {
|
|
{"name", "tool1"},
|
|
{"description", "Tool description"},
|
|
{"parameters", {
|
|
{"type", "object"},
|
|
{"properties", {
|
|
{"arg", {
|
|
{"type", "string"},
|
|
{"description", "Arg description"},
|
|
}},
|
|
}},
|
|
{"required", json::array({ "arg" })},
|
|
}},
|
|
}},
|
|
},
|
|
});
|
|
},
|
|
[&](bool success, value & messages, value & tools) {
|
|
if (!success) {
|
|
result.supports_tool_calls = false;
|
|
result.supports_tools = false;
|
|
return;
|
|
}
|
|
|
|
auto & tool_name = tools->at(0)->at("function")->at("name");
|
|
caps_print_stats(tool_name, "tools[0].function.name");
|
|
caps_print_stats(tools, "tools");
|
|
if (!tool_name->stats.used) {
|
|
result.supports_tools = false;
|
|
}
|
|
|
|
auto & tool_calls = messages->at(1)->at("tool_calls");
|
|
caps_print_stats(tool_calls, "messages[1].tool_calls");
|
|
if (!tool_calls->stats.used) {
|
|
result.supports_tool_calls = false;
|
|
return;
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
JJ_DEBUG("%s\n", ">>> Running capability check: parallel tool support");
|
|
|
|
// case: tools support: parallel calls
|
|
caps_try_execute(
|
|
prog,
|
|
[&]() {
|
|
json args = json(R"({"arg": "value"})");
|
|
if (result.supports_object_arguments) {
|
|
args = json{{"arg", "value"}};
|
|
}
|
|
|
|
// messages
|
|
return json::array({
|
|
{
|
|
{"role", "user"},
|
|
{"content", "User message"},
|
|
},
|
|
{
|
|
{"role", "assistant"},
|
|
{"content", ""}, // Some templates expect content to be empty with tool calls
|
|
{"tool_calls", json::array({
|
|
{
|
|
{"id", "call00001"},
|
|
{"type", "function"},
|
|
{"function", {
|
|
{"name", "tool1"},
|
|
{"arguments", args}
|
|
}}
|
|
},
|
|
{
|
|
{"id", "call00002"},
|
|
{"type", "function"},
|
|
{"function", {
|
|
{"name", "tool1"},
|
|
{"arguments", args}
|
|
}}
|
|
}
|
|
})}
|
|
},
|
|
{
|
|
{"role", "tool"},
|
|
{"content", "Tool response"},
|
|
{"tool_call_id", "call00001"}
|
|
},
|
|
{
|
|
{"role", "assistant"},
|
|
{"content", "The tool response was 'tool response'"}
|
|
},
|
|
{
|
|
{"role", "user"},
|
|
{"content", "User message"},
|
|
},
|
|
});
|
|
},
|
|
[&]() {
|
|
// tools
|
|
return json::array({
|
|
{
|
|
{"name", "tool"},
|
|
{"type", "function"},
|
|
{"function", {
|
|
{"name", "tool1"},
|
|
{"description", "Tool description"},
|
|
{"parameters", {
|
|
{"type", "object"},
|
|
{"properties", {
|
|
{"arg", {
|
|
{"type", "string"},
|
|
{"description", "Arg description"},
|
|
}},
|
|
}},
|
|
{"required", json::array({ "arg" })},
|
|
}},
|
|
}},
|
|
},
|
|
});
|
|
},
|
|
[&](bool success, value & messages, value & /*tools*/) {
|
|
if (!success) {
|
|
result.supports_parallel_tool_calls = false;
|
|
return;
|
|
}
|
|
|
|
auto & tool_calls = messages->at(1)->at("tool_calls");
|
|
caps_print_stats(tool_calls, "messages[1].tool_calls");
|
|
|
|
// check for second tool call usage
|
|
auto & tool_call_1 = tool_calls->at(1)->at("function");
|
|
caps_print_stats(tool_call_1, "messages[1].tool_calls[1].function");
|
|
if (!tool_call_1->stats.used) {
|
|
result.supports_parallel_tool_calls = false;
|
|
}
|
|
}
|
|
);
|
|
|
|
JJ_DEBUG("%s\n", ">>> Running capability check: preserve reasoning");
|
|
|
|
// case: preserve reasoning content in chat history
|
|
caps_try_execute(
|
|
prog,
|
|
[&]() {
|
|
// messages
|
|
return json::array({
|
|
{
|
|
{"role", "user"},
|
|
{"content", "User message"}
|
|
},
|
|
{
|
|
{"role", "assistant"},
|
|
{"content", "Assistant message"},
|
|
{"reasoning_content", "Reasoning content"}
|
|
},
|
|
{
|
|
{"role", "user"},
|
|
{"content", "User message"}
|
|
},
|
|
});
|
|
},
|
|
[&]() {
|
|
// tools
|
|
return json::array();
|
|
},
|
|
[&](bool, value & messages, value &) {
|
|
auto & content = messages->at(1)->at("reasoning_content");
|
|
caps_print_stats(content, "messages[1].reasoning_content");
|
|
if (content->stats.used) {
|
|
result.supports_preserve_reasoning = true;
|
|
}
|
|
}
|
|
);
|
|
|
|
JJ_DEBUG("%s\n", result.to_string().c_str());
|
|
|
|
caps_probe_error = nullptr;
|
|
return result;
|
|
}
|
|
|
|
} // namespace jinja
|