Skip to content

Commit 0af6c22

Browse files
Merge pull request #571 from janhq/update-dev-from-master-2026-06-26-01-15
Sync master with upstream release b9802
2 parents 9b3bb7a + beac530 commit 0af6c22

38 files changed

Lines changed: 993 additions & 493 deletions

.github/labeler.yml

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,20 @@ AMD ZenDNN:
3535
documentation:
3636
- changed-files:
3737
- any-glob-to-any-file:
38+
- "**/*.md"
3839
- docs/**
3940
- media/**
41+
examples:
42+
- all:
43+
- changed-files:
44+
- any-glob-to-any-file:
45+
- app/**
46+
- examples/**
47+
- tools/**
48+
- all-globs-to-all-files:
49+
- '!tools/server/**'
50+
- '!tools/mtmd/**'
51+
- '!tools/ui/**'
4052
testing:
4153
- changed-files:
4254
- any-glob-to-any-file:
@@ -47,28 +59,12 @@ build:
4759
- cmake/**
4860
- CMakeLists.txt
4961
- CMakePresets.json
50-
examples:
51-
- changed-files:
52-
- any-glob-to-any-file:
53-
- examples/**
54-
- tools/**
5562
devops:
5663
- changed-files:
5764
- any-glob-to-any-file:
5865
- .devops/**
5966
- .github/**
6067
- ci/**
61-
python:
62-
- changed-files:
63-
- any-glob-to-any-file:
64-
- "**/*.py"
65-
- requirements/**
66-
- gguf-py/**
67-
- .flake8
68-
script:
69-
- changed-files:
70-
- any-glob-to-any-file:
71-
- scripts/**
7268
android:
7369
- changed-files:
7470
- any-glob-to-any-file:
@@ -81,9 +77,20 @@ server:
8177
- changed-files:
8278
- any-glob-to-any-file:
8379
- tools/server/**
84-
85-
86-
80+
mtmd:
81+
- changed-files:
82+
- any-glob-to-any-file:
83+
- tools/mtmd/**
84+
conversion:
85+
- changed-files:
86+
- any-glob-to-any-file:
87+
- conversion/**
88+
- convert_*.py
89+
- gguf-py/**
90+
vendor:
91+
- changed-files:
92+
- any-glob-to-any-file:
93+
- vendor/**
8794
ggml:
8895
- changed-files:
8996
- any-glob-to-any-file:

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ if (LLAMA_BUILD_APP)
222222
add_subdirectory(app)
223223
endif()
224224

225+
# Standalone libmtmd build without pulling in the rest of the tools/ tree.
226+
# Useful when packaging just the mtmd library for language bindings (e.g. an
227+
# Apple XCFramework, or a WASM build). When the full tools build is enabled,
228+
# mtmd is already built by the tools/ subdirectory above; this hook only fires
229+
# when LLAMA_BUILD_TOOLS is OFF to avoid double-adding the target.
230+
option(LLAMA_BUILD_MTMD "llama: build tools/mtmd library standalone" OFF)
231+
if (LLAMA_BUILD_MTMD AND NOT (LLAMA_BUILD_COMMON AND LLAMA_BUILD_TOOLS))
232+
add_subdirectory(tools/mtmd)
233+
endif()
234+
225235
#
226236
# install
227237
#

app/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(TARGET llama-app)
22

3-
add_executable(${TARGET} llama.cpp)
3+
add_executable(${TARGET} llama.cpp download.cpp)
44
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME llama)
55

66
target_link_libraries(${TARGET} PRIVATE

app/download.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "arg.h"
2+
#include "common.h"
3+
#include "download.h"
4+
#include "log.h"
5+
6+
#include <cstdio>
7+
#include <filesystem>
8+
9+
static void print_usage(int /*argc*/, char ** argv) {
10+
printf(
11+
"\nexamples:\n"
12+
" %s -hf ggml-org/gemma-3-4b-it-qat-GGUF\n"
13+
" %s -hf ggml-org/gemma-3-4b-it-qat-GGUF:Q4_K_M\n"
14+
" %s -hf ggml-org/models -hff model.gguf\n"
15+
" %s -mu https://example.com/model.gguf -m model.gguf\n"
16+
"\n",
17+
argv[0], argv[0], argv[0], argv[0]
18+
);
19+
}
20+
21+
int llama_download(int argc, char ** argv);
22+
23+
int llama_download(int argc, char ** argv) {
24+
common_init();
25+
26+
common_params params;
27+
params.verbosity = LOG_LEVEL_ERROR;
28+
29+
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_DOWNLOAD, print_usage)) {
30+
return 1;
31+
}
32+
33+
const bool has_source = !params.model.hf_repo.empty() || !params.model.url.empty() ||
34+
!params.model.path.empty() || !params.model.docker_repo.empty();
35+
if (!has_source) {
36+
fprintf(stderr, "error: no model source specified (use --hf-repo, --model-url, --model or --docker-repo)\n");
37+
return 1;
38+
}
39+
40+
try {
41+
common_models_handler handler = common_models_handler_init(params, LLAMA_EXAMPLE_DOWNLOAD);
42+
common_models_handler_apply(handler, params);
43+
} catch (const std::exception & e) {
44+
fprintf(stderr, "error: %s\n", e.what());
45+
return 1;
46+
}
47+
48+
if (!params.models_preset.empty()) {
49+
// -hf pointed at a preset repo: print the preset path and stop
50+
printf("%s\n", params.models_preset.c_str());
51+
return 0;
52+
}
53+
if (params.model.path.empty()) {
54+
fprintf(stderr, "error: model download failed\n");
55+
return 1;
56+
}
57+
if (!std::filesystem::exists(params.model.path)) {
58+
fprintf(stderr, "error: model file does not exist: %s\n", params.model.path.c_str());
59+
return 1;
60+
}
61+
62+
printf("%s\n", params.model.path.c_str());
63+
if (!params.mmproj.path.empty()) {
64+
printf("%s\n", params.mmproj.path.c_str());
65+
}
66+
if (!params.speculative.draft.mparams.path.empty()) {
67+
printf("%s\n", params.speculative.draft.mparams.path.c_str());
68+
}
69+
70+
return 0;
71+
}

app/llama.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int llama_batched_bench(int argc, char ** argv);
1919
int llama_fit_params(int argc, char ** argv);
2020
int llama_quantize(int argc, char ** argv);
2121
int llama_perplexity(int argc, char ** argv);
22+
int llama_download(int argc, char ** argv);
2223

2324
// Self-update is only supported for binaries built with llama-install.sh
2425
static int llama_update(int argc, char ** argv) {
@@ -61,6 +62,7 @@ static const command cmds[] = {
6162
{"serve", "HTTP API server", {"server"}, false, llama_server },
6263
{"cli", "Command-line interactive interface", {"client"}, false, llama_cli },
6364
{"update", "Update llama to the latest release", {}, UPDATE_HIDDEN, llama_update },
65+
{"download", "Download a model", {"get"}, false, llama_download },
6466
{"completion", "Text completion", {"complete"}, true, llama_completion },
6567
{"bench", "Benchmark prompt processing and text generation", {}, true, llama_bench },
6668
{"batched-bench", "Benchmark batched decoding performance", {}, true, llama_batched_bench},

build-xcframework.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ LLAMA_BUILD_EXAMPLES=OFF
1313
LLAMA_BUILD_TOOLS=OFF
1414
LLAMA_BUILD_TESTS=OFF
1515
LLAMA_BUILD_SERVER=OFF
16+
LLAMA_BUILD_MTMD=ON
1617
GGML_METAL=ON
1718
GGML_METAL_EMBED_LIBRARY=ON
1819
GGML_BLAS_DEFAULT=ON
@@ -39,6 +40,7 @@ COMMON_CMAKE_ARGS=(
3940
-DLLAMA_BUILD_TOOLS=${LLAMA_BUILD_TOOLS}
4041
-DLLAMA_BUILD_TESTS=${LLAMA_BUILD_TESTS}
4142
-DLLAMA_BUILD_SERVER=${LLAMA_BUILD_SERVER}
43+
-DLLAMA_BUILD_MTMD=${LLAMA_BUILD_MTMD}
4244
-DGGML_METAL_EMBED_LIBRARY=${GGML_METAL_EMBED_LIBRARY}
4345
-DGGML_BLAS_DEFAULT=${GGML_BLAS_DEFAULT}
4446
-DGGML_METAL=${GGML_METAL}
@@ -126,6 +128,8 @@ setup_framework_structure() {
126128
cp ggml/include/ggml-cpu.h ${header_path}
127129
cp ggml/include/ggml-blas.h ${header_path}
128130
cp ggml/include/gguf.h ${header_path}
131+
cp tools/mtmd/mtmd.h ${header_path}
132+
cp tools/mtmd/mtmd-helper.h ${header_path}
129133

130134
# Create module map (common for all platforms)
131135
cat > ${module_path}module.modulemap << EOF
@@ -247,6 +251,7 @@ combine_static_libraries() {
247251
"${base_dir}/${build_dir}/ggml/src/${release_dir}/libggml-cpu.a"
248252
"${base_dir}/${build_dir}/ggml/src/ggml-metal/${release_dir}/libggml-metal.a"
249253
"${base_dir}/${build_dir}/ggml/src/ggml-blas/${release_dir}/libggml-blas.a"
254+
"${base_dir}/${build_dir}/tools/mtmd/${release_dir}/libmtmd.a"
250255
)
251256

252257
# Create temporary directory for processing
@@ -410,6 +415,7 @@ cmake -B build-ios-sim -G Xcode \
410415
-DCMAKE_C_FLAGS="${COMMON_C_FLAGS}" \
411416
-DCMAKE_CXX_FLAGS="${COMMON_CXX_FLAGS}" \
412417
-DLLAMA_OPENSSL=OFF \
418+
-DMTMD_VIDEO=OFF \
413419
-S .
414420
cmake --build build-ios-sim --config Release -j $(sysctl -n hw.logicalcpu) -- -quiet
415421

@@ -424,6 +430,7 @@ cmake -B build-ios-device -G Xcode \
424430
-DCMAKE_C_FLAGS="${COMMON_C_FLAGS}" \
425431
-DCMAKE_CXX_FLAGS="${COMMON_CXX_FLAGS}" \
426432
-DLLAMA_OPENSSL=OFF \
433+
-DMTMD_VIDEO=OFF \
427434
-S .
428435
cmake --build build-ios-device --config Release -j $(sysctl -n hw.logicalcpu) -- -quiet
429436

@@ -450,6 +457,7 @@ cmake -B build-visionos -G Xcode \
450457
-DCMAKE_CXX_FLAGS="${COMMON_CXX_FLAGS}" \
451458
-DLLAMA_OPENSSL=OFF \
452459
-DLLAMA_BUILD_SERVER=OFF \
460+
-DMTMD_VIDEO=OFF \
453461
-S .
454462
cmake --build build-visionos --config Release -j $(sysctl -n hw.logicalcpu) -- -quiet
455463

@@ -465,6 +473,7 @@ cmake -B build-visionos-sim -G Xcode \
465473
-DCMAKE_CXX_FLAGS="${COMMON_CXX_FLAGS}" \
466474
-DLLAMA_OPENSSL=OFF \
467475
-DLLAMA_BUILD_SERVER=OFF \
476+
-DMTMD_VIDEO=OFF \
468477
-S .
469478
cmake --build build-visionos-sim --config Release -j $(sysctl -n hw.logicalcpu) -- -quiet
470479

@@ -481,6 +490,7 @@ cmake -B build-tvos-sim -G Xcode \
481490
-DCMAKE_C_FLAGS="${COMMON_C_FLAGS}" \
482491
-DCMAKE_CXX_FLAGS="${COMMON_CXX_FLAGS}" \
483492
-DLLAMA_OPENSSL=OFF \
493+
-DMTMD_VIDEO=OFF \
484494
-S .
485495
cmake --build build-tvos-sim --config Release -j $(sysctl -n hw.logicalcpu) -- -quiet
486496

@@ -496,6 +506,7 @@ cmake -B build-tvos-device -G Xcode \
496506
-DCMAKE_C_FLAGS="${COMMON_C_FLAGS}" \
497507
-DCMAKE_CXX_FLAGS="${COMMON_CXX_FLAGS}" \
498508
-DLLAMA_OPENSSL=OFF \
509+
-DMTMD_VIDEO=OFF \
499510
-S .
500511
cmake --build build-tvos-device --config Release -j $(sysctl -n hw.logicalcpu) -- -quiet
501512

0 commit comments

Comments
 (0)