llama : drop the redundant cnv from llm_attn_mask (#31558)
The dspark block mask is now derived at input-fill time: llm_attn_mask::block_uniform fills every token of a sequence with the mask row of its first token, so the graph-level reshape/repeat in dflash is gone and cnv always aliases raw. Assisted-by: dsh:llama.cpp/ggml-org/GLM-5.3-Flash-GGUF (Mac Studio, M5 Ultra, 256GB)
This commit is contained in:
1 parent
0f663d2471
commit
ca8daad199
14 files changed
+46
-69
No files matched your search
+4
-18
@@ -1391,22 +1391,6 @@ llama_model_dflash::graph_dsv4::graph_dsv4(const llama_model & model, const llm_
|
||||
// * embd batch -> writes every stage's kv_norm(wkv(main_proj(target features))) into its window ring
|
||||
// * token batch -> [anchor, noise...] block through the stages, single-pass mHC, no per-head q norm
|
||||
// window of a block = window of its first query, see n_swa
|
||||
// TODO: move this to a new type of `llm_graph_input` and implement this in `set_input` [TAG_ATTN_MASK_CNV]
|
||||
static void build_dspark_block_mask(llm_graph_context & g, llm_graph_input_attn_k_iswa * inp_attn) {
|
||||
ggml_context * ctx0 = g.ctx0;
|
||||
|
||||
ggml_tensor * m = inp_attn->self_attn_mask_swa.cnv;
|
||||
const int64_t n_tokens = g.n_tokens;
|
||||
const int64_t n_blocks = g.ubatch.n_seqs_unq;
|
||||
const int64_t bd = n_blocks > 0 ? n_tokens / n_blocks : 0;
|
||||
if (m && bd > 1 && n_tokens % n_blocks == 0 && m->ne[2] == 1 && m->ne[1] % bd == 0 && ggml_is_contiguous(m)) {
|
||||
ggml_tensor * m4 = ggml_reshape_4d(ctx0, m, m->ne[0], bd, m->ne[1]/bd, m->ne[3]);
|
||||
ggml_tensor * r0 = ggml_view_4d(ctx0, m4, m4->ne[0], 1, m4->ne[2], m4->ne[3], m4->nb[1], m4->nb[2], m4->nb[3], 0);
|
||||
m4 = ggml_repeat(ctx0, r0, m4);
|
||||
inp_attn->self_attn_mask_swa.cnv = ggml_reshape_4d(ctx0, m4, m->ne[0], m->ne[1], 1, m->ne[3]);
|
||||
g.cb(inp_attn->self_attn_mask_swa.cnv, "dspark_block_mask", -1);
|
||||
}
|
||||
}
|
||||
|
||||
llama_model_dflash::graph_dsv41::graph_dsv41(const llama_model & model, const llm_graph_params & params) :
|
||||
llama_model_deepseek41::graph(params) {
|
||||
@@ -1496,7 +1480,8 @@ llama_model_dflash::graph_dsv41::graph_dsv41(const llama_model & model, const ll
|
||||
inpL = ggml_repeat_4d(ctx0, inpL, n_embd, hc, n_tokens, 1);
|
||||
cb(inpL, "hc_init", -1);
|
||||
|
||||
build_dspark_block_mask(*this, inp_attn);
|
||||
// the whole block shares the mask row of its first query (the anchor)
|
||||
inp_attn->self_attn_mask_swa.block_uniform = true;
|
||||
|
||||
ggml_tensor * pre_prev = nullptr;
|
||||
|
||||
@@ -1743,7 +1728,8 @@ llama_model_dflash::graph_mistral_large4::graph_mistral_large4(const llama_model
|
||||
}
|
||||
cb(inpL, "inp_noise_embd", -1);
|
||||
|
||||
build_dspark_block_mask(*this, inp_attn);
|
||||
// the whole block shares the mask row of its first query (the anchor)
|
||||
inp_attn->self_attn_mask_swa.block_uniform = true;
|
||||
|
||||
for (int il = 0; il < n_layer; ++il) {
|
||||
const auto & layer = model.layers[il];
|
||||
|
||||
Reference in new issue
Block a user