Skip to content

Commit 57c46aa

Browse files
authored
Merge pull request #6 from l3utterfly/master
merge latest changes from upstream
2 parents 28d9d38 + d0d5de4 commit 57c46aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+3874
-1611
lines changed

.github/workflows/build.yml

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ jobs:
4848
CC=gcc-8 make tests -j $(nproc)
4949
make test -j $(nproc)
5050
51-
ubuntu-latest-cmake:
52-
runs-on: ubuntu-latest
51+
ubuntu-focal-make-curl:
52+
runs-on: ubuntu-20.04
5353

5454
steps:
5555
- name: Clone
@@ -60,32 +60,19 @@ jobs:
6060
id: depends
6161
run: |
6262
sudo apt-get update
63-
sudo apt-get install build-essential
63+
sudo apt-get install build-essential gcc-8 libcurl4-openssl-dev
6464
6565
- name: Build
66-
id: cmake_build
67-
run: |
68-
mkdir build
69-
cd build
70-
cmake .. -DLLAMA_FATAL_WARNINGS=ON
71-
cmake --build . --config Release -j $(nproc)
72-
73-
- name: Test
74-
id: cmake_test
66+
id: make_build
67+
env:
68+
LLAMA_FATAL_WARNINGS: 1
69+
LLAMA_CURL: 1
7570
run: |
76-
cd build
77-
ctest -L main --verbose --timeout 900
71+
CC=gcc-8 make -j $(nproc)
7872
79-
ubuntu-latest-cmake-sanitizer:
73+
ubuntu-latest-cmake:
8074
runs-on: ubuntu-latest
8175

82-
continue-on-error: true
83-
84-
strategy:
85-
matrix:
86-
sanitizer: [ADDRESS, THREAD, UNDEFINED]
87-
build_type: [Debug, Release]
88-
8976
steps:
9077
- name: Clone
9178
id: checkout
@@ -102,15 +89,50 @@ jobs:
10289
run: |
10390
mkdir build
10491
cd build
105-
cmake .. -DLLAMA_FATAL_WARNINGS=ON -DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
106-
cmake --build . --config ${{ matrix.build_type }} -j $(nproc)
92+
cmake .. -DLLAMA_FATAL_WARNINGS=ON
93+
cmake --build . --config Release -j $(nproc)
10794
10895
- name: Test
10996
id: cmake_test
11097
run: |
11198
cd build
11299
ctest -L main --verbose --timeout 900
113100
101+
# ubuntu-latest-cmake-sanitizer:
102+
# runs-on: ubuntu-latest
103+
#
104+
# continue-on-error: true
105+
#
106+
# strategy:
107+
# matrix:
108+
# sanitizer: [ADDRESS, THREAD, UNDEFINED]
109+
# build_type: [Debug, Release]
110+
#
111+
# steps:
112+
# - name: Clone
113+
# id: checkout
114+
# uses: actions/checkout@v3
115+
#
116+
# - name: Dependencies
117+
# id: depends
118+
# run: |
119+
# sudo apt-get update
120+
# sudo apt-get install build-essential
121+
#
122+
# - name: Build
123+
# id: cmake_build
124+
# run: |
125+
# mkdir build
126+
# cd build
127+
# cmake .. -DLLAMA_FATAL_WARNINGS=ON -DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
128+
# cmake --build . --config ${{ matrix.build_type }} -j $(nproc)
129+
#
130+
# - name: Test
131+
# id: cmake_test
132+
# run: |
133+
# cd build
134+
# ctest -L main --verbose --timeout 900
135+
114136
ubuntu-latest-cmake-mpi:
115137
runs-on: ubuntu-latest
116138

@@ -333,6 +355,7 @@ jobs:
333355
mkdir build
334356
cd build
335357
cmake -G Xcode .. \
358+
-DLLAMA_METAL_EMBED_LIBRARY=ON \
336359
-DLLAMA_BUILD_EXAMPLES=OFF \
337360
-DLLAMA_BUILD_TESTS=OFF \
338361
-DLLAMA_BUILD_SERVER=OFF \
@@ -361,6 +384,7 @@ jobs:
361384
mkdir build
362385
cd build
363386
cmake -G Xcode .. \
387+
-DLLAMA_METAL_EMBED_LIBRARY=ON \
364388
-DLLAMA_BUILD_EXAMPLES=OFF \
365389
-DLLAMA_BUILD_TESTS=OFF \
366390
-DLLAMA_BUILD_SERVER=OFF \

.github/workflows/close-issue.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Close inactive issues
2+
on:
3+
schedule:
4+
- cron: "42 0 * * *"
5+
6+
jobs:
7+
close-issues:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
issues: write
11+
pull-requests: write
12+
steps:
13+
- uses: actions/stale@v5
14+
with:
15+
exempt-issue-labels: "refactor,help wanted,good first issue,research"
16+
days-before-issue-stale: 30
17+
days-before-issue-close: 14
18+
stale-issue-label: "stale"
19+
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
20+
days-before-pr-stale: -1
21+
days-before-pr-close: -1
22+
operations-per-run: 1000
23+
repo-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/server.yml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,15 @@ jobs:
2424

2525
strategy:
2626
matrix:
27-
sanitizer: [ADDRESS, THREAD, UNDEFINED]
28-
build_type: [Debug, Release]
27+
# TODO: temporary disabled due to linux kernel issues
28+
#sanitizer: [ADDRESS, THREAD, UNDEFINED]
29+
sanitizer: [UNDEFINED]
30+
build_type: [Debug]
2931
include:
3032
- build_type: Release
3133
sanitizer: ""
32-
exclude:
33-
- build_type: Release
34-
sanitizer: ADDRESS
35-
- build_type: Release
36-
sanitizer: THREAD
37-
- build_type: Release
38-
sanitizer: UNDEFINED
34+
disabled_on_pr: true
35+
fail-fast: false # While -DLLAMA_SANITIZE_THREAD=ON is broken
3936

4037
container:
4138
image: ubuntu:latest
@@ -60,7 +57,8 @@ jobs:
6057
cmake \
6158
python3-pip \
6259
wget \
63-
language-pack-en
60+
language-pack-en \
61+
libcurl4-openssl-dev
6462
6563
- name: Build
6664
id: cmake_build
@@ -70,6 +68,7 @@ jobs:
7068
cmake .. \
7169
-DLLAMA_NATIVE=OFF \
7270
-DLLAMA_BUILD_SERVER=ON \
71+
-DLLAMA_CURL=ON \
7372
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
7473
-DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON ;
7574
cmake --build . --config ${{ matrix.build_type }} -j $(nproc) --target server
@@ -81,13 +80,14 @@ jobs:
8180
8281
- name: Tests
8382
id: server_integration_tests
83+
if: ${{ !matrix.disabled_on_pr || !github.event.pull_request }}
8484
run: |
8585
cd examples/server/tests
8686
PORT=8888 ./tests.sh
8787
8888
- name: Slow tests
8989
id: server_integration_tests_slow
90-
if: ${{ github.event.schedule != '' && matrix.build_type == 'Release' || github.event.inputs.slow_tests == 'true' }}
90+
if: ${{ (github.event.schedule || github.event.inputs.slow_tests == 'true') && matrix.build_type == 'Release' }}
9191
run: |
9292
cd examples/server/tests
9393
PORT=8888 ./tests.sh --stop --no-skipped --no-capture --tags slow
@@ -103,12 +103,21 @@ jobs:
103103
with:
104104
fetch-depth: 0
105105

106+
- name: libCURL
107+
id: get_libcurl
108+
env:
109+
CURL_VERSION: 8.6.0_6
110+
run: |
111+
curl.exe -o $env:RUNNER_TEMP/curl.zip -L "https://curl.se/windows/dl-${env:CURL_VERSION}/curl-${env:CURL_VERSION}-win64-mingw.zip"
112+
mkdir $env:RUNNER_TEMP/libcurl
113+
tar.exe -xvf $env:RUNNER_TEMP/curl.zip --strip-components=1 -C $env:RUNNER_TEMP/libcurl
114+
106115
- name: Build
107116
id: cmake_build
108117
run: |
109118
mkdir build
110119
cd build
111-
cmake .. -DLLAMA_BUILD_SERVER=ON -DCMAKE_BUILD_TYPE=Release ;
120+
cmake .. -DLLAMA_CURL=ON -DCURL_LIBRARY="$env:RUNNER_TEMP/libcurl/lib/libcurl.dll.a" -DCURL_INCLUDE_DIR="$env:RUNNER_TEMP/libcurl/include"
112121
cmake --build . --config Release -j ${env:NUMBER_OF_PROCESSORS} --target server
113122
114123
- name: Python setup
@@ -122,15 +131,21 @@ jobs:
122131
run: |
123132
pip install -r examples/server/tests/requirements.txt
124133
134+
- name: Copy Libcurl
135+
id: prepare_libcurl
136+
run: |
137+
cp $env:RUNNER_TEMP/libcurl/bin/libcurl-x64.dll ./build/bin/Release/libcurl-x64.dll
138+
125139
- name: Tests
126140
id: server_integration_tests
141+
if: ${{ !matrix.disabled_on_pr || !github.event.pull_request }}
127142
run: |
128143
cd examples/server/tests
129144
behave.exe --summary --stop --no-capture --exclude 'issues|wrong_usages|passkey' --tags llama.cpp
130145
131146
- name: Slow tests
132147
id: server_integration_tests_slow
133-
if: ${{ github.event.schedule != '' || github.event.inputs.slow_tests == 'true' }}
148+
if: ${{ (github.event.schedule || github.event.inputs.slow_tests == 'true') && matrix.build_type == 'Release' }}
134149
run: |
135150
cd examples/server/tests
136151
behave.exe --stop --no-skipped --no-capture --tags slow

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
.vscode/
2626
.idea/
2727

28+
ggml-metal-embed.metal
29+
2830
lcov-report/
2931
gcovr-report/
3032

CMakeLists.txt

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ option(LLAMA_CUDA_F16 "llama: use 16 bit floats for some
9999
set(LLAMA_CUDA_KQUANTS_ITER "2" CACHE STRING "llama: iters./thread per block for Q2_K/Q6_K")
100100
set(LLAMA_CUDA_PEER_MAX_BATCH_SIZE "128" CACHE STRING
101101
"llama: max. batch size for using peer access")
102+
option(LLAMA_CURL "llama: use libcurl to download model from an URL" OFF)
102103
option(LLAMA_HIPBLAS "llama: use hipBLAS" OFF)
103104
option(LLAMA_HIP_UMA "llama: use HIP unified memory architecture" OFF)
104105
option(LLAMA_CLBLAST "llama: use CLBlast" OFF)
@@ -200,9 +201,6 @@ if (LLAMA_METAL)
200201
add_compile_definitions(GGML_METAL_NDEBUG)
201202
endif()
202203

203-
# get full path to the file
204-
#add_compile_definitions(GGML_METAL_DIR_KERNELS="${CMAKE_CURRENT_SOURCE_DIR}/")
205-
206204
# copy ggml-common.h and ggml-metal.metal to bin directory
207205
configure_file(ggml-common.h ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h COPYONLY)
208206
configure_file(ggml-metal.metal ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal COPYONLY)
@@ -211,53 +209,62 @@ if (LLAMA_METAL)
211209
enable_language(ASM)
212210
add_compile_definitions(GGML_METAL_EMBED_LIBRARY)
213211

212+
set(METALLIB_COMMON "${CMAKE_CURRENT_SOURCE_DIR}/ggml-common.h")
214213
set(METALLIB_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal.metal")
214+
215215
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/autogenerated")
216-
set(EMBED_METALLIB_ASSEMBLY "${CMAKE_BINARY_DIR}/autogenerated/ggml-embed-metallib.s")
216+
217+
# merge ggml-common.h and ggml-metal.metal into a single file
218+
set(METALLIB_EMBED_ASM "${CMAKE_BINARY_DIR}/autogenerated/ggml-metal-embed.s")
219+
set(METALLIB_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-metal-embed.metal")
217220

218221
add_custom_command(
219-
OUTPUT ${EMBED_METALLIB_ASSEMBLY}
220-
COMMAND echo ".section __DATA,__ggml_metallib" > ${EMBED_METALLIB_ASSEMBLY}
221-
COMMAND echo ".globl _ggml_metallib_start" >> ${EMBED_METALLIB_ASSEMBLY}
222-
COMMAND echo "_ggml_metallib_start:" >> ${EMBED_METALLIB_ASSEMBLY}
223-
COMMAND echo ".incbin \\\"${METALLIB_SOURCE}\\\"" >> ${EMBED_METALLIB_ASSEMBLY}
224-
COMMAND echo ".globl _ggml_metallib_end" >> ${EMBED_METALLIB_ASSEMBLY}
225-
COMMAND echo "_ggml_metallib_end:" >> ${EMBED_METALLIB_ASSEMBLY}
226-
DEPENDS ${METALLIB_SOURCE}
222+
OUTPUT ${METALLIB_EMBED_ASM}
223+
COMMAND echo "Embedding Metal library"
224+
COMMAND sed -e '/\#include \"ggml-common.h\"/r ${METALLIB_COMMON}' -e '/\#include \"ggml-common.h\"/d' < ${METALLIB_SOURCE} > ${METALLIB_SOURCE_EMBED}
225+
COMMAND echo ".section __DATA,__ggml_metallib" > ${METALLIB_EMBED_ASM}
226+
COMMAND echo ".globl _ggml_metallib_start" >> ${METALLIB_EMBED_ASM}
227+
COMMAND echo "_ggml_metallib_start:" >> ${METALLIB_EMBED_ASM}
228+
COMMAND echo ".incbin \\\"${METALLIB_SOURCE_EMBED}\\\"" >> ${METALLIB_EMBED_ASM}
229+
COMMAND echo ".globl _ggml_metallib_end" >> ${METALLIB_EMBED_ASM}
230+
COMMAND echo "_ggml_metallib_end:" >> ${METALLIB_EMBED_ASM}
231+
DEPENDS ggml-metal.metal ggml-common.h
227232
COMMENT "Generate assembly for embedded Metal library"
228233
)
229234

230-
set(GGML_SOURCES_METAL ${GGML_SOURCES_METAL} ${EMBED_METALLIB_ASSEMBLY})
231-
endif()
232-
233-
if (LLAMA_METAL_SHADER_DEBUG)
234-
# custom command to do the following:
235-
# xcrun -sdk macosx metal -fno-fast-math -c ggml-metal.metal -o ggml-metal.air
236-
# xcrun -sdk macosx metallib ggml-metal.air -o default.metallib
237-
#
238-
# note: this is the only way I found to disable fast-math in Metal. it's ugly, but at least it works
239-
# disabling fast math is needed in order to pass tests/test-backend-ops
240-
# note: adding -fno-inline fixes the tests when using MTL_SHADER_VALIDATION=1
241-
# note: unfortunately, we have to call it default.metallib instead of ggml.metallib
242-
# ref: https://github.com/ggerganov/whisper.cpp/issues/1720
243-
set(XC_FLAGS -fno-fast-math -fno-inline -g)
244-
if (LLAMA_QKK_64)
245-
set(XC_FLAGS ${XC_FLAGS} -DQK_K=64)
235+
set(GGML_SOURCES_METAL ${GGML_SOURCES_METAL} ${METALLIB_EMBED_ASM})
236+
else()
237+
if (LLAMA_METAL_SHADER_DEBUG)
238+
# custom command to do the following:
239+
# xcrun -sdk macosx metal -fno-fast-math -c ggml-metal.metal -o ggml-metal.air
240+
# xcrun -sdk macosx metallib ggml-metal.air -o default.metallib
241+
#
242+
# note: this is the only way I found to disable fast-math in Metal. it's ugly, but at least it works
243+
# disabling fast math is needed in order to pass tests/test-backend-ops
244+
# note: adding -fno-inline fixes the tests when using MTL_SHADER_VALIDATION=1
245+
# note: unfortunately, we have to call it default.metallib instead of ggml.metallib
246+
# ref: https://github.com/ggerganov/whisper.cpp/issues/1720
247+
set(XC_FLAGS -fno-fast-math -fno-inline -g)
248+
else()
249+
set(XC_FLAGS -O3)
246250
endif()
247251

248252
add_custom_command(
249253
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
250254
COMMAND xcrun -sdk macosx metal ${XC_FLAGS} -c ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air
251255
COMMAND xcrun -sdk macosx metallib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
252-
DEPENDS ggml-metal.metal
256+
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air
257+
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h
258+
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal
259+
DEPENDS ggml-metal.metal ggml-common.h
253260
COMMENT "Compiling Metal kernels"
254-
)
261+
)
255262

256263
add_custom_target(
257264
ggml-metal ALL
258265
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
259-
)
260-
endif()
266+
)
267+
endif() # LLAMA_METAL_EMBED_LIBRARY
261268

262269
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS}
263270
${FOUNDATION_LIBRARY}

0 commit comments

Comments
 (0)