Skip to content

Commit 3b06a95

Browse files
authored
Merge branch 'layla-build' into merge
2 parents d0d5b22 + ff0bea0 commit 3b06a95

33 files changed

+1696075
-134
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ autogen-*.md
7777
!.github/workflows/*.yml
7878

7979
# Models
80-
8180
models/*
8281
models-mnt
8382
!models/.editorconfig

common/common.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,9 @@ struct llama_model_params common_model_params_to_llama(common_params & params) {
10401040
auto mparams = llama_model_default_params();
10411041

10421042
if (!params.devices.empty()) {
1043+
// add nullptr to the end just in case
1044+
params.devices.push_back(nullptr);
1045+
10431046
mparams.devices = params.devices.data();
10441047
}
10451048

common/minja/chat-template.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#pragma once
1010

1111
#include "minja.hpp"
12-
1312
#include <chrono>
1413
#include <cstddef>
1514
#include <cstdio>
@@ -19,7 +18,6 @@
1918
#include <sstream>
2019
#include <string>
2120
#include <vector>
22-
2321
#include <json.hpp>
2422

2523
using json = nlohmann::ordered_json;

common/minja/minja.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <unordered_set>
2828
#include <utility>
2929
#include <vector>
30-
3130
#include <json.hpp>
3231

3332
using json = nlohmann::ordered_json;

common/sampling.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ struct ring_buffer {
6161
return value;
6262
}
6363

64+
T pop_back() {
65+
if (sz == 0) {
66+
throw std::runtime_error("ring buffer is empty");
67+
}
68+
// Move pos backwards, wrapping around if necessary
69+
pos = (pos == 0) ? capacity - 1 : pos - 1;
70+
T value = data[pos];
71+
sz--;
72+
return value;
73+
}
74+
6475
const T & rat(size_t i) const {
6576
if (i >= sz) {
6677
throw std::runtime_error("ring buffer: index out of bounds");
@@ -316,6 +327,12 @@ void common_sampler_reset(struct common_sampler * gsmpl) {
316327
llama_sampler_reset(gsmpl->chain);
317328
}
318329

330+
void common_sampler_reinit_grammar(struct common_sampler * gsmpl, const struct llama_model * model, const char * grammar) {
331+
llama_sampler_reset(gsmpl->grmr);
332+
333+
gsmpl->grmr = llama_sampler_init_grammar(llama_model_get_vocab(model), grammar, "root");
334+
}
335+
319336
struct common_sampler * common_sampler_clone(common_sampler * gsmpl) {
320337
return new common_sampler {
321338
/* .params = */ gsmpl->params,
@@ -469,6 +486,21 @@ std::string common_sampler_prev_str(common_sampler * gsmpl, llama_context * ctx_
469486
return result;
470487
}
471488

489+
const std::vector<llama_token> common_sampler_prev(common_sampler * gsmpl) {
490+
return gsmpl->prev.to_vector();
491+
}
492+
493+
void common_sampler_rollback(common_sampler * gsmpl, int rollback_num) {
494+
if(rollback_num > gsmpl->prev.size()) {
495+
rollback_num = gsmpl->prev.size();
496+
}
497+
498+
// continuously pop the last token
499+
for(int i = 0; i < rollback_num; i++) {
500+
gsmpl->prev.pop_back();
501+
}
502+
}
503+
472504
char common_sampler_type_to_chr(enum common_sampler_type cnstr) {
473505
switch (cnstr) {
474506
case COMMON_SAMPLER_TYPE_DRY: return 'd';

common/sampling.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void common_sampler_free(struct common_sampler * gsmpl);
4343
// if accept_grammar is true, the token is accepted both by the sampling chain and the grammar
4444
void common_sampler_accept(struct common_sampler * gsmpl, llama_token token, bool accept_grammar);
4545
void common_sampler_reset (struct common_sampler * gsmpl);
46+
void common_sampler_reinit_grammar(struct common_sampler * gsmpl, const struct llama_model * model, const char * grammar);
4647
struct common_sampler * common_sampler_clone (struct common_sampler * gsmpl);
4748

4849
// arguments can be nullptr to skip printing
@@ -96,6 +97,8 @@ std::string common_sampler_print(const struct common_sampler * gsmpl);
9697

9798
// get a string representation of the last accepted tokens
9899
std::string common_sampler_prev_str(common_sampler * gsmpl, llama_context * ctx, int n);
100+
const std::vector<llama_token> common_sampler_prev(common_sampler * gsmpl);
101+
void common_sampler_rollback(common_sampler * gsmpl, int rollback_num);
99102

100103
char common_sampler_type_to_chr(enum common_sampler_type cnstr);
101104
std::string common_sampler_type_to_str(enum common_sampler_type cnstr);

examples/llava/llava.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
# define LOG_WRN(...)
1717
# define LOG_ERR(...)
1818
# define LOG_DBG(...)
19+
#elif defined(ANDROID)
20+
# include "llama-impl.h"
21+
# define LOG_INF(...) LLAMA_LOG_INFO(__VA_ARGS__)
22+
# define LOG_WRN(...) LLAMA_LOG_WARN(__VA_ARGS__)
23+
# define LOG_ERR(...) LLAMA_LOG_ERROR(__VA_ARGS__)
24+
# define LOG_DBG(...) LLAMA_LOG_DEBUG(__VA_ARGS__)
1925
#else // defined(LLAVA_LOG_OFF)
2026
# define LOG_INF(...) do { fprintf(stdout, __VA_ARGS__); } while (0)
2127
# define LOG_WRN(...) do { fprintf(stderr, __VA_ARGS__); } while (0)

ggml/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ set(GGML_PUBLIC_HEADERS
272272
include/gguf.h)
273273

274274
set_target_properties(ggml PROPERTIES PUBLIC_HEADER "${GGML_PUBLIC_HEADERS}")
275+
276+
# link android log library
277+
if(ANDROID)
278+
find_library(log-lib log)
279+
target_link_libraries(ggml PRIVATE ${log-lib})
280+
endif()
281+
275282
#if (GGML_METAL)
276283
# set_target_properties(ggml PROPERTIES RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/src/ggml-metal.metal")
277284
#endif()

ggml/include/ggml-backend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ extern "C" {
202202
//
203203
// Backend registry
204204
//
205+
GGML_API void ggml_backend_reg_layla(bool useVulkan, bool useOpenCL);
205206

206207
GGML_API void ggml_backend_device_register(ggml_backend_dev_t device);
207208

ggml/src/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ add_library(ggml-base
203203
ggml-quants.h
204204
gguf.cpp)
205205

206+
# Search for the 'log' library on Android
207+
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
208+
find_library(log-lib log)
209+
set(GGML_EXTRA_LIBS ${GGML_EXTRA_LIBS} ${log-lib})
210+
211+
target_link_libraries(ggml-base PUBLIC ${GGML_EXTRA_LIBS})
212+
endif()
213+
206214
target_include_directories(ggml-base PRIVATE .)
207215
if (GGML_BACKEND_DL)
208216
target_compile_definitions(ggml-base PUBLIC GGML_BACKEND_DL)

0 commit comments

Comments
 (0)