llama.cpp
3bf41193 - models: early token crop before gate/o_proj in last layer for 5 gated-attn architectures (#33734)

Commit
19 hours ago
models: early token crop before gate/o_proj in last layer for 5 gated-attn architectures (#33734) * models: spark2-5: crop to output rows before gate and o_proj in the last layer Move the inp_out_ids crop of the last layer (il == n_layer - 1) to run right after build_attn and before the gate computation and wo output projection. The crop is applied to cur, attn_inp and inpSA. The old crop after attn_out_proj is removed. n_tokens_i = cur->ne[1] is already dynamic. This saves (n_tokens - n_outputs) projections in the last layer during prefill on all backends. * models: k2-horizon: crop to output rows before gate and o_proj in the last layer Move the inp_out_ids crop of the last layer (il == n_layer - 1) to run right after build_attn and before the gate/wo output projection. The crop is applied to cur, inpSA, and attn_inp (only when gated). The old crop after the gated block is removed. Without a gate, wo stays inside build_attn so nothing changes there. This saves (n_tokens - n_outputs) projections in the last layer during prefill on all backends. * models: muse-glimmer: crop to output rows before gate and o_proj in the last layer Move the wqkv_gate computation from before build_attn to after the inp_out_ids crop of the last layer (il == n_layer - 1). The crop is applied to cur, attn_inp and inpSA right after build_attn, and the gate is then computed from the cropped attn_inp, followed by sigmoid, mul and wo. The old crop after attn_post_norm is removed. This saves (n_tokens - n_outputs) projections in the last layer during prefill on all backends. * models: ricursive: crop to output rows before gate and o_proj in the last layer Move the inp_out_ids crop of the last layer (il == n_layer - 1) to run right after build_attn and before the gate/wo output projection. The crop is applied to cur and inpSA, and to attn_in only when layer.wqkv_gate exists. The old crop after the attention block is removed. The value residual (inp_vres/v_in) is not touched: it feeds the KV cache and must see all tokens. This saves (n_tokens - n_outputs) projections in the last layer during prefill on all backends. * models: muse-spark: crop to output rows before gate and o_proj in the last layer Save attn_inp = cur before build_qkv, and move the wqkv_gate computation from before build_attn to after the inp_out_ids crop of the last layer (il == n_layer - 1). The crop is applied to cur, attn_inp and inpSA right after build_attn, and the gate is then computed from the cropped attn_inp, followed by sigmoid, mul and wo. The attn_o_norm reshapes use n_tok_out = cur->ne[1]. The old crop after attn_post_norm is removed. This saves (n_tokens - n_outputs) projections in the last layer during prefill on all backends. * tests: update MTL.csv fusion counts for muse-glimmer and muse-spark
Author
Parents
Loading