Skip to content

Commit f80ce7a

Browse files
committed
Merge branch 'origin/master' into hipblas
2 parents 600ace3 + ac7876a commit f80ce7a

17 files changed

+35665
-562
lines changed

.github/workflows/build.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151
env:
152152
OPENBLAS_VERSION: 0.3.23
153153
OPENCL_VERSION: 2023.04.17
154-
CLBLAST_VERSION: 1.5.3
154+
CLBLAST_VERSION: 1.6.0
155155

156156
strategy:
157157
matrix:
@@ -184,13 +184,13 @@ jobs:
184184
id: get_clblast
185185
if: ${{ matrix.build == 'clblast' }}
186186
run: |
187-
curl.exe -o $env:RUNNER_TEMP/clblast.zip -L "https://github.com/CNugteren/CLBlast/releases/download/${env:CLBLAST_VERSION}/CLBlast-${env:CLBLAST_VERSION}-Windows-x64.zip"
187+
curl.exe -o $env:RUNNER_TEMP/clblast.7z -L "https://github.com/CNugteren/CLBlast/releases/download/${env:CLBLAST_VERSION}/CLBlast-${env:CLBLAST_VERSION}-windows-x64.7z"
188188
curl.exe -o $env:RUNNER_TEMP/CLBlast.LICENSE.txt -L "https://github.com/CNugteren/CLBlast/raw/${env:CLBLAST_VERSION}/LICENSE"
189-
mkdir $env:RUNNER_TEMP/clblast
190-
tar.exe -xvf $env:RUNNER_TEMP/clblast.zip -C $env:RUNNER_TEMP/clblast
189+
7z x "-o${env:RUNNER_TEMP}" $env:RUNNER_TEMP/clblast.7z
190+
rename-item $env:RUNNER_TEMP/clblast_release_dir clblast
191191
foreach ($f in (gci -Recurse -Path "$env:RUNNER_TEMP/clblast" -Filter '*.cmake')) {
192192
$txt = Get-Content -Path $f -Raw
193-
$txt.Replace('C:/dependencies/opencl/', "$($env:RUNNER_TEMP.Replace('\','/'))/opencl/") | Set-Content -Path $f -Encoding UTF8
193+
$txt.Replace('C:/vcpkg/packages/opencl_x64-windows/', "$($env:RUNNER_TEMP.Replace('\','/'))/opencl/") | Set-Content -Path $f -Encoding UTF8
194194
}
195195
196196
- name: Download OpenBLAS

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ option(LLAMA_HIPBLAS "llama: use hipBLAS"
7373

7474
option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
7575
option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
76+
option(LLAMA_BUILD_SERVER "llama: build server example" OFF)
7677

7778
#
7879
# Build info header
@@ -201,7 +202,7 @@ if (LLAMA_CLBLAST)
201202
if (CLBlast_FOUND)
202203
message(STATUS "CLBlast found")
203204

204-
set(GGML_OPENCL_SOURCES ggml-opencl.c ggml-opencl.h)
205+
set(GGML_OPENCL_SOURCES ggml-opencl.cpp ggml-opencl.h)
205206

206207
add_compile_definitions(GGML_USE_CLBLAST)
207208

Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,16 @@ ggml-cuda.o: ggml-cuda.cu ggml-cuda.h
138138
endif
139139
ifdef LLAMA_CLBLAST
140140
CFLAGS += -DGGML_USE_CLBLAST
141+
CXXFLAGS += -DGGML_USE_CLBLAST
141142
# Mac provides OpenCL as a framework
142143
ifeq ($(UNAME_S),Darwin)
143144
LDFLAGS += -lclblast -framework OpenCL
144145
else
145146
LDFLAGS += -lclblast -lOpenCL
146147
endif
147148
OBJS += ggml-opencl.o
148-
ggml-opencl.o: ggml-opencl.c ggml-opencl.h
149-
$(CC) $(CFLAGS) -c $< -o $@
149+
ggml-opencl.o: ggml-opencl.cpp ggml-opencl.h
150+
$(CXX) $(CXXFLAGS) -c $< -o $@
150151
endif
151152
ifdef LLAMA_HIPBLAS
152153
ROCM_PATH ?= /opt/rocm
@@ -258,6 +259,6 @@ benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o
258259
vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS)
259260
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
260261

261-
.PHONY: tests
262+
.PHONY: tests clean
262263
tests:
263264
bash ./tests/run-tests.sh

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,25 @@ Note the use of `--color` to distinguish between user input and generated text.
391391
392392
![image](https://user-images.githubusercontent.com/1991296/224575029-2af3c7dc-5a65-4f64-a6bb-517a532aea38.png)
393393
394+
### Persistent Interaction
395+
396+
The prompt, user inputs, and model generations can be saved and resumed across calls to `./main` by leveraging `--prompt-cache` and `--prompt-cache-all`. The `./examples/chat-persistent.sh` script demonstrates this with support for long-running, resumable chat sessions. To use this example, you must provide a file to cache the initial chat prompt and a directory to save the chat session, and may optionally provide the same variables as `chat-13B.sh`. The same prompt cache can be reused for new chat sessions. Note that both prompt cache and chat directory are tied to the initial prompt (`PROMPT_TEMPLATE`) and the model file.
397+
398+
```bash
399+
# Start a new chat
400+
PROMPT_CACHE_FILE=chat.prompt.bin CHAT_SAVE_DIR=./chat/default ./examples/chat-persistent.sh
401+
402+
# Resume that chat
403+
PROMPT_CACHE_FILE=chat.prompt.bin CHAT_SAVE_DIR=./chat/default ./examples/chat-persistent.sh
404+
405+
# Start a different chat with the same prompt/model
406+
PROMPT_CACHE_FILE=chat.prompt.bin CHAT_SAVE_DIR=./chat/another ./examples/chat-persistent.sh
407+
408+
# Different prompt cache for different prompt/model
409+
PROMPT_TEMPLATE=./prompts/chat-with-bob.txt PROMPT_CACHE_FILE=bob.prompt.bin \
410+
CHAT_SAVE_DIR=./chat/bob ./examples/chat-persistent.sh
411+
```
412+
394413
### Instruction mode with Alpaca
395414
396415
1. First, download the `ggml` Alpaca model into the `./models` folder

examples/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ else()
3737
add_subdirectory(save-load-state)
3838
add_subdirectory(benchmark)
3939
add_subdirectory(baby-llama)
40+
if(LLAMA_BUILD_SERVER)
41+
add_subdirectory(server)
42+
endif()
4043
endif()

examples/chat-persistent.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ CUR_PROMPT_CACHE="${CHAT_SAVE_DIR}/current-cache.bin"
2323
NEXT_PROMPT_FILE="${CHAT_SAVE_DIR}/next-prompt.txt"
2424
NEXT_PROMPT_CACHE="${CHAT_SAVE_DIR}/next-cache.bin"
2525

26-
SESSION_SIZE_MSG_PATTERN='main: session file matches \d+ / \d+'
27-
SAMPLE_TIME_MSG_PATTERN='sample time =\s+\d+.\d+ ms /\s+\d+'
26+
SESSION_SIZE_MSG_PATTERN='main: session file matches [[:digit:]]+ / [[:digit:]]+'
27+
SAMPLE_TIME_MSG_PATTERN='sample time =[[:space:]]+[[:digit:]]+.[[:digit:]]+ ms /[[:space:]]+[[:digit:]]+'
2828
SED_DELETE_MESSAGES="/^(${USER_NAME}:|${AI_NAME}:|\\.\\.\\.)/,\$d"
2929

3030
CTX_SIZE=2048

examples/server/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(TARGET server)
2+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
3+
add_executable(${TARGET} server.cpp json.hpp httplib.h)
4+
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
5+
target_compile_features(${TARGET} PRIVATE cxx_std_11)
6+
if(TARGET BUILD_INFO)
7+
add_dependencies(${TARGET} BUILD_INFO)
8+
endif()

0 commit comments

Comments
 (0)