model: support vllm d3 models (#30383)
* models: support pplx-decider * vllm d2 * update * clarify naming rule * stricter validation * d3
This commit is contained in:
1 parent
097cf33d94
commit
efe3626b11
11 files changed
+111
-23
No files matched your search
@@ -100,7 +100,7 @@ void server_decision_context::init(const llama_model * model) {
|
||||
}
|
||||
n_options_max = labels.size();
|
||||
noul_true_first = true;
|
||||
} else if (model_type == COMMON_DECISION_TYPE_LEV || model_type == COMMON_DECISION_TYPE_NIMBLE || model_type == COMMON_DECISION_TYPE_PPLX_DECIDER) {
|
||||
} else if (model_type == COMMON_DECISION_TYPE_LEV || model_type == COMMON_DECISION_TYPE_NIMBLE || model_type == COMMON_DECISION_TYPE_PPLX_DECIDER || model_type == COMMON_DECISION_TYPE_VLLM_D3) {
|
||||
// label codes are A..Z then AA..ZZ, only the ones that are a single token are used
|
||||
std::vector<std::string> codes;
|
||||
for (char a = 'A'; a <= 'Z'; a++) {
|
||||
@@ -119,6 +119,9 @@ void server_decision_context::init(const llama_model * model) {
|
||||
}
|
||||
}
|
||||
n_options_max = labels.size();
|
||||
if (model_type == COMMON_DECISION_TYPE_VLLM_D3) {
|
||||
canonical_legend = true;
|
||||
}
|
||||
} else if (model_type == COMMON_DECISION_TYPE_KEV) {
|
||||
// the hidden state of an option is read at the token that ends it
|
||||
const auto toks = common_tokenize(vocab, "<|box_end|>", false, true);
|
||||
@@ -149,6 +152,7 @@ void server_decision_context::init(const llama_model * model) {
|
||||
n_options_max = 255;
|
||||
noul_criteria_order = true;
|
||||
strict_payload = true;
|
||||
canonical_legend = true;
|
||||
} else if (model_type == COMMON_DECISION_TYPE_LFM2_D1) {
|
||||
n_options_max = 255;
|
||||
noul_true_first = true;
|
||||
@@ -175,8 +179,8 @@ static bool decision_is_payload(const json & val) {
|
||||
}
|
||||
|
||||
std::vector<server_decision_question> server_decision_context::parse_questions(const json & body) const {
|
||||
// lfm2-d1 and lfm2-d1-omni accept a null state, for example to ask about images only
|
||||
if (!body.contains("state") || (body.at("state").is_null() && type != COMMON_DECISION_TYPE_LFM2_D1 && type != COMMON_DECISION_TYPE_LFM2_D1_OMNI)) {
|
||||
// lfm2-d1, lfm2-d1-omni and vllm-d3 accept a null state, for example to ask about images only
|
||||
if (!body.contains("state") || (body.at("state").is_null() && type != COMMON_DECISION_TYPE_LFM2_D1 && type != COMMON_DECISION_TYPE_LFM2_D1_OMNI && type != COMMON_DECISION_TYPE_VLLM_D3)) {
|
||||
throw std::invalid_argument("\"state\" must be provided");
|
||||
}
|
||||
if (strict_payload && !decision_is_payload(body.at("state"))) {
|
||||
@@ -194,16 +198,18 @@ std::vector<server_decision_question> server_decision_context::parse_questions(c
|
||||
if (!q.is_object()) {
|
||||
throw err("must be an object");
|
||||
}
|
||||
if (!q.contains("instructions") || q.at("instructions").is_null()) {
|
||||
// the vllm-d3 prompt has a default question
|
||||
const json instructions = q.contains("instructions") ? q.at("instructions") : json();
|
||||
if (instructions.is_null() && type != COMMON_DECISION_TYPE_VLLM_D3) {
|
||||
throw err("\"instructions\" must be provided");
|
||||
}
|
||||
if (strict_payload && (!decision_is_payload(q.at("instructions")) || q.at("instructions") == "")) {
|
||||
if (strict_payload && (!decision_is_payload(instructions) || instructions == "")) {
|
||||
throw err("\"instructions\" must be non-empty text, an object or an array");
|
||||
}
|
||||
|
||||
server_decision_question question;
|
||||
question.id = id;
|
||||
question.instructions = q.at("instructions");
|
||||
question.instructions = instructions;
|
||||
|
||||
const std::string type_name = json_value(q, "type", std::string());
|
||||
const json criteria = q.contains("criteria") ? q.at("criteria") : json();
|
||||
@@ -722,7 +728,7 @@ void server_decision_context::fill_task(
|
||||
|
||||
const std::string prompt = render(state, questions, question, variant, files.size());
|
||||
|
||||
if (type == COMMON_DECISION_TYPE_OPENJEV || type == COMMON_DECISION_TYPE_LEV || type == COMMON_DECISION_TYPE_NIMBLE || type == COMMON_DECISION_TYPE_PPLX_DECIDER) {
|
||||
if (type == COMMON_DECISION_TYPE_OPENJEV || type == COMMON_DECISION_TYPE_LEV || type == COMMON_DECISION_TYPE_NIMBLE || type == COMMON_DECISION_TYPE_PPLX_DECIDER || type == COMMON_DECISION_TYPE_VLLM_D3) {
|
||||
// lev reads the ratings of a noul question at its first labels, not at the digits
|
||||
task.decision.labels.assign(labels.begin(), labels.begin() + n_outputs(question));
|
||||
}
|
||||
@@ -735,7 +741,7 @@ void server_decision_context::fill_task(
|
||||
task.decision.label_groups.push_back(group.size());
|
||||
}
|
||||
}
|
||||
if (type == COMMON_DECISION_TYPE_OPENJEV || type == COMMON_DECISION_TYPE_LEV || type == COMMON_DECISION_TYPE_NIMBLE || type == COMMON_DECISION_TYPE_PPLX_DECIDER || type == COMMON_DECISION_TYPE_LFM2_D1) {
|
||||
if (type == COMMON_DECISION_TYPE_OPENJEV || type == COMMON_DECISION_TYPE_LEV || type == COMMON_DECISION_TYPE_NIMBLE || type == COMMON_DECISION_TYPE_PPLX_DECIDER || type == COMMON_DECISION_TYPE_VLLM_D3 || type == COMMON_DECISION_TYPE_LFM2_D1) {
|
||||
if (!files.empty()) {
|
||||
task.tokens = process_mtmd_prompt(mctx, prompt, files, init_opt);
|
||||
return;
|
||||
@@ -1113,7 +1119,7 @@ static double decision_confidence_score(const std::vector<double> & probs) {
|
||||
return std::max(0.0, 1.0 - dist / dist_uniform);
|
||||
}
|
||||
|
||||
// VLLM_DECISION2: normalized entropy, as in the reference implementation
|
||||
// VLLM_DECISION2, VLLM_D3: normalized entropy, as in the reference implementation
|
||||
static double decision_confidence_entropy(const std::vector<double> & probs) {
|
||||
if (probs.size() < 2) {
|
||||
return 1.0;
|
||||
@@ -1128,7 +1134,7 @@ static double decision_confidence_entropy(const std::vector<double> & probs) {
|
||||
}
|
||||
|
||||
double server_decision_context::get_decision_confidence(server_decision_question_type question_type, const std::vector<double> & probs) const {
|
||||
if (type == COMMON_DECISION_TYPE_VLLM_DECISION2) {
|
||||
if (type == COMMON_DECISION_TYPE_VLLM_DECISION2 || type == COMMON_DECISION_TYPE_VLLM_D3) {
|
||||
return decision_confidence_entropy(probs);
|
||||
}
|
||||
switch (question_type) {
|
||||
@@ -1212,8 +1218,7 @@ json server_decision_context::format_answer(const server_decision_question & que
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
expected += i * probs[i];
|
||||
const json & description = question.options[i].description;
|
||||
// vllm-decision2 returns structured descriptions as canonical JSON text
|
||||
legend[question.options[i].key] = strict_payload && !description.is_string() ? json(decision_sort_keys(description).dump()) : description;
|
||||
legend[question.options[i].key] = canonical_legend && !description.is_string() ? json(decision_sort_keys(description).dump()) : description;
|
||||
}
|
||||
answer["score"] = expected;
|
||||
answer["legend"] = legend;
|
||||
|
||||
Reference in new issue
Block a user