VladHong commited on
Commit
ce71cb3
Β·
verified Β·
1 Parent(s): c59fd93

repo card: FAST2 fork description + measured speed table

Browse files
Files changed (1) hide show
  1. README.md +79 -123
README.md CHANGED
@@ -1,126 +1,82 @@
1
- # llama.cpp
2
-
3
- ![llama](https://raw.githubusercontent.com/ggml-org/llama.brand/refs/heads/master/cover/llama-cpp/cover-llama-cpp-dark.svg)
4
-
5
- <div align="center">
6
-
7
- <b>LLM inference in C/C++</b>
8
-
9
- [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
10
- [![Release](https://img.shields.io/github/v/release/ggml-org/llama.cpp?filter=v*&color=brightgreen)](https://github.com/ggml-org/llama.cpp/releases?q=tag:v0)
11
- [![Nightly](https://img.shields.io/github/v/release/ggml-org/llama.cpp?label=nightly&filter=b*&color=orange)](https://github.com/ggml-org/llama.cpp/releases?q=b)
12
- [![Server](https://img.shields.io/github/actions/workflow/status/ggml-org/llama.cpp/server.yml?label=Server)](https://github.com/ggml-org/llama.cpp/actions/workflows/server.yml)
13
- [![Docker](https://img.shields.io/github/actions/workflow/status/ggml-org/llama.cpp/docker.yml?label=Docker)](https://github.com/ggml-org/llama.cpp/actions/workflows/docker.yml)
14
- [![Winget](https://img.shields.io/github/actions/workflow/status/ggml-org/llama.cpp/winget.yml?label=Winget)](https://github.com/ggml-org/llama.cpp/actions/workflows/winget.yml)
15
-
16
- [ggml](https://github.com/ggml-org/ggml) / [ops](https://github.com/ggml-org/llama.cpp/blob/master/docs/ops.md) / [maintainer PRs](https://github.com/ggml-org/llama.cpp/issues?q=is%3Apr%20is%3Aopen%20draft%3AFalse%20(author%3Argerganov%20OR%20author%3AKitaitiMakoto%20OR%20author%3Adanbev%20OR%20author%3Aaldehir%20OR%20author%3Amax-krasnyansky%20OR%20author%3ACISC%20OR%20author%3Aggerganov%20OR%20author%3Aam17an%20OR%20author%3Abartowski1182%20OR%20author%3Anikwen%20OR%20author%3Ahipudding%20OR%20author%3AServeurpersoCom%20OR%20author%3Apwilkin%20OR%20author%3Areeselevine%20OR%20author%3Angxson%20OR%20author%3Ajeffbolznv%20OR%20author%3Amarty1885%20OR%20author%3A0cc4m%20OR%20author%3ATitaniumtown%20OR%20author%3Aangt%20OR%20author%3AIMbackK%20OR%20author%3Aarthw%20OR%20author%3AJohannesGaessler%20OR%20author%3AORippler%20OR%20author%3Aruixiang63%20OR%20author%3Axctan%20OR%20author%3Aallozaur%20OR%20author%3Ayomaytk%20OR%20author%3Aaendk%20OR%20author%3Agaugarg-nv%20OR%20author%3Ataronaeo%20OR%20author%3Aforforever73%20OR%20author%3Alhez%20OR%20author%3Anetrunnereve%20OR%20author%3Afairydreaming)%20sort%3Aupdated-desc) / [dev stats](https://github.com/ggml-org/llama.cpp-dev) / [lib llama API](https://github.com/ggml-org/llama.cpp/issues/9289) / [llama-server REST API](https://github.com/ggml-org/llama.cpp/issues/9291)
17
-
18
- </div>
19
-
20
- ## Quick start
21
-
22
- A few options to get `llama.cpp` installed on your machine:
23
-
24
- - Visit https://llama.app and follow the instructions
25
- - Run with Docker - see our [Docker documentation](docs/docker.md)
26
- - Download pre-built binaries from the [releases page](https://github.com/ggml-org/llama.cpp/releases)
27
- - Build from source by cloning this repository - check out [our build guide](docs/build.md)
28
-
29
- Once installed:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- ```sh
32
- # Download and run a model directly from Hugging Face
33
- llama cli -hf ggml-org/Qwen3.5-0.8B-GGUF
34
 
35
- # Launch OpenAI-compatible API server
36
- llama serve -hf ggml-org/Qwen3.5-0.8B-GGUF
37
- ```
 
 
38
 
39
- <table align="center">
40
- <tr>
41
- <td align="center" width=50%>
42
- <img width="1310" height="888" alt="VLM session with `llama cli`" src="https://github.com/user-attachments/assets/88726b48-1713-48aa-a525-95a02e78afc4" />
43
- <i>VLM session with <b>llama cli</b></i>
44
- </td>
45
- <td align="center">
46
- <img width="1392" height="958" alt="Built-in web UI against `llama serve` running Qwen 3.6" src="https://github.com/user-attachments/assets/b402f972-2e32-4def-8771-8d849f08cf2e" />
47
- <i>Built-in web UI against <b>llama serve</b></i>
48
- </td>
49
- </tr>
50
- <table>
51
-
52
- ## Description
53
-
54
- The main goal of `llama.cpp` is to enable LLM (and VLM) inference with minimal setup and state-of-the-art performance on
55
- a wide range of hardware - locally and in the cloud.
56
-
57
- - Plain C/C++ implementation without any dependencies
58
- - Apple silicon is a first-class citizen - optimized via ARM NEON, Accelerate and Metal frameworks
59
- - AVX, AVX2, AVX512 and AMX support for x86 architectures
60
- - RVV, ZVFH, ZFH, ZICBOP and ZIHINTPAUSE support for RISC-V architectures
61
- - 1.5-bit, 2-bit, 3-bit, 4-bit, 5-bit, 6-bit, and 8-bit integer quantization for faster inference and reduced memory use
62
- - Custom CUDA kernels for running LLMs on NVIDIA GPUs (support for AMD GPUs via HIP and Moore Threads GPUs via MUSA)
63
- - Vulkan and SYCL backend support
64
- - CPU+GPU hybrid inference to partially accelerate models larger than the total VRAM capacity
65
-
66
- The `llama.cpp` project is build on top of the [ggml](https://github.com/ggml-org/ggml) library.
67
-
68
- ## Supported backends
69
-
70
- | Backend | Target devices |
71
- | --- | --- |
72
- | [BLAS](docs/build.md#blas-build) | All |
73
- | [BLIS](docs/backend/BLIS.md) | All |
74
- | [CANN](docs/build.md#cann) | Ascend NPU |
75
- | [CUDA](docs/build.md#cuda) | Nvidia GPU |
76
- | [HIP](docs/build.md#hip) | AMD GPU |
77
- | [Hexagon [In Progress]](docs/backend/snapdragon/README.md) | Snapdragon |
78
- | [IBM zDNN](docs/backend/zDNN.md) | IBM Z & LinuxONE |
79
- | [MUSA](docs/build.md#musa) | Moore Threads GPU |
80
- | [Metal](docs/build.md#metal-build) | Apple Silicon |
81
- | [OpenCL](docs/backend/OPENCL.md) | Adreno GPU |
82
- | [OpenVINO [In Progress]](docs/backend/OPENVINO.md) | Intel CPUs, GPUs, and NPUs |
83
- | [RPC](https://github.com/ggml-org/llama.cpp/tree/master/tools/rpc) | All |
84
- | [SYCL](docs/backend/SYCL.md) | Intel GPU |
85
- | [VirtGPU](docs/backend/VirtGPU.md) | VirtGPU APIR |
86
- | [Vulkan](docs/build.md#vulkan) | GPU |
87
- | [WebGPU](docs/build.md#webgpu) | All |
88
- | [ZenDNN](docs/build.md#zendnn) | AMD CPU |
89
-
90
- ## Documentation
91
-
92
- #### Tools
93
-
94
- - [cli](tools/cli/README.md)
95
- - [completion](tools/completion/README.md)
96
- - [server](tools/server/README.md)
97
- - [GBNF grammars](grammars/README.md)
98
-
99
- #### Development
100
-
101
- - [How to build](docs/build.md)
102
- - [Running on Docker](docs/docker.md)
103
- - [Build on Android](docs/android.md)
104
- - [Multi-GPU usage](docs/multi-gpu.md)
105
- - [Performance troubleshooting](docs/development/token_generation_performance_tips.md)
106
- - [GGML tips & tricks](https://github.com/ggml-org/llama.cpp/wiki/GGML-Tips-&-Tricks)
107
- - [XCFramework](docs/xcframework.md)
108
- - [Completions](docs/completions.md)
109
- - [Models](docs/models.md)
110
- - [Release process](docs/release.md)
111
-
112
- ## Contributing
113
-
114
- - Contributors can open PRs
115
- - Collaborators will be invited based on contributions
116
- - Maintainers can push to branches in the `llama.cpp` repo and merge PRs into the `master` branch
117
- - Any help with managing issues, PRs and projects is very appreciated!
118
- - Read the [CONTRIBUTING.md](CONTRIBUTING.md) for more information
119
-
120
- ## Acknowledgements
121
-
122
- - [yhirose/cpp-httplib](https://github.com/yhirose/cpp-httplib) - Single-header HTTP server, used by `llama-server` - MIT license
123
- - [nothings/stb](https://github.com/nothings/stb) - Single-header image format decoder, used by multimodal subsystem - Public domain
124
- - [nlohmann/json](https://github.com/nlohmann/json) - Single-header JSON library, used by various tools/examples - MIT License
125
- - [mackron/miniaudio](https://github.com/mackron/miniaudio) - Single-header audio format decoder, used by multimodal subsystem - Public domain
126
- - [sheredom/subprocess.h](https://github.com/sheredom/subprocess.h) - Single-header process launching solution for C and C++ - Public domain
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model:
4
+ - MBZUAI-IFM/llama.cpp
5
+ tags:
6
+ - llama.cpp
7
+ - k2-horizon
8
+ - sliding-window-attention
9
+ - long-context
10
+ - fast-inference
11
+ ---
12
+
13
+ # llama.cpp β€” K2-FAST2 fork πŸš€
14
+
15
+ **This fork makes K2-Horizon GGUFs up to 3.1Γ— faster at long context.**
16
+ It is MBZUAI-IFM's `llama.cpp` `model/K2Horizon` branch (commit `42adf01`) plus one addition:
17
+ **sliding-window attention (SWA) support for `k2-horizon`** β€” 51 lines in `src/models/k2-horizon.cpp`.
18
+
19
+ > πŸ“¦ Companion model (self-contained, window embedded): **K2-Horizon-MoVA-36B-A4B-FAST2**
20
+ > β€” [HuggingFace](https://huggingface.co/VladHong/K2-Horizon-MoVA-36B-A4B-FAST2) Β·
21
+ > [ModelScope](https://modelscope.cn/models/Dalvlad/K2-Horizon-MoVA-36B-A4B-FAST2)
22
+
23
+ ## Measured speed increase vs vanilla APEX-Mini
24
+
25
+ Same binary, same frozen 61,337-token prompt, same context window, 5 interleaved rounds,
26
+ RTX 2080 Ti 22 GB, all layers in VRAM. Full data: `results-head2head.json` in the model repo.
27
+
28
+ | @ 61K context (61,354-token prompt) | decode tok/s | prefill tok/s | speedup |
29
+ |---|---|---|---|
30
+ | vanilla APEX-Mini (q8_0 KV β€” the only way vanilla fits 22 GB at 61K; default f16 KV OOMs) | 16.48 | 692 | β€” |
31
+ | **FAST2 (this fork + embedded W=8192 window)** | **50.72** | **1,482** | **decode 3.1Γ—, prefill 2.1Γ—** |
32
+ | FAST2 with W=16384 | 43.90 | 1,187 | decode 2.7Γ— |
33
+
34
+ At 32K context (W=8192): decode 52.64 vs 36.78 tok/s (**1.43Γ—**), prefill 1,051 vs 949.
35
+ At short context FAST2 equals vanilla β€” decode there is weight-bandwidth-bound and untouched.
36
+
37
+ **Quality:** perplexity inside the window is numerically identical to full attention
38
+ (2.1814 vs 2.1814 on a 240K-token stratified corpus); needle-in-haystack at 61K passes for
39
+ facts inside the window. Recall is limited to the last W tokens by design β€” pick W to match
40
+ your workload (W=16384 is a one-line rebuild, see the model repo's `make_swa_gguf.py`).
41
+
42
+ ## What the patch does
43
+
44
+ K2-Horizon runs **full attention in all 48 layers** (~192 KiB of KV per token β€” 6+ GiB read
45
+ per generated token at 61K context), which is why vanilla decode collapses from ~57 tok/s at
46
+ 4K to ~16 tok/s at 61K. The patch lets a GGUF declare a sliding window
47
+ (`k2-horizon.attention.sliding_window`), which:
48
+
49
+ 1. `load_arch_hparams`: reads the key (from GGUF metadata or `--override-kv`), sets
50
+ `n_swa`, `swa_type = LLAMA_SWA_TYPE_STANDARD`, and marks the attention layers SWA;
51
+ 2. `graph()`: routes attention through the iswa input path (`build_attn_inp_kv_iswa`) so each
52
+ layer's KV is capped at the last W tokens β€” decode cost flattens instead of growing.
53
+
54
+ Without a window key, behavior is bit-identical to stock `model/K2Horizon`.
55
+
56
+ ## Using it
57
+
58
+ ```bash
59
+ # build (same as the MBZUAI fork, plus FA_ALL_QUANTS for mixed KV quant support)
60
+ cmake -B build -DGGML_CUDA=ON -DGGML_CUDA_FA_ALL_QUANTS=ON -DLLAMA_CURL=OFF \
61
+ -DCMAKE_CUDA_ARCHITECTURES=<your-sm> -DCMAKE_BUILD_TYPE=Release
62
+ cmake --build build --target llama-server -j
63
+
64
+ # option A: the FAST2 GGUF (window embedded β€” no flags)
65
+ llama-server -m K2-Horizon-MoVA-36B-A4B-FAST2-SWA8K.gguf -c 65536 -ngl 99 --parallel 1 \
66
+ -fa on -b 2048 -ub 2048 -t 8 --port 8099
67
+
68
+ # option B: any k2-horizon GGUF + window at load time
69
+ llama-server -m K2-Horizon-MoVA-36B-A4B-APEX-Mini.gguf -c 65536 -ngl 99 \
70
+ --override-kv k2-horizon.attention.sliding_window=int:8192 ...
71
+ ```
72
 
73
+ ## Where to get what
 
 
74
 
75
+ | artifact | HuggingFace | ModelScope |
76
+ |---|---|---|
77
+ | FAST2 GGUF (window embedded) + card + measurements | [VladHong/K2-Horizon-MoVA-36B-A4B-FAST2](https://huggingface.co/VladHong/K2-Horizon-MoVA-36B-A4B-FAST2) | [Dalvlad/K2-Horizon-MoVA-36B-A4B-FAST2](https://modelscope.cn/models/Dalvlad/K2-Horizon-MoVA-36B-A4B-FAST2) |
78
+ | this fork as a source snapshot | [VladHong/llama-cpp-K2-FAST2](https://huggingface.co/VladHong/llama-cpp-K2-FAST2) | branch `k2-fast2` of [Dalvlad/llama-cpp-K2-FAST2](https://modelscope.cn/models/Dalvlad/llama-cpp-K2-FAST2) |
79
+ | standalone patch (apply to stock MBZUAI fork) | `k2-fast2-swa.patch` in either model repo | same |
80
 
81
+ The upstream llama.cpp README is preserved as `README-upstream.md`. All credit for the
82
+ `model/K2Horizon` support belongs to MBZUAI-IFM; the FAST2 change is the 51-line diff above.