Repository navigation
sync : llama.cpp - #1700
Merged
Merged
sync : llama.cpp#1700
Conversation
* ggml-openvino: write back consumed in-place nodes of op-test graphs On the naive path every node of an op-test graph is a model output, except an in-place node that another node reads: it got no output, so its destination buffer was never written. GATED_DELTA_NET_CACHE_FUSION copies the final state into the cache and then reads the copy, so the cache kept its old contents. Write such a node back through its view_src, as is already done when nothing reads it. Model graphs are unchanged. * ggml-openvino: keep the rest of the buffer in a partial in-place FILL An in-place FILL on a view into part of a larger buffer produced only the filled values. Its output stands for the whole in-place source, so the write-back put those values at the start of the buffer and not at the view's offset. For a contiguous view with a static shape, build the whole buffer: the elements before the view, the filled values, then the elements after it. Add NodeContext::get_inplace_op_src() to detect the in-place case. * ggml-openvino: fix softplus precision for large negative inputs softplus was computed as relu(x) + log(1 + exp(-|x|)). When exp(-|x|) is below the precision of 1 + exp(-|x|), the log returns 0 or one ulp, so for x below about -16 in f32 the result was 0 or far off. The SOFTPLUS test case with inputs in [-16.6, -16] fails on CPU and GPU. Compute log1p(y) for y = exp(-|x|) with the series y - y^2/2 + y^3/3 - y^4/4 when y < 0.01, where its relative error is below 2e-9, and keep log(1 + y) above that. * ggml-openvino: finer GPU KV rounding for decode batches Rounding the GPU KV length up to a power of two makes a batch attend up to twice the rows that hold data right after each power of two. Decode reads every attended row, so long contexts lose decode speed. The GPU plugin keeps memory for each attended length: several large buffers for a prompt batch, about one copy of K and V for a decode batch. Keep the power of two for prompt batches (more than 16 tokens per sequence), and round decode batches up to a multiple of 2^k / 4 and of 256. That is four lengths per power of two, with at most 25% masked rows. * ggml-openvino : keep the head axis of the 4-D KV cache static * ggml-openvino: split two one-line lambdas per clang-format The backend's .clang-format keeps a lambda on one line only when it is a function argument (AllowShortLambdasOnASingleLine: Inline). The constant helpers in the softplus and FILL translators are assigned to variables, so clang-format splits them. Formatting only. --------- Co-authored-by: Mustafa Cavus <mustafa.cavus@intel.com>
* model : add hy_v4_flash on the DSA iSWA cache Tencent Hy4 flash is a hy_v4 trunk (iHC, gated MLA, sinks) with sparse and sliding-window MLA layers, sandwich norms, latent routed experts and deepseek41 Engram tables. The sparse layers select their context with a pooled indexer: the keys of 4 consecutive tokens are pooled by a per-channel softmax of a gate plus a position bias, normed, and rotated at the position of the first token. A token attends to the best scored pools of its sequence plus its own pool. The model runs on llama_kv_cache_dsa_iswa as dots3note does. The indexer cache holds the projected value and gate of each token, and the pools are rebuilt from the cells for every ubatch by llama_kv_cache::set_input_kpool(), so there is no pooled state to keep in sync with sequence edits, checkpoints or state save/restore. The selection goes through ggml_top_k_mask with the pool members as blocks and the token's own pool as extra cells. Not covered yet: the MTP block (its tensors are skipped), the vision tower, multiple KV streams, and backends without GGML_OP_TOP_K_MASK. * convert : add hy_v4_flash The converter of the hy_v4_flash model, without the vision parts. The four Engram tables are written as one per_layer_token_embd tensor of about 127 GB in BF16. Concatenating them with torch.cat materializes the whole tensor at write time, so they are streamed one table at a time in row chunks through the _StreamedBytes path of deepseek41, which keeps the conversion within 100 GB of RAM. * tests : add hy_v4_flash to test-llama-archs A 4 layer fixture that alternates sparse and sliding-window layers, with hyper-connections, one Engram module, an indexer on the sparse layers and a latent width distinct from the expert width, so that a transposed routed_down or routed_up is caught. * kv-cache : do not shift the pooled indexer cache The pooled indexer of hy_v4_flash caches the value and the gate of each token, without a position: the pooled key is rotated in the graph. A K-shift rotated these rows as if they were roped keys, which broke the pooled keys after a context shift. * tests : add the hy_v4_flash Metal fusion baseline * model, mtmd : add hy_v4_flash vision The vision tower of hy_v4_flash, with its projector in mtmd and its converter. The published files carry M-RoPE sections, so the text model runs the interleaved M-RoPE path: the rope rows keep their reference order and are reordered to NeoX halves in the graph. The tokens of an image share their position, so the indexer pools now group consecutive tokens in sequence order instead of consecutive positions, and a pooled key is rotated at the four positions of its first member. Without a backend that runs GGML_OP_TOP_K_MASK, the picked pools are expanded to their cells and go through build_top_k_mask. * CUDA: lightning indexer for 16 heads hy_v4_flash scores its pools with 16 indexer heads, which the CUDA backend did not support, so the scheduler ran the 12 sparse layers' indexers on the CPU at every step. Both kernels already handle 16 heads: the mma kernel needs a multiple of 16 and the vector kernel splits the heads in 4 passes. * model : move the Hy4 flash Engram gathers before the token embeddings With the gathers after build_inp_embd, the mixed embedding DUP and SET_ROWS sat between two host nodes and stayed on the CPU. Those ops use every thread, so all the CPU workers woke up on each decoded token for a 12K copy. Gathering first lets the scheduler put them on the GPU, as in qwen4exp, and leaves only small single threaded lookups on the host. * llama : speed up the Hy4 flash pool inputs on long contexts set_input_kpool deduplicated the pools through a map keyed by vectors even with a single sequence, sorted cells that are already in order and scanned every pool owner for each token. Dedup only when the ubatch has several sequences, skip the sort when the cells are ordered and mark the earlier pools of the token's sequence directly. At 129k cells the host cost of a decode step drops from 4.0 ms to 0.5 ms, the logits are unchanged. * llama : use a unified KV cache for Hy4 flash The pools gather their members from a single KV stream, so a split cache with several sequences hit an assert in the graph. Switch to the unified cache with a warning, the sequences then share n_ctx. * rm redundant code in mtmd * clean up comments --------- Co-authored-by: Xuan Son Nguyen <son@huggingface.co>
…1815)" (llama/33050) This reverts commit 1f3ea67fbf857bb831d3fb9e3a91c0f8ad3fbe78.
* metal : spread the short mat-vec lanes over src1 rows The short mat-vec kernel (K < 32) mapped its 32 lanes to 32 src0 rows and handled one src1 row per threadgroup, so with few src0 rows most lanes were idle. It now covers min(ne01, 32) src0 rows of 32/that src1 rows. This is the weighted sum over the depth states of Inkling 2 since #32855 (1-3 src0 rows, K = number of states, 2304 src1 rows). Inkling-2-Mini UD-Q4_K_XL, M5 Max, master -> this PR: pp512 888 -> 1052 t/s, pp2048 771 -> 894 t/s, tg128 unchanged. PPL and greedy output bit-identical, the graph is unchanged. Tested: test-backend-ops -b MTL0 -o MUL_MAT (new small-K cases). * cont : clean-up comment --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Build the gradient dy * (1 - y^2) from the forward output with existing ops, no new op is needed. Add TANH to the gradient-checked unary ops. Signed-off-by: gianni-cor <gianfranco.cordella@tether.io>
…, and generic dma pipelines (llama/32582) * hexagon : add DMA pipeline, htp_tensor_read, and cache/mdev cleanup - Add dma-proxy thread/ring for main-thread DMA offload (clamp n_hvx <= hw_nth - 2) - Add syncht in hmx-queue after HMX VTCM stores * hexagon : add F16/collapse graph lowering and fusion updates * hexagon : update host kparams solver for W8A8 HMX, F16, and DMA * hexagon : add INT-HMX W8A8 matmul, F16 support, and DMA writeback - Use 64-col dual-acc (weight.b:deep + mxswapacc) across all arches and :cm activation layout - Pre-issue chunk-0 weight DMA via dma_proxy, balance 4-row quad output threads, and defer output DMA pop * hexagon : add HMX W8A8 Q8_0 KV flash attention and DMA writeback hex-fa: cleanup dma_queue usage and mask buffers hex-fa: fix new op tests and corner cases hex-fa: cleanup kernel selection and solver hex-fa: improve decode performance (split-kv) * hexagon : add F16, DMA, and micro-kernel optimizations for unary/norm ops * hexagon : add mixed F16/F32 and HVX optimizations for binary ops * hexagon : add F16, DMA, and state fusion for gated-delta-net Alsp pipeline GDN HMX/HVX with batched dispatch and spill-free inversion * hexagon : add F16, token-major fusion, and DMA updates for SSM ops * hexagon : add F16 and HVX optimizations for rope, softmax, and glu rope: optimize init and add common fast-path * hexagon : add F16, DMA, and spill fixes for argsort and top-k * hexagon : add F16 lowering and optimizations for lightning-indexer and dsv4 * hexagon : add F16 and DMA updates for row and concat ops * hexagon : convert simple ops to dma-pipeline, F16, and warning/mdev cleanup * hexagon: add support for fusing MUL_MAT_NX with GLU ops (GEGLU,SWIGLU,...) - Double-buffer vtcm_up/vtcm_wt_scales_up, add 0-spill direct loop0 FP16 GLU strip kernels, trim sub-ULP FP16 sigmoid terms - Balance 4-row quad GLU threads, defer output DMA pop, and pre-issue chunk-0 weight DMA via dma_proxy * tests : add F16/mixed-type and Hexagon op test cases For now do not include ssm_conv tests that break ggml-metal * hexagon : update trace and run scripts * hexagon : update Snapdragon backend README and developer docs Includes updated tensor tiling description (it is 32x4 now) -- Co-authored-by: Ehsan Bateni <ebateni@qti.qualcomm.com> Co-authored-by: Todor Boinovski <todorb@qti.qualcomm.com> Co-authored-by: Trivikram Reddy <tamarnat@qti.qualcomm.com> Co-authored-by: Yanzhao Wang <yanzhaow@qti.qualcomm.com> Assisted-by: Antigravity
…ma/31208) Signed-off-by: Todd Malsbary <todd.malsbary@intel.com>
danbev
approved these changes
Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.