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-04-24 16:10:58 +00:00
|
|
|
# renovate: datasource=github-tags depName=go-skynet/go-llama.cpp
|
2023-05-02 14:07:18 +00:00
|
|
|
GOLLAMA_VERSION?=llama.cpp-f4cef87
|
2023-04-24 16:10:58 +00:00
|
|
|
# renovate: datasource=git-refs packageNameTemplate=https://github.com/go-skynet/go-gpt4all-j.cpp currentValueTemplate=master depNameTemplate=go-gpt4all-j.cpp
|
2023-05-02 14:07:18 +00:00
|
|
|
GOGPT4ALLJ_VERSION?=1f7bff57f66cb7062e40d0ac3abd2217815e5109
|
2023-04-24 16:10:58 +00:00
|
|
|
# renovate: datasource=git-refs packageNameTemplate=https://github.com/go-skynet/go-gpt2.cpp currentValueTemplate=master depNameTemplate=go-gpt2.cpp
|
2023-04-22 09:05:23 +00:00
|
|
|
GOGPT2_VERSION?=245a5bfe6708ab80dc5c733dcdbfbe3cfd2acdaa
|
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-04-21 23:20:03 +00:00
|
|
|
C_INCLUDE_PATH=$(shell pwd)/go-llama:$(shell pwd)/go-gpt4all-j:$(shell pwd)/go-gpt2
|
2023-04-21 22:29:32 +00:00
|
|
|
LIBRARY_PATH=$(shell pwd)/go-llama:$(shell pwd)/go-gpt4all-j:$(shell pwd)/go-gpt2
|
|
|
|
|
|
|
|
# Use this if you want to set the default behavior
|
|
|
|
ifndef BUILD_TYPE
|
|
|
|
BUILD_TYPE:=default
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(BUILD_TYPE), "generic")
|
|
|
|
GENERIC_PREFIX:=generic-
|
|
|
|
else
|
|
|
|
GENERIC_PREFIX:=
|
|
|
|
endif
|
|
|
|
|
2023-04-15 23:39:07 +00:00
|
|
|
.PHONY: all test build vendor
|
|
|
|
|
|
|
|
all: help
|
|
|
|
|
|
|
|
## Build:
|
|
|
|
|
|
|
|
build: prepare ## Build the project
|
2023-04-21 22:29:32 +00:00
|
|
|
$(info ${GREEN}I local-ai build info:${RESET})
|
|
|
|
$(info ${GREEN}I BUILD_TYPE: ${YELLOW}$(BUILD_TYPE)${RESET})
|
|
|
|
C_INCLUDE_PATH=${C_INCLUDE_PATH} LIBRARY_PATH=${LIBRARY_PATH} $(GOCMD) build -o $(BINARY_NAME) ./
|
2023-04-19 15:10:29 +00:00
|
|
|
|
2023-04-21 22:29:32 +00:00
|
|
|
generic-build: ## Build the project using generic
|
|
|
|
BUILD_TYPE="generic" $(MAKE) build
|
2023-04-19 15:10:29 +00:00
|
|
|
|
2023-04-20 17:33:36 +00:00
|
|
|
## GPT4ALL-J
|
2023-04-19 15:10:29 +00:00
|
|
|
go-gpt4all-j:
|
2023-04-21 22:29:32 +00:00
|
|
|
git clone --recurse-submodules https://github.com/go-skynet/go-gpt4all-j.cpp go-gpt4all-j
|
2023-05-02 14:07:18 +00:00
|
|
|
cd go-gpt4all-j && git checkout -b build $(GOGPT4ALLJ_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-04-19 15:10:29 +00:00
|
|
|
@find ./go-gpt4all-j -type f -name "*.c" -exec sed -i'' -e 's/ggml_/ggml_gptj_/g' {} +
|
|
|
|
@find ./go-gpt4all-j -type f -name "*.cpp" -exec sed -i'' -e 's/ggml_/ggml_gptj_/g' {} +
|
|
|
|
@find ./go-gpt4all-j -type f -name "*.h" -exec sed -i'' -e 's/ggml_/ggml_gptj_/g' {} +
|
|
|
|
@find ./go-gpt4all-j -type f -name "*.cpp" -exec sed -i'' -e 's/gpt_/gptj_/g' {} +
|
|
|
|
@find ./go-gpt4all-j -type f -name "*.h" -exec sed -i'' -e 's/gpt_/gptj_/g' {} +
|
2023-04-20 17:33:36 +00:00
|
|
|
@find ./go-gpt4all-j -type f -name "*.cpp" -exec sed -i'' -e 's/json_/json_gptj_/g' {} +
|
|
|
|
@find ./go-gpt4all-j -type f -name "*.cpp" -exec sed -i'' -e 's/void replace/void json_gptj_replace/g' {} +
|
|
|
|
@find ./go-gpt4all-j -type f -name "*.cpp" -exec sed -i'' -e 's/::replace/::json_gptj_replace/g' {} +
|
2023-04-19 15:10:29 +00:00
|
|
|
|
|
|
|
go-gpt4all-j/libgptj.a: go-gpt4all-j
|
2023-05-02 14:07:18 +00:00
|
|
|
$(MAKE) -C go-gpt4all-j $(GENERIC_PREFIX)libgptj.a
|
2023-04-15 23:39:07 +00:00
|
|
|
|
2023-04-20 17:33:36 +00:00
|
|
|
# CEREBRAS GPT
|
2023-04-21 22:29:32 +00:00
|
|
|
go-gpt2:
|
|
|
|
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' {} +
|
|
|
|
@find ./go-gpt2 -type f -name "*.cpp" -exec sed -i'' -e 's/gpt_/gpt2_/g' {} +
|
|
|
|
@find ./go-gpt2 -type f -name "*.h" -exec sed -i'' -e 's/gpt_/gpt2_/g' {} +
|
|
|
|
@find ./go-gpt2 -type f -name "*.cpp" -exec sed -i'' -e 's/json_/json_gpt2_/g' {} +
|
|
|
|
|
|
|
|
go-gpt2/libgpt2.a: go-gpt2
|
|
|
|
$(MAKE) -C go-gpt2 $(GENERIC_PREFIX)libgpt2.a
|
|
|
|
|
2023-04-20 17:33:36 +00:00
|
|
|
|
2023-04-15 23:39:07 +00:00
|
|
|
go-llama:
|
|
|
|
git clone -b $(GOLLAMA_VERSION) --recurse-submodules https://github.com/go-skynet/go-llama.cpp go-llama
|
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
|
|
|
|
$(GOCMD) mod edit -replace github.com/go-skynet/go-gpt4all-j.cpp=$(shell pwd)/go-gpt4all-j
|
2023-04-21 22:29:32 +00:00
|
|
|
$(GOCMD) mod edit -replace github.com/go-skynet/go-gpt2.cpp=$(shell pwd)/go-gpt2
|
2023-04-20 17:33:36 +00:00
|
|
|
|
2023-04-29 18:38:37 +00:00
|
|
|
prepare-sources: go-llama go-gpt2 go-gpt4all-j
|
|
|
|
$(GOCMD) mod download
|
|
|
|
|
|
|
|
rebuild:
|
|
|
|
$(MAKE) -C go-llama clean
|
|
|
|
$(MAKE) -C go-gpt4all-j clean
|
|
|
|
$(MAKE) -C go-gpt2 clean
|
|
|
|
$(MAKE) build
|
|
|
|
|
|
|
|
prepare: prepare-sources go-llama/libbinding.a go-gpt4all-j/libgptj.a go-gpt2/libgpt2.a replace
|
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-04-19 15:10:29 +00:00
|
|
|
rm -rf ./go-gpt4all-j
|
2023-04-21 22:29:32 +00:00
|
|
|
rm -rf ./go-gpt2
|
2023-04-19 15:10:29 +00:00
|
|
|
rm -rf $(BINARY_NAME)
|
2023-04-15 23:39:07 +00:00
|
|
|
|
|
|
|
## Run:
|
|
|
|
run: prepare
|
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-04-29 12:56:00 +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) test -v -timeout 30m ./...
|
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)
|