In this article
Measure how many output rows the caller needs and verify that selected outputs and subsequent decoding remain equivalent.
Build b12962 of llama.cpp, published on December 3, moves last-layer output-row selection earlier in the Laguna and AFMoE graphs. Pull request #33557 puts the selection before the attention output projection and applies it to the residual stream as well. The maintainer explains that this projection operates independently on each position. The change can therefore avoid projecting rows that the caller will discard, while leaving the attention and KV cache path intact.
Find which rows your client requests
Some generation calls need logits only for particular positions. Other clients inspect scores for many positions, or ask for outputs from several sequences packed in a batch. Record the number of positions presented to the graph and how many are selected. The potential savings are largest when the projection receives many rows and the caller needs few. With all rows requested, moving the selection has little work to eliminate.
Test a representative pair of clients
Run generation and a scoring workload with fixed model weights, quantization and backend. For generation, include long prompts. For scoring, use the actual output selection required by the application. Compare the duration of the last-layer projection and the full request. Record time to first token and throughput where relevant. Use the same batch construction and sequence order.
Check the selected rows and later decode steps
Compare output for the same selected positions before and after the change within a suitable numerical tolerance. Include both mixed-length requests and the case where every position is returned. Run additional decode steps after the initial input to check that results remain within the agreed tolerance. Match rows by their sequence and position rather than by the order a batch happens to emit them.
Decide using end-to-end measurements
Report the savings separately for generation and scoring. Approve the upgrade with equivalent outputs and a demonstrated service benefit for the workload that matters. Mark any backend or input shape that was outside the test scope.
Sources
Related reading
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.