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

Function llama_new_context_with_model

llama.cpp:9833–10034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9831}
9832
9833struct llama_context * llama_new_context_with_model(
9834 struct llama_model * model,
9835 struct llama_context_params params) {
9836
9837 if (!model) {
9838 return nullptr;
9839 }
9840
9841 llama_context * ctx = new llama_context(*model);
9842
9843 const auto & hparams = model->hparams;
9844 auto & cparams = ctx->cparams;
9845
9846 cparams.n_batch = params.n_batch;
9847 cparams.n_threads = params.n_threads;
9848 cparams.n_threads_batch = params.n_threads_batch;
9849 cparams.yarn_ext_factor = params.yarn_ext_factor;
9850 cparams.yarn_attn_factor = params.yarn_attn_factor;
9851 cparams.yarn_beta_fast = params.yarn_beta_fast;
9852 cparams.yarn_beta_slow = params.yarn_beta_slow;
9853 cparams.mul_mat_q = params.mul_mat_q;
9854
9855 cparams.n_ctx = params.n_ctx == 0 ? hparams.n_ctx_train : params.n_ctx;
9856 cparams.rope_freq_base = params.rope_freq_base == 0.0f ? hparams.rope_freq_base_train : params.rope_freq_base;
9857 cparams.rope_freq_scale = params.rope_freq_scale == 0.0f ? hparams.rope_freq_scale_train : params.rope_freq_scale;
9858
9859 cparams.n_yarn_orig_ctx = params.yarn_orig_ctx != 0 ? params.yarn_orig_ctx :
9860 hparams.n_yarn_orig_ctx != 0 ? hparams.n_yarn_orig_ctx :
9861 hparams.n_ctx_train;
9862
9863 auto rope_scaling_type = params.rope_scaling_type;
9864 if (rope_scaling_type == LLAMA_ROPE_SCALING_UNSPECIFIED) {
9865 rope_scaling_type = hparams.rope_scaling_type_train;
9866 }
9867
9868 if (rope_scaling_type == LLAMA_ROPE_SCALING_NONE) {
9869 cparams.rope_freq_scale = 1.0f; // never scale if scaling type is none
9870 }
9871
9872 if (cparams.yarn_ext_factor < 0.0f) { // negative indicates 'not set'
9873 cparams.yarn_ext_factor = rope_scaling_type == LLAMA_ROPE_SCALING_YARN ? 1.0f : 0.0f;
9874 }
9875
9876 if (params.seed == LLAMA_DEFAULT_SEED) {
9877 params.seed = time(NULL);
9878 }
9879
9880 LLAMA_LOG_INFO("%s: n_ctx = %u\n", __func__, cparams.n_ctx);
9881 LLAMA_LOG_INFO("%s: freq_base = %.1f\n", __func__, cparams.rope_freq_base);
9882 LLAMA_LOG_INFO("%s: freq_scale = %g\n", __func__, cparams.rope_freq_scale);
9883
9884 ctx->rng = std::mt19937(params.seed);
9885 ctx->logits_all = params.logits_all;
9886
9887 ggml_type memory_type = params.f16_kv ? GGML_TYPE_F16 : GGML_TYPE_F32;
9888
9889 // reserve memory for context buffers
9890 if (!hparams.vocab_only) {

Callers 15

mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
llava_initFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50
mainFunction · 0.50

Calls 15

llama_kv_cache_initFunction · 0.85
ggml_allocr_new_measureFunction · 0.85
minFunction · 0.85
llama_build_graphFunction · 0.85
ggml_allocr_alloc_graphFunction · 0.85
ggml_allocr_freeFunction · 0.85
ggml_allocr_newFunction · 0.85
add_tensorFunction · 0.85
ggml_mpi_initFunction · 0.85
ggml_mpi_rankFunction · 0.85
reserveMethod · 0.80
llama_freeFunction · 0.70

Tested by 4

mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40