Merge branch 'ggerganov:master' into master
This commit is contained in:
commit
dbfa8a7b62
4 changed files with 15 additions and 14 deletions
|
@ -1880,6 +1880,7 @@ struct server_context {
|
||||||
if (slot.state == SLOT_STATE_STARTED) {
|
if (slot.state == SLOT_STATE_STARTED) {
|
||||||
slot.t_start_process_prompt = ggml_time_us();
|
slot.t_start_process_prompt = ggml_time_us();
|
||||||
slot.t_start_generation = 0;
|
slot.t_start_generation = 0;
|
||||||
|
|
||||||
slot.n_past = 0;
|
slot.n_past = 0;
|
||||||
slot.n_prompt_tokens = prompt_tokens.size();
|
slot.n_prompt_tokens = prompt_tokens.size();
|
||||||
slot.state = SLOT_STATE_PROCESSING_PROMPT;
|
slot.state = SLOT_STATE_PROCESSING_PROMPT;
|
||||||
|
|
|
@ -266,8 +266,10 @@ static llama_tokens format_infill(
|
||||||
}
|
}
|
||||||
|
|
||||||
// for now pick FIM context to fit in a batch (ratio prefix:suffix = 3:1, TODO: configurable?)
|
// for now pick FIM context to fit in a batch (ratio prefix:suffix = 3:1, TODO: configurable?)
|
||||||
const int n_suffix_take = std::min<int>(tokens_suffix.size(), (n_batch/4));
|
const int n_prefix_take = std::min<int>(tokens_prefix.size(), 3*(n_batch/4));
|
||||||
const int n_prefix_take = std::min<int>(tokens_prefix.size(), 3*(n_batch/4) - 3);
|
const int n_suffix_take = std::min<int>(tokens_suffix.size(), std::max<int>(0, (n_batch/4) - (2 + tokens_prompt.size())));
|
||||||
|
|
||||||
|
SRV_DBG("n_prefix_take = %d, n_suffix_take = %d, total = %d\n", n_prefix_take, n_suffix_take, (n_prefix_take + n_suffix_take));
|
||||||
|
|
||||||
// fill the rest of the context with extra chunks
|
// fill the rest of the context with extra chunks
|
||||||
const int n_extra_take = std::min<int>(std::max<int>(0, n_ctx - (n_batch) - 2*n_predict), extra_tokens.size());
|
const int n_extra_take = std::min<int>(std::max<int>(0, n_ctx - (n_batch) - 2*n_predict), extra_tokens.size());
|
||||||
|
|
|
@ -1484,7 +1484,12 @@ static void ggml_cuda_op_mul_mat(
|
||||||
const size_t nbytes_data = ggml_nbytes(src0);
|
const size_t nbytes_data = ggml_nbytes(src0);
|
||||||
const size_t nbytes_padding = ggml_row_size(src0->type, MATRIX_ROW_PADDING - ne00 % MATRIX_ROW_PADDING);
|
const size_t nbytes_padding = ggml_row_size(src0->type, MATRIX_ROW_PADDING - ne00 % MATRIX_ROW_PADDING);
|
||||||
dev[id].src0_dd = dev[id].src0_dd_alloc.alloc(ctx.pool(id), nbytes_data + nbytes_padding);
|
dev[id].src0_dd = dev[id].src0_dd_alloc.alloc(ctx.pool(id), nbytes_data + nbytes_padding);
|
||||||
|
// TODO: remove this for MUSA once the Guilty Lockup issue is resolved
|
||||||
|
#ifndef GGML_USE_MUSA
|
||||||
CUDA_CHECK(cudaMemsetAsync(dev[id].src0_dd, 0, nbytes_data + nbytes_padding, stream));
|
CUDA_CHECK(cudaMemsetAsync(dev[id].src0_dd, 0, nbytes_data + nbytes_padding, stream));
|
||||||
|
#else // GGML_USE_MUSA
|
||||||
|
CUDA_CHECK(cudaMemsetAsync(dev[id].src0_dd + nbytes_data, 0, nbytes_padding, stream));
|
||||||
|
#endif // !GGML_USE_MUSA
|
||||||
}
|
}
|
||||||
|
|
||||||
// If src0 is on a temporary compute buffer (partial offloading) there may be some padding that needs to be cleared:
|
// If src0 is on a temporary compute buffer (partial offloading) there may be some padding that needs to be cleared:
|
||||||
|
|
|
@ -9618,20 +9618,16 @@ static struct ggml_tensor * llm_build_kqv(
|
||||||
cur = ggml_flash_attn_ext(ctx, q, k, v, kq_mask, kq_scale, hparams.f_max_alibi_bias,
|
cur = ggml_flash_attn_ext(ctx, q, k, v, kq_mask, kq_scale, hparams.f_max_alibi_bias,
|
||||||
hparams.attn_soft_cap ? hparams.f_attn_logit_softcapping : 0.0f);
|
hparams.attn_soft_cap ? hparams.f_attn_logit_softcapping : 0.0f);
|
||||||
|
|
||||||
if (model.arch == LLM_ARCH_PHI2 || model.arch == LLM_ARCH_PHI3 || model.arch == LLM_ARCH_GPTNEOX || model.arch == LLM_ARCH_GEMMA2) {
|
|
||||||
ggml_flash_attn_ext_set_prec(cur, GGML_PREC_F32);
|
ggml_flash_attn_ext_set_prec(cur, GGML_PREC_F32);
|
||||||
}
|
|
||||||
|
|
||||||
cur = ggml_reshape_2d(ctx, cur, n_embd_head_v*n_head, n_tokens);
|
cur = ggml_reshape_2d(ctx, cur, n_embd_head_v*n_head, n_tokens);
|
||||||
} else {
|
} else {
|
||||||
struct ggml_tensor * kq = ggml_mul_mat(ctx, k, q);
|
struct ggml_tensor * kq = ggml_mul_mat(ctx, k, q);
|
||||||
cb(kq, "kq", il);
|
cb(kq, "kq", il);
|
||||||
|
|
||||||
if (model.arch == LLM_ARCH_PHI2 || model.arch == LLM_ARCH_PHI3 || model.arch == LLM_ARCH_GPTNEOX || model.arch == LLM_ARCH_QWEN2 || model.arch == LLM_ARCH_NEMOTRON || model.arch == LLM_ARCH_CHATGLM) {
|
// note: this op tends to require high floating point range
|
||||||
// for this arch, we need to perform the KQ multiplication with F32 precision, otherwise we get NaNs
|
// while for some models F16 is enough, for others it is not, so we default to F32 here
|
||||||
// ref: https://github.com/ggerganov/llama.cpp/pull/4490#issuecomment-1859055847
|
|
||||||
ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
|
ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
|
||||||
}
|
|
||||||
|
|
||||||
if (model.arch == LLM_ARCH_GROK) {
|
if (model.arch == LLM_ARCH_GROK) {
|
||||||
// need to do the following:
|
// need to do the following:
|
||||||
|
@ -9640,9 +9636,6 @@ static struct ggml_tensor * llm_build_kqv(
|
||||||
// kq = 30 * tanh(kq / 30)
|
// kq = 30 * tanh(kq / 30)
|
||||||
// before the softmax below
|
// before the softmax below
|
||||||
|
|
||||||
//try from phi2
|
|
||||||
//ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
|
|
||||||
|
|
||||||
kq = ggml_tanh(ctx, ggml_scale(ctx, kq, 0.08838834764831845f/30.0f));
|
kq = ggml_tanh(ctx, ggml_scale(ctx, kq, 0.08838834764831845f/30.0f));
|
||||||
kq = ggml_scale(ctx, kq, 30);
|
kq = ggml_scale(ctx, kq, 30);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue