Skip to content

Commit 53f9250

Browse files
authored
sync : vendor (ggml-org#13901)
* sync : vendor ggml-ci * cont : fix httplib version ggml-ci * cont : fix lint * cont : fix lint * vendor : move to common folder /vendor ggml-ci * cont : fix lint * cont : move httplib to /vendor + use json_fwd.hpp ggml-ci * cont : fix server build ggml-ci * cont : add missing headers ggml-ci * cont : header clean-up ggml-ci
1 parent db38704 commit 53f9250

27 files changed

+3313
-2325
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ charset = unset
4949
trim_trailing_whitespace = unset
5050
insert_final_newline = unset
5151

52-
[tools/mtmd/vendor/miniaudio.h]
52+
[vendor/miniaudio/miniaudio.h]
5353
trim_trailing_whitespace = unset
5454
insert_final_newline = unset

common/CMakeLists.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,20 @@ add_library(${TARGET} STATIC
5858
arg.cpp
5959
arg.h
6060
base64.hpp
61-
chat.cpp
62-
chat.h
6361
chat-parser.cpp
6462
chat-parser.h
63+
chat.cpp
64+
chat.h
6565
common.cpp
6666
common.h
6767
console.cpp
6868
console.h
69-
json-schema-to-grammar.cpp
70-
json.hpp
71-
json-partial.h
7269
json-partial.cpp
70+
json-partial.h
71+
json-schema-to-grammar.cpp
7372
llguidance.cpp
7473
log.cpp
7574
log.h
76-
minja/chat-template.hpp
77-
minja/minja.hpp
7875
ngram-cache.cpp
7976
ngram-cache.h
8077
regex-partial.cpp
@@ -147,7 +144,7 @@ if (LLAMA_LLGUIDANCE)
147144
set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} llguidance ${LLGUIDANCE_PLATFORM_LIBS})
148145
endif ()
149146

150-
target_include_directories(${TARGET} PUBLIC .)
147+
target_include_directories(${TARGET} PUBLIC . ../vendor)
151148
target_compile_features (${TARGET} PUBLIC cxx_std_17)
152149
target_link_libraries (${TARGET} PRIVATE ${LLAMA_COMMON_EXTRA_LIBS} PUBLIC llama Threads::Threads)
153150

common/arg.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
#include "gguf.h" // for reading GGUF splits
21
#include "arg.h"
32

3+
#include "chat.h"
44
#include "common.h"
5+
#include "gguf.h" // for reading GGUF splits
6+
#include "json-schema-to-grammar.h"
57
#include "log.h"
68
#include "sampling.h"
7-
#include "chat.h"
89

910
// fix problem with std::min and std::max
1011
#if defined(_WIN32)
@@ -15,6 +16,9 @@
1516
#include <windows.h>
1617
#endif
1718

19+
#define JSON_ASSERT GGML_ASSERT
20+
#include <nlohmann/json.hpp>
21+
1822
#include <algorithm>
1923
#include <climits>
2024
#include <cstdarg>
@@ -34,8 +38,6 @@
3438
#include <future>
3539
#endif
3640

37-
#include "json-schema-to-grammar.h"
38-
3941
using json = nlohmann::ordered_json;
4042

4143
std::initializer_list<enum llama_example> mmproj_examples = {

common/chat-parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
#include "chat.h"
44
#include "json-partial.h"
5-
#include "json.hpp"
65
#include "regex-partial.h"
76

7+
#include <nlohmann/json.hpp>
8+
89
#include <optional>
910
#include <string>
1011
#include <vector>

common/chat.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include "chat.h"
22
#include "chat-parser.h"
33
#include "common.h"
4+
#include "json-partial.h"
45
#include "json-schema-to-grammar.h"
56
#include "log.h"
6-
#include "json-partial.h"
7-
#include "minja/chat-template.hpp"
8-
#include "minja/minja.hpp"
97
#include "regex-partial.h"
108

9+
#include <minja/chat-template.hpp>
10+
#include <minja/minja.hpp>
11+
1112
#include <cstdio>
1213
#include <exception>
1314
#include <iostream>
@@ -16,7 +17,6 @@
1617
#include <string>
1718
#include <vector>
1819

19-
2020
static std::string format_time(const std::chrono::system_clock::time_point & now, const std::string & format) {
2121
auto time = std::chrono::system_clock::to_time_t(now);
2222
auto local_time = *std::localtime(&time);

common/json-partial.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#include <json-partial.h>
2-
#include "ggml.h"
1+
#include "json-partial.h"
2+
33
#include "log.h"
4-
#include <string>
54

6-
#include <json.hpp>
5+
#include <nlohmann/json.hpp>
6+
7+
#include <string>
78

89
using json = nlohmann::ordered_json;
910

common/json-partial.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
2-
#include <json.hpp>
2+
3+
#include <nlohmann/json.hpp>
34

45
// Healing marker (empty if the JSON was fully parsed / wasn't healed).
56
struct common_healing_marker {

common/json-schema-to-grammar.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "json-schema-to-grammar.h"
22
#include "common.h"
33

4+
#include <nlohmann/json.hpp>
5+
46
#include <algorithm>
5-
#include <fstream>
67
#include <map>
78
#include <regex>
89
#include <sstream>

common/json-schema-to-grammar.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

3-
#include "ggml.h"
4-
// Change JSON_ASSERT from assert() to GGML_ASSERT:
5-
#define JSON_ASSERT GGML_ASSERT
6-
#include "json.hpp"
3+
#include <nlohmann/json_fwd.hpp>
4+
5+
#include <functional>
6+
#include <string>
77

88
std::string json_schema_to_grammar(const nlohmann::ordered_json & schema,
99
bool force_gbnf = false);

scripts/sync_vendor.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
3+
import urllib.request
4+
5+
vendor = {
6+
"https://github.com/nlohmann/json/releases/latest/download/json.hpp": "vendor/nlohmann/json.hpp",
7+
"https://github.com/nlohmann/json/releases/latest/download/json_fwd.hpp": "vendor/nlohmann/json_fwd.hpp",
8+
9+
# sync manually
10+
# "https://github.com/raw/ochafik/minja/refs/heads/main/include/minja/minja.hpp": "vendor/minja/minja.hpp",
11+
# "https://github.com/raw/ochafik/minja/refs/heads/main/include/minja/chat-template.hpp": "vendor/minja/chat-template.hpp",
12+
13+
"https://github.com/raw/nothings/stb/refs/heads/master/stb_image.h": "vendor/stb/stb_image.h",
14+
15+
"https://github.com/mackron/miniaudio/raw/refs/tags/0.11.22/miniaudio.h": "vendor/miniaudio/miniaudio.h",
16+
17+
"https://github.com/raw/yhirose/cpp-httplib/refs/tags/v0.20.1/httplib.h": "vendor/cpp-httplib/httplib.h",
18+
}
19+
20+
for url, filename in vendor.items():
21+
print(f"downloading {url} to {filename}") # noqa: NP100
22+
urllib.request.urlretrieve(url, filename)

tests/test-chat.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
//
66
// cmake -B build && cmake --build build --parallel && ./build/bin/test-chat ../minja/build/tests/*.jinja 2>/dev/null
77
//
8-
#include <fstream>
9-
#include <iostream>
10-
#include <json.hpp>
11-
#include <string>
12-
138
#include "chat.h"
149

1510
#include "../src/unicode.h"
1611
#include "../src/llama-grammar.h"
1712

13+
#include <nlohmann/json.hpp>
14+
15+
#include <fstream>
16+
#include <iostream>
17+
#include <string>
18+
1819
using json = nlohmann::ordered_json;
1920

2021
static std::ostream & operator<<(std::ostream & os, const common_chat_msg_diff & diff) {

tests/test-grammar-integration.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "../src/unicode.h"
88
#include "../src/llama-grammar.h"
99

10+
#include <nlohmann/json.hpp>
11+
1012
#include <cassert>
1113
#include <string>
1214
#include <vector>

tests/test-json-schema-to-grammar.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "../src/llama-grammar.h"
88

9+
#include <nlohmann/json.hpp>
10+
911
#include <cassert>
1012
#include <fstream>
1113
#include <sstream>

tools/mtmd/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ add_library(mtmd_helper OBJECT
2323

2424
target_link_libraries(mtmd_helper PRIVATE ggml llama mtmd ${CMAKE_THREAD_LIBS_INIT})
2525
target_include_directories(mtmd_helper PUBLIC .)
26-
target_include_directories(mtmd_helper PRIVATE ./vendor)
27-
target_include_directories(mtmd_helper PRIVATE ../..)
26+
target_include_directories(mtmd_helper PRIVATE ../../vendor)
2827
target_compile_features(mtmd_helper PRIVATE cxx_std_17)
2928

3029
if (BUILD_SHARED_LIBS)

tools/mtmd/mtmd-helper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
#define MA_NO_ENGINE
2828
#define MA_NO_GENERATION
2929
#define MA_API static
30-
#include "vendor/miniaudio.h"
30+
#include "miniaudio/miniaudio.h"
3131

3232
#define STB_IMAGE_IMPLEMENTATION
33-
#include "vendor/stb_image.h"
33+
#include "stb/stb_image.h"
3434

3535
#define LOG_INF(...) fprintf(stdout, __VA_ARGS__)
3636
#define LOG_ERR(...) fprintf(stderr, __VA_ARGS__)

tools/run/run.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
#include "chat.h"
2+
#include "common.h"
3+
#include "llama-cpp.h"
4+
#include "log.h"
5+
6+
#include "linenoise.cpp/linenoise.h"
7+
8+
#define JSON_ASSERT GGML_ASSERT
9+
#include <nlohmann/json.hpp>
10+
111
#if defined(_WIN32)
212
# include <windows.h>
313
# include <io.h>
@@ -24,13 +34,6 @@
2434
#include <string>
2535
#include <vector>
2636

27-
#include "chat.h"
28-
#include "common.h"
29-
#include "json.hpp"
30-
#include "linenoise.cpp/linenoise.h"
31-
#include "llama-cpp.h"
32-
#include "log.h"
33-
3437
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(_WIN32)
3538
[[noreturn]] static void sigint_handler(int) {
3639
printf("\n" LOG_COL_DEFAULT);

tools/server/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ endif()
1212
set(TARGET_SRCS
1313
server.cpp
1414
utils.hpp
15-
httplib.h
1615
)
1716
set(PUBLIC_ASSETS
1817
index.html.gz

tools/server/server.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#include "mtmd.h"
1212
#include "mtmd-helper.h"
1313

14-
// Change JSON_ASSERT from assert() to GGML_ASSERT:
15-
#define JSON_ASSERT GGML_ASSERT
16-
#include "json.hpp"
1714
// mime type for sending response
1815
#define MIMETYPE_JSON "application/json; charset=utf-8"
1916

tools/server/utils.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
#include "base64.hpp"
88
#include "mtmd.h"
99
#include "mtmd-helper.h"
10+
#include "chat.h"
1011

1112
// increase max payload length to allow use of larger context size
1213
#define CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH 1048576
1314
// disable Nagle's algorithm
1415
#define CPPHTTPLIB_TCP_NODELAY true
15-
#include "httplib.h"
16+
#include <cpp-httplib/httplib.h>
1617

17-
// Change JSON_ASSERT from assert() to GGML_ASSERT:
1818
#define JSON_ASSERT GGML_ASSERT
19-
#include "json.hpp"
20-
#include "chat.h"
19+
#include <nlohmann/json.hpp>
2120

2221
#include <random>
2322
#include <sstream>

tools/tts/tts.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
#include "sampling.h"
66
#include "log.h"
77
#include "llama.h"
8-
#include "json.hpp"
8+
9+
#define JSON_ASSERT GGML_ASSERT
10+
#include <nlohmann/json.hpp>
911

1012
#include <algorithm>
1113
#include <cmath>

tools/server/httplib.h renamed to vendor/cpp-httplib/httplib.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef CPPHTTPLIB_HTTPLIB_H
99
#define CPPHTTPLIB_HTTPLIB_H
1010

11-
#define CPPHTTPLIB_VERSION "0.20.0"
11+
#define CPPHTTPLIB_VERSION "0.20.1"
1212

1313
/*
1414
* Configuration
@@ -145,6 +145,10 @@
145145
#define CPPHTTPLIB_LISTEN_BACKLOG 5
146146
#endif
147147

148+
#ifndef CPPHTTPLIB_MAX_LINE_LENGTH
149+
#define CPPHTTPLIB_MAX_LINE_LENGTH 32768
150+
#endif
151+
148152
/*
149153
* Headers
150154
*/
@@ -3067,6 +3071,11 @@ inline bool stream_line_reader::getline() {
30673071
#endif
30683072

30693073
for (size_t i = 0;; i++) {
3074+
if (size() >= CPPHTTPLIB_MAX_LINE_LENGTH) {
3075+
// Treat exceptionally long lines as an error to
3076+
// prevent infinite loops/memory exhaustion
3077+
return false;
3078+
}
30703079
char byte;
30713080
auto n = strm_.read(&byte, 1);
30723081

@@ -6055,6 +6064,8 @@ inline void calc_actual_timeout(time_t max_timeout_msec, time_t duration_msec,
60556064
auto actual_timeout_msec =
60566065
(std::min)(max_timeout_msec - duration_msec, timeout_msec);
60576066

6067+
if (actual_timeout_msec < 0) { actual_timeout_msec = 0; }
6068+
60586069
actual_timeout_sec = actual_timeout_msec / 1000;
60596070
actual_timeout_usec = (actual_timeout_msec % 1000) * 1000;
60606071
}
@@ -7327,8 +7338,9 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
73277338
}
73287339

73297340
// Setup `is_connection_closed` method
7330-
req.is_connection_closed = [&]() {
7331-
return !detail::is_socket_alive(strm.socket());
7341+
auto sock = strm.socket();
7342+
req.is_connection_closed = [sock]() {
7343+
return !detail::is_socket_alive(sock);
73327344
};
73337345

73347346
// Routing
File renamed without changes.

common/minja/chat-template.hpp renamed to vendor/minja/chat-template.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <string>
2323
#include <vector>
2424

25-
#include <json.hpp>
25+
#include <nlohmann/json.hpp>
2626

2727
using json = nlohmann::ordered_json;
2828

common/minja/minja.hpp renamed to vendor/minja/minja.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <utility>
3030
#include <vector>
3131

32-
#include <json.hpp>
32+
#include <nlohmann/json.hpp>
3333

3434
using json = nlohmann::ordered_json;
3535

0 commit comments

Comments
 (0)