mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-06 13:01:08 +02:00
common: add enum common_speculative_type
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "llama.h"
|
||||
#include "chat.h"
|
||||
#include "sampling.h"
|
||||
#include "speculative.h"
|
||||
#include "json-schema-to-grammar.h"
|
||||
|
||||
using json = nlohmann::ordered_json;
|
||||
@@ -237,8 +238,39 @@ task_params server_task::params_from_json_cmpl(
|
||||
params.speculative.n_min = json_value(data, "speculative.n_min", defaults.speculative.n_min);
|
||||
params.speculative.n_max = json_value(data, "speculative.n_max", defaults.speculative.n_max);
|
||||
params.speculative.p_min = json_value(data, "speculative.p_min", defaults.speculative.p_min);
|
||||
params.speculative.self_mode = json_value(data, "speculative.self_mode", defaults.speculative.self_mode);
|
||||
params.speculative.self_cfg = json_value(data, "speculative.self_cfg", defaults.speculative.self_cfg);
|
||||
//params.speculative.self_mode = json_value(data, "speculative.self_mode", defaults.speculative.self_mode);
|
||||
//params.speculative.self_cfg = json_value(data, "speculative.self_cfg", defaults.speculative.self_cfg);
|
||||
// Set params.speculative.configs. Use json-array "speculative.configs" if provided in data, otherwise use {}
|
||||
{
|
||||
params.speculative.configs = defaults.speculative.configs;
|
||||
const auto & configs = data.find("speculative.configs");
|
||||
if (configs != data.end() && configs->is_array()) {
|
||||
params.speculative.configs.clear();
|
||||
for (const auto & config : *configs) {
|
||||
if (config.is_object()) {
|
||||
// config should have keys "type" and "config" (optional)
|
||||
const auto & type = config.find("type");
|
||||
if (type != config.end() && type->is_string()) {
|
||||
const auto type_name = type->get<std::string>();
|
||||
const auto type_enum = common_speculative_type_from_name(type_name);
|
||||
if (type_enum != COMMON_SPECULATIVE_TYPE_COUNT) {
|
||||
common_speculative_config cfg(type_enum);
|
||||
const auto & cfg_map = config.find("config");
|
||||
if (cfg_map != config.end() && cfg_map->is_object()) {
|
||||
for (const auto & [key, value] : cfg_map->items()) {
|
||||
cfg.config[key] = value.get<std::string>();
|
||||
}
|
||||
}
|
||||
params.speculative.configs.push_back(cfg);
|
||||
} else {
|
||||
SRV_WRN("Unknown speculative type: %s\n", type_name.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
params.speculative.n_min = std::min(params.speculative.n_max, params.speculative.n_min);
|
||||
params.speculative.n_min = std::max(params.speculative.n_min, 0);
|
||||
|
||||
Reference in New Issue
Block a user