2023-04-15 23:39:07 +00:00
GOCMD = go
GOTEST = $( GOCMD) test
GOVET = $( GOCMD) vet
2023-04-19 16:43:10 +00:00
BINARY_NAME = local-ai
2023-05-04 10:26:59 +00:00
2023-05-11 21:43:55 +00:00
GOLLAMA_VERSION ?= 70593fccbe4b01dedaab805b0f25cb58192c7b38
2023-05-11 12:31:19 +00:00
GPT4ALL_REPO ?= https://github.com/go-skynet/gpt4all
GPT4ALL_VERSION ?= 3657f9417e17edf378c27d0a9274a1bf41caa914
2023-05-11 21:43:44 +00:00
GOGPT2_VERSION ?= 6a10572a23328e18a62cfdb45e4a3c8ddbe75f25
2023-05-03 13:51:54 +00:00
RWKV_REPO ?= https://github.com/donomii/go-rwkv.cpp
2023-05-10 23:13:28 +00:00
RWKV_VERSION ?= 07166da10cb2a9e8854395a4f210464dcea76e47
2023-05-09 09:43:50 +00:00
WHISPER_CPP_VERSION ?= bf2449dfae35a46b2cd92ab22661ce81a48d4993
2023-05-10 13:20:21 +00:00
BERT_VERSION ?= ec771ec715576ac050263bb7bb74bfd616a5ba13
2023-05-10 23:12:58 +00:00
BLOOMZ_VERSION ?= e9366e82abdfe70565644fbfae9651976714efd1
2023-05-09 09:43:50 +00:00
2023-05-03 09:45:22 +00:00
2023-04-15 23:39:07 +00:00
GREEN := $( shell tput -Txterm setaf 2)
YELLOW := $( shell tput -Txterm setaf 3)
WHITE := $( shell tput -Txterm setaf 7)
CYAN := $( shell tput -Txterm setaf 6)
RESET := $( shell tput -Txterm sgr0)
2023-05-11 12:31:19 +00:00
C_INCLUDE_PATH = $( shell pwd ) /go-llama:$( shell pwd ) /gpt4all/gpt4all-bindings/golang/:$( shell pwd ) /go-gpt2:$( shell pwd ) /go-rwkv:$( shell pwd ) /whisper.cpp:$( shell pwd ) /go-bert:$( shell pwd ) /bloomz
LIBRARY_PATH = $( shell pwd ) /go-llama:$( shell pwd ) /gpt4all/gpt4all-bindings/golang/:$( shell pwd ) /go-gpt2:$( shell pwd ) /go-rwkv:$( shell pwd ) /whisper.cpp:$( shell pwd ) /go-bert:$( shell pwd ) /bloomz
2023-04-21 22:29:32 +00:00
# Use this if you want to set the default behavior
i f n d e f B U I L D _ T Y P E
BUILD_TYPE:= default
e n d i f
i f e q ( $( BUILD_TYPE ) , "generic" )
GENERIC_PREFIX:= generic-
e l s e
GENERIC_PREFIX:=
e n d i f
2023-04-15 23:39:07 +00:00
.PHONY : all test build vendor
all : help
2023-05-11 12:31:19 +00:00
## GPT4ALL
gpt4all :
git clone --recurse-submodules $( GPT4ALL_REPO) gpt4all
cd gpt4all && git checkout -b build $( GPT4ALL_VERSION) && git submodule update --init --recursive --depth 1
2023-04-21 22:29:32 +00:00
# This is hackish, but needed as both go-llama and go-gpt4allj have their own version of ggml..
2023-05-11 12:31:19 +00:00
@find ./gpt4all -type f -name "*.c" -exec sed -i'' -e 's/ggml_/ggml_gptj_/g' { } +
@find ./gpt4all -type f -name "*.cpp" -exec sed -i'' -e 's/ggml_/ggml_gptj_/g' { } +
@find ./gpt4all -type f -name "*.h" -exec sed -i'' -e 's/ggml_/ggml_gptj_/g' { } +
@find ./gpt4all -type f -name "*.cpp" -exec sed -i'' -e 's/gpt_/gptj_/g' { } +
@find ./gpt4all -type f -name "*.h" -exec sed -i'' -e 's/gpt_/gptj_/g' { } +
@find ./gpt4all -type f -name "*.h" -exec sed -i'' -e 's/set_console_color/set_gptj_console_color/g' { } +
2023-05-11 17:38:27 +00:00
@find ./gpt4all -type f -name "*.cpp" -exec sed -i'' -e 's/set_console_color/set_gptj_console_color/g' { } +
2023-05-11 12:31:19 +00:00
@find ./gpt4all -type f -name "*.cpp" -exec sed -i'' -e 's/llama_/gptjllama_/g' { } +
@find ./gpt4all -type f -name "*.go" -exec sed -i'' -e 's/llama_/gptjllama_/g' { } +
@find ./gpt4all -type f -name "*.h" -exec sed -i'' -e 's/llama_/gptjllama_/g' { } +
@find ./gpt4all -type f -name "*.txt" -exec sed -i'' -e 's/llama_/gptjllama_/g' { } +
@find ./gpt4all -type f -name "*.cpp" -exec sed -i'' -e 's/json_/json_gptj_/g' { } +
@find ./gpt4all -type f -name "*.cpp" -exec sed -i'' -e 's/void replace/void json_gptj_replace/g' { } +
@find ./gpt4all -type f -name "*.cpp" -exec sed -i'' -e 's/::replace/::json_gptj_replace/g' { } +
mv ./gpt4all/gpt4all-backend/llama.cpp/llama_util.h ./gpt4all/gpt4all-backend/llama.cpp/gptjllama_util.h
2023-04-19 15:10:29 +00:00
2023-05-10 13:20:21 +00:00
## BERT embeddings
go-bert :
git clone --recurse-submodules https://github.com/go-skynet/go-bert.cpp go-bert
cd go-bert && git checkout -b build $( BERT_VERSION) && git submodule update --init --recursive --depth 1
@find ./go-bert -type f -name "*.c" -exec sed -i'' -e 's/ggml_/ggml_bert_/g' { } +
@find ./go-bert -type f -name "*.cpp" -exec sed -i'' -e 's/ggml_/ggml_bert_/g' { } +
@find ./go-bert -type f -name "*.h" -exec sed -i'' -e 's/ggml_/ggml_bert_/g' { } +
2023-05-03 09:45:22 +00:00
## RWKV
go-rwkv :
git clone --recurse-submodules $( RWKV_REPO) go-rwkv
cd go-rwkv && git checkout -b build $( RWKV_VERSION) && git submodule update --init --recursive --depth 1
2023-05-05 09:20:06 +00:00
@find ./go-rwkv -type f -name "*.c" -exec sed -i'' -e 's/ggml_/ggml_rwkv_/g' { } +
@find ./go-rwkv -type f -name "*.cpp" -exec sed -i'' -e 's/ggml_/ggml_rwkv_/g' { } +
@find ./go-rwkv -type f -name "*.h" -exec sed -i'' -e 's/ggml_/ggml_rwkv_/g' { } +
2023-05-03 09:45:22 +00:00
go-rwkv/librwkv.a : go -rwkv
cd go-rwkv && cd rwkv.cpp && cmake . -DRWKV_BUILD_SHARED_LIBRARY= OFF && cmake --build . && cp librwkv.a .. && cp ggml/src/libggml.a ..
2023-05-10 23:12:58 +00:00
## bloomz
bloomz :
git clone --recurse-submodules https://github.com/go-skynet/bloomz.cpp bloomz
@find ./bloomz -type f -name "*.c" -exec sed -i'' -e 's/ggml_/ggml_bloomz_/g' { } +
@find ./bloomz -type f -name "*.cpp" -exec sed -i'' -e 's/ggml_/ggml_bloomz_/g' { } +
@find ./bloomz -type f -name "*.h" -exec sed -i'' -e 's/ggml_/ggml_bloomz_/g' { } +
@find ./bloomz -type f -name "*.cpp" -exec sed -i'' -e 's/gpt_/gpt_bloomz_/g' { } +
@find ./bloomz -type f -name "*.h" -exec sed -i'' -e 's/gpt_/gpt_bloomz_/g' { } +
bloomz/libbloomz.a : bloomz
cd bloomz && make libbloomz.a
2023-05-10 13:20:21 +00:00
go-bert/libgobert.a : go -bert
$( MAKE) -C go-bert libgobert.a
2023-05-11 12:31:19 +00:00
gpt4all/gpt4all-bindings/golang/libgpt4all.a : gpt 4all
$( MAKE) -C gpt4all/gpt4all-bindings/golang/ $( GENERIC_PREFIX) libgpt4all.a
2023-04-15 23:39:07 +00:00
2023-05-03 09:45:22 +00:00
## CEREBRAS GPT
go-gpt2 :
2023-04-21 22:29:32 +00:00
git clone --recurse-submodules https://github.com/go-skynet/go-gpt2.cpp go-gpt2
2023-05-02 14:07:18 +00:00
cd go-gpt2 && git checkout -b build $( GOGPT2_VERSION) && git submodule update --init --recursive --depth 1
2023-04-21 22:29:32 +00:00
# This is hackish, but needed as both go-llama and go-gpt4allj have their own version of ggml..
@find ./go-gpt2 -type f -name "*.c" -exec sed -i'' -e 's/ggml_/ggml_gpt2_/g' { } +
@find ./go-gpt2 -type f -name "*.cpp" -exec sed -i'' -e 's/ggml_/ggml_gpt2_/g' { } +
@find ./go-gpt2 -type f -name "*.h" -exec sed -i'' -e 's/ggml_/ggml_gpt2_/g' { } +
2023-05-11 17:38:27 +00:00
@find ./go-gpt2 -type f -name "*.cpp" -exec sed -i'' -e 's/gpt_print_usage/gpt2_print_usage/g' { } +
@find ./go-gpt2 -type f -name "*.h" -exec sed -i'' -e 's/gpt_print_usage/gpt2_print_usage/g' { } +
@find ./go-gpt2 -type f -name "*.cpp" -exec sed -i'' -e 's/gpt_params_parse/gpt2_params_parse/g' { } +
@find ./go-gpt2 -type f -name "*.h" -exec sed -i'' -e 's/gpt_params_parse/gpt2_params_parse/g' { } +
@find ./go-gpt2 -type f -name "*.cpp" -exec sed -i'' -e 's/gpt_random_prompt/gpt2_random_prompt/g' { } +
@find ./go-gpt2 -type f -name "*.h" -exec sed -i'' -e 's/gpt_random_prompt/gpt2_random_prompt/g' { } +
2023-04-21 22:29:32 +00:00
@find ./go-gpt2 -type f -name "*.cpp" -exec sed -i'' -e 's/json_/json_gpt2_/g' { } +
go-gpt2/libgpt2.a : go -gpt 2
$( MAKE) -C go-gpt2 $( GENERIC_PREFIX) libgpt2.a
2023-04-20 17:33:36 +00:00
2023-05-09 09:43:50 +00:00
whisper.cpp :
git clone https://github.com/ggerganov/whisper.cpp.git
cd whisper.cpp && git checkout -b build $( WHISPER_CPP_VERSION) && git submodule update --init --recursive --depth 1
whisper.cpp/libwhisper.a : whisper .cpp
cd whisper.cpp && make libwhisper.a
2023-04-15 23:39:07 +00:00
go-llama :
2023-05-04 09:55:14 +00:00
git clone --recurse-submodules https://github.com/go-skynet/go-llama.cpp go-llama
cd go-llama && git checkout -b build $( GOLLAMA_VERSION) && git submodule update --init --recursive --depth 1
2023-04-19 15:10:29 +00:00
2023-04-29 18:38:37 +00:00
go-llama/libbinding.a : go -llama
2023-04-21 22:29:32 +00:00
$( MAKE) -C go-llama $( GENERIC_PREFIX) libbinding.a
2023-04-19 15:10:29 +00:00
2023-04-20 17:33:36 +00:00
replace :
2023-04-19 15:10:29 +00:00
$( GOCMD) mod edit -replace github.com/go-skynet/go-llama.cpp= $( shell pwd ) /go-llama
2023-05-11 12:31:19 +00:00
$( GOCMD) mod edit -replace github.com/nomic/gpt4all/gpt4all-bindings/golang= $( shell pwd ) /gpt4all/gpt4all-bindings/golang
2023-04-21 22:29:32 +00:00
$( GOCMD) mod edit -replace github.com/go-skynet/go-gpt2.cpp= $( shell pwd ) /go-gpt2
2023-05-03 09:45:22 +00:00
$( GOCMD) mod edit -replace github.com/donomii/go-rwkv.cpp= $( shell pwd ) /go-rwkv
2023-05-09 09:43:50 +00:00
$( GOCMD) mod edit -replace github.com/ggerganov/whisper.cpp= $( shell pwd ) /whisper.cpp
2023-05-10 13:20:21 +00:00
$( GOCMD) mod edit -replace github.com/go-skynet/go-bert.cpp= $( shell pwd ) /go-bert
2023-05-10 23:12:58 +00:00
$( GOCMD) mod edit -replace github.com/go-skynet/bloomz.cpp= $( shell pwd ) /bloomz
2023-04-20 17:33:36 +00:00
2023-05-11 12:31:19 +00:00
prepare-sources : go -llama go -gpt 2 gpt 4all go -rwkv whisper .cpp go -bert bloomz replace
2023-04-29 18:38:37 +00:00
$( GOCMD) mod download
2023-05-03 09:45:22 +00:00
## GENERIC
rebuild : ## Rebuilds the project
2023-04-29 18:38:37 +00:00
$( MAKE) -C go-llama clean
2023-05-11 12:31:19 +00:00
$( MAKE) -C gpt4all/gpt4all-bindings/golang/ clean
2023-04-29 18:38:37 +00:00
$( MAKE) -C go-gpt2 clean
2023-05-03 09:45:22 +00:00
$( MAKE) -C go-rwkv clean
2023-05-09 09:43:50 +00:00
$( MAKE) -C whisper.cpp clean
2023-05-10 13:20:21 +00:00
$( MAKE) -C go-bert clean
2023-05-10 23:12:58 +00:00
$( MAKE) -C bloomz clean
2023-04-29 18:38:37 +00:00
$( MAKE) build
2023-05-11 12:31:19 +00:00
prepare : prepare -sources gpt 4all /gpt 4all -bindings /golang /libgpt 4all .a go -llama /libbinding .a go -bert /libgobert .a go -gpt 2/libgpt 2.a go -rwkv /librwkv .a whisper .cpp /libwhisper .a bloomz /libbloomz .a ## Prepares for building
2023-04-19 15:10:29 +00:00
2023-04-15 23:39:07 +00:00
clean : ## Remove build related file
rm -fr ./go-llama
2023-05-11 12:31:19 +00:00
rm -rf ./gpt4all
2023-04-21 22:29:32 +00:00
rm -rf ./go-gpt2
2023-05-03 09:45:22 +00:00
rm -rf ./go-rwkv
2023-05-10 13:20:21 +00:00
rm -rf ./go-bert
2023-05-10 23:12:58 +00:00
rm -rf ./bloomz
2023-04-19 15:10:29 +00:00
rm -rf $( BINARY_NAME)
2023-04-15 23:39:07 +00:00
2023-05-03 09:45:22 +00:00
## Build:
build : prepare ## Build the project
$( info ${ GREEN } I local-ai build info:${ RESET } )
$( info ${ GREEN } I BUILD_TYPE: ${ YELLOW } $( BUILD_TYPE) ${ RESET } )
2023-05-11 12:31:19 +00:00
C_INCLUDE_PATH = ${ C_INCLUDE_PATH } LIBRARY_PATH = ${ LIBRARY_PATH } $( GOCMD) build -x -o $( BINARY_NAME) ./
2023-05-03 09:45:22 +00:00
generic-build : ## Build the project using generic
BUILD_TYPE = "generic" $( MAKE) build
## Run
run : prepare ## run local-ai
2023-04-21 22:29:32 +00:00
C_INCLUDE_PATH = ${ C_INCLUDE_PATH } LIBRARY_PATH = ${ LIBRARY_PATH } $( GOCMD) run ./main.go
2023-04-15 23:39:07 +00:00
2023-04-21 22:44:52 +00:00
test-models/testmodel :
mkdir test-models
wget https://huggingface.co/concedo/cerebras-111M-ggml/resolve/main/cerberas-111m-q4_0.bin -O test-models/testmodel
2023-04-27 04:18:18 +00:00
cp tests/fixtures/* test-models
2023-04-21 22:44:52 +00:00
test : prepare test -models /testmodel
2023-04-27 04:18:18 +00:00
cp tests/fixtures/* test-models
2023-05-10 13:20:21 +00:00
@C_INCLUDE_PATH= ${ C_INCLUDE_PATH } LIBRARY_PATH = ${ LIBRARY_PATH } CONFIG_FILE = $( abspath ./) /test-models/config.yaml MODELS_PATH = $( abspath ./) /test-models $( GOCMD) run github.com/onsi/ginkgo/v2/ginkgo -v -r ./api
2023-04-15 23:39:07 +00:00
## Help:
help : ## Show this help.
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk ' BEGIN { FS = ":.*?## " } { \
if ( /^[ a-zA-Z_-] +:.*?##.*$$ /) { printf " ${ YELLOW } %-20s ${ GREEN } %s ${ RESET } \n " , $$ 1, $$ 2} \
else if ( /^## .*$$ /) { printf " ${ CYAN } %s ${ RESET } \n " , substr( $$ 1,4) } \
2023-04-17 19:34:02 +00:00
} ' $( MAKEFILE_LIST)