Go to file
Kawrakow 97680f602c Update README.md 2024-07-23 12:23:06 +02:00
.devops `build`: rename main → llama-cli, server → llama-server, llava-cli → llama-llava-cli, etc... (#7809) 2024-06-13 00:41:52 +01:00
.github Remove all workflows 2024-06-27 09:45:56 +03:00
ci `build`: rename main → llama-cli, server → llama-server, llava-cli → llama-llava-cli, etc... (#7809) 2024-06-13 00:41:52 +01:00
cmake ggml : prevent builds with -ffinite-math-only (#7726) 2024-06-04 17:01:09 +10:00
common imatrix: be able to specify the name of the output tensor 2024-06-26 17:38:18 +03:00
docs `build`: rename main → llama-cli, server → llama-server, llava-cli → llama-llava-cli, etc... (#7809) 2024-06-13 00:41:52 +01:00
examples imatrix: be able to specify the name of the output tensor 2024-06-26 17:38:18 +03:00
ggml-cuda iq1bn(no lookup): better version 2024-07-17 08:54:11 +03:00
ggml-sycl [SYCL] Fix windows build and inference (#8003) 2024-06-20 21:19:05 +08:00
gguf-py bitnet: python + llama 2024-06-22 12:02:51 +03:00
grammars `build`: rename main → llama-cli, server → llama-server, llava-cli → llama-llava-cli, etc... (#7809) 2024-06-13 00:41:52 +01:00
kompute@4565194ed7 Nomic Vulkan backend (#4456) 2024-01-29 15:50:50 -05:00
kompute-shaders ggml : refactor rope norm/neox (#7634) 2024-06-05 11:29:20 +03:00
media README: add graphic for matrix multiplication (#6881) 2024-04-24 21:29:13 +02:00
models Per token attributes (#7685) 2024-06-04 09:17:17 +02:00
pocs `build`: rename main → llama-cli, server → llama-server, llava-cli → llama-llava-cli, etc... (#7809) 2024-06-13 00:41:52 +01:00
prompts llama : add Qwen support (#4281) 2023-12-01 20:16:31 +02:00
requirements requirements : Bump torch and numpy for python3.12 (#8041) 2024-06-20 22:01:15 +02:00
scripts tokenizer : BPE fixes (#7530) 2024-06-18 18:40:52 +02:00
spm-headers swift : package no longer use ggml dependency (#5465) 2024-02-12 19:54:29 +02:00
tests bitnet: qnfs tests 2024-06-22 12:02:53 +03:00
vulkan-shaders Vulkan Shader Refactor, Memory Debugging Option (#7947) 2024-06-16 07:17:31 +02:00
.dockerignore `build`: rename main → llama-cli, server → llama-server, llava-cli → llama-llava-cli, etc... (#7809) 2024-06-13 00:41:52 +01:00
.ecrc Nomic Vulkan backend (#4456) 2024-01-29 15:50:50 -05:00
.editorconfig Add `cvector-generator` example (#7514) 2024-06-15 18:53:40 +02:00
.flake8 py : logging and flake8 suppression refactoring (#7081) 2024-05-05 08:07:48 +03:00
.gitignore un-ignore `build-info.cmake` and `build-info.sh` (#7996) 2024-06-19 22:10:42 +02:00
.gitmodules Nomic Vulkan backend (#4456) 2024-01-29 15:50:50 -05:00
.pre-commit-config.yaml convert.py : add python logging instead of print() (#6511) 2024-05-03 22:36:41 +03:00
AUTHORS license : update copyright notice + add AUTHORS (#6405) 2024-04-09 09:23:19 +03:00
CMakeLists.txt bitnet: CUDA, scalar, AVX2 2024-06-22 12:02:51 +03:00
CMakePresets.json [SYCL] Fix windows build and inference (#8003) 2024-06-20 21:19:05 +08:00
CONTRIBUTING.md docs: Added initial PR template with directions for doc only changes and squash merges [no ci] (#7700) 2024-06-10 01:24:29 +10:00
LICENSE license : update copyright notice + add AUTHORS (#6405) 2024-04-09 09:23:19 +03:00
Makefile Fix Makefile, add GGML_USE_IQK_MULMAT ifdefs to iqk-quantize 2024-07-17 16:51:34 +03:00
Package.swift ggml : add llamafile sgemm (#6414) 2024-04-16 21:55:30 +03:00
README-sycl.md [SYCL] Fix windows build and inference (#8003) 2024-06-20 21:19:05 +08:00
README.md Update README.md 2024-07-23 12:23:06 +02:00
SECURITY.md chore: Fix markdown warnings (#6625) 2024-04-12 10:52:36 +02:00
convert-hf-to-gguf-update.py convert-hf : Fix the encoding in the convert-hf-to-gguf-update.py (#8040) 2024-06-20 21:59:59 +02:00
convert-hf-to-gguf.py bitnet: put the scale in a separate tensor 2024-06-22 12:02:52 +03:00
convert-llama-ggml-to-gguf.py convert.py : add python logging instead of print() (#6511) 2024-05-03 22:36:41 +03:00
flake.lock flake.lock: Update (#7951) 2024-06-16 09:16:21 -07:00
flake.nix `build`: rename main → llama-cli, server → llama-server, llava-cli → llama-llava-cli, etc... (#7809) 2024-06-13 00:41:52 +01:00
ggml-alloc.c move BLAS to a separate backend (#6210) 2024-06-13 03:11:35 +02:00
ggml-alloc.h llama : add pipeline parallelism support (#6017) 2024-03-13 18:54:21 +01:00
ggml-backend-impl.h move BLAS to a separate backend (#6210) 2024-06-13 03:11:35 +02:00
ggml-backend.c whisper : use ggml_backend_sched (whisper/2239) 2024-06-18 09:50:40 +03:00
ggml-backend.h whisper : use ggml_backend_sched (whisper/2239) 2024-06-18 09:50:40 +03:00
ggml-blas.cpp move BLAS to a separate backend (#6210) 2024-06-13 03:11:35 +02:00
ggml-blas.h move BLAS to a separate backend (#6210) 2024-06-13 03:11:35 +02:00
ggml-common.h Remove the no longer used iq1bn_grid_u16 2024-07-17 10:16:50 +03:00
ggml-cuda.cu Bitnet(2.25 bpw): CUDA 2024-06-22 12:02:52 +03:00
ggml-cuda.h Capture CUDA logging output (#7298) 2024-05-19 00:44:42 +02:00
ggml-impl.h Make updates to type cast based on compiler instead of OS (#7851) 2024-06-17 20:23:17 +02:00
ggml-kompute.cpp move BLAS to a separate backend (#6210) 2024-06-13 03:11:35 +02:00
ggml-kompute.h Nomic Vulkan backend (#4456) 2024-01-29 15:50:50 -05:00
ggml-metal.h ggml : remove OpenCL (#7735) 2024-06-04 21:23:20 +03:00
ggml-metal.m Adding add_4, mul_4, div_4 kernels to Metal 2024-06-24 10:22:10 +02:00
ggml-metal.metal iq1bn(no lookup): better version 2024-07-17 08:54:11 +03:00
ggml-quants.c bitnet: qnfs tests 2024-06-22 12:02:53 +03:00
ggml-quants.h iq1bn: adjust scalar dot product and some cleanup 2024-07-17 08:44:46 +02:00
ggml-rpc.cpp rpc : fix load/store misaligned addresses (#7948) 2024-06-17 11:09:20 +03:00
ggml-rpc.h ggml : add RPC backend (#6829) 2024-05-14 14:27:19 +03:00
ggml-sycl.cpp [SYCL] Fix windows build and inference (#8003) 2024-06-20 21:19:05 +08:00
ggml-sycl.h [SYCL] remove global variables (#7710) 2024-06-15 14:05:10 +08:00
ggml-vulkan-shaders.hpp Vulkan Shader Refactor, Memory Debugging Option (#7947) 2024-06-16 07:17:31 +02:00
ggml-vulkan.cpp vulkan: detect multiple devices by deviceUUID instead of deviceID (#8022) 2024-06-21 10:28:20 +02:00
ggml-vulkan.h Vulkan k-quant mmq and ggml-backend offload functionality (#6155) 2024-03-29 17:29:21 +01:00
ggml.c iqk_mul_mat: attentions matrix multiplications 2024-07-18 14:00:56 +03:00
ggml.h bitnet: add 2 bpw quantization 2024-06-22 12:02:51 +03:00
ggml_vk_generate_shaders.py Vulkan Shader Refactor, Memory Debugging Option (#7947) 2024-06-16 07:17:31 +02:00
iqk-quantize.cpp Fix Makefile, add GGML_USE_IQK_MULMAT ifdefs to iqk-quantize 2024-07-17 16:51:34 +03:00
iqk-quantize.h Bitnet(1.75 bpw): higher precision fp8 scale 2024-06-22 12:02:52 +03:00
iqk_mul_mat.cpp iqk_mul_mat(f16): make it work for row sizes that are multiple of 4 on NEON 2024-07-18 13:55:51 +02:00
iqk_mul_mat.h iqk_mul_mat: be independent of llamafile_sgemm (WIP) 2024-06-22 12:02:50 +03:00
llama.cpp When tokenizer info is missing in the model, use llama3 by default 2024-07-19 12:29:01 +03:00
llama.h bitnet: add 2 bpw quantization 2024-06-22 12:02:51 +03:00
mypy.ini convert : partially revert PR #4818 (#5041) 2024-01-20 18:14:18 -05:00
pyrightconfig.json convert-hf : save memory with lazy evaluation (#7075) 2024-05-08 18:16:38 -04:00
requirements.txt Move convert.py to examples/convert-legacy-llama.py (#7430) 2024-05-30 21:40:00 +10:00
sgemm.cpp iqk_mul_mat: be independent of llamafile_sgemm (WIP) 2024-06-22 12:02:50 +03:00
sgemm.h llamafile : use 64-bit integers in sgemm (#6928) 2024-04-26 17:05:33 +03:00
unicode-data.cpp tokenizer : BPE fixes (#7530) 2024-06-18 18:40:52 +02:00
unicode-data.h Unicode codepoint flags for custom regexs (#7245) 2024-05-18 01:09:13 +02:00
unicode.cpp llama : optimize long word tokenization with WPM (#8034) 2024-06-21 08:51:28 +03:00
unicode.h unicode : avoid char32_t (#7957) 2024-06-16 14:51:40 +03:00

README.md

llama.cpp clone with better CPU performance

License: MIT


Table of Contents
  1. Description
  2. Usage
  3. Contributing
  4. Coding guidelines
  5. Docs

TL;DR

This repository is a clone of llama.cpp with the following improvements

  • Better implementation of CPU matrix multiplications (AVX2 and ARM_NEON) for fp16/fp32 and all k-, i-, and legacy llama.cpp quants, that leads to a significant improvement in prompt processing (PP) speed. Token generation (TG) also benefits, but to a lesser extent due to TG being memory bound
  • Implementation of the Bitnet b1.58 model for the CPU (AVX2 and ARM_NEON) and GPU (CUDA and Metal)
  • Faster CPU inferrence for MoE models

If you are not already familiar with llama.cpp, it is better to start there. For those familiar with llama.cpp, everything works the same as llama.cpp (or at least the way llama.cpp worked when I last synced on June 21).

Note that I have published some, but not all, of the code in the respository in a series of llamafile PRs (394, 405, 428, 435, 453, and 464)

Why

Mostly out of curiosity:

  • Justine Tunney's tinyBLAS, which she contributed to llama.cpp in PR 6414, only works for Q4_0, Q8_0 and fp16/bf16 models. In the surrounding discussion about possibly extending tinyBLAS to k- and i-quants, she felt that k-quants are not ammenable to block-tiling, which is required to improve performance. This statement piqued my curiosity, so here we are.
  • Bitnet-1.58b has been one of the most discussed topics in the llama.cpp project, so eventually I decided to see how efficiently one can implement a tertiary model

Curiosity aside, improved CPU performance may be (or may become) important in practice. According to The Register, 70% of AI inferrence is done on the CPU, at least in the Android world. With ever increasing number of LLM model parameters, and with Meta's 400B model release imminent, the CPU may become the only option for people not willing (or not able to) rent/buy uber expensive GPU instances capable of running such models. Granted, one would need a pretty beefy computer to run a 400B model, inference speed will be sluggsh, but at least one will not need to spend the equivalent of a luxury apartmenty in the downtown of the city where I live.

Bitnet-1.58B

Two implementations are provided

  • IQ1_BN - uses 1.625 bits-per-weight (bpw)
  • IQ2_BN - uses 2.0 bpw

IQ2_BN is faster for PP. IQ1_BN can arrive at a higher TG performance on the CPU (given enough threads), but is always slower on the GPU.

There is the unmerged PR 8151 in llama.cpp that implements Bitnet-1.58B for the CPU (AVX and ARM_NEON). The following table compares performance between this repo and PR-8151 in llama.cpp.

Performance comparison to llama.cpp

The results in the following table are obtained with the following parameters:

  • Model is LLaMA-v3-8B
  • The AVX2 CPU is a 16-core Ryzen-7950X
  • The ARM_NEON CPU is M2-Max
  • tinyBLAS is enabled in llama.cpp
  • llama.cpp results are for build: 081fe431 (3441), which is the master branch as of July 23 2024.

MoE models

There is PR-6840 from Justine Tunney in llama.cpp, but it has not been merged since April 23, so I'll compare performance to the master branch for Mixtral-8x7B.

To tile or not to tile