Skip to content
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
3 changes: 2 additions & 1 deletion src/llama-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3066,7 +3066,8 @@ ggml_cgraph * llama_context::graph_reserve(

auto * res = gf_res_reserve.get();

const auto gparams = graph_params(res, ubatch, mctx, ctx_type_to_graph_type(cparams.ctx_type));
auto gparams = graph_params(res, ubatch, mctx, ctx_type_to_graph_type(cparams.ctx_type));
gparams.reserve_mixed_inputs = true;

res->reset();

Expand Down
6 changes: 5 additions & 1 deletion src/llama-graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,7 @@ llm_graph_context::llm_graph_context(const llm_graph_params & params) :
hparams (model.hparams),
cparams (params.cparams),
ubatch (params.ubatch),
reserve_mixed_inputs(params.reserve_mixed_inputs),
prec_policy (model.prec_policy),
n_embd (hparams.n_embd),
n_layer (hparams.n_layer()),
Expand Down Expand Up @@ -2757,7 +2758,10 @@ ggml_tensor * llm_graph_context::build_inp_embd(ggml_tensor * tok_embd, float to

// mixed path (ubatch.is_mixed()): set_rows the token rows into a copy of the embd rows, with its own inputs as select branches must not share tensors
// TODO: use inp->tokens and inp->embd once ggml_build_forward_select allows it
const bool has_mixed = llm_arch_supports_mixed_batch(model.arch) && cparams.ctx_type == LLAMA_CONTEXT_TYPE_DEFAULT;
// Reserve for a mixed batch, but only put its row writes into an execution graph
// when the batch supplies the slot indices consumed by those writes.
const bool has_mixed = (reserve_mixed_inputs || ubatch.is_mixed()) &&
llm_arch_supports_mixed_batch(model.arch) && cparams.ctx_type == LLAMA_CONTEXT_TYPE_DEFAULT;

const int64_t n_tok_rows = has_mixed ? llm_graph_n_tok_rows(ubatch) : 0;

Expand Down
2 changes: 2 additions & 0 deletions src/llama-graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ struct llm_graph_params {
// rows (n_shadow_rows of them); a ubatch with no label never applies it, so serving is the stable set's graph
const llama_adapter_lora * shadow = nullptr;
uint32_t n_shadow_rows = 0;
bool reserve_mixed_inputs = false;
// the physical attention stream of each of the ubatch's unique sequences (seq_id_unq order): the graph's K/V
// views are built at these streams, so a graph is reused only when they match
std::vector<uint32_t> streams = {};
Expand Down Expand Up @@ -1157,6 +1158,7 @@ struct llm_graph_context {
const llama_hparams & hparams;
const llama_cparams & cparams;
const llama_ubatch & ubatch;
const bool reserve_mixed_inputs;

const llama_prec_policy & prec_policy;

Expand Down
Loading