MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / common_init_result

Method common_init_result

subprojects/llama.cpp/common/common.cpp:1092–1190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1090};
1091
1092common_init_result::common_init_result(common_params & params) :
1093 pimpl(new impl{}) {
1094 auto mparams = common_model_params_to_llama(params);
1095 auto cparams = common_context_params_to_llama(params);
1096
1097 if (params.fit_params) {
1098 LOG_INF("%s: fitting params to device memory, for bugs during this step try to reproduce them with -fit off, or provide --verbose logs if the bug only occurs with -fit on\n", __func__);
1099 llama_params_fit(params.model.path.c_str(), &mparams, &cparams,
1100 params.tensor_split,
1101 params.tensor_buft_overrides.data(),
1102 params.fit_params_target.data(),
1103 params.fit_params_min_ctx,
1104 params.verbosity >= 4 ? GGML_LOG_LEVEL_DEBUG : GGML_LOG_LEVEL_ERROR);
1105 }
1106
1107 llama_model * model = llama_model_load_from_file(params.model.path.c_str(), mparams);
1108 if (model == NULL) {
1109 return;
1110 }
1111
1112 pimpl->model.reset(model);
1113
1114 const llama_vocab * vocab = llama_model_get_vocab(model);
1115
1116 // load and optionally apply lora adapters (must be loaded before context creation)
1117 for (auto & la : params.lora_adapters) {
1118 llama_adapter_lora_ptr lora;
1119 lora.reset(llama_adapter_lora_init(model, la.path.c_str()));
1120 if (lora == nullptr) {
1121 LOG_ERR("%s: failed to load lora adapter '%s'\n", __func__, la.path.c_str());
1122 pimpl->model.reset(model);
1123 return;
1124 }
1125
1126 char buf[1024];
1127 la.ptr = lora.get();
1128 llama_adapter_meta_val_str(la.ptr, "adapter.lora.task_name", buf, sizeof(buf));
1129 la.task_name = buf;
1130 llama_adapter_meta_val_str(la.ptr, "adapter.lora.prompt_prefix", buf, sizeof(buf));
1131 la.prompt_prefix = buf;
1132 pimpl->lora.emplace_back(std::move(lora)); // copy to list of loaded adapters
1133 }
1134
1135 // updates params.sampling
1136 // TODO: fix naming
1137 common_init_sampler_from_model(model, params.sampling);
1138
1139 if (params.sampling.ignore_eos && llama_vocab_eos(vocab) == LLAMA_TOKEN_NULL) {
1140 LOG_WRN("%s: warning: vocab does not have an EOS token, ignoring --ignore-eos\n", __func__);
1141 params.sampling.ignore_eos = false;
1142 }
1143
1144 // initialize once
1145 for (llama_token i = 0; i < llama_vocab_n_tokens(vocab); i++) {
1146 if (llama_vocab_is_eog(vocab, i)) {
1147 LOG_INF("%s: added %s logit bias = %f\n", __func__, common_token_to_piece(vocab, i).c_str(), -INFINITY);
1148 params.sampling.logit_bias_eog.push_back({i, -INFINITY});
1149 }

Callers

nothing calls this directly

Calls 15

llama_params_fitFunction · 0.85
llama_model_get_vocabFunction · 0.85
llama_adapter_lora_initFunction · 0.85
llama_vocab_eosFunction · 0.85
llama_vocab_n_tokensFunction · 0.85
llama_vocab_is_eogFunction · 0.85
common_token_to_pieceFunction · 0.85

Tested by

no test coverage detected