Instructions to use VladHong/llama-cpp-K2-FAST2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use VladHong/llama-cpp-K2-FAST2 with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf VladHong/llama-cpp-K2-FAST2 # Run inference directly in the terminal: llama cli -hf VladHong/llama-cpp-K2-FAST2
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf VladHong/llama-cpp-K2-FAST2 # Run inference directly in the terminal: llama cli -hf VladHong/llama-cpp-K2-FAST2
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf VladHong/llama-cpp-K2-FAST2 # Run inference directly in the terminal: ./build/bin/llama cli -hf VladHong/llama-cpp-K2-FAST2
Use Docker
docker model run hf.co/VladHong/llama-cpp-K2-FAST2
- Llama new
- LM Studio
- Jan
- Ollama
How to use VladHong/llama-cpp-K2-FAST2 with Ollama:
ollama run hf.co/VladHong/llama-cpp-K2-FAST2
- Unsloth Desktop
- Docker Model Runner
How to use VladHong/llama-cpp-K2-FAST2 with Docker Model Runner:
docker model run hf.co/VladHong/llama-cpp-K2-FAST2
- Lemonade
How to use VladHong/llama-cpp-K2-FAST2 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull VladHong/llama-cpp-K2-FAST2
Run and chat with the model
lemonade run user.llama-cpp-K2-FAST2-{{QUANT_TAG}}List all available models
lemonade list
- Atomic Chat
repo card: FAST2 fork description + measured speed table
Browse files
README.md
CHANGED
|
@@ -1,126 +1,82 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
# Download and run a model directly from Hugging Face
|
| 33 |
-
llama cli -hf ggml-org/Qwen3.5-0.8B-GGUF
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|