Skip to content

Commit 43eef8d

Browse files
authored
Merge branch 'ggerganov:master' into gguf-model-template
2 parents a083c6c + 01aec4a commit 43eef8d

File tree

91 files changed

+5889
-8955
lines changed

Some content is hidden

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

91 files changed

+5889
-8955
lines changed

.devops/llama-cli-intel.Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ RUN if [ "${GGML_SYCL_F16}" = "ON" ]; then \
1414
echo "GGML_SYCL_F16 is set" && \
1515
export OPT_SYCL_F16="-DGGML_SYCL_F16=ON"; \
1616
fi && \
17-
cmake -B build -DGGML_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx ${OPT_SYCL_F16} && \
17+
echo "Building with static libs" && \
18+
cmake -B build -DGGML_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx \
19+
${OPT_SYCL_F16} -DBUILD_SHARED_LIBS=OFF && \
1820
cmake --build build --config Release --target llama-cli
1921

2022
FROM intel/oneapi-basekit:$ONEAPI_VERSION AS runtime

.devops/llama-server-intel.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RUN if [ "${GGML_SYCL_F16}" = "ON" ]; then \
1414
echo "GGML_SYCL_F16 is set" && \
1515
export OPT_SYCL_F16="-DGGML_SYCL_F16=ON"; \
1616
fi && \
17+
echo "Building with dynamic libs" && \
1718
cmake -B build -DGGML_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_CURL=ON ${OPT_SYCL_F16} && \
1819
cmake --build build --config Release --target llama-server
1920

.devops/nix/apps.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"llama-embedding"
1111
"llama-server"
1212
"llama-quantize"
13-
"llama-train-text-from-scratch"
1413
];
1514
mkApp = name: {
1615
type = "app";

.devops/tools.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ elif [[ "$arg1" == '--quantize' || "$arg1" == '-q' ]]; then
1313
./llama-quantize "$@"
1414
elif [[ "$arg1" == '--run' || "$arg1" == '-r' ]]; then
1515
./llama-cli "$@"
16-
elif [[ "$arg1" == '--finetune' || "$arg1" == '-f' ]]; then
17-
./llama-finetune "$@"
1816
elif [[ "$arg1" == '--all-in-one' || "$arg1" == '-a' ]]; then
1917
echo "Converting PTH to GGML..."
2018
for i in `ls $1/$2/ggml-model-f16.bin*`; do
@@ -36,8 +34,6 @@ else
3634
echo " ex: --outtype f16 \"/models/7B/\" "
3735
echo " --quantize (-q): Optimize with quantization process ggml"
3836
echo " ex: \"/models/7B/ggml-model-f16.bin\" \"/models/7B/ggml-model-q4_0.bin\" 2"
39-
echo " --finetune (-f): Run finetune command to create a lora finetune of the model"
40-
echo " See documentation for finetune for command-line parameters"
4137
echo " --all-in-one (-a): Execute --convert & --quantize"
4238
echo " ex: \"/models/\" 7B"
4339
echo " --server (-s): Run a model on the server"

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ jobs:
860860
mkdir build
861861
cd build
862862
cmake .. -DGGML_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DGGML_CUDA=ON -DBUILD_SHARED_LIBS=ON
863-
cmake --build . --config Release -j ${env:NUMBER_OF_PROCESSORS}
863+
cmake --build . --config Release -j $((${env:NUMBER_OF_PROCESSORS} - 1))
864864
865865
- name: Determine tag name
866866
id: tag

CONTRIBUTING.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
# Pull requests
1+
# Pull requests (for contributors)
22

3-
- Always squash-merge the PR before merging
4-
- Use the following format for your final commit: `<module> : <commit title> (#<issue_number>)`. For example: `utils : fix typo in utils.py (#1234)`
53
- Test your changes:
64
- Using the commands in the [`tests`](tests) folder. For instance, running the `./tests/test-backend-ops` command tests different backend implementations of the GGML library
75
- Execute [the full CI locally on your machine](ci/README.md) before publishing
86
- Please rate the complexity of your PR (i.e. `Review Complexity : Low`, `Review Complexity : Medium`, `Review Complexity : High`). This makes it easier for maintainers to triage the PRs.
9-
- The PR template has a series of review complexity checkboxes `[ ]` that [you can mark as](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/about-task-lists) `[X]` for your conveience
7+
- The PR template has a series of review complexity checkboxes `[ ]` that [you can mark as](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/about-task-lists) `[X]` for your convenience
8+
- If your PR becomes stale, don't hesitate to ping the maintainers in the comments
9+
10+
# Pull requests (for collaborators)
11+
12+
- Squash-merge PRs
13+
- Use the following format for the squashed commit title: `<module> : <commit title> (#<issue_number>)`. For example: `utils : fix typo in utils.py (#1234)`
14+
- Optionally, pick a `<module>` from here: https://github.com/ggerganov/llama.cpp/wiki/Modules
1015

1116
# Coding guidelines
1217

Makefile

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ BUILD_TARGETS = \
1111
llama-embedding \
1212
llama-eval-callback \
1313
llama-export-lora \
14-
llama-finetune \
1514
llama-gbnf-validator \
1615
llama-gguf \
1716
llama-gguf-hash \
@@ -37,7 +36,6 @@ BUILD_TARGETS = \
3736
llama-simple \
3837
llama-speculative \
3938
llama-tokenize \
40-
llama-train-text-from-scratch \
4139
llama-vdot \
4240
llama-cvector-generator \
4341
tests/test-c.o
@@ -64,13 +62,13 @@ TEST_TARGETS = \
6462
tests/test-tokenizer-1-spm
6563

6664
# Legacy build targets that were renamed in #7809, but should still be removed when the project is cleaned
67-
LEGACY_TARGETS_CLEAN = main quantize quantize-stats perplexity imatrix embedding vdot q8dot train-text-from-scratch convert-llama2c-to-ggml \
65+
LEGACY_TARGETS_CLEAN = main quantize quantize-stats perplexity imatrix embedding vdot q8dot convert-llama2c-to-ggml \
6866
simple batched batched-bench save-load-state server gguf gguf-split eval-callback llama-bench libllava.a llava-cli baby-llama \
69-
retrieval speculative infill tokenize benchmark-matmult parallel finetune export-lora lookahead lookup passkey gritlm
67+
retrieval speculative infill tokenize benchmark-matmult parallel export-lora lookahead lookup passkey gritlm
7068

7169
# Legacy build targets that were renamed in #7809, but we want to build binaries that for them that output a deprecation warning if people try to use them.
7270
# We don't want to clutter things too much, so we only build replacements for the most commonly used binaries.
73-
LEGACY_TARGETS_BUILD = main quantize perplexity embedding server finetune
71+
LEGACY_TARGETS_BUILD = main quantize perplexity embedding server
7472

7573
# Deprecation aliases
7674
ifdef LLAMA_CUBLAS
@@ -876,6 +874,9 @@ OBJ_GGML += \
876874

877875
OBJ_LLAMA = \
878876
src/llama.o \
877+
src/llama-vocab.o \
878+
src/llama-grammar.o \
879+
src/llama-sampling.o \
879880
src/unicode.o \
880881
src/unicode-data.o
881882

@@ -1055,6 +1056,10 @@ src/unicode-data.o: \
10551056

10561057
src/llama.o: \
10571058
src/llama.cpp \
1059+
src/llama-impl.h \
1060+
src/llama-vocab.h \
1061+
src/llama-grammar.h \
1062+
src/llama-sampling.h \
10581063
src/unicode.h \
10591064
include/llama.h \
10601065
ggml/include/ggml-cuda.h \
@@ -1064,6 +1069,29 @@ src/llama.o: \
10641069
ggml/include/ggml-backend.h
10651070
$(CXX) $(CXXFLAGS) -c $< -o $@
10661071

1072+
src/llama-vocab.o: \
1073+
src/llama-vocab.cpp \
1074+
src/llama-vocab.h \
1075+
src/llama-impl.h \
1076+
include/llama.h
1077+
$(CXX) $(CXXFLAGS) -c $< -o $@
1078+
1079+
src/llama-grammar.o: \
1080+
src/llama-grammar.cpp \
1081+
src/llama-grammar.h \
1082+
src/llama-impl.h \
1083+
src/llama-vocab.h \
1084+
src/llama-sampling.h \
1085+
include/llama.h
1086+
$(CXX) $(CXXFLAGS) -c $< -o $@
1087+
1088+
src/llama-sampling.o: \
1089+
src/llama-sampling.cpp \
1090+
src/llama-sampling.h \
1091+
src/llama-impl.h \
1092+
include/llama.h
1093+
$(CXX) $(CXXFLAGS) -c $< -o $@
1094+
10671095
$(LIB_LLAMA): \
10681096
$(OBJ_LLAMA) \
10691097
$(LIB_GGML)
@@ -1266,11 +1294,6 @@ llama-cvector-generator: examples/cvector-generator/cvector-generator.cpp \
12661294
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
12671295
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
12681296

1269-
llama-train-text-from-scratch: examples/train-text-from-scratch/train-text-from-scratch.cpp \
1270-
$(OBJ_ALL)
1271-
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
1272-
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
1273-
12741297
llama-convert-llama2c-to-ggml: examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp \
12751298
$(OBJ_GGML) $(OBJ_LLAMA)
12761299
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
@@ -1286,13 +1309,8 @@ llama-baby-llama: examples/baby-llama/baby-llama.cpp \
12861309
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
12871310
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
12881311

1289-
llama-finetune: examples/finetune/finetune.cpp \
1290-
$(OBJ_ALL)
1291-
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
1292-
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
1293-
12941312
llama-export-lora: examples/export-lora/export-lora.cpp \
1295-
$(OBJ_GGML) common/log.h
1313+
$(OBJ_ALL)
12961314
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
12971315
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
12981316

@@ -1439,7 +1457,7 @@ run-benchmark-matmult: llama-benchmark-matmult
14391457
.PHONY: run-benchmark-matmult swift
14401458

14411459
tests/test-llama-grammar: tests/test-llama-grammar.cpp \
1442-
$(OBJ_GGML) $(OBJ_COMMON) src/unicode.o src/unicode-data.o
1460+
$(OBJ_ALL)
14431461
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
14441462
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
14451463

@@ -1548,7 +1566,7 @@ llama-q8dot: pocs/vdot/q8dot.cpp ggml/src/ggml.o \
15481566
# Deprecated binaries that we want to keep around long enough for people to migrate to the new filenames, then these can be removed.
15491567
#
15501568
# Mark legacy binary targets as .PHONY so that they are always checked.
1551-
.PHONY: main quantize perplexity embedding server finetune
1569+
.PHONY: main quantize perplexity embedding server
15521570

15531571
# NOTE: We currently will always build the deprecation-warning `main` and `server` binaries to help users migrate.
15541572
# Eventually we will want to remove these target from building all the time.
@@ -1591,13 +1609,3 @@ ifneq (,$(wildcard embedding))
15911609
@echo " Remove the 'embedding' binary to remove this warning."
15921610
@echo "#########"
15931611
endif
1594-
1595-
finetune: examples/deprecation-warning/deprecation-warning.cpp
1596-
ifneq (,$(wildcard finetune))
1597-
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
1598-
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
1599-
@echo "#########"
1600-
@echo "WARNING: The 'finetune' binary is deprecated. Please use 'llama-finetune' instead."
1601-
@echo " Remove the 'finetune' binary to remove this warning."
1602-
@echo "#########"
1603-
endif

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import PackageDescription
44

55
var sources = [
66
"src/llama.cpp",
7+
"src/llama-vocab.cpp",
8+
"src/llama-grammar.cpp",
9+
"src/llama-sampling.cpp",
710
"src/unicode.cpp",
811
"src/unicode-data.cpp",
912
"ggml/src/ggml.c",

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Typically finetunes of the base models below are supported as well.
138138

139139
Unless otherwise noted these projects are open-source with permissive licensing:
140140

141+
- [MindWorkAI/AI-Studio](https://github.com/MindWorkAI/AI-Studio) (FSL-1.1-MIT)
141142
- [iohub/collama](https://github.com/iohub/coLLaMA)
142143
- [janhq/jan](https://github.com/janhq/jan) (AGPL)
143144
- [nat/openplayground](https://github.com/nat/openplayground)
@@ -181,6 +182,9 @@ Unless otherwise noted these projects are open-source with permissive licensing:
181182

182183
- [Paddler](https://github.com/distantmagic/paddler) - Stateful load balancer custom-tailored for llama.cpp
183184

185+
**Games:**
186+
- [Lucy's Labyrinth](https://github.com/MorganRO8/Lucys_Labyrinth) - A simple maze game where agents controlled by an AI model will try to trick you.
187+
184188
## Demo
185189

186190
<details>

common/common.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -694,11 +694,6 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
694694
params.lora_adapter.emplace_back(lora_adapter, std::stof(argv[i]));
695695
return true;
696696
}
697-
if (arg == "--lora-base") {
698-
CHECK_ARG
699-
params.lora_base = argv[i];
700-
return true;
701-
}
702697
if (arg == "--control-vector") {
703698
CHECK_ARG
704699
params.control_vectors.push_back({ 1.0f, argv[i], });
@@ -1274,6 +1269,7 @@ bool gpt_params_find_arg(int argc, char ** argv, const std::string & arg, gpt_pa
12741269
CHECK_ARG
12751270
params.out_file = argv[i];
12761271
params.cvector_outfile = argv[i];
1272+
params.lora_outfile = argv[i];
12771273
return true;
12781274
}
12791275
if (arg == "-ofreq" || arg == "--output-frequency") {
@@ -1583,9 +1579,8 @@ void gpt_params_print_usage(int /*argc*/, char ** argv, const gpt_params & param
15831579
options.push_back({ "*", " --override-kv KEY=TYPE:VALUE",
15841580
"advanced option to override model metadata by key. may be specified multiple times.\n"
15851581
"types: int, float, bool, str. example: --override-kv tokenizer.ggml.add_bos_token=bool:false" });
1586-
options.push_back({ "*", " --lora FNAME", "apply LoRA adapter (implies --no-mmap)" });
1587-
options.push_back({ "*", " --lora-scaled FNAME S", "apply LoRA adapter with user defined scaling S (implies --no-mmap)" });
1588-
options.push_back({ "*", " --lora-base FNAME", "optional model to use as a base for the layers modified by the LoRA adapter" });
1582+
options.push_back({ "*", " --lora FNAME", "apply LoRA adapter (can be repeated to use multiple adapters)" });
1583+
options.push_back({ "*", " --lora-scaled FNAME S", "apply LoRA adapter with user defined scaling S (can be repeated to use multiple adapters)" });
15891584
options.push_back({ "*", " --control-vector FNAME", "add a control vector\n"
15901585
"note: this argument can be repeated to add multiple control vectors" });
15911586
options.push_back({ "*", " --control-vector-scaled FNAME SCALE",
@@ -1676,6 +1671,13 @@ void gpt_params_print_usage(int /*argc*/, char ** argv, const gpt_params & param
16761671
options.push_back({ "cvector", " --pca-iter N", "number of iterations used for PCA (default: %d)", params.n_pca_iterations });
16771672
options.push_back({ "cvector", " --method {pca,mean}", "dimensionality reduction method to be used (default: pca)" });
16781673

1674+
options.push_back({ "export-lora" });
1675+
options.push_back({ "export-lora", "-m, --model", "model path from which to load base model (default '%s')", params.model.c_str() });
1676+
options.push_back({ "export-lora", " --lora FNAME", "path to LoRA adapter (can be repeated to use multiple adapters)" });
1677+
options.push_back({ "export-lora", " --lora-scaled FNAME S", "path to LoRA adapter with user defined scaling S (can be repeated to use multiple adapters)" });
1678+
options.push_back({ "*", "-t, --threads N", "number of threads to use during computation (default: %d)", params.n_threads });
1679+
options.push_back({ "export-lora", "-o, --output FNAME", "output file (default: '%s')", params.lora_outfile.c_str() });
1680+
16791681
printf("usage: %s [options]\n", argv[0]);
16801682

16811683
for (const auto & o : options) {
@@ -2721,7 +2723,7 @@ std::string llama_chat_format_single(const struct llama_model * model,
27212723
const llama_chat_msg & new_msg,
27222724
bool add_ass) {
27232725
std::ostringstream ss;
2724-
auto fmt_past_msg = llama_chat_apply_template(model, tmpl, past_msg, false);
2726+
auto fmt_past_msg = past_msg.empty() ? "" : llama_chat_apply_template(model, tmpl, past_msg, false);
27252727
std::vector<llama_chat_msg> chat_new(past_msg);
27262728
// if the past_msg ends with a newline, we must preserve it in the formatted version
27272729
if (add_ass && !fmt_past_msg.empty() && fmt_past_msg.back() == '\n') {
@@ -3166,7 +3168,6 @@ void yaml_dump_non_result_info(FILE * stream, const gpt_params & params, const l
31663168
}
31673169
fprintf(stream, " - %s: %f\n", std::get<0>(la).c_str(), std::get<1>(la));
31683170
}
3169-
fprintf(stream, "lora_base: %s\n", params.lora_base.c_str());
31703171
fprintf(stream, "main_gpu: %d # default: 0\n", params.main_gpu);
31713172
fprintf(stream, "min_keep: %d # default: 0 (disabled)\n", sparams.min_keep);
31723173
fprintf(stream, "mirostat: %d # default: 0 (disabled)\n", sparams.mirostat);

common/common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ struct gpt_params {
128128

129129
// TODO: avoid tuple, use struct
130130
std::vector<std::tuple<std::string, float>> lora_adapter; // lora adapter path with user defined scale
131-
std::string lora_base = ""; // base model path for the lora adapter
132131

133132
std::vector<llama_control_vector_load_info> control_vectors; // control vector with user defined scale
134133

@@ -255,6 +254,8 @@ struct gpt_params {
255254
std::string cvector_negative_file = "examples/cvector-generator/negative.txt";
256255

257256
bool spm_infill = false; // suffix/prefix/middle pattern for infill
257+
258+
std::string lora_outfile = "ggml-lora-merged-f16.gguf";
258259
};
259260

260261
void gpt_params_handle_hf_token(gpt_params & params);

common/sampling.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static llama_token llama_sampling_sample_impl(
330330
llama_token_data_array single_token_data_array = { &single_token_data, 1, false };
331331

332332
// Apply grammar constraints to the single token
333-
llama_sample_grammar(ctx_main, &single_token_data_array, ctx_sampling->grammar);
333+
llama_grammar_sample(ctx_sampling->grammar, ctx_main, &single_token_data_array);
334334

335335
// Check if the token is valid according to the grammar by seeing if its logit has been set to -INFINITY
336336
bool is_valid = single_token_data_array.data[0].logit != -INFINITY;
@@ -421,7 +421,7 @@ static llama_token_data_array llama_sampling_prepare_impl(
421421

422422
// apply grammar checks before sampling logic
423423
if (apply_grammar && ctx_sampling->grammar != NULL) {
424-
llama_sample_grammar(ctx_main, &cur_p, ctx_sampling->grammar);
424+
llama_grammar_sample(ctx_sampling->grammar, ctx_main, &cur_p);
425425
}
426426

427427
return cur_p;
@@ -455,6 +455,6 @@ void llama_sampling_accept(
455455
ctx_sampling->prev.push_back(id);
456456

457457
if (ctx_sampling->grammar != NULL && apply_grammar) {
458-
llama_grammar_accept_token(ctx_main, ctx_sampling->grammar, id);
458+
llama_grammar_accept_token(ctx_sampling->grammar, ctx_main, id);
459459
}
460460
}

0 commit comments

Comments
 (0)