MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / common_init_from_params

Function common_init_from_params

common/common.cpp:1269–1382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1267}
1268
1269common_init_result_ptr common_init_from_params(common_params & params) {
1270 common_init_result_ptr res(new common_init_result(params));
1271
1272 llama_model * model = res->model();
1273 if (model == NULL) {
1274 LOG_ERR("%s: failed to load model '%s'\n", __func__, params.model.path.c_str());
1275 return res;
1276 }
1277
1278 llama_context * lctx = res->context();
1279 if (lctx == NULL) {
1280 LOG_ERR("%s: failed to create context with model '%s'\n", __func__, params.model.path.c_str());
1281 return res;
1282 }
1283
1284 const llama_vocab * vocab = llama_model_get_vocab(model);
1285
1286 if (params.ctx_shift && !llama_memory_can_shift(llama_get_memory(lctx))) {
1287 LOG_WRN("%s: KV cache shifting is not supported for this context, disabling KV cache shifting\n", __func__);
1288 params.ctx_shift = false;
1289 }
1290
1291 if (!params.control_vectors.empty()) {
1292 if (params.control_vector_layer_start <= 0) params.control_vector_layer_start = 1;
1293 if (params.control_vector_layer_end <= 0) params.control_vector_layer_end = llama_model_n_layer(model);
1294
1295 const auto cvec = common_control_vector_load(params.control_vectors);
1296 if (cvec.n_embd == -1) {
1297 return res;
1298 }
1299
1300 int err = llama_set_adapter_cvec(
1301 lctx,
1302 cvec.data.data(),
1303 cvec.data.size(),
1304 cvec.n_embd,
1305 params.control_vector_layer_start,
1306 params.control_vector_layer_end);
1307 if (err) {
1308 return res;
1309 }
1310 }
1311
1312 if (llama_pooling_type(lctx) == LLAMA_POOLING_TYPE_RANK) {
1313 bool ok = true;
1314
1315 if (llama_vocab_bos(vocab) == LLAMA_TOKEN_NULL) {
1316 LOG_WRN("%s: warning: vocab does not have a BOS token, reranking will not work\n", __func__);
1317 ok = false;
1318 }
1319
1320 bool has_eos = llama_vocab_eos(vocab) != LLAMA_TOKEN_NULL;
1321 bool has_sep = llama_vocab_sep(vocab) != LLAMA_TOKEN_NULL;
1322 bool has_rerank_prompt = llama_model_chat_template(model, "rerank") != NULL;
1323
1324 if (!has_eos && !has_sep && !has_rerank_prompt) {
1325 LOG_WRN("%s: warning: vocab does not have an EOS token, SEP token, or rerank prompt. Reranking will not work\n", __func__);
1326 ok = false;

Callers 15

mainFunction · 0.85
mainFunction · 0.85
mtmd_cli_contextMethod · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
load_modelMethod · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 15

llama_model_get_vocabFunction · 0.85
llama_memory_can_shiftFunction · 0.85
llama_get_memoryFunction · 0.85
llama_model_n_layerFunction · 0.85
llama_set_adapter_cvecFunction · 0.85
llama_vocab_bosFunction · 0.85
llama_vocab_eosFunction · 0.85
llama_vocab_sepFunction · 0.85
common_set_adapter_loraFunction · 0.85
llama_set_warmupFunction · 0.85

Tested by 3

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68