UPSTREAM PR #17592: Feature/kimi linear support#363
Conversation
- Implement KDA layer (linear attention with gates and decay) - Implement MLA layer (multi-head latent attention with KV compression) - Support MoE FFN with shared experts - Add TikToken tokenizer support for Kimi models - Fix vocab loading for large vocabularies - Model loads and runs inference (27 layers, 603 tensors)
- Add missing MoE metadata to GGUF conversion: - moe_intermediate_size (1024) - num_shared_experts (1) - first_k_dense_replace (1) - routed_scaling_factor (2.446) - expert_gating_func (sigmoid) - Fix MoE gating function default to SIGMOID (was SOFTMAX) - Add expert_weights_scale loading with default 2.446 - Enable moe_renormalize (norm_w=true) in build_moe_ffn - Add fallback for exp_probs_b tensor suffix compatibility
- Add KDA (Kimi Delta Attention) CUDA kernel (kda-scan.cu) - Fix recurrence order: decay first, then retrieval - Verify CPU/CUDA implementation consistency - Support head_dim=128, L2 normalization for Q/K
|
Explore the complete analysis inside the Version Insights Performance Analysis Summary - PR #363: Kimi-Linear SupportPR Overview: Adds support for Kimi-Linear-48B model with hybrid MLA+KDA architecture across 24 files (1,676 additions, 29 deletions). Key FindingsCode Changes OverviewThis PR implements a new model architecture combining Multi-head Latent Attention (MLA) and Kimi Delta Attention (KDA) with recurrent state management. The implementation adds:
Performance-Critical Function ChangesModel Parameter Accessors (src/llama-hparams.cpp):
Architecture Classification (src/llama-arch.cpp):
SSM Convolution (ggml/src/ggml-cpu/ops.cpp):
New KDA Scan Operation (ggml/src/ggml-cpu/ops.cpp):
Inference Impact AnalysisTokens Per Second Impact: The core inference functions (
Reference Impact: For the model (ollama://smollm:135m) on CPU (12th Gen Intel Core i7-1255U, Ubuntu 24.04.3 LTS, x86_64), a 2 ms increase in Impacted Functions for Inference:
Power Consumption AnalysisBinary-Level Impact:
Total Impact: Cumulative power consumption increase of approximately 2,810 nJ across all modified binaries, representing a modest increase distributed across multiple small regressions rather than a single dominant source. |
e4a4e1d to
d0b408b
Compare
|
Explore the complete analysis inside the Version Insights Based on the diff, this appears to be a Metal GPU backend change for the llama.cpp project. The changes primarily involve:
However, since the performance analysis tools are returning errors, let me provide a summary based on the code changes: Performance Analysis SummaryThe changes in this commit focus on Metal GPU backend enhancements and do not directly impact CPU-based inference performance metrics. The modifications are specific to Apple Metal GPU acceleration and include refactoring of matrix multiplication kernels with conditional tensor API support. Key Changes:
Impact on Inference: Scope: |
a2a0d0e to
8c4a3c3
Compare
cb46586 to
1a14b3a
Compare
Add debug dump points throughout the KDA and MLA layers to enable tensor inspection during inference: KDA Layer: - Conv states (q, k, v) before processing - Q, K, V after conv1d + SiLU - SSM state before and after KDA scan - Output gate (g2) MLA Layer: - Added detailed comments mapping tensor names to vLLM equivalents - Q projection, KV compression, attention output These callbacks help verify correctness against reference implementations.
…view/llama.cpp into feature/kimi-linear-support
- Fix fattn-tile.cuh config: change nbatch_K from 64 to 48 for head_dim=192 - Add fattn-tile-instance-dkq192-dv192.cu template instance - Add repeat.cu/cuh for CUDA repeat operation - Improve MLA warning message in llama-context.cpp - Update fattn-mma-f16 template instances for various ncols configurations Tested with kimi-q4.gguf (Q4_K - Medium) on RTX 4070
Mirrored from ggml-org/llama.cpp#17592
Make sure to read the contributing guidelines before submitting a PR
This is the current work progress:
ggml-org/llama.cpp#16930 (comment)