| 2028 | } |
| 2029 | |
| 2030 | void init() { |
| 2031 | const int32_t n_ctx_slot = n_ctx / params_base.n_parallel; |
| 2032 | |
| 2033 | SRV_INF("initializing slots, n_slots = %d\n", params_base.n_parallel); |
| 2034 | |
| 2035 | for (int i = 0; i < params_base.n_parallel; i++) { |
| 2036 | server_slot slot; |
| 2037 | |
| 2038 | slot.id = i; |
| 2039 | slot.ctx = ctx; |
| 2040 | slot.n_ctx = n_ctx_slot; |
| 2041 | slot.n_predict = params_base.n_predict; |
| 2042 | slot.mctx = mctx; |
| 2043 | slot.cache_tokens.has_mtmd = mctx != nullptr; |
| 2044 | |
| 2045 | if (model_dft) { |
| 2046 | slot.batch_spec = llama_batch_init(params_base.speculative.n_max + 1, 0, 1); |
| 2047 | |
| 2048 | slot.ctx_dft = llama_init_from_model(model_dft, cparams_dft); |
| 2049 | if (slot.ctx_dft == nullptr) { |
| 2050 | SRV_ERR("%s", "failed to create draft context\n"); |
| 2051 | return; |
| 2052 | } |
| 2053 | |
| 2054 | slot.spec = common_speculative_init(slot.ctx_dft); |
| 2055 | if (slot.spec == nullptr) { |
| 2056 | SRV_ERR("%s", "failed to create speculator\n"); |
| 2057 | return; |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | SLT_INF(slot, "new slot n_ctx_slot = %d\n", slot.n_ctx); |
| 2062 | |
| 2063 | slot.params.sampling = params_base.sampling; |
| 2064 | |
| 2065 | slot.callback_on_release = [this](int) { |
| 2066 | queue_tasks.pop_deferred_task(); |
| 2067 | }; |
| 2068 | |
| 2069 | slot.reset(); |
| 2070 | |
| 2071 | slots.push_back(std::move(slot)); |
| 2072 | } |
| 2073 | |
| 2074 | default_generation_settings_for_props = slots[0].to_json(); |
| 2075 | |
| 2076 | // the update_slots() logic will always submit a maximum of n_batch or n_parallel tokens |
| 2077 | // note that n_batch can be > n_ctx (e.g. for non-causal attention models such as BERT where the KV cache is not used) |
| 2078 | { |
| 2079 | const int32_t n_batch = llama_n_batch(ctx); |
| 2080 | batch = llama_batch_init(std::max(n_batch, params_base.n_parallel), 0, 1); |
| 2081 | } |
| 2082 | |
| 2083 | metrics.init(); |
| 2084 | |
| 2085 | oai_parser_opt = { |
| 2086 | /* use_jinja */ params_base.use_jinja, |
| 2087 | /* prefill_assistant */ params_base.prefill_assistant, |
nothing calls this directly
no test coverage detected