Merged upstream, fixed OSX compile errors, integrated noavx2 build into main
This commit is contained in:
commit
4faae0afa9
15 changed files with 135 additions and 75 deletions
5
.ecrc
Normal file
5
.ecrc
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"Disable": {
|
||||
"IndentSize": true
|
||||
}
|
||||
}
|
16
.editorconfig
Normal file
16
.editorconfig
Normal file
|
@ -0,0 +1,16 @@
|
|||
# https://EditorConfig.org
|
||||
|
||||
# Top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file, utf-8 charset
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
17
.github/workflows/editorconfig.yml
vendored
Normal file
17
.github/workflows/editorconfig.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
name: EditorConfig Checker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
editorconfig:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: editorconfig-checker/action-editorconfig-checker@main
|
||||
- run: editorconfig-checker
|
37
Makefile
37
Makefile
|
@ -34,6 +34,7 @@ endif
|
|||
CFLAGS = -I. -Ofast -DNDEBUG -std=c11 -fPIC
|
||||
CXXFLAGS = -I. -I./examples -Ofast -DNDEBUG -std=c++11 -fPIC
|
||||
LDFLAGS =
|
||||
BONUSCFLAGS =
|
||||
|
||||
#lets try enabling everything
|
||||
CFLAGS += -pthread -s
|
||||
|
@ -71,7 +72,8 @@ endif
|
|||
# feel free to update the Makefile for your architecture and send a pull request or issue
|
||||
ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686))
|
||||
# Use all CPU extensions that are available:
|
||||
CFLAGS += -mf16c -mfma -mavx2 -mavx -msse3
|
||||
CFLAGS += -mf16c -mavx -msse3
|
||||
BONUSCFLAGS += -mfma -mavx2
|
||||
endif
|
||||
ifneq ($(filter ppc64%,$(UNAME_M)),)
|
||||
POWER9_M := $(shell grep "POWER9" /proc/cpuinfo)
|
||||
|
@ -122,17 +124,19 @@ ifneq ($(filter armv8%,$(UNAME_M)),)
|
|||
endif
|
||||
|
||||
OPENBLAS_BUILD =
|
||||
CLBLAST_BUILD =
|
||||
OPENBLAS_NOAVX2_BUILD =
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
OPENBLAS_BUILD = $(CXX) $(CXXFLAGS) ggml_openblas.o ggml_v1.o expose.o common.o llama_adapter.o gpttype_adapter.o lib/libopenblas.lib -shared -o koboldcpp_openblas.dll $(LDFLAGS)
|
||||
else
|
||||
OPENBLAS_BUILD = @echo 'Your OS $(OS) does not appear to be Windows. If you want to use openblas, please install it seperately, then link it manually with LLAMA_OPENBLAS=1. This is just a reminder, not an error.'
|
||||
endif
|
||||
|
||||
CLBLAST_BUILD =
|
||||
ifeq ($(OS),Windows_NT)
|
||||
CLBLAST_BUILD = $(CXX) $(CXXFLAGS) ggml_clblast.o ggml_v1.o expose.o common.o llama_adapter.o gpttype_adapter.o lib/OpenCL.lib lib/clblast.lib -shared -o koboldcpp_clblast.dll $(LDFLAGS)
|
||||
OPENBLAS_NOAVX2_BUILD = $(CXX) $(CXXFLAGS) ggml_openblas_noavx2.o ggml_v1.o expose.o common.o llama_adapter.o gpttype_adapter.o lib/libopenblas.lib -shared -o koboldcpp_openblas_noavx2.dll $(LDFLAGS)
|
||||
else
|
||||
CLBLAST_BUILD = @echo 'Your OS $(OS) does not appear to be Windows. If you want to use CLBlast, please install it seperately, then link it manually with LLAMA_CLBLAST=1. This is just a reminder, not an error.'
|
||||
ifndef LLAMA_OPENBLAS
|
||||
ifndef LLAMA_CLBLAST
|
||||
OPENBLAS_BUILD = @echo 'Your OS $(OS) does not appear to be Windows. For faster speeds, install and link a BLAS library. Set LLAMA_OPENBLAS=1 to compile with OpenBLAS support or LLAMA_CLBLAST=1 to compile with ClBlast support. This is just a reminder, not an error.'
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
#
|
||||
|
@ -150,22 +154,28 @@ $(info I CC: $(CCV))
|
|||
$(info I CXX: $(CXXV))
|
||||
$(info )
|
||||
|
||||
default: llamalib llamalib_openblas llamalib_clblast
|
||||
default: llamalib llamalib_openblas llamalib_openblas_noavx2 llamalib_clblast
|
||||
|
||||
#
|
||||
# Build library
|
||||
#
|
||||
|
||||
ggml.o: ggml.c ggml.h
|
||||
$(CC) $(CFLAGS) -c ggml.c -o ggml.o
|
||||
$(CC) $(CFLAGS) $(BONUSCFLAGS) -c ggml.c -o ggml.o
|
||||
|
||||
ggml_openblas.o: ggml.c ggml.h
|
||||
$(CC) $(CFLAGS) -DGGML_USE_OPENBLAS -c ggml.c -o ggml_openblas.o
|
||||
$(CC) $(CFLAGS) $(BONUSCFLAGS) -DGGML_USE_OPENBLAS -c ggml.c -o ggml_openblas.o
|
||||
|
||||
ggml_openblas_noavx2.o: ggml.c ggml.h
|
||||
$(CC) $(CFLAGS) -DGGML_USE_OPENBLAS -c ggml.c -o ggml_openblas_noavx2.o
|
||||
|
||||
ggml_clblast.o: ggml.c ggml.h
|
||||
$(CC) $(CFLAGS) -DGGML_USE_OPENBLAS -DGGML_USE_CLBLAST -c ggml.c -o ggml_clblast.o
|
||||
$(CC) $(CFLAGS) $(BONUSCFLAGS) -DGGML_USE_OPENBLAS -DGGML_USE_CLBLAST -c ggml.c -o ggml_clblast.o
|
||||
|
||||
ggml_v1.o: otherarch/ggml_v1.c otherarch/ggml_v1.h
|
||||
$(CC) $(CFLAGS) $(BONUSCFLAGS) -c otherarch/ggml_v1.c -o ggml_v1.o
|
||||
|
||||
ggml_v1_noavx2.o: otherarch/ggml_v1.c otherarch/ggml_v1.h
|
||||
$(CC) $(CFLAGS) -c otherarch/ggml_v1.c -o ggml_v1.o
|
||||
|
||||
llama.o: llama.cpp llama.h llama_internal.h
|
||||
|
@ -198,6 +208,9 @@ llamalib: ggml.o ggml_v1.o expose.o common.o llama_adapter.o gpttype_adapter.o
|
|||
llamalib_openblas: ggml_openblas.o ggml_v1.o expose.o common.o llama_adapter.o gpttype_adapter.o
|
||||
$(OPENBLAS_BUILD)
|
||||
|
||||
llamalib_openblas_noavx2: ggml_openblas_noavx2.o ggml_v1_noavx2.o expose.o common.o llama_adapter.o gpttype_adapter.o
|
||||
$(OPENBLAS_NOAVX2_BUILD)
|
||||
|
||||
llamalib_clblast: ggml_clblast.o ggml_v1.o expose.o common.o llama_adapter.o gpttype_adapter.o
|
||||
$(CLBLAST_BUILD)
|
||||
|
||||
|
|
4
ggml.c
4
ggml.c
|
@ -127,9 +127,9 @@ typedef void* thread_ret_t;
|
|||
|
||||
#ifdef GGML_USE_ACCELERATE
|
||||
#include <Accelerate/Accelerate.h>
|
||||
#elif GGML_USE_OPENBLAS
|
||||
#include <ggml_blas_adapter.c>
|
||||
#endif
|
||||
#include <ggml_blas_adapter.c>
|
||||
|
||||
|
||||
#undef MIN
|
||||
#undef MAX
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
//windows binaries for clblast obtained from https://github.com/CNugteren/CLBlast (apache license)
|
||||
//windows binaries for opencl obtained from https://github.com/KhronosGroup/OpenCL-SDK (apache license)
|
||||
|
||||
#if GGML_USE_OPENBLAS
|
||||
#include <cblas.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -104,21 +105,16 @@ static void ggml_cl_sgemm_wrapper(const enum CBLAS_ORDER order, const enum CBLAS
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
static void do_blas_sgemm(OPENBLAS_CONST enum CBLAS_ORDER Order, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransA, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransB, OPENBLAS_CONST blasint M, OPENBLAS_CONST blasint N, OPENBLAS_CONST blasint K,
|
||||
OPENBLAS_CONST float alpha, OPENBLAS_CONST float *A, OPENBLAS_CONST blasint lda, OPENBLAS_CONST float *B, OPENBLAS_CONST blasint ldb, OPENBLAS_CONST float beta, float *C, OPENBLAS_CONST blasint ldc)
|
||||
{
|
||||
#if GGML_USE_CLBLAST
|
||||
ggml_cl_sgemm_wrapper(Order, TransA, TransB,
|
||||
M, N, K,
|
||||
alpha, A, lda,
|
||||
B, ldb,
|
||||
beta, C, ldc);
|
||||
#else
|
||||
cblas_sgemm(Order, TransA, TransB,
|
||||
M, N, K,
|
||||
alpha, A, lda,
|
||||
B, ldb,
|
||||
beta, C, ldc);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(GGML_USE_ACCELERATE) || defined(GGML_USE_OPENBLAS)
|
||||
#if GGML_USE_CLBLAST
|
||||
#define do_blas_sgemm(Order, TransA, TransB,M, N, K,alpha, A, lda, B, ldb, beta, C, ldc) ({\
|
||||
ggml_cl_sgemm_wrapper(Order, TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc);\
|
||||
})
|
||||
#else
|
||||
#define do_blas_sgemm(Order, TransA, TransB,M, N, K,alpha, A, lda, B, ldb, beta, C, ldc) ({\
|
||||
cblas_sgemm(Order, TransA, TransB, M, N, K, alpha, A, lda, B, ldb, beta, C, ldc);\
|
||||
})
|
||||
#endif
|
||||
#endif
|
23
koboldcpp.py
23
koboldcpp.py
|
@ -36,11 +36,14 @@ class generation_outputs(ctypes.Structure):
|
|||
handle = None
|
||||
use_blas = False # if true, uses OpenBLAS for acceleration. libopenblas.dll must exist in the same dir.
|
||||
use_clblast = False #uses CLBlast instead
|
||||
use_noavx2 = False #uses openblas with no avx2 instructions
|
||||
|
||||
def init_library():
|
||||
global handle, use_blas, use_clblast
|
||||
global handle, use_blas, use_clblast, use_noavx2
|
||||
libname = ""
|
||||
if use_blas:
|
||||
if use_noavx2:
|
||||
libname = "koboldcpp_openblas_noavx2.dll"
|
||||
elif use_blas:
|
||||
libname = "koboldcpp_openblas.dll"
|
||||
elif use_clblast:
|
||||
libname = "koboldcpp_clblast.dll"
|
||||
|
@ -309,7 +312,7 @@ def RunServerMultiThreaded(addr, port, embedded_kailite = None):
|
|||
sys.exit(0)
|
||||
|
||||
def main(args):
|
||||
global use_blas, use_clblast
|
||||
global use_blas, use_clblast, use_noavx2
|
||||
if not os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "libopenblas.dll")) or not os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "koboldcpp_openblas.dll")):
|
||||
print("Warning: libopenblas.dll or koboldcpp_openblas.dll not found. Non-BLAS library will be used. Ignore this if you have manually linked with OpenBLAS.")
|
||||
use_blas = False
|
||||
|
@ -322,6 +325,14 @@ def main(args):
|
|||
else:
|
||||
print("Attempting to use CLBlast library for faster prompt ingestion. A compatible clblast.dll will be required.")
|
||||
use_clblast = True
|
||||
elif args.noavx2:
|
||||
if not os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "libopenblas.dll")) or not os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "koboldcpp_openblas_noavx2.dll")):
|
||||
print("Warning: libopenblas.dll or koboldcpp_openblas_noavx2.dll not found. This mode cannot be used.")
|
||||
elif os.name == 'nt':
|
||||
print("Attempting to use non-avx2 compatibility openblas library.")
|
||||
use_noavx2 = True
|
||||
else:
|
||||
print("Non-AVX2 compatibility OpenBLAS mode only available on windows. On other OS, please manually rebuild without AVX2 flags.")
|
||||
elif not args.noblas:
|
||||
print("Attempting to use OpenBLAS library for faster prompt ingestion. A compatible libopenblas.dll will be required.")
|
||||
use_blas = True
|
||||
|
@ -409,8 +420,10 @@ if __name__ == '__main__':
|
|||
parser.add_argument("--threads", help="Use a custom number of threads if specified. Otherwise, uses an amount based on CPU cores", type=int, default=default_threads)
|
||||
parser.add_argument("--psutil_set_threads", help="Experimental flag. If set, uses psutils to determine thread count based on physical cores.", action='store_true')
|
||||
parser.add_argument("--stream", help="Uses pseudo streaming", action='store_true')
|
||||
parser.add_argument("--noblas", help="Do not use OpenBLAS for accelerated prompt ingestion", action='store_true')
|
||||
parser.add_argument("--nommap", help="If set, do not use mmap to load newer models", action='store_true')
|
||||
parser.add_argument("--useclblast", help="Use CLBlast instead of OpenBLAS for prompt ingestion. Must specify exactly 2 arguments, platform ID and device ID (e.g. --useclblast 1 0).", type=int, choices=range(0,9), nargs=2)
|
||||
compatgroup = parser.add_mutually_exclusive_group()
|
||||
compatgroup.add_argument("--noblas", help="Do not use OpenBLAS for accelerated prompt ingestion", action='store_true')
|
||||
compatgroup.add_argument("--noavx2", help="Do not use AVX2 instructions, a slower compatibility mode for older devices. Does not work with --noblas or --clblast.", action='store_true')
|
||||
compatgroup.add_argument("--useclblast", help="Use CLBlast instead of OpenBLAS for prompt ingestion. Must specify exactly 2 arguments, platform ID and device ID (e.g. --useclblast 1 0).", type=int, choices=range(0,9), nargs=2)
|
||||
args = parser.parse_args()
|
||||
main(args)
|
||||
|
|
|
@ -1 +1 @@
|
|||
pyinstaller --noconfirm --onefile --clean --console --icon "./niko.ico" --add-data "./klite.embd;." --add-data "./koboldcpp.dll;." --add-data "./koboldcpp_openblas.dll;." --add-data "./libopenblas.dll;." --add-data "./koboldcpp_clblast.dll;." --add-data "./clblast.dll;." "./koboldcpp.py" -n "koboldcpp.exe"
|
||||
pyinstaller --noconfirm --onefile --clean --console --icon "./niko.ico" --add-data "./klite.embd;." --add-data "./koboldcpp.dll;." --add-data "./koboldcpp_openblas.dll;." --add-data "./koboldcpp_openblas_noavx2.dll;." --add-data "./libopenblas.dll;." --add-data "./koboldcpp_clblast.dll;." --add-data "./clblast.dll;." "./koboldcpp.py" -n "koboldcpp.exe"
|
Loading…
Add table
Add a link
Reference in a new issue