Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load all MoE experts during warmup #11571

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/llama-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3552,7 +3552,7 @@ size_t llama_model::size() const {
}

size_t llama_model::max_nodes() const {
return std::max<size_t>(8192, tensors_by_name.size()*5);
return std::max<size_t>(65536, tensors_by_name.size()*5);
}

size_t llama_model::n_devices() const {
Expand Down
15 changes: 10 additions & 5 deletions src/llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,8 @@ struct llm_build_context {
llama_context & lctx,
const llama_ubatch & ubatch,
const llm_build_cb & cb,
bool worst_case) :
bool worst_case,
bool warmup) :
model (lctx.model),
lctx (lctx),
hparams (model.hparams),
Expand All @@ -1110,7 +1111,7 @@ struct llm_build_context {
n_embd_head_v (hparams.n_embd_head_v),
n_embd_v_gqa (hparams.n_embd_v_gqa()),
n_expert (hparams.n_expert),
n_expert_used (hparams.n_expert_used),
n_expert_used (warmup ? hparams.n_expert : hparams.n_expert_used),
freq_base (cparams.rope_freq_base),
freq_scale (cparams.rope_freq_scale),
ext_factor (cparams.yarn_ext_factor),
Expand Down Expand Up @@ -8103,7 +8104,7 @@ static struct ggml_cgraph * llama_build_graph_defrag(llama_context & lctx, const

llm_build_cb cb = [&](struct ggml_tensor * , const char * , int ) { };

struct llm_build_context llm(lctx, dummy, cb, false);
struct llm_build_context llm(lctx, dummy, cb, false, false);

llm.init();

Expand All @@ -8120,7 +8121,7 @@ static struct ggml_cgraph * llama_build_graph_k_shift(llama_context & lctx) {

llm_build_cb cb = [&](struct ggml_tensor * , const char * , int ) { };

struct llm_build_context llm(lctx, dummy, cb, false);
struct llm_build_context llm(lctx, dummy, cb, false, false);

llm.init();

Expand Down Expand Up @@ -8171,7 +8172,11 @@ static struct ggml_cgraph * llama_build_graph(

struct ggml_cgraph * result = NULL;

struct llm_build_context llm(lctx, ubatch, cb, worst_case);
const llama_vocab * vocab = llama_model_get_vocab(&model);
llama_token bos = llama_vocab_bos(vocab);
llama_token eos = llama_vocab_eos(vocab);
bool is_warming_up = (ubatch.n_tokens == 2 && ubatch.token[0] == bos && ubatch.token[1] == eos);
struct llm_build_context llm(lctx, ubatch, cb, worst_case, is_warming_up);

llm.init();

Expand Down
Loading