llama.cpp with the Entrit d2 kernel (D2NL)
Browse files- LICENSE +22 -0
- LLAMA_CPP_VERSION +1 -0
- README.md +162 -0
- get-model.sh +32 -0
- install.sh +122 -0
- patches/entrit-d2nl.diff +1352 -0
- run.sh +22 -0
LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 Entrit Systems
|
| 4 |
+
Copyright (c) 2023-2026 The ggml authors
|
| 5 |
+
|
| 6 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
in the Software without restriction, including without limitation the rights
|
| 9 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
furnished to do so, subject to the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 22 |
+
SOFTWARE.
|
LLAMA_CPP_VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
62061f91088281e65071cc38c5f69ee95c39f14e
|
README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- entrit
|
| 5 |
+
- d2
|
| 6 |
+
- llama.cpp
|
| 7 |
+
- gguf
|
| 8 |
+
- quantization
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Run Entrit d2 models with llama.cpp
|
| 12 |
+
|
| 13 |
+
This installs **llama.cpp**, the free program that runs AI models on your own computer, with
|
| 14 |
+
Entrit's **d2 kernel** added. Our d2 models store each weight as one of 9 levels, and stock
|
| 15 |
+
llama.cpp can't read that format. The install script downloads llama.cpp, adds our kernel, and
|
| 16 |
+
builds it for your graphics card. With no graphics card, it builds a slower version that runs on
|
| 17 |
+
the processor.
|
| 18 |
+
|
| 19 |
+
You'll type a few commands into a terminal. You don't need to know how to program.
|
| 20 |
+
|
| 21 |
+
## Which models it runs
|
| 22 |
+
|
| 23 |
+
| Model | File to download | Runs here? |
|
| 24 |
+
|---|---|---|
|
| 25 |
+
| [Qwen3.8-27B d2](https://huggingface.co/Entrit/Qwen3.8-27B-d2-GGUF) | `Qwen3.8-27B-d2-D2NL.gguf` (15.3 GB) | yes |
|
| 26 |
+
| [Muse-Glimmer-30B d2](https://huggingface.co/Entrit/Muse-Glimmer-30B-d2) | — | no: llama.cpp doesn't support this architecture yet. Use `transformers`. |
|
| 27 |
+
| [DeepSeek-V4-Flash d2](https://huggingface.co/Entrit/DeepSeek-V4-Flash-d2swap-mp2) | — | no: needs DeepSeek's own inference code. |
|
| 28 |
+
|
| 29 |
+
## What you need
|
| 30 |
+
|
| 31 |
+
- A Mac with Apple Silicon (M1 or newer), or a Linux PC.
|
| 32 |
+
Windows works through WSL (see the end of this page).
|
| 33 |
+
- About 5 GB of free disk space for the program, plus room for the model.
|
| 34 |
+
- Enough memory for the model. Qwen3.8-27B needs a graphics card with **24 GB** (RTX 3090, 4090,
|
| 35 |
+
or similar), or a Mac with at least **32 GB**.
|
| 36 |
+
- Internet, for the first install.
|
| 37 |
+
|
| 38 |
+
## Step 1: Open a terminal
|
| 39 |
+
|
| 40 |
+
- **Mac:** press Cmd-Space, type `Terminal`, press Enter.
|
| 41 |
+
- **Linux:** press Ctrl-Alt-T.
|
| 42 |
+
|
| 43 |
+
Every grey box below is a command. Copy it, paste it into the terminal, and press Enter.
|
| 44 |
+
|
| 45 |
+
## Step 2: Install the build tools (once)
|
| 46 |
+
|
| 47 |
+
**Mac:**
|
| 48 |
+
```bash
|
| 49 |
+
xcode-select --install
|
| 50 |
+
```
|
| 51 |
+
A window pops up. Click Install and wait for it to finish. Then install Homebrew (a tool installer)
|
| 52 |
+
if you don't have it, from https://brew.sh, and run:
|
| 53 |
+
```bash
|
| 54 |
+
brew install cmake
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
**Linux (Ubuntu or Debian):**
|
| 58 |
+
```bash
|
| 59 |
+
sudo apt update && sudo apt install -y build-essential cmake curl patch
|
| 60 |
+
```
|
| 61 |
+
Then add the part for your graphics card:
|
| 62 |
+
|
| 63 |
+
| Your graphics card | Extra command |
|
| 64 |
+
|---|---|
|
| 65 |
+
| NVIDIA | Install the CUDA Toolkit from https://developer.nvidia.com/cuda-downloads |
|
| 66 |
+
| AMD or Intel | `sudo apt install -y libvulkan-dev glslc` |
|
| 67 |
+
| None | nothing; you'll get the processor version |
|
| 68 |
+
|
| 69 |
+
## Step 3: Download and install
|
| 70 |
+
|
| 71 |
+
```bash
|
| 72 |
+
mkdir ~/entrit-llama && cd ~/entrit-llama
|
| 73 |
+
curl -fsSLO https://huggingface.co/Entrit/llama.cpp-d2nl/resolve/main/install.sh
|
| 74 |
+
bash install.sh
|
| 75 |
+
```
|
| 76 |
+
The first two lines make a folder and download the installer into it. The installer then downloads
|
| 77 |
+
the rest of our files and llama.cpp, finds your graphics card, and builds for it. The first build
|
| 78 |
+
takes 5 to 20 minutes. At the end you should see:
|
| 79 |
+
```
|
| 80 |
+
==> Self-test: Entrit kernel on ... vs the CPU
|
| 81 |
+
PASS
|
| 82 |
+
==> Done
|
| 83 |
+
```
|
| 84 |
+
**PASS** means our kernel gives the same answers on your graphics card as on the processor.
|
| 85 |
+
|
| 86 |
+
## Step 4: Download a model
|
| 87 |
+
|
| 88 |
+
```bash
|
| 89 |
+
./get-model.sh Entrit/Qwen3.8-27B-d2-GGUF Qwen3.8-27B-d2-D2NL.gguf
|
| 90 |
+
```
|
| 91 |
+
It's 15 GB, so give it a while. If the download stops, run the same command again and it picks up
|
| 92 |
+
where it left off.
|
| 93 |
+
|
| 94 |
+
## Step 5: Chat with it
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
./run.sh models/Qwen3.8-27B-d2-D2NL.gguf
|
| 98 |
+
```
|
| 99 |
+
Wait until the terminal says `server is listening`. Then open **http://localhost:8080** in your web
|
| 100 |
+
browser and type a message. To stop, go back to the terminal and press Ctrl-C.
|
| 101 |
+
|
| 102 |
+
Other programs can talk to it too. It answers the OpenAI chat API at `http://localhost:8080/v1`.
|
| 103 |
+
|
| 104 |
+
## Updating
|
| 105 |
+
|
| 106 |
+
When we release a new version of the kernel:
|
| 107 |
+
```bash
|
| 108 |
+
cd ~/entrit-llama
|
| 109 |
+
./install.sh --update
|
| 110 |
+
```
|
| 111 |
+
It downloads the newest files and rebuilds. Your downloaded models stay where they are.
|
| 112 |
+
|
| 113 |
+
## If something goes wrong
|
| 114 |
+
|
| 115 |
+
| What you see | What to do |
|
| 116 |
+
|---|---|
|
| 117 |
+
| `'cmake' is missing` (or c++, curl, patch) | Do Step 2 again. |
|
| 118 |
+
| `could not download ...` | Check your internet connection and try again. |
|
| 119 |
+
| `Vulkan needs glslc` | Run `sudo apt install -y libvulkan-dev glslc`, or install the Vulkan SDK from https://vulkan.lunarg.com |
|
| 120 |
+
| `configure failed` or `build failed` | Open `build-config.log` or `build.log`. The last 30 lines usually say what is missing. |
|
| 121 |
+
| `the kernel patch did not apply` | Run `./install.sh --update` to get matching files. |
|
| 122 |
+
| The self-test doesn't say PASS | Open an issue on this page's Community tab with `build.log` and the name of your graphics card. |
|
| 123 |
+
| `out of memory`, or the model loads very slowly | The model is too big for your card. Add `-ngl 30` to put only part of it on the graphics card: `./run.sh models/<file>.gguf -ngl 30` |
|
| 124 |
+
| It picked the wrong backend | Choose one yourself: `./install.sh --backend vulkan` (or cuda, metal, hip, cpu) |
|
| 125 |
+
|
| 126 |
+
## Windows
|
| 127 |
+
|
| 128 |
+
Install WSL, which gives you Linux inside Windows. Open PowerShell as administrator and run
|
| 129 |
+
`wsl --install`, restart, then open "Ubuntu" from the Start menu. From there, follow the Linux steps.
|
| 130 |
+
NVIDIA cards work inside WSL with NVIDIA's normal Windows driver.
|
| 131 |
+
|
| 132 |
+
## How it works
|
| 133 |
+
|
| 134 |
+
d2 stores each weight as one of 9 levels, `{0, ±1, ±2.83, ±5.20, ±8}`, times one scale per group of
|
| 135 |
+
64 weights. The kernel adds a GGUF type, **D2NL**, that holds the level index in the same 4-bit block
|
| 136 |
+
llama.cpp uses for its IQ4_NL type, and expands it through a 16-entry int8 table:
|
| 137 |
+
|
| 138 |
+
```
|
| 139 |
+
level 0 ±1 ±2.828 ±5.196 ±8
|
| 140 |
+
int8 0 ±11 ±31 ±57 ±88 (10.981 × level, within 0.19% of each level)
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
So every IQ4_NL code path serves D2NL with the table swapped in: dp4a and int8 tensor cores on
|
| 144 |
+
NVIDIA, Vulkan shaders on AMD and Intel, Metal on Apple, and plain C on the processor. The AMD ROCm
|
| 145 |
+
route (`--backend hip`) builds from the CUDA code but hasn't been tested; use `--backend vulkan` if it
|
| 146 |
+
gives you trouble.
|
| 147 |
+
|
| 148 |
+
| File | What it does |
|
| 149 |
+
|---|---|
|
| 150 |
+
| `install.sh` | downloads llama.cpp, adds our kernel, builds, runs the self-test |
|
| 151 |
+
| `get-model.sh` | downloads a model from Hugging Face into `models/` |
|
| 152 |
+
| `run.sh` | starts the chat server |
|
| 153 |
+
| `patches/entrit-d2nl.diff` | our changes to llama.cpp |
|
| 154 |
+
| `LLAMA_CPP_VERSION` | the exact llama.cpp version our changes apply to (from [PrismML-Eng/llama.cpp](https://github.com/PrismML-Eng/llama.cpp)) |
|
| 155 |
+
|
| 156 |
+
After installing, the folder also holds `llama.cpp/` (the source), `build/` (the program) and
|
| 157 |
+
`models/`. You can delete `llama.cpp/` and `build/` at any time; `./install.sh` makes them again.
|
| 158 |
+
|
| 159 |
+
## License and notice
|
| 160 |
+
|
| 161 |
+
The patch and scripts are released under the MIT License, the same as llama.cpp. The d2 codec is the
|
| 162 |
+
subject of pending patent applications by Entrit Systems. Contact: eric@entrit.io
|
get-model.sh
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Download a model file from Hugging Face into models/.
|
| 3 |
+
#
|
| 4 |
+
# ./get-model.sh <repo> list the .gguf files in the repo
|
| 5 |
+
# ./get-model.sh <repo> <file> download one of them
|
| 6 |
+
#
|
| 7 |
+
# Private repos need a token: export HF_TOKEN=hf_... (huggingface.co -> Settings -> Access Tokens)
|
| 8 |
+
set -euo pipefail
|
| 9 |
+
|
| 10 |
+
HERE=$(cd "$(dirname "$0")" && pwd)
|
| 11 |
+
REPO=${1:?usage: ./get-model.sh <huggingface-repo> [file.gguf]}
|
| 12 |
+
FILE=${2:-}
|
| 13 |
+
AUTH=()
|
| 14 |
+
[[ -n "${HF_TOKEN:-}" ]] && AUTH=(-H "Authorization: Bearer $HF_TOKEN")
|
| 15 |
+
|
| 16 |
+
if [[ -z "$FILE" ]]; then
|
| 17 |
+
echo "GGUF files in $REPO:"
|
| 18 |
+
curl -fsSL ${AUTH[@]+"${AUTH[@]}"} "https://huggingface.co/api/models/$REPO" \
|
| 19 |
+
| grep -o '"rfilename":"[^"]*\.gguf"' | sed 's/"rfilename":"\(.*\)"/ \1/' \
|
| 20 |
+
|| { echo "Could not read $REPO. Check the name, and set HF_TOKEN if the repo is private."; exit 1; }
|
| 21 |
+
echo
|
| 22 |
+
echo "Download one with: ./get-model.sh $REPO <file>"
|
| 23 |
+
exit 0
|
| 24 |
+
fi
|
| 25 |
+
|
| 26 |
+
mkdir -p "$HERE/models"
|
| 27 |
+
OUT="$HERE/models/$(basename "$FILE")"
|
| 28 |
+
echo "Downloading $FILE to models/ (it resumes if interrupted)"
|
| 29 |
+
curl -fL -C - --progress-bar ${AUTH[@]+"${AUTH[@]}"} -o "$OUT" "https://huggingface.co/$REPO/resolve/main/$FILE" \
|
| 30 |
+
|| { echo "Download failed. Check the file name, and set HF_TOKEN if the repo is private."; exit 1; }
|
| 31 |
+
echo "Saved $OUT"
|
| 32 |
+
echo "Run it with: ./run.sh models/$(basename "$FILE")"
|
install.sh
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Install llama.cpp with the Entrit d2 kernel (D2NL).
|
| 3 |
+
#
|
| 4 |
+
# bash install.sh first install: fetches the other files, then builds
|
| 5 |
+
# ./install.sh --update download the newest kernel, then rebuild
|
| 6 |
+
# ./install.sh --backend vulkan force one backend: cuda | vulkan | metal | hip | cpu
|
| 7 |
+
#
|
| 8 |
+
# Private repo? Set your Hugging Face token first: export HF_TOKEN=hf_...
|
| 9 |
+
set -euo pipefail
|
| 10 |
+
|
| 11 |
+
HERE=$(cd "$(dirname "$0")" && pwd)
|
| 12 |
+
REPO_URL=${ENTRIT_REPO:-https://huggingface.co/Entrit/llama.cpp-d2nl/resolve/main}
|
| 13 |
+
FILES=(install.sh get-model.sh run.sh README.md LLAMA_CPP_VERSION patches/entrit-d2nl.diff)
|
| 14 |
+
BACKEND=auto
|
| 15 |
+
UPDATE=0
|
| 16 |
+
|
| 17 |
+
while [[ $# -gt 0 ]]; do
|
| 18 |
+
case "$1" in
|
| 19 |
+
--backend) BACKEND=${2:?--backend needs a value}; shift 2 ;;
|
| 20 |
+
--update) UPDATE=1; shift ;;
|
| 21 |
+
--fetched) UPDATE=0; FETCHED=1; shift ;;
|
| 22 |
+
-h|--help) sed -n '2,9p' "$0"; exit 0 ;;
|
| 23 |
+
*) echo "unknown option: $1 (try --help)"; exit 1 ;;
|
| 24 |
+
esac
|
| 25 |
+
done
|
| 26 |
+
|
| 27 |
+
say() { printf '\n\033[1m==> %s\033[0m\n' "$*"; }
|
| 28 |
+
fail() { printf '\n\033[31mERROR: %s\033[0m\n' "$*"; exit 1; }
|
| 29 |
+
OS=$(uname -s)
|
| 30 |
+
|
| 31 |
+
need() {
|
| 32 |
+
command -v "$1" >/dev/null 2>&1 && return
|
| 33 |
+
case "$OS" in
|
| 34 |
+
Darwin) fail "'$1' is missing. Install the build tools: xcode-select --install and then: brew install cmake" ;;
|
| 35 |
+
*) fail "'$1' is missing. On Ubuntu/Debian: sudo apt install -y build-essential cmake curl patch" ;;
|
| 36 |
+
esac
|
| 37 |
+
}
|
| 38 |
+
need curl
|
| 39 |
+
|
| 40 |
+
# ------------------------------------------------------------------ 1. our files
|
| 41 |
+
AUTH=()
|
| 42 |
+
[[ -n "${HF_TOKEN:-}" ]] && AUTH=(-H "Authorization: Bearer $HF_TOKEN")
|
| 43 |
+
missing=0
|
| 44 |
+
for f in "${FILES[@]}"; do [[ -f "$HERE/$f" ]] || missing=1; done
|
| 45 |
+
if [[ "$UPDATE" == 1 || ( "$missing" == 1 && -z "${FETCHED:-}" ) ]]; then
|
| 46 |
+
say "Downloading the Entrit files"
|
| 47 |
+
mkdir -p "$HERE/patches"
|
| 48 |
+
for f in "${FILES[@]}"; do
|
| 49 |
+
curl -fsSL ${AUTH[@]+"${AUTH[@]}"} -o "$HERE/$f.new" "$REPO_URL/$f" \
|
| 50 |
+
|| fail "could not download $f. If the repository is private, set HF_TOKEN (see the top of this file)."
|
| 51 |
+
mv "$HERE/$f.new" "$HERE/$f"
|
| 52 |
+
done
|
| 53 |
+
chmod +x "$HERE/install.sh" "$HERE/get-model.sh" "$HERE/run.sh"
|
| 54 |
+
exec bash "$HERE/install.sh" --fetched --backend "$BACKEND" # run the version we just downloaded
|
| 55 |
+
fi
|
| 56 |
+
|
| 57 |
+
# ------------------------------------------------------------------ 2. tools
|
| 58 |
+
say "Checking tools"
|
| 59 |
+
need cmake; need c++; need tar; need patch
|
| 60 |
+
echo "cmake, a C++ compiler, tar and patch are present"
|
| 61 |
+
|
| 62 |
+
# ------------------------------------------------------------------ 3. backend
|
| 63 |
+
if [[ "$BACKEND" == auto ]]; then
|
| 64 |
+
if [[ "$OS" == Darwin ]]; then BACKEND=metal
|
| 65 |
+
elif command -v nvcc >/dev/null 2>&1 || [[ -x /usr/local/cuda/bin/nvcc ]]; then BACKEND=cuda
|
| 66 |
+
elif command -v hipcc >/dev/null 2>&1; then BACKEND=hip
|
| 67 |
+
elif command -v glslc >/dev/null 2>&1; then BACKEND=vulkan
|
| 68 |
+
else BACKEND=cpu
|
| 69 |
+
fi
|
| 70 |
+
fi
|
| 71 |
+
case "$BACKEND" in
|
| 72 |
+
metal) FLAGS=(-DGGML_METAL=ON) ;;
|
| 73 |
+
cuda) [[ -x /usr/local/cuda/bin/nvcc ]] && export PATH="/usr/local/cuda/bin:$PATH"
|
| 74 |
+
FLAGS=(-DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=native) ;; # build for the GPU in this machine only
|
| 75 |
+
hip) FLAGS=(-DGGML_HIP=ON) ;;
|
| 76 |
+
vulkan) command -v glslc >/dev/null 2>&1 || fail "Vulkan needs glslc. Ubuntu: sudo apt install -y libvulkan-dev glslc Other: install the Vulkan SDK from https://vulkan.lunarg.com"
|
| 77 |
+
FLAGS=(-DGGML_VULKAN=ON) ;;
|
| 78 |
+
cpu) FLAGS=(-DGGML_CUDA=OFF -DGGML_VULKAN=OFF -DGGML_METAL=OFF) ;;
|
| 79 |
+
*) fail "unknown backend '$BACKEND' (use cuda, vulkan, metal, hip or cpu)" ;;
|
| 80 |
+
esac
|
| 81 |
+
say "Backend: $BACKEND"
|
| 82 |
+
[[ "$BACKEND" == cpu ]] && echo "No GPU toolkit found, so this build runs on the CPU only. It works, but it is slow."
|
| 83 |
+
|
| 84 |
+
# ------------------------------------------------------------------ 4. source
|
| 85 |
+
VERSION=$(tr -d '[:space:]' < "$HERE/LLAMA_CPP_VERSION")
|
| 86 |
+
SRC="$HERE/llama.cpp"
|
| 87 |
+
say "Downloading llama.cpp (version ${VERSION:0:7})"
|
| 88 |
+
rm -rf "$SRC" && mkdir -p "$SRC"
|
| 89 |
+
curl -fsSL "https://github.com/PrismML-Eng/llama.cpp/archive/$VERSION.tar.gz" | tar -xz -C "$SRC" --strip-components 1 \
|
| 90 |
+
|| fail "could not download llama.cpp from GitHub. Check your internet connection."
|
| 91 |
+
|
| 92 |
+
say "Adding the Entrit kernel"
|
| 93 |
+
POPTS=(-p1 -s)
|
| 94 |
+
patch --version 2>/dev/null | grep -q GNU && POPTS+=(--no-backup-if-mismatch) # GNU patch (Linux); macOS patch has no .orig files to avoid
|
| 95 |
+
(cd "$SRC" && patch "${POPTS[@]}" < "$HERE/patches/entrit-d2nl.diff") \
|
| 96 |
+
|| fail "the kernel patch did not apply. Run ./install.sh --update and try again."
|
| 97 |
+
chmod +x "$SRC"/entrit/*.sh "$SRC"/entrit/*.py 2>/dev/null || true
|
| 98 |
+
|
| 99 |
+
# ------------------------------------------------------------------ 5. build
|
| 100 |
+
say "Building (this takes 5-20 minutes the first time)"
|
| 101 |
+
BUILD="$HERE/build"
|
| 102 |
+
JOBS=$( (command -v nproc >/dev/null && nproc) || sysctl -n hw.ncpu 2>/dev/null || echo 4)
|
| 103 |
+
cmake -S "$SRC" -B "$BUILD" -DCMAKE_BUILD_TYPE=Release "${FLAGS[@]}" > "$HERE/build-config.log" 2>&1 \
|
| 104 |
+
|| fail "configure failed; the details are in build-config.log"
|
| 105 |
+
cmake --build "$BUILD" -j "$JOBS" --target llama-server llama-cli llama-completion llama-bench test-backend-ops \
|
| 106 |
+
> "$HERE/build.log" 2>&1 || fail "build failed; the details are in build.log"
|
| 107 |
+
|
| 108 |
+
# ------------------------------------------------------------------ 6. self-test
|
| 109 |
+
DEV=""
|
| 110 |
+
case "$BACKEND" in cuda|hip) DEV=CUDA0 ;; vulkan) DEV=Vulkan0 ;; metal) DEV=MTL0 ;; esac
|
| 111 |
+
if [[ -n "$DEV" ]]; then
|
| 112 |
+
say "Self-test: Entrit kernel on $DEV vs the CPU"
|
| 113 |
+
if "$BUILD/bin/test-backend-ops" test -o MUL_MAT -b "$DEV" -p d2nl 2>&1 | grep -q "tests passed"; then
|
| 114 |
+
echo "PASS"
|
| 115 |
+
else
|
| 116 |
+
echo "The self-test did not pass. The build may still run, but please report this, with build.log."
|
| 117 |
+
fi
|
| 118 |
+
fi
|
| 119 |
+
|
| 120 |
+
say "Done"
|
| 121 |
+
echo "Next: download a model with ./get-model.sh <huggingface-repo>"
|
| 122 |
+
echo "Then run it with ./run.sh models/<file>.gguf"
|
patches/entrit-d2nl.diff
ADDED
|
@@ -0,0 +1,1352 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
--- a/ggml/include/ggml.h
|
| 2 |
+
+++ b/ggml/include/ggml.h
|
| 3 |
+
@@ -430,7 +430,9 @@ extern "C" {
|
| 4 |
+
GGML_TYPE_NVFP4 = 40, // NVFP4 (4 blocks, E4M3 scale)
|
| 5 |
+
GGML_TYPE_Q1_0 = 41,
|
| 6 |
+
GGML_TYPE_Q2_0 = 42,
|
| 7 |
+
- GGML_TYPE_COUNT = 43,
|
| 8 |
+
+ // GGML_TYPE_43 is reserved
|
| 9 |
+
+ GGML_TYPE_D2NL = 44, // Entrit d2: 9 power-mapped levels through an int8 table, IQ4_NL layout
|
| 10 |
+
+ GGML_TYPE_COUNT = 45,
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
// precision
|
| 14 |
+
@@ -475,6 +477,7 @@ extern "C" {
|
| 15 |
+
GGML_FTYPE_MOSTLY_NVFP4 = 26, // except 1d tensors
|
| 16 |
+
GGML_FTYPE_MOSTLY_Q1_0 = 27, // except 1d tensors
|
| 17 |
+
GGML_FTYPE_MOSTLY_Q2_0 = 28, // except 1d tensors
|
| 18 |
+
+ GGML_FTYPE_MOSTLY_D2NL = 129, // except 1d tensors
|
| 19 |
+
};
|
| 20 |
+
|
| 21 |
+
// available tensor operations:
|
| 22 |
+
--- a/ggml/src/ggml-common.h
|
| 23 |
+
+++ b/ggml/src/ggml-common.h
|
| 24 |
+
@@ -451,6 +451,22 @@ typedef struct {
|
| 25 |
+
} block_iq4_nl;
|
| 26 |
+
static_assert(sizeof(block_iq4_nl) == sizeof(ggml_half) + QK4_NL/2, "wrong iq4_nl block size/padding");
|
| 27 |
+
|
| 28 |
+
+// d2nl: Entrit d2 weights. Each weight is one of 9 levels {0, +-1, +-2.828, +-5.196, +-8} (k^1.5 for
|
| 29 |
+
+// k = 0..4) times one scale per group of 64 weights. Stored in IQ4_NL's block so IQ4_NL's kernels can
|
| 30 |
+
+// run it with kvalues_d2nl in place of kvalues_iq4nl: 32 weights = fp16 scale + 16 bytes of 4-bit level
|
| 31 |
+
+// indices (4.50 bpw). qs[j] low nibble = weight j, high nibble = weight j+16. Index 4 is zero.
|
| 32 |
+
+// The stored scale is the group scale divided by GGML_D2NL_K.
|
| 33 |
+
+#define QK_D2NL 32
|
| 34 |
+
+#define QR_D2NL 2
|
| 35 |
+
+#define QI_D2NL (QK_D2NL / (4 * QR_D2NL))
|
| 36 |
+
+typedef struct {
|
| 37 |
+
+ ggml_half d;
|
| 38 |
+
+ uint8_t qs[QK_D2NL/2];
|
| 39 |
+
+} block_d2nl;
|
| 40 |
+
+static_assert(sizeof(block_d2nl) == sizeof(ggml_half) + QK_D2NL/2, "wrong d2nl block size/padding");
|
| 41 |
+
+// kvalues_d2nl = round(GGML_D2NL_K * level). This K keeps every level within 0.19% of its exact value.
|
| 42 |
+
+#define GGML_D2NL_K 10.981f
|
| 43 |
+
+
|
| 44 |
+
typedef struct {
|
| 45 |
+
ggml_half d;
|
| 46 |
+
uint16_t scales_h;
|
| 47 |
+
@@ -1121,6 +1137,11 @@ GGML_TABLE_BEGIN(int8_t, kvalues_iq4nl, 16)
|
| 48 |
+
-127, -104, -83, -65, -49, -35, -22, -10, 1, 13, 25, 38, 53, 69, 89, 113,
|
| 49 |
+
GGML_TABLE_END()
|
| 50 |
+
|
| 51 |
+
+// Entrit d2 levels {0, +-1, +-2.828, +-5.196, +-8} x GGML_D2NL_K, as int8. Index 4 is zero; 9..15 are unused.
|
| 52 |
+
+GGML_TABLE_BEGIN(int8_t, kvalues_d2nl, 16)
|
| 53 |
+
+ -88, -57, -31, -11, 0, 11, 31, 57, 88, 0, 0, 0, 0, 0, 0, 0,
|
| 54 |
+
+GGML_TABLE_END()
|
| 55 |
+
+
|
| 56 |
+
// e2m1 values (doubled)
|
| 57 |
+
// ref: https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf
|
| 58 |
+
GGML_TABLE_BEGIN(int8_t, kvalues_mxfp4, 16)
|
| 59 |
+
--- a/ggml/src/ggml-cpu/ggml-cpu.c
|
| 60 |
+
+++ b/ggml/src/ggml-cpu/ggml-cpu.c
|
| 61 |
+
@@ -383,6 +383,12 @@ static const struct ggml_type_traits_cpu type_traits_cpu[GGML_TYPE_COUNT] = {
|
| 62 |
+
.vec_dot_type = GGML_TYPE_Q8_0,
|
| 63 |
+
.nrows = 1,
|
| 64 |
+
},
|
| 65 |
+
+ [GGML_TYPE_D2NL] = {
|
| 66 |
+
+ .from_float = quantize_row_d2nl,
|
| 67 |
+
+ .vec_dot = ggml_vec_dot_d2nl_q8_0,
|
| 68 |
+
+ .vec_dot_type = GGML_TYPE_Q8_0,
|
| 69 |
+
+ .nrows = 1,
|
| 70 |
+
+ },
|
| 71 |
+
[GGML_TYPE_IQ4_XS] = {
|
| 72 |
+
.from_float = quantize_row_iq4_xs,
|
| 73 |
+
.vec_dot = ggml_vec_dot_iq4_xs_q8_K,
|
| 74 |
+
--- a/ggml/src/ggml-cpu/ops.cpp
|
| 75 |
+
+++ b/ggml/src/ggml-cpu/ops.cpp
|
| 76 |
+
@@ -685,6 +685,7 @@ void ggml_compute_forward_add(
|
| 77 |
+
case GGML_TYPE_IQ3_XXS:
|
| 78 |
+
case GGML_TYPE_IQ1_S:
|
| 79 |
+
case GGML_TYPE_IQ1_M:
|
| 80 |
+
+ case GGML_TYPE_D2NL:
|
| 81 |
+
case GGML_TYPE_IQ4_NL:
|
| 82 |
+
case GGML_TYPE_IQ4_XS:
|
| 83 |
+
case GGML_TYPE_IQ3_S:
|
| 84 |
+
@@ -1137,6 +1138,7 @@ void ggml_compute_forward_add1(
|
| 85 |
+
case GGML_TYPE_IQ3_XXS:
|
| 86 |
+
case GGML_TYPE_IQ1_S:
|
| 87 |
+
case GGML_TYPE_IQ1_M:
|
| 88 |
+
+ case GGML_TYPE_D2NL:
|
| 89 |
+
case GGML_TYPE_IQ4_NL:
|
| 90 |
+
case GGML_TYPE_IQ4_XS:
|
| 91 |
+
case GGML_TYPE_IQ3_S:
|
| 92 |
+
@@ -1268,6 +1270,7 @@ void ggml_compute_forward_acc(
|
| 93 |
+
case GGML_TYPE_IQ3_XXS:
|
| 94 |
+
case GGML_TYPE_IQ1_S:
|
| 95 |
+
case GGML_TYPE_IQ1_M:
|
| 96 |
+
+ case GGML_TYPE_D2NL:
|
| 97 |
+
case GGML_TYPE_IQ4_NL:
|
| 98 |
+
case GGML_TYPE_IQ4_XS:
|
| 99 |
+
case GGML_TYPE_IQ3_S:
|
| 100 |
+
@@ -4438,6 +4441,7 @@ void ggml_compute_forward_out_prod(
|
| 101 |
+
case GGML_TYPE_IQ3_XXS:
|
| 102 |
+
case GGML_TYPE_IQ1_S:
|
| 103 |
+
case GGML_TYPE_IQ1_M:
|
| 104 |
+
+ case GGML_TYPE_D2NL:
|
| 105 |
+
case GGML_TYPE_IQ4_NL:
|
| 106 |
+
case GGML_TYPE_IQ4_XS:
|
| 107 |
+
case GGML_TYPE_IQ3_S:
|
| 108 |
+
@@ -4716,6 +4720,7 @@ void ggml_compute_forward_set(
|
| 109 |
+
case GGML_TYPE_IQ3_XXS:
|
| 110 |
+
case GGML_TYPE_IQ1_S:
|
| 111 |
+
case GGML_TYPE_IQ1_M:
|
| 112 |
+
+ case GGML_TYPE_D2NL:
|
| 113 |
+
case GGML_TYPE_IQ4_NL:
|
| 114 |
+
case GGML_TYPE_IQ4_XS:
|
| 115 |
+
case GGML_TYPE_IQ3_S:
|
| 116 |
+
@@ -4941,6 +4946,7 @@ void ggml_compute_forward_get_rows(
|
| 117 |
+
case GGML_TYPE_IQ3_XXS:
|
| 118 |
+
case GGML_TYPE_IQ1_S:
|
| 119 |
+
case GGML_TYPE_IQ1_M:
|
| 120 |
+
+ case GGML_TYPE_D2NL:
|
| 121 |
+
case GGML_TYPE_IQ4_NL:
|
| 122 |
+
case GGML_TYPE_IQ4_XS:
|
| 123 |
+
case GGML_TYPE_IQ3_S:
|
| 124 |
+
@@ -5668,6 +5674,7 @@ void ggml_compute_forward_clamp(
|
| 125 |
+
case GGML_TYPE_IQ3_XXS:
|
| 126 |
+
case GGML_TYPE_IQ1_S:
|
| 127 |
+
case GGML_TYPE_IQ1_M:
|
| 128 |
+
+ case GGML_TYPE_D2NL:
|
| 129 |
+
case GGML_TYPE_IQ4_NL:
|
| 130 |
+
case GGML_TYPE_IQ4_XS:
|
| 131 |
+
case GGML_TYPE_IQ3_S:
|
| 132 |
+
--- a/ggml/src/ggml-cpu/quants.c
|
| 133 |
+
+++ b/ggml/src/ggml-cpu/quants.c
|
| 134 |
+
@@ -1332,6 +1332,31 @@ void quantize_row_iq4_nl(const float * GGML_RESTRICT x, void * GGML_RESTRICT y,
|
| 135 |
+
quantize_row_iq4_nl_ref(x, y, k);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
+// d2nl: portable C. GPU backends are the fast path; this keeps CPU-only and offloaded runs correct.
|
| 139 |
+
+void quantize_row_d2nl(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k) {
|
| 140 |
+
+ quantize_row_d2nl_ref(x, (block_d2nl *) y, k);
|
| 141 |
+
+}
|
| 142 |
+
+
|
| 143 |
+
+void ggml_vec_dot_d2nl_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc) {
|
| 144 |
+
+ assert(nrc == 1);
|
| 145 |
+
+ UNUSED(nrc); UNUSED(bs); UNUSED(bx); UNUSED(by);
|
| 146 |
+
+ assert(n % QK_D2NL == 0);
|
| 147 |
+
+ static_assert(QK_D2NL == QK8_0, "QK_D2NL and QK8_0 must be the same");
|
| 148 |
+
+ const block_d2nl * GGML_RESTRICT x = vx;
|
| 149 |
+
+ const block_q8_0 * GGML_RESTRICT y = vy;
|
| 150 |
+
+ const int nb = n / QK_D2NL;
|
| 151 |
+
+ float sumf = 0.0f;
|
| 152 |
+
+ for (int ib = 0; ib < nb; ++ib) {
|
| 153 |
+
+ int sumi1 = 0, sumi2 = 0;
|
| 154 |
+
+ for (int j = 0; j < QK_D2NL/2; ++j) {
|
| 155 |
+
+ sumi1 += y[ib].qs[j] * kvalues_d2nl[x[ib].qs[j] & 0xf];
|
| 156 |
+
+ sumi2 += y[ib].qs[j + QK_D2NL/2] * kvalues_d2nl[x[ib].qs[j] >> 4];
|
| 157 |
+
+ }
|
| 158 |
+
+ sumf += GGML_CPU_FP16_TO_FP32(x[ib].d) * GGML_CPU_FP16_TO_FP32(y[ib].d) * (sumi1 + sumi2);
|
| 159 |
+
+ }
|
| 160 |
+
+ *s = sumf;
|
| 161 |
+
+}
|
| 162 |
+
+
|
| 163 |
+
void quantize_row_iq4_xs(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k) {
|
| 164 |
+
assert(k % QK_K == 0);
|
| 165 |
+
quantize_iq4_xs(x, y, 1, k, NULL);
|
| 166 |
+
--- a/ggml/src/ggml-cpu/quants.h
|
| 167 |
+
+++ b/ggml/src/ggml-cpu/quants.h
|
| 168 |
+
@@ -35,6 +35,8 @@ void quantize_row_tq1_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, i
|
| 169 |
+
void quantize_row_tq2_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
|
| 170 |
+
|
| 171 |
+
void quantize_row_iq4_nl (const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
|
| 172 |
+
+void quantize_row_d2nl(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
|
| 173 |
+
+void ggml_vec_dot_d2nl_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const void * GGML_RESTRICT vx, size_t bx, const void * GGML_RESTRICT vy, size_t by, int nrc);
|
| 174 |
+
void quantize_row_iq4_xs (const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);
|
| 175 |
+
|
| 176 |
+
// Dot product
|
| 177 |
+
--- a/ggml/src/ggml-cuda/common.cuh
|
| 178 |
+
+++ b/ggml/src/ggml-cuda/common.cuh
|
| 179 |
+
@@ -1105,6 +1105,13 @@ struct ggml_cuda_type_traits<GGML_TYPE_IQ4_NL> {
|
| 180 |
+
static constexpr int qi = QI4_NL;
|
| 181 |
+
};
|
| 182 |
+
|
| 183 |
+
+template<>
|
| 184 |
+
+struct ggml_cuda_type_traits<GGML_TYPE_D2NL> {
|
| 185 |
+
+ static constexpr int qk = QK_D2NL;
|
| 186 |
+
+ static constexpr int qr = QR_D2NL;
|
| 187 |
+
+ static constexpr int qi = QI_D2NL;
|
| 188 |
+
+};
|
| 189 |
+
+
|
| 190 |
+
template<>
|
| 191 |
+
struct ggml_cuda_type_traits<GGML_TYPE_IQ4_XS> {
|
| 192 |
+
static constexpr int qk = QK_K;
|
| 193 |
+
--- a/ggml/src/ggml-cuda/convert.cu
|
| 194 |
+
+++ b/ggml/src/ggml-cuda/convert.cu
|
| 195 |
+
@@ -451,6 +451,24 @@ static __global__ void dequantize_block_iq4_nl(const void * __restrict__ vx, dst
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
+template<typename dst_t>
|
| 200 |
+
+static __global__ void dequantize_block_d2nl(const void * __restrict__ vx, dst_t * __restrict__ yy) {
|
| 201 |
+
+
|
| 202 |
+
+ const int64_t i = blockIdx.x;
|
| 203 |
+
+ const block_d2nl * x = (const block_d2nl *) vx + i*(QK_K/QK_D2NL);
|
| 204 |
+
+
|
| 205 |
+
+ const int64_t tid = threadIdx.x;
|
| 206 |
+
+ const int64_t il = tid/8; // 0...3
|
| 207 |
+
+ const int64_t ib = tid%8; // 0...7
|
| 208 |
+
+ dst_t * y = yy + i*QK_K + 32*ib + 4*il;
|
| 209 |
+
+ const uint8_t * q4 = x[ib].qs + 4*il;
|
| 210 |
+
+ const float d = (float)x[ib].d;
|
| 211 |
+
+ for (int j = 0; j < 4; ++j) {
|
| 212 |
+
+ y[j+ 0] = d * kvalues_d2nl[q4[j] & 0xf];
|
| 213 |
+
+ y[j+16] = d * kvalues_d2nl[q4[j] >> 4];
|
| 214 |
+
+ }
|
| 215 |
+
+}
|
| 216 |
+
+
|
| 217 |
+
template<typename dst_t>
|
| 218 |
+
static __global__ void dequantize_block_iq4_xs(const void * __restrict__ vx, dst_t * __restrict__ yy) {
|
| 219 |
+
const int64_t i = blockIdx.x;
|
| 220 |
+
@@ -599,6 +617,12 @@ static void dequantize_row_iq4_nl_cuda(const void * vx, dst_t * y, const int64_t
|
| 221 |
+
dequantize_block_iq4_nl<<<nb, 32, 0, stream>>>(vx, y);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
+template<typename dst_t>
|
| 225 |
+
+static void dequantize_row_d2nl_cuda(const void * vx, dst_t * y, const int64_t k, cudaStream_t stream) {
|
| 226 |
+
+ const int nb = (k + QK_K - 1) / QK_K;
|
| 227 |
+
+ dequantize_block_d2nl<<<nb, 32, 0, stream>>>(vx, y);
|
| 228 |
+
+}
|
| 229 |
+
+
|
| 230 |
+
template<typename dst_t>
|
| 231 |
+
static void dequantize_row_iq1_m_cuda(const void * vx, dst_t * y, const int64_t k, cudaStream_t stream) {
|
| 232 |
+
const int nb = k / QK_K;
|
| 233 |
+
@@ -752,6 +776,8 @@ to_fp16_cuda_t ggml_get_to_fp16_cuda(ggml_type type) {
|
| 234 |
+
return dequantize_row_iq1_m_cuda;
|
| 235 |
+
case GGML_TYPE_IQ4_NL:
|
| 236 |
+
return dequantize_row_iq4_nl_cuda;
|
| 237 |
+
+ case GGML_TYPE_D2NL:
|
| 238 |
+
+ return dequantize_row_d2nl_cuda;
|
| 239 |
+
case GGML_TYPE_IQ4_XS:
|
| 240 |
+
return dequantize_row_iq4_xs_cuda;
|
| 241 |
+
case GGML_TYPE_IQ3_S:
|
| 242 |
+
@@ -809,6 +835,8 @@ to_fp32_cuda_t ggml_get_to_fp32_cuda(ggml_type type) {
|
| 243 |
+
return dequantize_row_iq1_m_cuda;
|
| 244 |
+
case GGML_TYPE_IQ4_NL:
|
| 245 |
+
return dequantize_row_iq4_nl_cuda;
|
| 246 |
+
+ case GGML_TYPE_D2NL:
|
| 247 |
+
+ return dequantize_row_d2nl_cuda;
|
| 248 |
+
case GGML_TYPE_IQ4_XS:
|
| 249 |
+
return dequantize_row_iq4_xs_cuda;
|
| 250 |
+
case GGML_TYPE_IQ3_S:
|
| 251 |
+
--- a/ggml/src/ggml-cuda/dequantize.cuh
|
| 252 |
+
+++ b/ggml/src/ggml-cuda/dequantize.cuh
|
| 253 |
+
@@ -56,6 +56,17 @@ static __device__ __forceinline__ void dequantize_q4_0(const void * vx, const in
|
| 254 |
+
v.y = (v.y - 8.0f) * d;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
+static __device__ __forceinline__ void dequantize_d2nl(const void * vx, const int64_t ib, const int iqs, float2 & v){
|
| 258 |
+
+ const block_d2nl * x = (const block_d2nl *) vx;
|
| 259 |
+
+
|
| 260 |
+
+ const float d = x[ib].d;
|
| 261 |
+
+
|
| 262 |
+
+ const int vui = x[ib].qs[iqs];
|
| 263 |
+
+
|
| 264 |
+
+ v.x = d * kvalues_d2nl[vui & 0xF];
|
| 265 |
+
+ v.y = d * kvalues_d2nl[vui >> 4];
|
| 266 |
+
+}
|
| 267 |
+
+
|
| 268 |
+
static __device__ __forceinline__ void dequantize_q4_1(const void * vx, const int64_t ib, const int iqs, float2 & v){
|
| 269 |
+
const block_q4_1 * x = (const block_q4_1 *) vx;
|
| 270 |
+
|
| 271 |
+
--- a/ggml/src/ggml-cuda/getrows.cu
|
| 272 |
+
+++ b/ggml/src/ggml-cuda/getrows.cu
|
| 273 |
+
@@ -205,6 +205,10 @@ static void ggml_cuda_get_rows_switch_src0_type(
|
| 274 |
+
get_rows_cuda_q<QK2_0, QR2_0, dequantize_q2_0>(src0_d, src1_d, dst_d,
|
| 275 |
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
| 276 |
+
break;
|
| 277 |
+
+ case GGML_TYPE_D2NL:
|
| 278 |
+
+ get_rows_cuda_q<QK_D2NL, QR_D2NL, dequantize_d2nl>(src0_d, src1_d, dst_d,
|
| 279 |
+
+ ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
| 280 |
+
+ break;
|
| 281 |
+
case GGML_TYPE_Q4_0:
|
| 282 |
+
get_rows_cuda_q<QK4_0, QR4_0, dequantize_q4_0>(src0_d, src1_d, dst_d,
|
| 283 |
+
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
| 284 |
+
--- a/ggml/src/ggml-cuda/ggml-cuda.cu
|
| 285 |
+
+++ b/ggml/src/ggml-cuda/ggml-cuda.cu
|
| 286 |
+
@@ -5179,6 +5179,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g
|
| 287 |
+
case GGML_TYPE_IQ2_XXS:
|
| 288 |
+
case GGML_TYPE_IQ3_S:
|
| 289 |
+
case GGML_TYPE_IQ3_XXS:
|
| 290 |
+
+ case GGML_TYPE_D2NL:
|
| 291 |
+
case GGML_TYPE_IQ4_NL:
|
| 292 |
+
case GGML_TYPE_IQ4_XS:
|
| 293 |
+
case GGML_TYPE_BF16:
|
| 294 |
+
@@ -5198,6 +5199,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g
|
| 295 |
+
case GGML_TYPE_I32:
|
| 296 |
+
case GGML_TYPE_Q1_0:
|
| 297 |
+
case GGML_TYPE_Q2_0:
|
| 298 |
+
+ case GGML_TYPE_D2NL:
|
| 299 |
+
case GGML_TYPE_Q4_0:
|
| 300 |
+
case GGML_TYPE_Q4_1:
|
| 301 |
+
case GGML_TYPE_Q5_0:
|
| 302 |
+
--- a/ggml/src/ggml-cuda/mmq.cu
|
| 303 |
+
+++ b/ggml/src/ggml-cuda/mmq.cu
|
| 304 |
+
@@ -71,6 +71,9 @@ static void ggml_cuda_mul_mat_q_switch_type(ggml_backend_cuda_context & ctx, con
|
| 305 |
+
case GGML_TYPE_IQ4_NL:
|
| 306 |
+
mul_mat_q_case<GGML_TYPE_IQ4_NL>(ctx, args, stream);
|
| 307 |
+
break;
|
| 308 |
+
+ case GGML_TYPE_D2NL:
|
| 309 |
+
+ mul_mat_q_case<GGML_TYPE_D2NL>(ctx, args, stream);
|
| 310 |
+
+ break;
|
| 311 |
+
default:
|
| 312 |
+
GGML_ABORT("fatal error");
|
| 313 |
+
break;
|
| 314 |
+
@@ -299,6 +302,9 @@ bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_t
|
| 315 |
+
case GGML_TYPE_IQ4_NL:
|
| 316 |
+
mmq_supported = true;
|
| 317 |
+
break;
|
| 318 |
+
+ case GGML_TYPE_D2NL:
|
| 319 |
+
+ mmq_supported = true;
|
| 320 |
+
+ break;
|
| 321 |
+
default:
|
| 322 |
+
mmq_supported = false;
|
| 323 |
+
break;
|
| 324 |
+
--- a/ggml/src/ggml-cuda/mmq.cuh
|
| 325 |
+
+++ b/ggml/src/ggml-cuda/mmq.cuh
|
| 326 |
+
@@ -95,6 +95,8 @@ static mmq_q8_1_ds_layout mmq_get_q8_1_ds_layout(const ggml_type type_x) {
|
| 327 |
+
case GGML_TYPE_IQ4_XS:
|
| 328 |
+
case GGML_TYPE_IQ4_NL:
|
| 329 |
+
return MMQ_Q8_1_DS_LAYOUT_D4;
|
| 330 |
+
+ case GGML_TYPE_D2NL:
|
| 331 |
+
+ return MMQ_Q8_1_DS_LAYOUT_D4;
|
| 332 |
+
default:
|
| 333 |
+
GGML_ABORT("fatal error");
|
| 334 |
+
break;
|
| 335 |
+
@@ -214,6 +216,7 @@ static constexpr __host__ __device__ tile_x_sizes mmq_get_dp4a_tile_x_sizes(ggml
|
| 336 |
+
case GGML_TYPE_IQ1_S: return MMQ_DP4A_TXS_Q8_0;
|
| 337 |
+
case GGML_TYPE_IQ4_XS: return MMQ_DP4A_TXS_Q8_0;
|
| 338 |
+
case GGML_TYPE_IQ4_NL: return MMQ_DP4A_TXS_Q8_0;
|
| 339 |
+
+ case GGML_TYPE_D2NL: return MMQ_DP4A_TXS_Q8_0;
|
| 340 |
+
default: return tile_x_sizes{0, 0, 0};
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
@@ -265,6 +268,7 @@ static constexpr __host__ __device__ int mmq_get_mma_tile_x_k(ggml_type type) {
|
| 344 |
+
case GGML_TYPE_IQ1_S: return MMQ_MMA_TILE_X_K_Q8_0;
|
| 345 |
+
case GGML_TYPE_IQ4_XS: return MMQ_MMA_TILE_X_K_Q8_0;
|
| 346 |
+
case GGML_TYPE_IQ4_NL: return MMQ_MMA_TILE_X_K_Q8_0;
|
| 347 |
+
+ case GGML_TYPE_D2NL: return MMQ_MMA_TILE_X_K_Q8_0;
|
| 348 |
+
default: return 0;
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
@@ -2836,6 +2840,71 @@ template <int mmq_y, bool need_check> static __device__ __forceinline__ void loa
|
| 352 |
+
}
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
+template <int mmq_y, bool need_check> static __device__ __forceinline__ void load_tiles_d2nl(
|
| 356 |
+
+ const char * __restrict__ x, int * __restrict__ x_tile, const int kbx0, const int i_max, const int stride) {
|
| 357 |
+
+ constexpr int nwarps = mmq_get_nwarps_device();
|
| 358 |
+
+ constexpr int warp_size = ggml_cuda_get_physical_warp_size();
|
| 359 |
+
+
|
| 360 |
+
+#if defined(AMD_MFMA_AVAILABLE) || defined(TURING_MMA_AVAILABLE) || defined(AMD_WMMA_AVAILABLE)
|
| 361 |
+
+ int * x_qs = (int *) x_tile;
|
| 362 |
+
+ float * x_df = (float *) (x_qs + MMQ_TILE_NE_K*2);
|
| 363 |
+
+#else
|
| 364 |
+
+ constexpr tile_x_sizes txs = mmq_get_dp4a_tile_x_sizes(GGML_TYPE_D2NL, mmq_y);
|
| 365 |
+
+ int * x_qs = (int *) x_tile;
|
| 366 |
+
+ float * x_df = (float *) (x_qs + txs.qs);
|
| 367 |
+
+#endif // defined(AMD_MFMA_AVAILABLE) || defined(TURING_MMA_AVAILABLE) || defined(AMD_WMMA_AVAILABLE)
|
| 368 |
+
+
|
| 369 |
+
+ constexpr int threads_per_row = MMQ_ITER_K / (4 * QR_D2NL);
|
| 370 |
+
+ constexpr int nrows = warp_size / threads_per_row;
|
| 371 |
+
+ const int txi = warp_size > threads_per_row ? threadIdx.x % threads_per_row : threadIdx.x;
|
| 372 |
+
+ const int kbx = txi / QI_D2NL;
|
| 373 |
+
+ const int kqsx = txi % QI_D2NL;
|
| 374 |
+
+
|
| 375 |
+
+#pragma unroll
|
| 376 |
+
+ for (int i0 = 0; i0 < mmq_y; i0 += nrows*nwarps) {
|
| 377 |
+
+ int i = i0 + (nrows == 1 ? threadIdx.y : threadIdx.y*nrows + threadIdx.x/threads_per_row);
|
| 378 |
+
+
|
| 379 |
+
+ if (need_check) {
|
| 380 |
+
+ i = min(i, i_max);
|
| 381 |
+
+ }
|
| 382 |
+
+
|
| 383 |
+
+ const block_d2nl * bxi = (const block_d2nl *) x + kbx0 + i*stride + kbx;
|
| 384 |
+
+
|
| 385 |
+
+ const int aux_q4 = get_int_b2(bxi->qs, kqsx);
|
| 386 |
+
+ const int2 v = get_int_from_table_16(aux_q4, kvalues_d2nl);
|
| 387 |
+
+ const int k0 = kbx * (2 * QI_D2NL) + kqsx;
|
| 388 |
+
+
|
| 389 |
+
+#if defined(AMD_MFMA_AVAILABLE) || defined(TURING_MMA_AVAILABLE) || defined(AMD_WMMA_AVAILABLE)
|
| 390 |
+
+ x_qs[i*MMQ_MMA_TILE_X_K_Q8_0 + k0 + 0] = v.x;
|
| 391 |
+
+ x_qs[i*MMQ_MMA_TILE_X_K_Q8_0 + k0 + QI_D2NL] = v.y;
|
| 392 |
+
+#else
|
| 393 |
+
+ x_qs[i*(2*MMQ_TILE_NE_K + 1) + k0 + 0] = v.x;
|
| 394 |
+
+ x_qs[i*(2*MMQ_TILE_NE_K + 1) + k0 + QI_D2NL] = v.y;
|
| 395 |
+
+#endif // defined(AMD_MFMA_AVAILABLE) || defined(TURING_MMA_AVAILABLE) || defined(AMD_WMMA_AVAILABLE)
|
| 396 |
+
+ }
|
| 397 |
+
+
|
| 398 |
+
+ constexpr int blocks_per_tile_x_row = MMQ_TILE_NE_K / QI_D2NL;
|
| 399 |
+
+ constexpr int rows_per_warp = warp_size / blocks_per_tile_x_row;
|
| 400 |
+
+ const int kbxd = threadIdx.x % blocks_per_tile_x_row;
|
| 401 |
+
+
|
| 402 |
+
+#pragma unroll
|
| 403 |
+
+ for (int i0 = 0; i0 < mmq_y; i0 += nwarps * rows_per_warp) {
|
| 404 |
+
+ int i = i0 + threadIdx.y * rows_per_warp + threadIdx.x / blocks_per_tile_x_row;
|
| 405 |
+
+
|
| 406 |
+
+ if (need_check) {
|
| 407 |
+
+ i = min(i, i_max);
|
| 408 |
+
+ }
|
| 409 |
+
+
|
| 410 |
+
+ const block_d2nl * bxi = (const block_d2nl *) x + kbx0 + i*stride + kbxd;
|
| 411 |
+
+
|
| 412 |
+
+#if defined(AMD_MFMA_AVAILABLE) || defined(TURING_MMA_AVAILABLE) || defined(AMD_WMMA_AVAILABLE)
|
| 413 |
+
+ x_df[i*MMQ_MMA_TILE_X_K_Q8_0 + kbxd] = __half2float(bxi->d);
|
| 414 |
+
+#else
|
| 415 |
+
+ x_df[i*(MMQ_TILE_NE_K/QI_D2NL) + i/QI_D2NL + kbxd] = __half2float(bxi->d);
|
| 416 |
+
+#endif // defined(AMD_MFMA_AVAILABLE) || defined(TURING_MMA_AVAILABLE) || defined(AMD_WMMA_AVAILABLE)
|
| 417 |
+
+ }
|
| 418 |
+
+}
|
| 419 |
+
+
|
| 420 |
+
template <int mmq_y, bool need_check> static __device__ __forceinline__ void load_tiles_iq2_xxs(
|
| 421 |
+
const char * __restrict__ x, int * __restrict__ x_tile, const int kbx0, const int i_max, const int stride) {
|
| 422 |
+
constexpr int nwarps = mmq_get_nwarps_device();
|
| 423 |
+
@@ -3541,6 +3610,14 @@ struct mmq_type_traits<mmq_x, mmq_y, need_check, GGML_TYPE_IQ4_NL> {
|
| 424 |
+
static constexpr vec_dot_mmq_t vec_dot_dp4a = vec_dot_q8_0_q8_1_dp4a<mmq_x, mmq_y>;
|
| 425 |
+
};
|
| 426 |
+
|
| 427 |
+
+template <int mmq_x, int mmq_y, bool need_check>
|
| 428 |
+
+struct mmq_type_traits<mmq_x, mmq_y, need_check, GGML_TYPE_D2NL> {
|
| 429 |
+
+ static constexpr int vdr = VDR_D2NL_Q8_1_MMQ;
|
| 430 |
+
+ static constexpr load_tiles_mmq_t load_tiles = load_tiles_d2nl<mmq_y, need_check>;
|
| 431 |
+
+ static constexpr vec_dot_mmq_t vec_dot_mma = vec_dot_q8_0_q8_1_mma<mmq_x, mmq_y, MMQ_Q8_1_DS_LAYOUT_D4>;
|
| 432 |
+
+ static constexpr vec_dot_mmq_t vec_dot_dp4a = vec_dot_q8_0_q8_1_dp4a<mmq_x, mmq_y>;
|
| 433 |
+
+};
|
| 434 |
+
+
|
| 435 |
+
template <int mmq_x, int mmq_y, bool need_check>
|
| 436 |
+
struct mmq_type_traits<mmq_x, mmq_y, need_check, GGML_TYPE_IQ4_XS> {
|
| 437 |
+
static constexpr int vdr = VDR_IQ4_XS_Q8_1_MMQ;
|
| 438 |
+
@@ -4265,6 +4342,7 @@ extern DECL_MMQ_CASE(GGML_TYPE_IQ3_XXS);
|
| 439 |
+
extern DECL_MMQ_CASE(GGML_TYPE_IQ3_S);
|
| 440 |
+
extern DECL_MMQ_CASE(GGML_TYPE_IQ1_S);
|
| 441 |
+
extern DECL_MMQ_CASE(GGML_TYPE_IQ4_NL);
|
| 442 |
+
+extern DECL_MMQ_CASE(GGML_TYPE_D2NL);
|
| 443 |
+
extern DECL_MMQ_CASE(GGML_TYPE_IQ4_XS);
|
| 444 |
+
|
| 445 |
+
// -------------------------------------------------------------------------------------------------------------------------
|
| 446 |
+
--- a/ggml/src/ggml-cuda/mmvq.cu
|
| 447 |
+
+++ b/ggml/src/ggml-cuda/mmvq.cu
|
| 448 |
+
@@ -30,6 +30,7 @@ static constexpr __device__ vec_dot_q_cuda_t get_vec_dot_q_cuda(ggml_type type)
|
| 449 |
+
case GGML_TYPE_IQ1_S: return vec_dot_iq1_s_q8_1;
|
| 450 |
+
case GGML_TYPE_IQ1_M: return vec_dot_iq1_m_q8_1;
|
| 451 |
+
case GGML_TYPE_IQ4_NL: return vec_dot_iq4_nl_q8_1;
|
| 452 |
+
+ case GGML_TYPE_D2NL: return vec_dot_d2nl_q8_1;
|
| 453 |
+
case GGML_TYPE_IQ4_XS: return vec_dot_iq4_xs_q8_1;
|
| 454 |
+
case GGML_TYPE_IQ3_S: return vec_dot_iq3_s_q8_1;
|
| 455 |
+
default: return nullptr;
|
| 456 |
+
@@ -58,6 +59,7 @@ static constexpr __host__ __device__ int get_vdr_mmvq(ggml_type type) {
|
| 457 |
+
case GGML_TYPE_IQ3_XXS: return VDR_IQ3_XXS_Q8_1_MMVQ;
|
| 458 |
+
case GGML_TYPE_IQ3_S: return VDR_IQ3_S_Q8_1_MMVQ;
|
| 459 |
+
case GGML_TYPE_IQ4_NL: return VDR_IQ4_NL_Q8_1_MMVQ;
|
| 460 |
+
+ case GGML_TYPE_D2NL: return VDR_D2NL_Q8_1_MMVQ;
|
| 461 |
+
case GGML_TYPE_IQ4_XS: return VDR_IQ4_XS_Q8_1_MMVQ;
|
| 462 |
+
default: return 1;
|
| 463 |
+
}
|
| 464 |
+
@@ -121,6 +123,7 @@ static constexpr __host__ __device__ int get_mmvq_mmid_max_batch_pascal_older(gg
|
| 465 |
+
case GGML_TYPE_IQ3_S: return 4;
|
| 466 |
+
case GGML_TYPE_IQ3_XXS: return 4;
|
| 467 |
+
case GGML_TYPE_IQ4_NL: return 6;
|
| 468 |
+
+ case GGML_TYPE_D2NL: return 6;
|
| 469 |
+
case GGML_TYPE_IQ4_XS: return 5;
|
| 470 |
+
case GGML_TYPE_MXFP4: return 4;
|
| 471 |
+
case GGML_TYPE_NVFP4: return 4;
|
| 472 |
+
@@ -161,6 +164,7 @@ static constexpr __host__ __device__ int get_mmvq_mmid_max_batch_gcn(ggml_type t
|
| 473 |
+
case GGML_TYPE_IQ3_S: return 4;
|
| 474 |
+
case GGML_TYPE_IQ3_XXS: return 4;
|
| 475 |
+
case GGML_TYPE_IQ4_NL: return 6;
|
| 476 |
+
+ case GGML_TYPE_D2NL: return 6;
|
| 477 |
+
case GGML_TYPE_IQ4_XS: return 4;
|
| 478 |
+
case GGML_TYPE_Q2_K: return 4;
|
| 479 |
+
case GGML_TYPE_Q3_K: return 4;
|
| 480 |
+
@@ -211,6 +215,7 @@ static constexpr __host__ __device__ int get_mmvq_mmid_max_batch_rdna3(ggml_type
|
| 481 |
+
case GGML_TYPE_IQ3_S: return 4;
|
| 482 |
+
case GGML_TYPE_IQ3_XXS: return 4;
|
| 483 |
+
case GGML_TYPE_IQ4_NL: return 6;
|
| 484 |
+
+ case GGML_TYPE_D2NL: return 6;
|
| 485 |
+
case GGML_TYPE_IQ4_XS: return 6;
|
| 486 |
+
case GGML_TYPE_Q4_K: return 4;
|
| 487 |
+
case GGML_TYPE_Q5_K: return 4;
|
| 488 |
+
@@ -229,6 +234,7 @@ static constexpr __host__ __device__ int get_mmvq_mmid_max_batch_rdna4(ggml_type
|
| 489 |
+
case GGML_TYPE_IQ3_S: return 4;
|
| 490 |
+
case GGML_TYPE_IQ3_XXS: return 4;
|
| 491 |
+
case GGML_TYPE_IQ4_NL: return 7;
|
| 492 |
+
+ case GGML_TYPE_D2NL: return 7;
|
| 493 |
+
case GGML_TYPE_IQ4_XS: return 5;
|
| 494 |
+
case GGML_TYPE_MXFP4: return 5;
|
| 495 |
+
case GGML_TYPE_NVFP4: return 5;
|
| 496 |
+
@@ -394,6 +400,7 @@ static constexpr __host__ __device__ int calc_nwarps(ggml_type type, int ncols_d
|
| 497 |
+
case GGML_TYPE_Q4_K:
|
| 498 |
+
case GGML_TYPE_Q5_K:
|
| 499 |
+
case GGML_TYPE_Q6_K:
|
| 500 |
+
+ case GGML_TYPE_D2NL:
|
| 501 |
+
case GGML_TYPE_IQ4_NL:
|
| 502 |
+
case GGML_TYPE_IQ4_XS:
|
| 503 |
+
return 8;
|
| 504 |
+
@@ -419,6 +426,8 @@ static constexpr __host__ __device__ int calc_nwarps(ggml_type type, int ncols_d
|
| 505 |
+
return 2;
|
| 506 |
+
case GGML_TYPE_IQ4_NL:
|
| 507 |
+
return 8;
|
| 508 |
+
+ case GGML_TYPE_D2NL:
|
| 509 |
+
+ return 8;
|
| 510 |
+
default:
|
| 511 |
+
return 1;
|
| 512 |
+
}
|
| 513 |
+
@@ -1111,6 +1120,12 @@ static void mul_mat_vec_q_switch_type(
|
| 514 |
+
nchannels_x, nchannels_y, nchannels_dst, stride_channel_x, stride_channel_y, stride_channel_dst,
|
| 515 |
+
nsamples_x, nsamples_dst, stride_sample_x, stride_sample_y, stride_sample_dst, ids_stride, stream);
|
| 516 |
+
break;
|
| 517 |
+
+ case GGML_TYPE_D2NL:
|
| 518 |
+
+ mul_mat_vec_q_switch_ncols_dst<GGML_TYPE_D2NL>
|
| 519 |
+
+ (vx, vy, ids, fusion, dst, ncols_x, nrows_x, ncols_dst, stride_row_x, stride_col_y, stride_col_dst,
|
| 520 |
+
+ nchannels_x, nchannels_y, nchannels_dst, stride_channel_x, stride_channel_y, stride_channel_dst,
|
| 521 |
+
+ nsamples_x, nsamples_dst, stride_sample_x, stride_sample_y, stride_sample_dst, ids_stride, stream);
|
| 522 |
+
+ break;
|
| 523 |
+
case GGML_TYPE_IQ4_XS:
|
| 524 |
+
mul_mat_vec_q_switch_ncols_dst<GGML_TYPE_IQ4_XS>
|
| 525 |
+
(vx, vy, ids, fusion, dst, ncols_x, nrows_x, ncols_dst, stride_row_x, stride_col_y, stride_col_dst,
|
| 526 |
+
--- /dev/null
|
| 527 |
+
+++ b/ggml/src/ggml-cuda/template-instances/mmq-instance-d2nl.cu
|
| 528 |
+
@@ -0,0 +1,5 @@
|
| 529 |
+
+// Entrit d2nl: the IQ4_NL MMQ path with the d2 table.
|
| 530 |
+
+
|
| 531 |
+
+#include "../mmq.cuh"
|
| 532 |
+
+
|
| 533 |
+
+DECL_MMQ_CASE(GGML_TYPE_D2NL);
|
| 534 |
+
--- a/ggml/src/ggml-cuda/vecdotq.cuh
|
| 535 |
+
+++ b/ggml/src/ggml-cuda/vecdotq.cuh
|
| 536 |
+
@@ -1336,6 +1336,8 @@ static __device__ __forceinline__ float vec_dot_iq1_m_q8_1(
|
| 537 |
+
|
| 538 |
+
#define VDR_IQ4_NL_Q8_1_MMVQ 2
|
| 539 |
+
#define VDR_IQ4_NL_Q8_1_MMQ 4
|
| 540 |
+
+#define VDR_D2NL_Q8_1_MMVQ 2
|
| 541 |
+
+#define VDR_D2NL_Q8_1_MMQ 4
|
| 542 |
+
|
| 543 |
+
static __device__ __forceinline__ float vec_dot_iq4_nl_q8_1(
|
| 544 |
+
const void * __restrict__ vbq, const block_q8_1 * __restrict__ bq8_1, const int & kbx, const int & iqs) {
|
| 545 |
+
@@ -1358,6 +1360,27 @@ static __device__ __forceinline__ float vec_dot_iq4_nl_q8_1(
|
| 546 |
+
return d * sumi;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
+static __device__ __forceinline__ float vec_dot_d2nl_q8_1(
|
| 550 |
+
+ const void * __restrict__ vbq, const block_q8_1 * __restrict__ bq8_1, const int & kbx, const int & iqs) {
|
| 551 |
+
+
|
| 552 |
+
+ const block_d2nl * bq4 = (const block_d2nl *) vbq + kbx;
|
| 553 |
+
+
|
| 554 |
+
+ const int * q8 = (const int *) bq8_1->qs + iqs;
|
| 555 |
+
+
|
| 556 |
+
+ int sumi = 0;
|
| 557 |
+
+#pragma unroll
|
| 558 |
+
+ for (int l = 0; l < VDR_Q4_0_Q8_1_MMVQ; ++l) {
|
| 559 |
+
+ const int aux_q4 = get_int_b2(bq4->qs, iqs + l);
|
| 560 |
+
+ const int2 v = get_int_from_table_16(aux_q4, kvalues_d2nl);
|
| 561 |
+
+
|
| 562 |
+
+ sumi = ggml_cuda_dp4a(v.x, q8[l + 0], sumi);
|
| 563 |
+
+ sumi = ggml_cuda_dp4a(v.y, q8[l + 4], sumi);
|
| 564 |
+
+ }
|
| 565 |
+
+
|
| 566 |
+
+ const float d = __half2float(bq4->d) * __low2float(bq8_1->ds);
|
| 567 |
+
+ return d * sumi;
|
| 568 |
+
+}
|
| 569 |
+
+
|
| 570 |
+
#define VDR_IQ4_XS_Q8_1_MMVQ 4
|
| 571 |
+
#define VDR_IQ4_XS_Q8_1_MMQ 4
|
| 572 |
+
|
| 573 |
+
--- a/ggml/src/ggml-metal/ggml-metal-device.cpp
|
| 574 |
+
+++ b/ggml/src/ggml-metal/ggml-metal-device.cpp
|
| 575 |
+
@@ -993,6 +993,12 @@ ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv(ggml_meta
|
| 576 |
+
nr0 = N_R0_IQ4_NL;
|
| 577 |
+
smem = 32*sizeof(float);
|
| 578 |
+
} break;
|
| 579 |
+
+ case GGML_TYPE_D2NL:
|
| 580 |
+
+ {
|
| 581 |
+
+ nsg = N_SG_D2NL;
|
| 582 |
+
+ nr0 = N_R0_D2NL;
|
| 583 |
+
+ smem = 32*sizeof(float);
|
| 584 |
+
+ } break;
|
| 585 |
+
case GGML_TYPE_IQ4_XS:
|
| 586 |
+
{
|
| 587 |
+
nsg = N_SG_IQ4_XS;
|
| 588 |
+
@@ -1222,6 +1228,12 @@ ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv_id(ggml_m
|
| 589 |
+
nr0 = N_R0_IQ4_NL;
|
| 590 |
+
smem = 32*sizeof(float);
|
| 591 |
+
} break;
|
| 592 |
+
+ case GGML_TYPE_D2NL:
|
| 593 |
+
+ {
|
| 594 |
+
+ nsg = N_SG_D2NL;
|
| 595 |
+
+ nr0 = N_R0_D2NL;
|
| 596 |
+
+ smem = 32*sizeof(float);
|
| 597 |
+
+ } break;
|
| 598 |
+
case GGML_TYPE_IQ4_XS:
|
| 599 |
+
{
|
| 600 |
+
nsg = N_SG_IQ4_XS;
|
| 601 |
+
--- a/ggml/src/ggml-metal/ggml-metal-impl.h
|
| 602 |
+
+++ b/ggml/src/ggml-metal/ggml-metal-impl.h
|
| 603 |
+
@@ -84,6 +84,9 @@
|
| 604 |
+
#define N_R0_IQ4_NL 2
|
| 605 |
+
#define N_SG_IQ4_NL 2
|
| 606 |
+
|
| 607 |
+
+#define N_R0_D2NL 2
|
| 608 |
+
+#define N_SG_D2NL 2
|
| 609 |
+
+
|
| 610 |
+
#define N_R0_IQ4_XS 2
|
| 611 |
+
#define N_SG_IQ4_XS 2
|
| 612 |
+
|
| 613 |
+
--- a/ggml/src/ggml-metal/ggml-metal-ops.cpp
|
| 614 |
+
+++ b/ggml/src/ggml-metal/ggml-metal-ops.cpp
|
| 615 |
+
@@ -2247,6 +2247,7 @@ int ggml_metal_op_mul_mat(ggml_metal_op_t ctx, int idx) {
|
| 616 |
+
op->src[0]->type == GGML_TYPE_Q8_0 ||
|
| 617 |
+
op->src[0]->type == GGML_TYPE_MXFP4 ||
|
| 618 |
+
op->src[0]->type == GGML_TYPE_IQ4_NL ||
|
| 619 |
+
+ op->src[0]->type == GGML_TYPE_D2NL ||
|
| 620 |
+
false) && (ne11 >= 2 && ne11 <= ne11_ext_max)
|
| 621 |
+
) ||
|
| 622 |
+
(
|
| 623 |
+
--- a/ggml/src/ggml-metal/ggml-metal.metal
|
| 624 |
+
+++ b/ggml/src/ggml-metal/ggml-metal.metal
|
| 625 |
+
@@ -46,6 +46,11 @@ constexpr constant static float kvalues_iq4nl_f[16] = {
|
| 626 |
+
-127.f, -104.f, -83.f, -65.f, -49.f, -35.f, -22.f, -10.f, 1.f, 13.f, 25.f, 38.f, 53.f, 69.f, 89.f, 113.f
|
| 627 |
+
};
|
| 628 |
+
|
| 629 |
+
+// Entrit d2nl: d2 levels {0, +-1, +-2.828, +-5.196, +-8} x 10.981; index 4 is zero (kvalues_d2nl in ggml-common.h)
|
| 630 |
+
+constexpr constant static float kvalues_d2nl_f[16] = {
|
| 631 |
+
+ -88.f, -57.f, -31.f, -11.f, 0.f, 11.f, 31.f, 57.f, 88.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f
|
| 632 |
+
+};
|
| 633 |
+
+
|
| 634 |
+
constexpr constant static float kvalues_mxfp4_f[16] = {
|
| 635 |
+
0, .5f, 1.f, 1.5f, 2.f, 3.f, 4.f, 6.f, -0, -.5f, -1.f, -1.5f, -2.f, -3.f, -4.f, -6.f
|
| 636 |
+
};
|
| 637 |
+
@@ -986,6 +991,21 @@ void dequantize_iq4_nl(device const block_iq4_nl * xb, short il, thread type4x4
|
| 638 |
+
}
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
+template <typename type4x4>
|
| 642 |
+
+void dequantize_d2nl(device const block_d2nl * xb, short il, thread type4x4 & reg) {
|
| 643 |
+
+ device const uint16_t * q4 = (device const uint16_t *)xb->qs;
|
| 644 |
+
+ const float d = xb->d;
|
| 645 |
+
+ uint32_t aux32;
|
| 646 |
+
+ thread const uint8_t * q8 = (thread const uint8_t *)&aux32;
|
| 647 |
+
+ for (int i = 0; i < 4; ++i) {
|
| 648 |
+
+ aux32 = ((q4[2*i] | (q4[2*i+1] << 16)) >> 4*il) & 0x0f0f0f0f;
|
| 649 |
+
+ reg[i][0] = d * kvalues_d2nl_f[q8[0]];
|
| 650 |
+
+ reg[i][1] = d * kvalues_d2nl_f[q8[1]];
|
| 651 |
+
+ reg[i][2] = d * kvalues_d2nl_f[q8[2]];
|
| 652 |
+
+ reg[i][3] = d * kvalues_d2nl_f[q8[3]];
|
| 653 |
+
+ }
|
| 654 |
+
+}
|
| 655 |
+
+
|
| 656 |
+
template <typename type4>
|
| 657 |
+
void dequantize_iq4_nl_t4(device const block_iq4_nl * xb, short il, thread type4 & reg) {
|
| 658 |
+
device const uint16_t * q4 = (device const uint16_t *)xb->qs;
|
| 659 |
+
@@ -999,6 +1019,19 @@ void dequantize_iq4_nl_t4(device const block_iq4_nl * xb, short il, thread type4
|
| 660 |
+
reg[3] = d * kvalues_iq4nl_f[q8[3]];
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
+template <typename type4>
|
| 664 |
+
+void dequantize_d2nl_t4(device const block_d2nl * xb, short il, thread type4 & reg) {
|
| 665 |
+
+ device const uint16_t * q4 = (device const uint16_t *)xb->qs;
|
| 666 |
+
+ const float d = xb->d;
|
| 667 |
+
+ uint32_t aux32;
|
| 668 |
+
+ thread const uint8_t * q8 = (thread const uint8_t *)&aux32;
|
| 669 |
+
+ aux32 = ((q4[2*(il%4)] | (q4[2*(il%4)+1] << 16)) >> 4*(il/4)) & 0x0f0f0f0f;
|
| 670 |
+
+ reg[0] = d * kvalues_d2nl_f[q8[0]];
|
| 671 |
+
+ reg[1] = d * kvalues_d2nl_f[q8[1]];
|
| 672 |
+
+ reg[2] = d * kvalues_d2nl_f[q8[2]];
|
| 673 |
+
+ reg[3] = d * kvalues_d2nl_f[q8[3]];
|
| 674 |
+
+}
|
| 675 |
+
+
|
| 676 |
+
template <typename type4x4>
|
| 677 |
+
void dequantize_iq4_xs(device const block_iq4_xs * xb, short il, thread type4x4 & reg) {
|
| 678 |
+
// il is 0...15 for QK_K = 256 => index of block of 32 is il/2
|
| 679 |
+
@@ -4451,9 +4484,13 @@ template [[host_name("kernel_mul_mv_ext_mxfp4_f32_r1_4")]] kernel mul_mv_ext_q4
|
| 680 |
+
template [[host_name("kernel_mul_mv_ext_mxfp4_f32_r1_5")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<5, block_mxfp4, 32, dequantize_mxfp4_t4>;
|
| 681 |
+
|
| 682 |
+
template [[host_name("kernel_mul_mv_ext_iq4_nl_f32_r1_2")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<2, block_iq4_nl, 32, dequantize_iq4_nl_t4>;
|
| 683 |
+
+template [[host_name("kernel_mul_mv_ext_d2nl_f32_r1_2")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<2, block_d2nl, 32, dequantize_d2nl_t4>;
|
| 684 |
+
template [[host_name("kernel_mul_mv_ext_iq4_nl_f32_r1_3")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<3, block_iq4_nl, 32, dequantize_iq4_nl_t4>;
|
| 685 |
+
+template [[host_name("kernel_mul_mv_ext_d2nl_f32_r1_3")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<3, block_d2nl, 32, dequantize_d2nl_t4>;
|
| 686 |
+
template [[host_name("kernel_mul_mv_ext_iq4_nl_f32_r1_4")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<4, block_iq4_nl, 32, dequantize_iq4_nl_t4>;
|
| 687 |
+
+template [[host_name("kernel_mul_mv_ext_d2nl_f32_r1_4")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<4, block_d2nl, 32, dequantize_d2nl_t4>;
|
| 688 |
+
template [[host_name("kernel_mul_mv_ext_iq4_nl_f32_r1_5")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<5, block_iq4_nl, 32, dequantize_iq4_nl_t4>;
|
| 689 |
+
+template [[host_name("kernel_mul_mv_ext_d2nl_f32_r1_5")]] kernel mul_mv_ext_q4_f32_t kernel_mul_mv_ext_q4_f32_disp<5, block_d2nl, 32, dequantize_d2nl_t4>;
|
| 690 |
+
|
| 691 |
+
template [[host_name("kernel_mul_mv_ext_q4_K_f32_r1_2")]] kernel mul_mv_ext_q4x4_f32_t kernel_mul_mv_ext_q4x4_f32_disp<2, block_q4_K, 256, dequantize_q4_K>;
|
| 692 |
+
template [[host_name("kernel_mul_mv_ext_q4_K_f32_r1_3")]] kernel mul_mv_ext_q4x4_f32_t kernel_mul_mv_ext_q4x4_f32_disp<3, block_q4_K, 256, dequantize_q4_K>;
|
| 693 |
+
@@ -9484,6 +9521,102 @@ void kernel_mul_mv_iq4_nl_f32_impl(
|
| 694 |
+
}
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
+template<int NR0, typename args_t>
|
| 698 |
+
+void kernel_mul_mv_d2nl_f32_impl(
|
| 699 |
+
+ args_t args,
|
| 700 |
+
+ device const char * src0,
|
| 701 |
+
+ device const char * src1,
|
| 702 |
+
+ device char * dst,
|
| 703 |
+
+ threadgroup char * shmem,
|
| 704 |
+
+ uint3 tgpig,
|
| 705 |
+
+ ushort tiisg,
|
| 706 |
+
+ ushort sgitg) {
|
| 707 |
+
+ const short NSG = FC_mul_mv_nsg;
|
| 708 |
+
+
|
| 709 |
+
+ threadgroup float * shmem_f32 = (threadgroup float *) shmem;
|
| 710 |
+
+
|
| 711 |
+
+ const int r0 = tgpig.x;
|
| 712 |
+
+ const int r1 = tgpig.y;
|
| 713 |
+
+ const int im = tgpig.z;
|
| 714 |
+
+
|
| 715 |
+
+ const int first_row = (r0 * NSG + sgitg) * NR0;
|
| 716 |
+
+
|
| 717 |
+
+ const uint i12 = im%FC_mul_mv_ne12;
|
| 718 |
+
+ const uint i13 = im/FC_mul_mv_ne12;
|
| 719 |
+
+
|
| 720 |
+
+ const uint64_t offset0 = first_row*args.nb01 + (i12/FC_mul_mv_r2)*args.nb02 + (i13/FC_mul_mv_r3)*args.nb03;
|
| 721 |
+
+ const uint64_t offset1 = r1*args.nb11 + (i12 )*args.nb12 + (i13 )*args.nb13;
|
| 722 |
+
+
|
| 723 |
+
+ device const block_d2nl * x = (device const block_d2nl *) (src0 + offset0);
|
| 724 |
+
+ device const float * y = (device const float *) (src1 + offset1);
|
| 725 |
+
+
|
| 726 |
+
+ const int nb = args.ne00/QK_D2NL;
|
| 727 |
+
+ const int ns01 = args.nb01/args.nb00;
|
| 728 |
+
+
|
| 729 |
+
+ const short ix = tiisg/2; // 0...15
|
| 730 |
+
+ const short it = tiisg%2; // 0 or 1
|
| 731 |
+
+
|
| 732 |
+
+ shmem_f32[tiisg] = kvalues_d2nl_f[tiisg%16];
|
| 733 |
+
+ threadgroup_barrier(mem_flags::mem_threadgroup);
|
| 734 |
+
+
|
| 735 |
+
+ float4 yl[4];
|
| 736 |
+
+ float sumf[NR0]={0.f};
|
| 737 |
+
+
|
| 738 |
+
+ device const float * yb = y + ix*QK_D2NL + it*8;
|
| 739 |
+
+
|
| 740 |
+
+ uint32_t aux32[2];
|
| 741 |
+
+ thread const uint8_t * q8 = (thread const uint8_t *)aux32;
|
| 742 |
+
+
|
| 743 |
+
+ float4 qf1, qf2;
|
| 744 |
+
+
|
| 745 |
+
+ // [TAG_MUL_MV_WEIRD]
|
| 746 |
+
+ for (int ib = ix; ib < nb && ib < ns01; ib += 16) {
|
| 747 |
+
+ device const float4 * y4 = (device const float4 *)yb;
|
| 748 |
+
+ yl[0] = y4[0];
|
| 749 |
+
+ yl[1] = y4[4];
|
| 750 |
+
+ yl[2] = y4[1];
|
| 751 |
+
+ yl[3] = y4[5];
|
| 752 |
+
+
|
| 753 |
+
+ for (short row = 0; row < NR0; row++) {
|
| 754 |
+
+ device const block_d2nl & xb = x[row*ns01 + ib];
|
| 755 |
+
+ device const uint16_t * q4 = (device const uint16_t *)(xb.qs + 8*it);
|
| 756 |
+
+
|
| 757 |
+
+ float4 acc1 = {0.f}, acc2 = {0.f};
|
| 758 |
+
+
|
| 759 |
+
+ aux32[0] = q4[0] | (q4[1] << 16);
|
| 760 |
+
+ aux32[1] = (aux32[0] >> 4) & 0x0f0f0f0f;
|
| 761 |
+
+ aux32[0] &= 0x0f0f0f0f;
|
| 762 |
+
+ qf1 = {shmem_f32[q8[0]], shmem_f32[q8[1]], shmem_f32[q8[2]], shmem_f32[q8[3]]};
|
| 763 |
+
+ qf2 = {shmem_f32[q8[4]], shmem_f32[q8[5]], shmem_f32[q8[6]], shmem_f32[q8[7]]};
|
| 764 |
+
+ acc1 += yl[0] * qf1;
|
| 765 |
+
+ acc2 += yl[1] * qf2;
|
| 766 |
+
+
|
| 767 |
+
+ aux32[0] = q4[2] | (q4[3] << 16);
|
| 768 |
+
+ aux32[1] = (aux32[0] >> 4) & 0x0f0f0f0f;
|
| 769 |
+
+ aux32[0] &= 0x0f0f0f0f;
|
| 770 |
+
+ qf1 = {shmem_f32[q8[0]], shmem_f32[q8[1]], shmem_f32[q8[2]], shmem_f32[q8[3]]};
|
| 771 |
+
+ qf2 = {shmem_f32[q8[4]], shmem_f32[q8[5]], shmem_f32[q8[6]], shmem_f32[q8[7]]};
|
| 772 |
+
+ acc1 += yl[2] * qf1;
|
| 773 |
+
+ acc2 += yl[3] * qf2;
|
| 774 |
+
+
|
| 775 |
+
+ acc1 += acc2;
|
| 776 |
+
+
|
| 777 |
+
+ sumf[row] += (float)xb.d * (acc1[0] + acc1[1] + acc1[2] + acc1[3]);
|
| 778 |
+
+ }
|
| 779 |
+
+
|
| 780 |
+
+ yb += 16 * QK_D2NL;
|
| 781 |
+
+ }
|
| 782 |
+
+
|
| 783 |
+
+ device float * dst_f32 = (device float *) dst + (uint64_t)im*args.ne0*args.ne1 + (uint64_t)r1*args.ne0;
|
| 784 |
+
+
|
| 785 |
+
+ for (int row = 0; row < NR0 && first_row + row < args.ne0; ++row) {
|
| 786 |
+
+ float sum_all = simd_sum(sumf[row]);
|
| 787 |
+
+ if (tiisg == 0) {
|
| 788 |
+
+ dst_f32[first_row + row] = sum_all;
|
| 789 |
+
+ }
|
| 790 |
+
+ }
|
| 791 |
+
+}
|
| 792 |
+
+
|
| 793 |
+
[[host_name("kernel_mul_mv_iq4_nl_f32")]]
|
| 794 |
+
kernel void kernel_mul_mv_iq4_nl_f32(
|
| 795 |
+
constant ggml_metal_kargs_mul_mv & args,
|
| 796 |
+
@@ -9498,6 +9631,20 @@ kernel void kernel_mul_mv_iq4_nl_f32(
|
| 797 |
+
kernel_mul_mv_iq4_nl_f32_impl<N_R0_IQ4_NL, constant ggml_metal_kargs_mul_mv &>(args, src0, src1, dst, shmem, tgpig, tiisg, sgitg);
|
| 798 |
+
}
|
| 799 |
+
|
| 800 |
+
+[[host_name("kernel_mul_mv_d2nl_f32")]]
|
| 801 |
+
+kernel void kernel_mul_mv_d2nl_f32(
|
| 802 |
+
+ constant ggml_metal_kargs_mul_mv & args,
|
| 803 |
+
+ device const char * src0,
|
| 804 |
+
+ device const char * src1,
|
| 805 |
+
+ device char * dst,
|
| 806 |
+
+ threadgroup char * shmem [[threadgroup(0)]],
|
| 807 |
+
+ uint3 tgpig[[threadgroup_position_in_grid]],
|
| 808 |
+
+ ushort tiisg[[thread_index_in_simdgroup]],
|
| 809 |
+
+ ushort sgitg[[simdgroup_index_in_threadgroup]]) {
|
| 810 |
+
+
|
| 811 |
+
+ kernel_mul_mv_d2nl_f32_impl<N_R0_D2NL, constant ggml_metal_kargs_mul_mv &>(args, src0, src1, dst, shmem, tgpig, tiisg, sgitg);
|
| 812 |
+
+}
|
| 813 |
+
+
|
| 814 |
+
template<int NR0, typename args_t>
|
| 815 |
+
void kernel_mul_mv_iq4_xs_f32_impl(
|
| 816 |
+
args_t args,
|
| 817 |
+
@@ -10711,6 +10858,7 @@ template [[host_name("kernel_get_rows_iq2_s")]] kernel get_rows_q_t kernel_get
|
| 818 |
+
template [[host_name("kernel_get_rows_iq1_s")]] kernel get_rows_q_t kernel_get_rows_q<block_iq1_s, QK_NL, dequantize_iq1_s>;
|
| 819 |
+
template [[host_name("kernel_get_rows_iq1_m")]] kernel get_rows_q_t kernel_get_rows_q<block_iq1_m, QK_NL, dequantize_iq1_m>;
|
| 820 |
+
template [[host_name("kernel_get_rows_iq4_nl")]] kernel get_rows_q_t kernel_get_rows_q<block_iq4_nl, 2, dequantize_iq4_nl>;
|
| 821 |
+
+template [[host_name("kernel_get_rows_d2nl")]] kernel get_rows_q_t kernel_get_rows_q<block_d2nl, 2, dequantize_d2nl>;
|
| 822 |
+
template [[host_name("kernel_get_rows_iq4_xs")]] kernel get_rows_q_t kernel_get_rows_q<block_iq4_xs, QK_NL, dequantize_iq4_xs>;
|
| 823 |
+
|
| 824 |
+
//
|
| 825 |
+
@@ -10775,6 +10923,7 @@ template [[host_name("kernel_mul_mm_iq2_s_f32")]] kernel mul_mm_t kernel_mul_m
|
| 826 |
+
template [[host_name("kernel_mul_mm_iq1_s_f32")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq1_s, QK_NL, dequantize_iq1_s, float, float4x4, float, float2x4>;
|
| 827 |
+
template [[host_name("kernel_mul_mm_iq1_m_f32")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq1_m, QK_NL, dequantize_iq1_m, float, float4x4, float, float2x4>;
|
| 828 |
+
template [[host_name("kernel_mul_mm_iq4_nl_f32")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq4_nl, 2, dequantize_iq4_nl, float, float4x4, float, float2x4>;
|
| 829 |
+
+template [[host_name("kernel_mul_mm_d2nl_f32")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_d2nl, 2, dequantize_d2nl, float, float4x4, float, float2x4>;
|
| 830 |
+
template [[host_name("kernel_mul_mm_iq4_xs_f32")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq4_xs, QK_NL, dequantize_iq4_xs, float, float4x4, float, float2x4>;
|
| 831 |
+
|
| 832 |
+
template [[host_name("kernel_mul_mm_f32_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, float4x4, 1, dequantize_f32, float, float4x4, half, half2x4>;
|
| 833 |
+
@@ -10800,6 +10949,7 @@ template [[host_name("kernel_mul_mm_iq2_s_f16")]] kernel mul_mm_t kernel_mul_m
|
| 834 |
+
template [[host_name("kernel_mul_mm_iq1_s_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq1_s, QK_NL, dequantize_iq1_s, float, float4x4, half, half2x4>;
|
| 835 |
+
template [[host_name("kernel_mul_mm_iq1_m_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq1_m, QK_NL, dequantize_iq1_m, float, float4x4, half, half2x4>;
|
| 836 |
+
template [[host_name("kernel_mul_mm_iq4_nl_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq4_nl, 2, dequantize_iq4_nl, float, float4x4, half, half2x4>;
|
| 837 |
+
+template [[host_name("kernel_mul_mm_d2nl_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_d2nl, 2, dequantize_d2nl, float, float4x4, half, half2x4>;
|
| 838 |
+
template [[host_name("kernel_mul_mm_iq4_xs_f16")]] kernel mul_mm_t kernel_mul_mm<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq4_xs, QK_NL, dequantize_iq4_xs, float, float4x4, half, half2x4>;
|
| 839 |
+
|
| 840 |
+
//
|
| 841 |
+
@@ -10834,6 +10984,7 @@ template [[host_name("kernel_mul_mm_id_iq2_s_f32")]] kernel mul_mm_id kernel_m
|
| 842 |
+
template [[host_name("kernel_mul_mm_id_iq1_s_f32")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq1_s, QK_NL, dequantize_iq1_s, float, float4x4, float, float2x4>;
|
| 843 |
+
template [[host_name("kernel_mul_mm_id_iq1_m_f32")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq1_m, QK_NL, dequantize_iq1_m, float, float4x4, float, float2x4>;
|
| 844 |
+
template [[host_name("kernel_mul_mm_id_iq4_nl_f32")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq4_nl, 2, dequantize_iq4_nl, float, float4x4, float, float2x4>;
|
| 845 |
+
+template [[host_name("kernel_mul_mm_id_d2nl_f32")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_d2nl, 2, dequantize_d2nl, float, float4x4, float, float2x4>;
|
| 846 |
+
template [[host_name("kernel_mul_mm_id_iq4_xs_f32")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq4_xs, QK_NL, dequantize_iq4_xs, float, float4x4, float, float2x4>;
|
| 847 |
+
|
| 848 |
+
template [[host_name("kernel_mul_mm_id_f32_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, float4x4, 1, dequantize_f32, float, float4x4, half, half2x4>;
|
| 849 |
+
@@ -10859,6 +11010,7 @@ template [[host_name("kernel_mul_mm_id_iq2_s_f16")]] kernel mul_mm_id kernel_m
|
| 850 |
+
template [[host_name("kernel_mul_mm_id_iq1_s_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq1_s, QK_NL, dequantize_iq1_s, float, float4x4, half, half2x4>;
|
| 851 |
+
template [[host_name("kernel_mul_mm_id_iq1_m_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq1_m, QK_NL, dequantize_iq1_m, float, float4x4, half, half2x4>;
|
| 852 |
+
template [[host_name("kernel_mul_mm_id_iq4_nl_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq4_nl, 2, dequantize_iq4_nl, float, float4x4, half, half2x4>;
|
| 853 |
+
+template [[host_name("kernel_mul_mm_id_d2nl_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_d2nl, 2, dequantize_d2nl, float, float4x4, half, half2x4>;
|
| 854 |
+
template [[host_name("kernel_mul_mm_id_iq4_xs_f16")]] kernel mul_mm_id kernel_mul_mm_id<half, half4x4, simdgroup_half8x8, half, half2x4, simdgroup_half8x8, block_iq4_xs, QK_NL, dequantize_iq4_xs, float, float4x4, half, half2x4>;
|
| 855 |
+
|
| 856 |
+
//
|
| 857 |
+
@@ -11016,6 +11168,7 @@ template [[host_name("kernel_mul_mv_id_iq3_xxs_f32")]] kernel kernel_mul_mv_id_t
|
| 858 |
+
template [[host_name("kernel_mul_mv_id_iq3_s_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<kernel_mul_mv_iq3_s_f32_impl <N_R0_IQ3_S>>>;
|
| 859 |
+
template [[host_name("kernel_mul_mv_id_iq2_s_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<kernel_mul_mv_iq2_s_f32_impl <N_R0_IQ2_S>>>;
|
| 860 |
+
template [[host_name("kernel_mul_mv_id_iq4_nl_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<kernel_mul_mv_iq4_nl_f32_impl <N_R0_IQ4_NL>>>;
|
| 861 |
+
+template [[host_name("kernel_mul_mv_id_d2nl_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<kernel_mul_mv_d2nl_f32_impl <N_R0_D2NL>>>;
|
| 862 |
+
template [[host_name("kernel_mul_mv_id_iq4_xs_f32")]] kernel kernel_mul_mv_id_t kernel_mul_mv_id<mmv_fn<kernel_mul_mv_iq4_xs_f32_impl <N_R0_IQ4_XS>>>;
|
| 863 |
+
|
| 864 |
+
kernel void kernel_pool_2d_max_f32(
|
| 865 |
+
--- a/ggml/src/ggml-quants.c
|
| 866 |
+
+++ b/ggml/src/ggml-quants.c
|
| 867 |
+
@@ -5096,6 +5096,80 @@ size_t quantize_iq4_nl(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst
|
| 868 |
+
return nrow * nblock * sizeof(block_iq4_nl);
|
| 869 |
+
}
|
| 870 |
+
|
| 871 |
+
+// ============================ d2nl (Entrit d2) ============================
|
| 872 |
+
+// Converts weights that already lie on the d2 grid. Each 64-group's scale is recovered by trying the
|
| 873 |
+
+// four possible top levels and keeping the one that reconstructs the group best; it is written into
|
| 874 |
+
+// both 32-weight blocks of the group.
|
| 875 |
+
+static const float ggml_d2nl_levels[9] = { -8.0f, -5.19615242f, -2.82842712f, -1.0f, 0.0f,
|
| 876 |
+
+ 1.0f, 2.82842712f, 5.19615242f, 8.0f };
|
| 877 |
+
+
|
| 878 |
+
+void quantize_row_d2nl_ref(const float * GGML_RESTRICT x, block_d2nl * GGML_RESTRICT y, int64_t k) {
|
| 879 |
+
+ assert(k % QK_D2NL == 0);
|
| 880 |
+
+ const int64_t nb = k / QK_D2NL;
|
| 881 |
+
+ static const float tops[4] = { 8.0f, 5.19615242f, 2.82842712f, 1.0f };
|
| 882 |
+
+ for (int64_t ib = 0; ib < nb; ib += 2) {
|
| 883 |
+
+ const int n = (ib + 1 < nb) ? 2*QK_D2NL : QK_D2NL;
|
| 884 |
+
+ const float * xg = x + ib*QK_D2NL;
|
| 885 |
+
+ float amax = 0.0f;
|
| 886 |
+
+ for (int j = 0; j < n; j++) {
|
| 887 |
+
+ const float a = fabsf(xg[j]);
|
| 888 |
+
+ if (a > amax) amax = a;
|
| 889 |
+
+ }
|
| 890 |
+
+ uint8_t idx[2*QK_D2NL];
|
| 891 |
+
+ float d = 0.0f;
|
| 892 |
+
+ float bestres = INFINITY;
|
| 893 |
+
+ for (int t = 0; t < 4; t++) {
|
| 894 |
+
+ const float dt = amax / tops[t];
|
| 895 |
+
+ const float it = dt ? 1.0f/dt : 0.0f;
|
| 896 |
+
+ uint8_t cand[2*QK_D2NL];
|
| 897 |
+
+ float res = 0.0f;
|
| 898 |
+
+ for (int j = 0; j < n; j++) {
|
| 899 |
+
+ const float v = xg[j] * it;
|
| 900 |
+
+ int b = 4;
|
| 901 |
+
+ float bd = fabsf(v);
|
| 902 |
+
+ for (int c = 0; c < 9; c++) {
|
| 903 |
+
+ const float e = fabsf(v - ggml_d2nl_levels[c]);
|
| 904 |
+
+ if (e < bd) { bd = e; b = c; }
|
| 905 |
+
+ }
|
| 906 |
+
+ cand[j] = (uint8_t) b;
|
| 907 |
+
+ res += bd;
|
| 908 |
+
+ }
|
| 909 |
+
+ if (res < bestres) { bestres = res; d = dt; memcpy(idx, cand, n); }
|
| 910 |
+
+ }
|
| 911 |
+
+ const ggml_half dh = GGML_FP32_TO_FP16(d / GGML_D2NL_K);
|
| 912 |
+
+ for (int b = 0; b < n/QK_D2NL; b++) {
|
| 913 |
+
+ y[ib + b].d = dh;
|
| 914 |
+
+ for (int j = 0; j < QK_D2NL/2; j++) {
|
| 915 |
+
+ y[ib + b].qs[j] = idx[b*QK_D2NL + j] | (idx[b*QK_D2NL + j + QK_D2NL/2] << 4);
|
| 916 |
+
+ }
|
| 917 |
+
+ }
|
| 918 |
+
+ }
|
| 919 |
+
+}
|
| 920 |
+
+
|
| 921 |
+
+void dequantize_row_d2nl(const block_d2nl * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k) {
|
| 922 |
+
+ assert(k % QK_D2NL == 0);
|
| 923 |
+
+ const int64_t nb = k / QK_D2NL;
|
| 924 |
+
+ for (int64_t i = 0; i < nb; i++) {
|
| 925 |
+
+ const float d = GGML_FP16_TO_FP32(x[i].d);
|
| 926 |
+
+ for (int j = 0; j < QK_D2NL/2; j++) {
|
| 927 |
+
+ y[i*QK_D2NL + j] = d * kvalues_d2nl[x[i].qs[j] & 0xf];
|
| 928 |
+
+ y[i*QK_D2NL + j + QK_D2NL/2] = d * kvalues_d2nl[x[i].qs[j] >> 4];
|
| 929 |
+
+ }
|
| 930 |
+
+ }
|
| 931 |
+
+}
|
| 932 |
+
+
|
| 933 |
+
+size_t quantize_d2nl(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * quant_weights) {
|
| 934 |
+
+ (void) quant_weights;
|
| 935 |
+
+ const size_t row_size = ggml_row_size(GGML_TYPE_D2NL, n_per_row);
|
| 936 |
+
+ char * qrow = (char *) dst;
|
| 937 |
+
+ for (int64_t row = 0; row < nrows; ++row) {
|
| 938 |
+
+ quantize_row_d2nl_ref(src, (block_d2nl *) qrow, n_per_row);
|
| 939 |
+
+ src += n_per_row;
|
| 940 |
+
+ qrow += row_size;
|
| 941 |
+
+ }
|
| 942 |
+
+ return nrows * row_size;
|
| 943 |
+
+}
|
| 944 |
+
+
|
| 945 |
+
//void quantize_row_iq4_nl_ref(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy, int64_t k) {
|
| 946 |
+
void quantize_row_iq4_nl_ref(const float * GGML_RESTRICT x, block_iq4_nl * GGML_RESTRICT y, int64_t k) {
|
| 947 |
+
GGML_ASSERT(k%QK4_NL == 0);
|
| 948 |
+
@@ -5649,6 +5723,21 @@ bool ggml_validate_row_data(enum ggml_type type, const void * data, size_t nbyte
|
| 949 |
+
{
|
| 950 |
+
VALIDATE_ROW_DATA_D_F16_IMPL(block_iq4_nl, data, nb);
|
| 951 |
+
} break;
|
| 952 |
+
+ case GGML_TYPE_D2NL:
|
| 953 |
+
+ {
|
| 954 |
+
+ const block_d2nl * q = (const block_d2nl *) data;
|
| 955 |
+
+ for (size_t i = 0; i < nb; ++i) {
|
| 956 |
+
+ if (!validate_fp16(q[i].d, i)) {
|
| 957 |
+
+ return false;
|
| 958 |
+
+ }
|
| 959 |
+
+ for (int j = 0; j < QK_D2NL/2; ++j) {
|
| 960 |
+
+ if ((q[i].qs[j] & 0xf) > 8 || (q[i].qs[j] >> 4) > 8) {
|
| 961 |
+
+ fprintf(stderr, "ggml_validate_row_data: d2nl block %zu byte %d has a level index > 8\n", i, j);
|
| 962 |
+
+ return false;
|
| 963 |
+
+ }
|
| 964 |
+
+ }
|
| 965 |
+
+ }
|
| 966 |
+
+ } break;
|
| 967 |
+
|
| 968 |
+
case GGML_TYPE_I8:
|
| 969 |
+
case GGML_TYPE_I16:
|
| 970 |
+
--- a/ggml/src/ggml-quants.h
|
| 971 |
+
+++ b/ggml/src/ggml-quants.h
|
| 972 |
+
@@ -83,6 +83,9 @@ GGML_API size_t quantize_iq3_xxs(const float * GGML_RESTRICT src, void * GGML_RE
|
| 973 |
+
GGML_API size_t quantize_iq1_s (const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
|
| 974 |
+
GGML_API size_t quantize_iq1_m (const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
|
| 975 |
+
GGML_API size_t quantize_iq4_nl (const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
|
| 976 |
+
+GGML_API void quantize_row_d2nl_ref(const float * GGML_RESTRICT x, block_d2nl * GGML_RESTRICT y, int64_t k);
|
| 977 |
+
+GGML_API void dequantize_row_d2nl(const block_d2nl * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
|
| 978 |
+
+GGML_API size_t quantize_d2nl(const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
|
| 979 |
+
GGML_API size_t quantize_iq4_xs (const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
|
| 980 |
+
GGML_API size_t quantize_iq3_s (const float * GGML_RESTRICT src, void * GGML_RESTRICT dst, int64_t nrows, int64_t n_per_row, const float * imatrix);
|
| 981 |
+
|
| 982 |
+
--- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp
|
| 983 |
+
+++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp
|
| 984 |
+
@@ -3391,6 +3391,7 @@ static bool ggml_vk_matmul_shmem_support(const vk_device& device, const std::vec
|
| 985 |
+
case GGML_TYPE_IQ3_S:
|
| 986 |
+
lut_size = 4*512;
|
| 987 |
+
break;
|
| 988 |
+
+ case GGML_TYPE_D2NL:
|
| 989 |
+
case GGML_TYPE_IQ4_NL:
|
| 990 |
+
case GGML_TYPE_IQ4_XS:
|
| 991 |
+
case GGML_TYPE_MXFP4:
|
| 992 |
+
@@ -4050,6 +4051,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 993 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_IQ3_S], matmul_iq3_s_f16, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
| 994 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_IQ4_XS], matmul_iq4_xs_f16, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
| 995 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_IQ4_NL], matmul_iq4_nl_f16, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
| 996 |
+
+ CREATE_MM2(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_D2NL], matmul_d2nl_f16, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
| 997 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_MXFP4], matmul_mxfp4_f16, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
| 998 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_f16[GGML_TYPE_NVFP4], matmul_nvfp4_f16, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3)
|
| 999 |
+
|
| 1000 |
+
@@ -4082,6 +4084,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1001 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ3_S], matmul_id_subgroup_iq3_s_f16, mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 5)
|
| 1002 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_XS], matmul_id_subgroup_iq4_xs_f16, mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 5)
|
| 1003 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_NL], matmul_id_subgroup_iq4_nl_f16, mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 5)
|
| 1004 |
+
+ CREATE_MM2(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_D2NL], matmul_id_subgroup_d2nl_f16, mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 5)
|
| 1005 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_MXFP4], matmul_id_subgroup_mxfp4_f16, mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 5)
|
| 1006 |
+
CREATE_MM2(pipeline_dequant_mul_mat_mat_id[GGML_TYPE_NVFP4], matmul_id_subgroup_nvfp4_f16, mmqid_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, 5)
|
| 1007 |
+
#undef CREATE_MM
|
| 1008 |
+
@@ -4147,6 +4150,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1009 |
+
CREATE_MM2(GGML_TYPE_IQ3_S, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ3_S], matmul_iq3_s_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1010 |
+
CREATE_MM2(GGML_TYPE_IQ4_XS, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ4_XS], matmul_iq4_xs_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1011 |
+
CREATE_MM2(GGML_TYPE_IQ4_NL, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ4_NL], matmul_iq4_nl_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1012 |
+
+ CREATE_MM2(GGML_TYPE_D2NL, pipeline_dequant_mul_mat_mat[GGML_TYPE_D2NL], matmul_d2nl_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1013 |
+
CREATE_MM2(GGML_TYPE_MXFP4, pipeline_dequant_mul_mat_mat[GGML_TYPE_MXFP4], matmul_mxfp4_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1014 |
+
CREATE_MM2(GGML_TYPE_NVFP4, pipeline_dequant_mul_mat_mat[GGML_TYPE_NVFP4], matmul_nvfp4_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1015 |
+
} else {
|
| 1016 |
+
@@ -4172,6 +4176,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1017 |
+
CREATE_MM(GGML_TYPE_IQ3_S, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ3_S].f32acc, matmul_iq3_s_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1018 |
+
CREATE_MM(GGML_TYPE_IQ4_XS, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ4_XS].f32acc, matmul_iq4_xs_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1019 |
+
CREATE_MM(GGML_TYPE_IQ4_NL, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ4_NL].f32acc, matmul_iq4_nl_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1020 |
+
+ CREATE_MM(GGML_TYPE_D2NL, pipeline_dequant_mul_mat_mat[GGML_TYPE_D2NL].f32acc, matmul_d2nl_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1021 |
+
CREATE_MM(GGML_TYPE_MXFP4, pipeline_dequant_mul_mat_mat[GGML_TYPE_MXFP4].f32acc, matmul_mxfp4_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1022 |
+
CREATE_MM(GGML_TYPE_NVFP4, pipeline_dequant_mul_mat_mat[GGML_TYPE_NVFP4].f32acc, matmul_nvfp4_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, );
|
| 1023 |
+
}
|
| 1024 |
+
@@ -4208,6 +4213,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1025 |
+
CREATE_MM2(GGML_TYPE_IQ3_S, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ3_S], matmul_id_subgroup_iq3_s_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id);
|
| 1026 |
+
CREATE_MM2(GGML_TYPE_IQ4_XS, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_XS], matmul_id_subgroup_iq4_xs_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id);
|
| 1027 |
+
CREATE_MM2(GGML_TYPE_IQ4_NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_NL], matmul_id_subgroup_iq4_nl_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id);
|
| 1028 |
+
+ CREATE_MM2(GGML_TYPE_D2NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_D2NL], matmul_id_subgroup_d2nl_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id);
|
| 1029 |
+
CREATE_MM2(GGML_TYPE_MXFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_MXFP4], matmul_id_subgroup_mxfp4_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id);
|
| 1030 |
+
CREATE_MM2(GGML_TYPE_NVFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_NVFP4], matmul_id_subgroup_nvfp4_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id);
|
| 1031 |
+
#undef CREATE_MM2
|
| 1032 |
+
@@ -4275,6 +4281,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1033 |
+
CREATE_MM2(GGML_TYPE_IQ3_S, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ3_S], matmul_iq3_s_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1034 |
+
CREATE_MM2(GGML_TYPE_IQ4_XS, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ4_XS], matmul_iq4_xs_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1035 |
+
CREATE_MM2(GGML_TYPE_IQ4_NL, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ4_NL], matmul_iq4_nl_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1036 |
+
+ CREATE_MM2(GGML_TYPE_D2NL, pipeline_dequant_mul_mat_mat[GGML_TYPE_D2NL], matmul_d2nl_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1037 |
+
CREATE_MM2(GGML_TYPE_MXFP4, pipeline_dequant_mul_mat_mat[GGML_TYPE_MXFP4], matmul_mxfp4_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1038 |
+
CREATE_MM2(GGML_TYPE_NVFP4, pipeline_dequant_mul_mat_mat[GGML_TYPE_NVFP4], matmul_nvfp4_f32, mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1039 |
+
|
| 1040 |
+
@@ -4323,6 +4330,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1041 |
+
CREATE_MM2(GGML_TYPE_IQ3_S, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ3_S], matmul_id_subgroup_iq3_s_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1042 |
+
CREATE_MM2(GGML_TYPE_IQ4_XS, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_XS], matmul_id_subgroup_iq4_xs_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1043 |
+
CREATE_MM2(GGML_TYPE_IQ4_NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_NL], matmul_id_subgroup_iq4_nl_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1044 |
+
+ CREATE_MM2(GGML_TYPE_D2NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_D2NL], matmul_id_subgroup_d2nl_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1045 |
+
CREATE_MM2(GGML_TYPE_MXFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_MXFP4], matmul_id_subgroup_mxfp4_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1046 |
+
CREATE_MM2(GGML_TYPE_NVFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_NVFP4], matmul_id_subgroup_nvfp4_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1047 |
+
|
| 1048 |
+
@@ -4370,6 +4378,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1049 |
+
CREATE_MM2(GGML_TYPE_IQ3_S, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ3_S], matmul_id_iq3_s_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1050 |
+
CREATE_MM2(GGML_TYPE_IQ4_XS, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_XS], matmul_id_iq4_xs_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1051 |
+
CREATE_MM2(GGML_TYPE_IQ4_NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_NL], matmul_id_iq4_nl_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1052 |
+
+ CREATE_MM2(GGML_TYPE_D2NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_D2NL], matmul_id_d2nl_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1053 |
+
CREATE_MM2(GGML_TYPE_MXFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_MXFP4], matmul_id_mxfp4_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1054 |
+
CREATE_MM2(GGML_TYPE_NVFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_NVFP4], matmul_id_nvfp4_f32, mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1055 |
+
|
| 1056 |
+
@@ -4447,6 +4456,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1057 |
+
CREATE_MM(GGML_TYPE_IQ3_S, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ3_S].f32acc, matmul_iq3_s_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1058 |
+
CREATE_MM(GGML_TYPE_IQ4_XS, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ4_XS].f32acc, matmul_iq4_xs_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1059 |
+
CREATE_MM(GGML_TYPE_IQ4_NL, pipeline_dequant_mul_mat_mat[GGML_TYPE_IQ4_NL].f32acc, matmul_iq4_nl_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1060 |
+
+ CREATE_MM(GGML_TYPE_D2NL, pipeline_dequant_mul_mat_mat[GGML_TYPE_D2NL].f32acc, matmul_d2nl_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1061 |
+
CREATE_MM(GGML_TYPE_MXFP4, pipeline_dequant_mul_mat_mat[GGML_TYPE_MXFP4].f32acc, matmul_mxfp4_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1062 |
+
CREATE_MM(GGML_TYPE_NVFP4, pipeline_dequant_mul_mat_mat[GGML_TYPE_NVFP4].f32acc, matmul_nvfp4_f32, , mmq_wg_denoms, warptile_mmq, vk_mat_mat_push_constants, 3, , 0);
|
| 1063 |
+
|
| 1064 |
+
@@ -4493,6 +4503,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1065 |
+
CREATE_MM(GGML_TYPE_IQ3_S, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ3_S].f32acc, matmul_id_subgroup_iq3_s_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1066 |
+
CREATE_MM(GGML_TYPE_IQ4_XS, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_XS].f32acc, matmul_id_subgroup_iq4_xs_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1067 |
+
CREATE_MM(GGML_TYPE_IQ4_NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_NL].f32acc, matmul_id_subgroup_iq4_nl_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1068 |
+
+ CREATE_MM(GGML_TYPE_D2NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_D2NL].f32acc, matmul_id_subgroup_d2nl_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1069 |
+
CREATE_MM(GGML_TYPE_MXFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_MXFP4].f32acc, matmul_id_subgroup_mxfp4_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1070 |
+
CREATE_MM(GGML_TYPE_NVFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_NVFP4].f32acc, matmul_id_subgroup_nvfp4_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, mul_mat_subgroup_size);
|
| 1071 |
+
} else {
|
| 1072 |
+
@@ -4522,6 +4533,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1073 |
+
CREATE_MM(GGML_TYPE_IQ3_S, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ3_S].f32acc, matmul_id_iq3_s_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1074 |
+
CREATE_MM(GGML_TYPE_IQ4_XS, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_XS].f32acc, matmul_id_iq4_xs_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1075 |
+
CREATE_MM(GGML_TYPE_IQ4_NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_IQ4_NL].f32acc, matmul_id_iq4_nl_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1076 |
+
+ CREATE_MM(GGML_TYPE_D2NL, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_D2NL].f32acc, matmul_id_d2nl_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1077 |
+
CREATE_MM(GGML_TYPE_MXFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_MXFP4].f32acc, matmul_id_mxfp4_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1078 |
+
CREATE_MM(GGML_TYPE_NVFP4, pipeline_dequant_mul_mat_mat_id[GGML_TYPE_NVFP4].f32acc, matmul_id_nvfp4_f32, , mmq_wg_denoms, warptile_mmqid, vk_mat_mat_id_push_constants, mul_mat_id_param_count, _id, 0);
|
| 1079 |
+
}
|
| 1080 |
+
@@ -4617,6 +4629,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1081 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f32_f32[w][GGML_TYPE_IQ3_S][i], "mul_mat_vec_iq3_s_f32_f32", arr_dmmv_iq3_s_f32_f32_len[reduc16], arr_dmmv_iq3_s_f32_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1082 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f32_f32[w][GGML_TYPE_IQ4_XS][i], "mul_mat_vec_iq4_xs_f32_f32", arr_dmmv_iq4_xs_f32_f32_len[reduc16], arr_dmmv_iq4_xs_f32_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1083 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f32_f32[w][GGML_TYPE_IQ4_NL][i], "mul_mat_vec_iq4_nl_f32_f32", arr_dmmv_iq4_nl_f32_f32_len[reduc16], arr_dmmv_iq4_nl_f32_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1084 |
+
+ ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f32_f32[w][GGML_TYPE_D2NL][i], "mul_mat_vec_d2nl_f32_f32", arr_dmmv_d2nl_f32_f32_len[reduc16], arr_dmmv_d2nl_f32_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1085 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f32_f32[w][GGML_TYPE_MXFP4][i], "mul_mat_vec_mxfp4_f32_f32", arr_dmmv_mxfp4_f32_f32_len[reduc16], arr_dmmv_mxfp4_f32_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1086 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f32_f32[w][GGML_TYPE_NVFP4][i], "mul_mat_vec_nvfp4_f32_f32", arr_dmmv_nvfp4_f32_f32_len[reduc16], arr_dmmv_nvfp4_f32_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1087 |
+
|
| 1088 |
+
@@ -4644,6 +4657,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1089 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f16_f32[w][GGML_TYPE_IQ3_S][i], "mul_mat_vec_iq3_s_f16_f32", arr_dmmv_iq3_s_f16_f32_len[reduc16], arr_dmmv_iq3_s_f16_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1090 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f16_f32[w][GGML_TYPE_IQ4_XS][i], "mul_mat_vec_iq4_xs_f16_f32", arr_dmmv_iq4_xs_f16_f32_len[reduc16], arr_dmmv_iq4_xs_f16_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1091 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f16_f32[w][GGML_TYPE_IQ4_NL][i], "mul_mat_vec_iq4_nl_f16_f32", arr_dmmv_iq4_nl_f16_f32_len[reduc16], arr_dmmv_iq4_nl_f16_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1092 |
+
+ ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f16_f32[w][GGML_TYPE_D2NL][i], "mul_mat_vec_d2nl_f16_f32", arr_dmmv_d2nl_f16_f32_len[reduc16], arr_dmmv_d2nl_f16_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1093 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f16_f32[w][GGML_TYPE_MXFP4][i], "mul_mat_vec_mxfp4_f16_f32", arr_dmmv_mxfp4_f16_f32_len[reduc16], arr_dmmv_mxfp4_f16_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1094 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_f16_f32[w][GGML_TYPE_NVFP4][i], "mul_mat_vec_nvfp4_f16_f32", arr_dmmv_nvfp4_f16_f32_len[reduc16], arr_dmmv_nvfp4_f16_f32_data[reduc16], "main", mul_mat_vec_num_bindings, sizeof(vk_mat_vec_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq, i+1}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1095 |
+
|
| 1096 |
+
@@ -4697,6 +4711,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1097 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_id_f32[w][GGML_TYPE_IQ3_S], "mul_mat_vec_id_iq3_s_f32", arr_dmmv_id_iq3_s_f32_f32_len[reduc16], arr_dmmv_id_iq3_s_f32_f32_data[reduc16], "main", mul_mat_vec_id_num_bindings, sizeof(vk_mat_vec_id_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1098 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_id_f32[w][GGML_TYPE_IQ4_XS], "mul_mat_vec_id_iq4_xs_f32", arr_dmmv_id_iq4_xs_f32_f32_len[reduc16], arr_dmmv_id_iq4_xs_f32_f32_data[reduc16], "main", mul_mat_vec_id_num_bindings, sizeof(vk_mat_vec_id_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1099 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_id_f32[w][GGML_TYPE_IQ4_NL], "mul_mat_vec_id_iq4_nl_f32", arr_dmmv_id_iq4_nl_f32_f32_len[reduc16], arr_dmmv_id_iq4_nl_f32_f32_data[reduc16], "main", mul_mat_vec_id_num_bindings, sizeof(vk_mat_vec_id_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1100 |
+
+ ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_id_f32[w][GGML_TYPE_D2NL], "mul_mat_vec_id_d2nl_f32", arr_dmmv_id_d2nl_f32_f32_len[reduc16], arr_dmmv_id_d2nl_f32_f32_data[reduc16], "main", mul_mat_vec_id_num_bindings, sizeof(vk_mat_vec_id_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1101 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_id_f32[w][GGML_TYPE_MXFP4], "mul_mat_vec_id_mxfp4_f32", arr_dmmv_id_mxfp4_f32_f32_len[reduc16], arr_dmmv_id_mxfp4_f32_f32_data[reduc16], "main", mul_mat_vec_id_num_bindings, sizeof(vk_mat_vec_id_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1102 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant_mul_mat_vec_id_f32[w][GGML_TYPE_NVFP4], "mul_mat_vec_id_nvfp4_f32", arr_dmmv_id_nvfp4_f32_f32_len[reduc16], arr_dmmv_id_nvfp4_f32_f32_data[reduc16], "main", mul_mat_vec_id_num_bindings, sizeof(vk_mat_vec_id_push_constants), {rm_iq, 1, 1}, {wg_size_subgroup16, rm_iq}, 1, true, use_subgroups16, force_subgroup_size16);
|
| 1103 |
+
|
| 1104 |
+
@@ -4754,6 +4769,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1105 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant[GGML_TYPE_IQ3_S], "dequant_iq3_s", dequant_iq3_s_len, dequant_iq3_s_data, "main", 2, 5 * sizeof(uint32_t), {256 * 32, 1, 1}, {}, 1);
|
| 1106 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant[GGML_TYPE_IQ4_XS], "dequant_iq4_xs", dequant_iq4_xs_len, dequant_iq4_xs_data, "main", 2, 5 * sizeof(uint32_t), {256 * 32, 1, 1}, {}, 1);
|
| 1107 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant[GGML_TYPE_IQ4_NL], "dequant_iq4_nl", dequant_iq4_nl_len, dequant_iq4_nl_data, "main", 2, 5 * sizeof(uint32_t), {256 * 16, 1, 1}, {}, 1);
|
| 1108 |
+
+ ggml_vk_create_pipeline(device, device->pipeline_dequant[GGML_TYPE_D2NL], "dequant_d2nl", dequant_d2nl_len, dequant_d2nl_data, "main", 2, 5 * sizeof(uint32_t), {256 * 16, 1, 1}, {}, 1);
|
| 1109 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant[GGML_TYPE_MXFP4], "dequant_mxfp4", dequant_mxfp4_len, dequant_mxfp4_data, "main", 2, 5 * sizeof(uint32_t), {256 * 16, 1, 1}, {}, 1);
|
| 1110 |
+
ggml_vk_create_pipeline(device, device->pipeline_dequant[GGML_TYPE_NVFP4], "dequant_nvfp4", dequant_nvfp4_len, dequant_nvfp4_data, "main", 2, 5 * sizeof(uint32_t), {256 * 16, 1, 1}, {}, 1);
|
| 1111 |
+
|
| 1112 |
+
@@ -4782,6 +4798,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1113 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows[GGML_TYPE_IQ3_S], "get_rows_iq3_s", get_rows_iq3_s_len, get_rows_iq3_s_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1114 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows[GGML_TYPE_IQ4_XS], "get_rows_iq4_xs", get_rows_iq4_xs_len, get_rows_iq4_xs_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1115 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows[GGML_TYPE_IQ4_NL], "get_rows_iq4_nl", get_rows_iq4_nl_len, get_rows_iq4_nl_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1116 |
+
+ ggml_vk_create_pipeline(device, device->pipeline_get_rows[GGML_TYPE_D2NL], "get_rows_d2nl", get_rows_d2nl_len, get_rows_d2nl_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1117 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows[GGML_TYPE_MXFP4], "get_rows_mxfp4", get_rows_mxfp4_len, get_rows_mxfp4_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1118 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows[GGML_TYPE_NVFP4], "get_rows_nvfp4", get_rows_nvfp4_len, get_rows_nvfp4_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1119 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows[GGML_TYPE_I32], "get_rows_i32", get_rows_i32_len, get_rows_i32_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1120 |
+
@@ -4810,6 +4827,7 @@ static void ggml_vk_load_shaders(vk_device& device, vk_pipeline requested) {
|
| 1121 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows_f32[GGML_TYPE_IQ3_S], "get_rows_iq3_s_f32", get_rows_iq3_s_f32_len, get_rows_iq3_s_f32_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1122 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows_f32[GGML_TYPE_IQ4_XS], "get_rows_iq4_xs_f32", get_rows_iq4_xs_f32_len, get_rows_iq4_xs_f32_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1123 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows_f32[GGML_TYPE_IQ4_NL], "get_rows_iq4_nl_f32", get_rows_iq4_nl_f32_len, get_rows_iq4_nl_f32_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1124 |
+
+ ggml_vk_create_pipeline(device, device->pipeline_get_rows_f32[GGML_TYPE_D2NL], "get_rows_d2nl_f32", get_rows_d2nl_f32_len, get_rows_d2nl_f32_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1125 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows_f32[GGML_TYPE_MXFP4], "get_rows_mxfp4_f32", get_rows_mxfp4_f32_len, get_rows_mxfp4_f32_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1126 |
+
ggml_vk_create_pipeline(device, device->pipeline_get_rows_f32[GGML_TYPE_NVFP4], "get_rows_nvfp4_f32", get_rows_nvfp4_f32_len, get_rows_nvfp4_f32_data, "main", 3, sizeof(vk_op_binary_push_constants), {1024, 1, 1}, {}, 1);
|
| 1127 |
+
|
| 1128 |
+
@@ -6769,6 +6787,7 @@ static vk_pipeline ggml_vk_get_to_fp16(ggml_backend_vk_context * ctx, ggml_type
|
| 1129 |
+
case GGML_TYPE_IQ3_XXS:
|
| 1130 |
+
case GGML_TYPE_IQ3_S:
|
| 1131 |
+
case GGML_TYPE_IQ4_XS:
|
| 1132 |
+
+ case GGML_TYPE_D2NL:
|
| 1133 |
+
case GGML_TYPE_IQ4_NL:
|
| 1134 |
+
case GGML_TYPE_MXFP4:
|
| 1135 |
+
case GGML_TYPE_NVFP4:
|
| 1136 |
+
@@ -6843,6 +6862,7 @@ static vk_matmul_pipeline ggml_vk_get_mul_mat_mat_pipeline(ggml_backend_vk_conte
|
| 1137 |
+
case GGML_TYPE_IQ3_XXS:
|
| 1138 |
+
case GGML_TYPE_IQ3_S:
|
| 1139 |
+
case GGML_TYPE_IQ4_XS:
|
| 1140 |
+
+ case GGML_TYPE_D2NL:
|
| 1141 |
+
case GGML_TYPE_IQ4_NL:
|
| 1142 |
+
case GGML_TYPE_MXFP4:
|
| 1143 |
+
case GGML_TYPE_NVFP4:
|
| 1144 |
+
@@ -6911,6 +6931,7 @@ static vk_pipeline ggml_vk_get_dequantize_mul_mat_vec(ggml_backend_vk_context *
|
| 1145 |
+
case GGML_TYPE_IQ3_XXS:
|
| 1146 |
+
case GGML_TYPE_IQ3_S:
|
| 1147 |
+
case GGML_TYPE_IQ4_XS:
|
| 1148 |
+
+ case GGML_TYPE_D2NL:
|
| 1149 |
+
case GGML_TYPE_IQ4_NL:
|
| 1150 |
+
case GGML_TYPE_MXFP4:
|
| 1151 |
+
case GGML_TYPE_NVFP4:
|
| 1152 |
+
@@ -7004,6 +7025,7 @@ static vk_matmul_pipeline ggml_vk_get_mul_mat_mat_id_pipeline(ggml_backend_vk_co
|
| 1153 |
+
case GGML_TYPE_IQ3_XXS:
|
| 1154 |
+
case GGML_TYPE_IQ3_S:
|
| 1155 |
+
case GGML_TYPE_IQ4_XS:
|
| 1156 |
+
+ case GGML_TYPE_D2NL:
|
| 1157 |
+
case GGML_TYPE_IQ4_NL:
|
| 1158 |
+
case GGML_TYPE_MXFP4:
|
| 1159 |
+
case GGML_TYPE_NVFP4:
|
| 1160 |
+
@@ -7075,6 +7097,7 @@ static vk_pipeline ggml_vk_get_dequantize_mul_mat_vec_id(ggml_backend_vk_context
|
| 1161 |
+
case GGML_TYPE_IQ3_XXS:
|
| 1162 |
+
case GGML_TYPE_IQ3_S:
|
| 1163 |
+
case GGML_TYPE_IQ4_XS:
|
| 1164 |
+
+ case GGML_TYPE_D2NL:
|
| 1165 |
+
case GGML_TYPE_IQ4_NL:
|
| 1166 |
+
case GGML_TYPE_MXFP4:
|
| 1167 |
+
case GGML_TYPE_NVFP4:
|
| 1168 |
+
@@ -16528,6 +16551,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
|
| 1169 |
+
case GGML_TYPE_IQ3_XXS:
|
| 1170 |
+
case GGML_TYPE_IQ3_S:
|
| 1171 |
+
case GGML_TYPE_IQ4_XS:
|
| 1172 |
+
+ case GGML_TYPE_D2NL:
|
| 1173 |
+
case GGML_TYPE_IQ4_NL:
|
| 1174 |
+
case GGML_TYPE_MXFP4:
|
| 1175 |
+
case GGML_TYPE_NVFP4:
|
| 1176 |
+
@@ -16634,6 +16658,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
|
| 1177 |
+
case GGML_TYPE_IQ3_XXS:
|
| 1178 |
+
case GGML_TYPE_IQ3_S:
|
| 1179 |
+
case GGML_TYPE_IQ4_XS:
|
| 1180 |
+
+ case GGML_TYPE_D2NL:
|
| 1181 |
+
case GGML_TYPE_IQ4_NL:
|
| 1182 |
+
case GGML_TYPE_MXFP4:
|
| 1183 |
+
case GGML_TYPE_NVFP4:
|
| 1184 |
+
--- a/ggml/src/ggml-vulkan/vulkan-shaders/types.glsl
|
| 1185 |
+
+++ b/ggml/src/ggml-vulkan/vulkan-shaders/types.glsl
|
| 1186 |
+
@@ -1757,8 +1757,14 @@ struct block_nvfp4_packed32
|
| 1187 |
+
|
| 1188 |
+
#if defined(DATA_A_IQ4_NL) || defined(DATA_A_IQ4_XS)
|
| 1189 |
+
const int8_t kvalues_iq4nl_const[16] = {
|
| 1190 |
+
+#if defined(D2NL_TABLE)
|
| 1191 |
+
+ // Entrit d2nl: d2 levels {0, +-1, +-2.828, +-5.196, +-8} x 10.981; index 4 is zero (kvalues_d2nl in ggml-common.h)
|
| 1192 |
+
+ int8_t(-88), int8_t(-57), int8_t(-31), int8_t(-11), int8_t(0), int8_t(11), int8_t(31), int8_t(57),
|
| 1193 |
+
+ int8_t(88), int8_t(0), int8_t(0), int8_t(0), int8_t(0), int8_t(0), int8_t(0), int8_t(0)
|
| 1194 |
+
+#else
|
| 1195 |
+
int8_t(-127), int8_t(-104), int8_t(-83), int8_t(-65), int8_t(-49), int8_t(-35), int8_t(-22), int8_t(-10),
|
| 1196 |
+
int8_t(1), int8_t(13), int8_t(25), int8_t(38), int8_t(53), int8_t(69), int8_t(89), int8_t(113)
|
| 1197 |
+
+#endif
|
| 1198 |
+
};
|
| 1199 |
+
|
| 1200 |
+
shared FLOAT_TYPE kvalues_iq4nl[16];
|
| 1201 |
+
--- a/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp
|
| 1202 |
+
+++ b/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp
|
| 1203 |
+
@@ -66,6 +66,7 @@ const std::vector<std::string> type_names = {
|
| 1204 |
+
"iq3_s",
|
| 1205 |
+
"iq4_xs",
|
| 1206 |
+
"iq4_nl",
|
| 1207 |
+
+ "d2nl",
|
| 1208 |
+
"mxfp4",
|
| 1209 |
+
"nvfp4",
|
| 1210 |
+
"bf16",
|
| 1211 |
+
@@ -408,7 +409,18 @@ std::map<std::string, std::string> merge_maps(const std::map<std::string, std::s
|
| 1212 |
+
}
|
| 1213 |
+
|
| 1214 |
+
static std::vector<std::future<void>> compiles;
|
| 1215 |
+
-void string_to_spv(std::string name, const std::string& source, const std::map<std::string, std::string>& defines, bool fp16 = true, bool coopmat = false, bool coopmat2 = false, bool f16acc = false, const std::string& suffix = "") {
|
| 1216 |
+
+void string_to_spv(std::string name, const std::string& source_in, const std::map<std::string, std::string>& defines_in, bool fp16 = true, bool coopmat = false, bool coopmat2 = false, bool f16acc = false, const std::string& suffix = "") {
|
| 1217 |
+
+ // Entrit d2nl shaders are the IQ4_NL shaders with the d2 table (types.glsl, D2NL_TABLE).
|
| 1218 |
+
+ std::string source = source_in;
|
| 1219 |
+
+ std::map<std::string, std::string> defines = defines_in;
|
| 1220 |
+
+ if (defines.erase("DATA_A_D2NL")) {
|
| 1221 |
+
+ defines["DATA_A_IQ4_NL"] = "1";
|
| 1222 |
+
+ defines["D2NL_TABLE"] = "1";
|
| 1223 |
+
+ }
|
| 1224 |
+
+ const size_t d2nl_pos = source.find("d2nl");
|
| 1225 |
+
+ if (d2nl_pos != std::string::npos) {
|
| 1226 |
+
+ source.replace(d2nl_pos, 4, "iq4_nl");
|
| 1227 |
+
+ }
|
| 1228 |
+
name = name + (f16acc ? "_f16acc" : "") + (coopmat ? "_cm1" : "") + (coopmat2 ? "_cm2" : (fp16 ? "" : "_fp32")) + suffix;
|
| 1229 |
+
std::string out_path = join_paths(output_dir, name + ".spv");
|
| 1230 |
+
|
| 1231 |
+
@@ -558,7 +570,7 @@ void matmul_shaders(bool fp16, MatMulIdType matmul_id_type, bool coopmat, bool c
|
| 1232 |
+
std::string load_vec_quant = "2";
|
| 1233 |
+
if ((tname == "q1_0") || (tname == "q4_0") || (tname == "q4_1") || (tname == "q5_1") || (tname == "iq1_s") || (tname == "iq1_m") || (tname == "iq2_xxs") || (tname == "iq2_xs") || (tname == "iq2_s"))
|
| 1234 |
+
load_vec_quant = "8";
|
| 1235 |
+
- else if ((tname == "q2_0") || (tname == "q5_0") || (tname == "q8_0") || (tname == "q2_k") || (tname == "q4_k") || (tname == "q5_k") || (tname == "iq3_xxs") || (tname == "iq3_s") || (tname == "iq4_xs") || (tname == "iq4_nl") || (tname == "mxfp4") || (tname == "nvfp4"))
|
| 1236 |
+
+ else if ((tname == "q2_0") || (tname == "q5_0") || (tname == "q8_0") || (tname == "q2_k") || (tname == "q4_k") || (tname == "q5_k") || (tname == "iq3_xxs") || (tname == "iq3_s") || (tname == "iq4_xs") || (tname == "iq4_nl") || (tname == "d2nl") || (tname == "mxfp4") || (tname == "nvfp4"))
|
| 1237 |
+
load_vec_quant = "4";
|
| 1238 |
+
|
| 1239 |
+
if (tname == "bf16") {
|
| 1240 |
+
--- a/ggml/src/ggml.c
|
| 1241 |
+
+++ b/ggml/src/ggml.c
|
| 1242 |
+
@@ -861,6 +861,20 @@ static const struct ggml_type_traits type_traits[GGML_TYPE_COUNT] = {
|
| 1243 |
+
.to_float = (ggml_to_float_t) dequantize_row_iq4_nl,
|
| 1244 |
+
.from_float_ref = (ggml_from_float_t)quantize_row_iq4_nl_ref,
|
| 1245 |
+
},
|
| 1246 |
+
+ [43] = { // reserved
|
| 1247 |
+
+ .type_name = "TYPE_43 RESERVED",
|
| 1248 |
+
+ .blck_size = 0,
|
| 1249 |
+
+ .type_size = 0,
|
| 1250 |
+
+ .is_quantized = false,
|
| 1251 |
+
+ },
|
| 1252 |
+
+ [GGML_TYPE_D2NL] = {
|
| 1253 |
+
+ .type_name = "d2nl",
|
| 1254 |
+
+ .blck_size = QK_D2NL,
|
| 1255 |
+
+ .type_size = sizeof(block_d2nl),
|
| 1256 |
+
+ .is_quantized = true,
|
| 1257 |
+
+ .to_float = (ggml_to_float_t) dequantize_row_d2nl,
|
| 1258 |
+
+ .from_float_ref = (ggml_from_float_t) quantize_row_d2nl_ref,
|
| 1259 |
+
+ },
|
| 1260 |
+
[GGML_TYPE_IQ4_XS] = {
|
| 1261 |
+
.type_name = "iq4_xs",
|
| 1262 |
+
.blck_size = QK_K,
|
| 1263 |
+
@@ -1433,6 +1447,7 @@ enum ggml_type ggml_ftype_to_ggml_type(enum ggml_ftype ftype) {
|
| 1264 |
+
case GGML_FTYPE_MOSTLY_IQ1_S: wtype = GGML_TYPE_IQ1_S; break;
|
| 1265 |
+
case GGML_FTYPE_MOSTLY_IQ1_M: wtype = GGML_TYPE_IQ1_M; break;
|
| 1266 |
+
case GGML_FTYPE_MOSTLY_IQ4_NL: wtype = GGML_TYPE_IQ4_NL; break;
|
| 1267 |
+
+ case GGML_FTYPE_MOSTLY_D2NL: wtype = GGML_TYPE_D2NL; break;
|
| 1268 |
+
case GGML_FTYPE_MOSTLY_IQ4_XS: wtype = GGML_TYPE_IQ4_XS; break;
|
| 1269 |
+
case GGML_FTYPE_MOSTLY_IQ3_S: wtype = GGML_TYPE_IQ3_S; break;
|
| 1270 |
+
case GGML_FTYPE_MOSTLY_IQ2_S: wtype = GGML_TYPE_IQ2_S; break;
|
| 1271 |
+
@@ -7786,6 +7801,7 @@ size_t ggml_quantize_chunk(
|
| 1272 |
+
case GGML_TYPE_IQ1_S: result = quantize_iq1_s (src + start, (char *) dst + start_row * row_size, nrows, n_per_row, imatrix); break;
|
| 1273 |
+
case GGML_TYPE_IQ1_M: result = quantize_iq1_m (src + start, (char *) dst + start_row * row_size, nrows, n_per_row, imatrix); break;
|
| 1274 |
+
case GGML_TYPE_IQ4_NL: result = quantize_iq4_nl (src + start, (char *) dst + start_row * row_size, nrows, n_per_row, imatrix); break;
|
| 1275 |
+
+ case GGML_TYPE_D2NL: result = quantize_d2nl (src + start, (char *) dst + start_row * row_size, nrows, n_per_row, imatrix); break;
|
| 1276 |
+
case GGML_TYPE_IQ4_XS: result = quantize_iq4_xs (src + start, (char *) dst + start_row * row_size, nrows, n_per_row, imatrix); break;
|
| 1277 |
+
case GGML_TYPE_F16:
|
| 1278 |
+
{
|
| 1279 |
+
--- a/gguf-py/gguf/constants.py
|
| 1280 |
+
+++ b/gguf-py/gguf/constants.py
|
| 1281 |
+
@@ -4406,6 +4406,7 @@ class GGMLQuantizationType(IntEnum):
|
| 1282 |
+
NVFP4 = 40
|
| 1283 |
+
Q1_0 = 41
|
| 1284 |
+
Q2_0 = 42
|
| 1285 |
+
+ D2NL = 44
|
| 1286 |
+
|
| 1287 |
+
|
| 1288 |
+
class ExpertGatingFuncType(IntEnum):
|
| 1289 |
+
@@ -4461,6 +4462,7 @@ class LlamaFileType(IntEnum):
|
| 1290 |
+
MOSTLY_NVFP4 = 39 # except 1d tensors
|
| 1291 |
+
MOSTLY_Q1_0 = 40 # except 1d tensors
|
| 1292 |
+
MOSTLY_Q2_0 = 41 # except 1d tensors
|
| 1293 |
+
+ MOSTLY_D2NL = 43 # except 1d tensors
|
| 1294 |
+
|
| 1295 |
+
GUESSED = 1024 # not specified in the model file
|
| 1296 |
+
|
| 1297 |
+
@@ -4587,6 +4589,7 @@ GGML_QUANT_SIZES: dict[GGMLQuantizationType, tuple[int, int]] = {
|
| 1298 |
+
GGMLQuantizationType.NVFP4: (64, 4 + 32),
|
| 1299 |
+
GGMLQuantizationType.Q1_0: (128, 2 + 16),
|
| 1300 |
+
GGMLQuantizationType.Q2_0: (128, 2 + 32),
|
| 1301 |
+
+ GGMLQuantizationType.D2NL: (32, 2 + 16),
|
| 1302 |
+
}
|
| 1303 |
+
|
| 1304 |
+
|
| 1305 |
+
--- a/include/llama.h
|
| 1306 |
+
+++ b/include/llama.h
|
| 1307 |
+
@@ -156,6 +156,7 @@ extern "C" {
|
| 1308 |
+
LLAMA_FTYPE_MOSTLY_NVFP4 = 39, // except 1d tensors
|
| 1309 |
+
LLAMA_FTYPE_MOSTLY_Q1_0 = 40, // except 1d tensors
|
| 1310 |
+
LLAMA_FTYPE_MOSTLY_Q2_0 = 41, // except 1d tensors
|
| 1311 |
+
+ LLAMA_FTYPE_MOSTLY_D2NL = 43, // except 1d tensors
|
| 1312 |
+
|
| 1313 |
+
LLAMA_FTYPE_GUESSED = 1024, // not specified in the model file
|
| 1314 |
+
};
|
| 1315 |
+
--- a/src/llama-model-loader.cpp
|
| 1316 |
+
+++ b/src/llama-model-loader.cpp
|
| 1317 |
+
@@ -66,6 +66,7 @@ static std::string llama_model_ftype_name(llama_ftype ftype) {
|
| 1318 |
+
case LLAMA_FTYPE_MOSTLY_IQ1_S: return "IQ1_S - 1.5625 bpw";
|
| 1319 |
+
case LLAMA_FTYPE_MOSTLY_IQ1_M: return "IQ1_M - 1.75 bpw";
|
| 1320 |
+
case LLAMA_FTYPE_MOSTLY_IQ4_NL: return "IQ4_NL - 4.5 bpw";
|
| 1321 |
+
+ case LLAMA_FTYPE_MOSTLY_D2NL: return "D2NL - 4.5 bpw (Entrit d2)";
|
| 1322 |
+
case LLAMA_FTYPE_MOSTLY_IQ4_XS: return "IQ4_XS - 4.25 bpw";
|
| 1323 |
+
case LLAMA_FTYPE_MOSTLY_IQ3_S: return "IQ3_S - 3.4375 bpw";
|
| 1324 |
+
case LLAMA_FTYPE_MOSTLY_IQ3_M: return "IQ3_S mix - 3.66 bpw";
|
| 1325 |
+
@@ -758,6 +759,7 @@ llama_model_loader::llama_model_loader(
|
| 1326 |
+
case GGML_TYPE_IQ1_S: ftype = LLAMA_FTYPE_MOSTLY_IQ1_S; break;
|
| 1327 |
+
case GGML_TYPE_IQ1_M: ftype = LLAMA_FTYPE_MOSTLY_IQ1_M; break;
|
| 1328 |
+
case GGML_TYPE_IQ4_NL: ftype = LLAMA_FTYPE_MOSTLY_IQ4_NL; break;
|
| 1329 |
+
+ case GGML_TYPE_D2NL: ftype = LLAMA_FTYPE_MOSTLY_D2NL; break;
|
| 1330 |
+
case GGML_TYPE_IQ4_XS: ftype = LLAMA_FTYPE_MOSTLY_IQ4_XS; break;
|
| 1331 |
+
case GGML_TYPE_IQ3_S: ftype = LLAMA_FTYPE_MOSTLY_IQ3_S; break;
|
| 1332 |
+
case GGML_TYPE_NVFP4: ftype = LLAMA_FTYPE_MOSTLY_NVFP4; break;
|
| 1333 |
+
--- a/tests/test-backend-ops.cpp
|
| 1334 |
+
+++ b/tests/test-backend-ops.cpp
|
| 1335 |
+
@@ -7596,7 +7596,7 @@ static const ggml_type all_types[] = {
|
| 1336 |
+
// GGML_TYPE_TQ1_0, GGML_TYPE_TQ2_0, // TODO: implement for all backends
|
| 1337 |
+
GGML_TYPE_IQ2_XXS, GGML_TYPE_IQ2_XS, GGML_TYPE_IQ2_S,
|
| 1338 |
+
GGML_TYPE_IQ3_XXS, GGML_TYPE_IQ1_S, GGML_TYPE_IQ1_M,
|
| 1339 |
+
- GGML_TYPE_IQ4_NL, GGML_TYPE_IQ3_S, GGML_TYPE_IQ4_XS,
|
| 1340 |
+
+ GGML_TYPE_IQ4_NL, GGML_TYPE_IQ3_S, GGML_TYPE_IQ4_XS, GGML_TYPE_D2NL,
|
| 1341 |
+
};
|
| 1342 |
+
|
| 1343 |
+
static const ggml_type base_types[] = {
|
| 1344 |
+
@@ -7623,7 +7623,7 @@ static const ggml_type other_types[] = {
|
| 1345 |
+
// GGML_TYPE_TQ1_0, GGML_TYPE_TQ2_0, // TODO: implement for all backends
|
| 1346 |
+
GGML_TYPE_IQ2_XS, GGML_TYPE_IQ2_S,
|
| 1347 |
+
GGML_TYPE_IQ3_XXS, GGML_TYPE_IQ1_S, GGML_TYPE_IQ1_M,
|
| 1348 |
+
- GGML_TYPE_IQ4_NL, GGML_TYPE_IQ3_S, GGML_TYPE_IQ4_XS,
|
| 1349 |
+
+ GGML_TYPE_IQ4_NL, GGML_TYPE_IQ3_S, GGML_TYPE_IQ4_XS, GGML_TYPE_D2NL,
|
| 1350 |
+
GGML_TYPE_BF16,
|
| 1351 |
+
};
|
| 1352 |
+
|
run.sh
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Start a chat server for a model, then open http://localhost:8080 in your browser.
|
| 3 |
+
#
|
| 4 |
+
# ./run.sh models/<file>.gguf [extra llama-server options]
|
| 5 |
+
#
|
| 6 |
+
# Stop it with Ctrl-C.
|
| 7 |
+
set -euo pipefail
|
| 8 |
+
|
| 9 |
+
HERE=$(cd "$(dirname "$0")" && pwd)
|
| 10 |
+
MODEL=${1:?usage: ./run.sh models/<file>.gguf}
|
| 11 |
+
shift
|
| 12 |
+
SERVER="$HERE/build/bin/llama-server"
|
| 13 |
+
[[ -x "$SERVER" ]] || { echo "llama.cpp is not built yet. Run ./install.sh first."; exit 1; }
|
| 14 |
+
[[ -f "$MODEL" ]] || { echo "No model at $MODEL. Download one with ./get-model.sh first."; exit 1; }
|
| 15 |
+
|
| 16 |
+
OPTS=(-m "$MODEL" -ngl 99 -c 8192 --port 8080)
|
| 17 |
+
# On Linux, read the whole model into memory instead of paging it from disk. A model paged
|
| 18 |
+
# from a slow disk can make every token wait on the drive. Macs page from fast SSD, so skip it.
|
| 19 |
+
[[ "$(uname -s)" != Darwin ]] && OPTS+=(--no-mmap)
|
| 20 |
+
|
| 21 |
+
echo "Starting. When you see 'server is listening', open http://localhost:8080"
|
| 22 |
+
exec "$SERVER" "${OPTS[@]}" "$@"
|