Skip to content

Commit f75ab47

Browse files
committed
feat(rwkv): use rwkv from llama.cpp
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 7492179 commit f75ab47

File tree

10 files changed

+43
-61
lines changed

10 files changed

+43
-61
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ prepare-sources
1212

1313
go-ggml-transformers
1414
go-gpt2
15-
go-rwkv
1615
whisper.cpp
1716
/bloomz
1817
go-bert

Makefile

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ GOLLAMA_REPO?=https://github.com/go-skynet/go-llama.cpp
1010
GOLLAMA_VERSION?=2b57a8ae43e4699d3dc5d1496a1ccd42922993be
1111
CPPLLAMA_VERSION?=cce5a9007572c6e9fa522296b77571d2e5071357
1212

13-
# go-rwkv version
14-
RWKV_REPO?=https://github.com/donomii/go-rwkv.cpp
15-
RWKV_VERSION?=661e7ae26d442f5cfebd2a0881b44e8c55949ec6
16-
1713
# whisper.cpp version
1814
WHISPER_REPO?=https://github.com/ggerganov/whisper.cpp
1915
WHISPER_CPP_VERSION?=6266a9f9e56a5b925e9892acf650f3eb1245814d
@@ -209,7 +205,6 @@ ALL_GRPC_BACKENDS+=backend-assets/grpc/llama-cpp-fallback
209205
ALL_GRPC_BACKENDS+=backend-assets/grpc/llama-ggml
210206
ALL_GRPC_BACKENDS+=backend-assets/grpc/llama-cpp-grpc
211207
ALL_GRPC_BACKENDS+=backend-assets/util/llama-cpp-rpc-server
212-
ALL_GRPC_BACKENDS+=backend-assets/grpc/rwkv
213208
ALL_GRPC_BACKENDS+=backend-assets/grpc/whisper
214209
ALL_GRPC_BACKENDS+=backend-assets/grpc/local-store
215210
ALL_GRPC_BACKENDS+=backend-assets/grpc/silero-vad
@@ -272,20 +267,6 @@ sources/go-piper:
272267
sources/go-piper/libpiper_binding.a: sources/go-piper
273268
$(MAKE) -C sources/go-piper libpiper_binding.a example/main piper.o
274269

275-
276-
## RWKV
277-
sources/go-rwkv.cpp:
278-
mkdir -p sources/go-rwkv.cpp
279-
cd sources/go-rwkv.cpp && \
280-
git init && \
281-
git remote add origin $(RWKV_REPO) && \
282-
git fetch origin && \
283-
git checkout $(RWKV_VERSION) && \
284-
git submodule update --init --recursive --depth 1 --single-branch
285-
286-
sources/go-rwkv.cpp/librwkv.a: sources/go-rwkv.cpp
287-
cd sources/go-rwkv.cpp && cd rwkv.cpp && cmake . -DRWKV_BUILD_SHARED_LIBRARY=OFF && cmake --build . && cp librwkv.a ..
288-
289270
## stable diffusion
290271
sources/go-stable-diffusion:
291272
mkdir -p sources/go-stable-diffusion
@@ -339,10 +320,9 @@ sources/whisper.cpp:
339320
sources/whisper.cpp/libwhisper.a: sources/whisper.cpp
340321
cd sources/whisper.cpp && $(MAKE) libwhisper.a libggml.a
341322

342-
get-sources: sources/go-llama.cpp sources/go-piper sources/go-rwkv.cpp sources/whisper.cpp sources/go-bert.cpp sources/go-stable-diffusion sources/go-tiny-dream backend/cpp/llama/llama.cpp
323+
get-sources: sources/go-llama.cpp sources/go-piper sources/whisper.cpp sources/go-bert.cpp sources/go-stable-diffusion sources/go-tiny-dream backend/cpp/llama/llama.cpp
343324

344325
replace:
345-
$(GOCMD) mod edit -replace github.com/donomii/go-rwkv.cpp=$(CURDIR)/sources/go-rwkv.cpp
346326
$(GOCMD) mod edit -replace github.com/ggerganov/whisper.cpp=$(CURDIR)/sources/whisper.cpp
347327
$(GOCMD) mod edit -replace github.com/ggerganov/whisper.cpp/bindings/go=$(CURDIR)/sources/whisper.cpp/bindings/go
348328
$(GOCMD) mod edit -replace github.com/go-skynet/go-bert.cpp=$(CURDIR)/sources/go-bert.cpp
@@ -352,7 +332,6 @@ replace:
352332
$(GOCMD) mod edit -replace github.com/go-skynet/go-llama.cpp=$(CURDIR)/sources/go-llama.cpp
353333

354334
dropreplace:
355-
$(GOCMD) mod edit -dropreplace github.com/donomii/go-rwkv.cpp
356335
$(GOCMD) mod edit -dropreplace github.com/ggerganov/whisper.cpp
357336
$(GOCMD) mod edit -dropreplace github.com/ggerganov/whisper.cpp/bindings/go
358337
$(GOCMD) mod edit -dropreplace github.com/go-skynet/go-bert.cpp
@@ -368,7 +347,6 @@ prepare-sources: get-sources replace
368347
rebuild: ## Rebuilds the project
369348
$(GOCMD) clean -cache
370349
$(MAKE) -C sources/go-llama.cpp clean
371-
$(MAKE) -C sources/go-rwkv.cpp clean
372350
$(MAKE) -C sources/whisper.cpp clean
373351
$(MAKE) -C sources/go-stable-diffusion clean
374352
$(MAKE) -C sources/go-bert.cpp clean
@@ -477,8 +455,6 @@ test-models/testmodel.ggml:
477455
wget -q https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin -O test-models/whisper-en
478456
wget -q https://huggingface.co/mudler/all-MiniLM-L6-v2/resolve/main/ggml-model-q4_0.bin -O test-models/bert
479457
wget -q https://cdn.openai.com/whisper/draft-20220913a/micro-machines.wav -O test-dir/audio.wav
480-
wget -q https://huggingface.co/mudler/rwkv-4-raven-1.5B-ggml/resolve/main/RWKV-4-Raven-1B5-v11-Eng99%2525-Other1%2525-20230425-ctx4096_Q4_0.bin -O test-models/rwkv
481-
wget -q https://raw.githubusercontent.com/saharNooby/rwkv.cpp/5eb8f09c146ea8124633ab041d9ea0b1f1db4459/rwkv/20B_tokenizer.json -O test-models/rwkv.tokenizer.json
482458
cp tests/models_fixtures/* test-models
483459

484460
prepare-test: grpcs
@@ -855,13 +831,6 @@ ifneq ($(UPX),)
855831
$(UPX) backend-assets/grpc/piper
856832
endif
857833

858-
backend-assets/grpc/rwkv: sources/go-rwkv.cpp sources/go-rwkv.cpp/librwkv.a backend-assets/grpc
859-
CGO_LDFLAGS="$(CGO_LDFLAGS)" C_INCLUDE_PATH=$(CURDIR)/sources/go-rwkv.cpp LIBRARY_PATH=$(CURDIR)/sources/go-rwkv.cpp \
860-
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/rwkv ./backend/go/llm/rwkv
861-
ifneq ($(UPX),)
862-
$(UPX) backend-assets/grpc/rwkv
863-
endif
864-
865834
backend-assets/grpc/stablediffusion: sources/go-stable-diffusion sources/go-stable-diffusion/libstablediffusion.a backend-assets/grpc
866835
CGO_LDFLAGS="$(CGO_LDFLAGS)" CPATH="$(CPATH):$(CURDIR)/sources/go-stable-diffusion/:/usr/include/opencv4" LIBRARY_PATH=$(CURDIR)/sources/go-stable-diffusion/ \
867836
$(GOCMD) build -ldflags "$(LD_FLAGS)" -tags "$(GO_TAGS)" -o backend-assets/grpc/stablediffusion ./backend/go/image/stablediffusion

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ LocalAI couldn't have been built without the help of great software already avai
241241
- https://github.com/antimatter15/alpaca.cpp
242242
- https://github.com/EdVince/Stable-Diffusion-NCNN
243243
- https://github.com/ggerganov/whisper.cpp
244-
- https://github.com/saharNooby/rwkv.cpp
245244
- https://github.com/rhasspy/piper
246245

247246
## 🤗 Contributors

backend/cpp/llama/grpc-server.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,7 @@ static void params_parse(const backend::ModelOptions* request,
22992299
params.use_mmap = request->mmap();
23002300
params.flash_attn = request->flashattention();
23012301
params.no_kv_offload = request->nokvoffload();
2302+
params.ctx_shift = false; // We control context-shifting in any case (and we disable it as it could just lead to infinite loops)
23022303

23032304
params.embedding = request->embeddings();
23042305

gallery/rwkv.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: "rwkv"
3+
4+
config_file: |
5+
parameters:
6+
top_k: 80
7+
temperature: 0.9
8+
max_tokens: 4098
9+
top_p: 0.8
10+
context_size: 4098
11+
12+
roles:
13+
user: "User: "
14+
system: "System: "
15+
assistant: "Assistant: "
16+
17+
stopwords:
18+
- 'Assistant:'
19+
20+
template:
21+
chat: |
22+
{{.Input}}
23+
Assistant:
24+
completion: |
25+
{{.Input}}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ require (
1515
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b
1616
github.com/containerd/containerd v1.7.19
1717
github.com/dave-gray101/v2keyauth v0.0.0-20240624150259-c45d584d25e2
18-
github.com/donomii/go-rwkv.cpp v0.0.0-20240228065144-661e7ae26d44
1918
github.com/elliotchance/orderedmap/v2 v2.2.0
2019
github.com/fsnotify/fsnotify v1.7.0
2120
github.com/ggerganov/whisper.cpp/bindings/go v0.0.0-20240626202019-c118733a29ad

pkg/model/initializers.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const (
4646
LLamaCPPGRPC = "llama-cpp-grpc"
4747

4848
BertEmbeddingsBackend = "bert-embeddings"
49-
RwkvBackend = "rwkv"
5049
WhisperBackend = "whisper"
5150
StableDiffusionBackend = "stablediffusion"
5251
TinyDreamBackend = "tinydream"

tests/models_fixtures/rwkv.yaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
name: rwkv_test
22
parameters:
3-
model: rwkv
3+
model: huggingface://bartowski/rwkv-6-world-7b-GGUF/rwkv-6-world-7b-Q4_K_M.gguf
44
top_k: 80
55
temperature: 0.9
6-
max_tokens: 100
6+
max_tokens: 4098
77
top_p: 0.8
8-
context_size: 1024
9-
backend: "rwkv"
10-
cutwords:
11-
- "Bob:.*"
8+
context_size: 4098
9+
1210
roles:
13-
user: "Bob:"
14-
system: "Alice:"
15-
assistant: "Alice:"
11+
user: "User: "
12+
system: "System: "
13+
assistant: "Assistant: "
14+
15+
stopwords:
16+
- 'Assistant:'
17+
1618
template:
17-
completion: rwkv_completion
18-
chat: rwkv_chat
19+
chat: |
20+
{{.Input}}
21+
Assistant:
22+
completion: |
23+
{{.Input}}

tests/models_fixtures/rwkv_chat.tmpl

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/models_fixtures/rwkv_completion.tmpl

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)