MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / llama_init_from_model

Function llama_init_from_model

smallthinker/src/llama-context.cpp:2220–2256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2218}
2219
2220llama_context * llama_init_from_model(
2221 llama_model * model,
2222 llama_context_params params) {
2223 if (!model) {
2224 LLAMA_LOG_ERROR("%s: model cannot be NULL\n", __func__);
2225 return nullptr;
2226 }
2227
2228 if (params.n_batch == 0 && params.n_ubatch == 0) {
2229 LLAMA_LOG_ERROR("%s: n_batch and n_ubatch cannot both be zero\n", __func__);
2230 return nullptr;
2231 }
2232
2233 if (params.n_ctx == 0 && model->hparams.n_ctx_train == 0) {
2234 LLAMA_LOG_ERROR("%s: n_ctx and model->hparams.n_ctx_train cannot both be zero\n", __func__);
2235 return nullptr;
2236 }
2237
2238 if (params.flash_attn && model->arch == LLM_ARCH_GROK) {
2239 LLAMA_LOG_WARN("%s: flash_attn is not compatible with Grok - forcing off\n", __func__);
2240 params.flash_attn = false;
2241 }
2242
2243 if (ggml_is_quantized(params.type_v) && !params.flash_attn) {
2244 LLAMA_LOG_ERROR("%s: V cache quantization requires flash_attn\n", __func__);
2245 return nullptr;
2246 }
2247
2248 try {
2249 auto * ctx = new llama_context(*model, params);
2250 return ctx;
2251 } catch (const std::exception & err) {
2252 LLAMA_LOG_ERROR("%s: failed to initialize the context: %s\n", __func__, err.what());
2253 }
2254
2255 return nullptr;
2256}
2257
2258// deprecated
2259llama_context * llama_new_context_with_model(

Callers 15

mainFunction · 0.85
mainFunction · 0.85
initMethod · 0.85
mainFunction · 0.85
initialize_contextMethod · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 2

ggml_is_quantizedFunction · 0.50
whatMethod · 0.45

Tested by 6

mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68