mirror of
https://github.com/ikawrakow/ik_llama.cpp.git
synced 2026-04-30 11:21:56 +00:00
Add mtmd: mtmd.cpp compiles
This commit is contained in:
@@ -334,10 +334,10 @@ private:
|
|||||||
std::string token_to_piece(const llama_vocab * vocab, llama_token token, bool special) {
|
std::string token_to_piece(const llama_vocab * vocab, llama_token token, bool special) {
|
||||||
std::string piece;
|
std::string piece;
|
||||||
piece.resize(piece.capacity()); // using string internal cache, 15 bytes + '\n'
|
piece.resize(piece.capacity()); // using string internal cache, 15 bytes + '\n'
|
||||||
const int n_chars = llama_token_to_piece(vocab, token, &piece[0], piece.size(), 0, special);
|
const int n_chars = llama_vocab_token_to_piece(vocab, token, &piece[0], piece.size(), 0, special);
|
||||||
if (n_chars < 0) {
|
if (n_chars < 0) {
|
||||||
piece.resize(-n_chars);
|
piece.resize(-n_chars);
|
||||||
int check = llama_token_to_piece(vocab, token, &piece[0], piece.size(), 0, special);
|
int check = llama_vocab_token_to_piece(vocab, token, &piece[0], piece.size(), 0, special);
|
||||||
GGML_ASSERT(check == -n_chars);
|
GGML_ASSERT(check == -n_chars);
|
||||||
} else {
|
} else {
|
||||||
piece.resize(n_chars);
|
piece.resize(n_chars);
|
||||||
@@ -720,10 +720,10 @@ struct mtmd_tokenizer {
|
|||||||
// upper limit for the number of tokens
|
// upper limit for the number of tokens
|
||||||
int n_tokens = text.length() + 2 * add_special;
|
int n_tokens = text.length() + 2 * add_special;
|
||||||
std::vector<llama_token> result(n_tokens);
|
std::vector<llama_token> result(n_tokens);
|
||||||
n_tokens = llama_tokenize(vocab, text.data(), text.length(), result.data(), result.size(), add_special, parse_special);
|
n_tokens = llama_vocab_tokenize(vocab, text.data(), text.length(), result.data(), result.size(), add_special, parse_special);
|
||||||
if (n_tokens < 0) {
|
if (n_tokens < 0) {
|
||||||
result.resize(-n_tokens);
|
result.resize(-n_tokens);
|
||||||
int check = llama_tokenize(vocab, text.data(), text.length(), result.data(), result.size(), add_special, parse_special);
|
int check = llama_vocab_tokenize(vocab, text.data(), text.length(), result.data(), result.size(), add_special, parse_special);
|
||||||
GGML_ASSERT(check == -n_tokens);
|
GGML_ASSERT(check == -n_tokens);
|
||||||
} else {
|
} else {
|
||||||
result.resize(n_tokens);
|
result.resize(n_tokens);
|
||||||
|
|||||||
@@ -581,6 +581,14 @@ extern "C" {
|
|||||||
LLAMA_API int32_t llama_n_embd (const struct llama_model * model);
|
LLAMA_API int32_t llama_n_embd (const struct llama_model * model);
|
||||||
LLAMA_API int32_t llama_n_layer (const struct llama_model * model);
|
LLAMA_API int32_t llama_n_layer (const struct llama_model * model);
|
||||||
|
|
||||||
|
// Compat
|
||||||
|
static int32_t llama_model_n_embd(const struct llama_model * model) { return llama_n_embd(model); }
|
||||||
|
LLAMA_API bool llama_vocab_get_add_bos(const struct llama_vocab * vocab);
|
||||||
|
LLAMA_API bool llama_vocab_get_add_eos(const struct llama_vocab * vocab);
|
||||||
|
LLAMA_API int32_t llama_vocab_n_tokens(const struct llama_vocab * vocab);
|
||||||
|
LLAMA_API llama_token llama_vocab_bos(const struct llama_vocab * vocab);
|
||||||
|
LLAMA_API llama_token llama_vocab_eos(const struct llama_vocab * vocab);
|
||||||
|
|
||||||
// Get the model's RoPE frequency scaling factor
|
// Get the model's RoPE frequency scaling factor
|
||||||
LLAMA_API float llama_rope_freq_scale_train(const struct llama_model * model);
|
LLAMA_API float llama_rope_freq_scale_train(const struct llama_model * model);
|
||||||
|
|
||||||
@@ -1061,6 +1069,14 @@ extern "C" {
|
|||||||
int32_t n_tokens_max,
|
int32_t n_tokens_max,
|
||||||
bool add_special,
|
bool add_special,
|
||||||
bool parse_special);
|
bool parse_special);
|
||||||
|
LLAMA_API int32_t llama_vocab_tokenize(
|
||||||
|
const struct llama_vocab * vocab,
|
||||||
|
const char * text,
|
||||||
|
int32_t text_len,
|
||||||
|
llama_token * tokens,
|
||||||
|
int32_t n_tokens_max,
|
||||||
|
bool add_special,
|
||||||
|
bool parse_special);
|
||||||
|
|
||||||
// Token Id -> Piece.
|
// Token Id -> Piece.
|
||||||
// Uses the vocabulary in the provided context.
|
// Uses the vocabulary in the provided context.
|
||||||
@@ -1074,6 +1090,13 @@ extern "C" {
|
|||||||
int32_t length,
|
int32_t length,
|
||||||
int32_t lstrip,
|
int32_t lstrip,
|
||||||
bool special);
|
bool special);
|
||||||
|
LLAMA_API int32_t llama_vocab_token_to_piece(
|
||||||
|
const struct llama_vocab * vocab,
|
||||||
|
llama_token token,
|
||||||
|
char * buf,
|
||||||
|
int32_t length,
|
||||||
|
int32_t lstrip,
|
||||||
|
bool special);
|
||||||
|
|
||||||
/// @details Convert the provided tokens into text (inverse of llama_tokenize()).
|
/// @details Convert the provided tokens into text (inverse of llama_tokenize()).
|
||||||
/// @param text The char pointer must be large enough to hold the resulting text.
|
/// @param text The char pointer must be large enough to hold the resulting text.
|
||||||
|
|||||||
@@ -3770,7 +3770,7 @@ llama_token llama_token_fim_sep(const struct llama_vocab * vocab) {
|
|||||||
// tokenization
|
// tokenization
|
||||||
//
|
//
|
||||||
|
|
||||||
int32_t llama_tokenize(
|
int32_t llama_vocab_tokenize(
|
||||||
const struct llama_vocab * vocab,
|
const struct llama_vocab * vocab,
|
||||||
const char * text,
|
const char * text,
|
||||||
int32_t text_len,
|
int32_t text_len,
|
||||||
@@ -3781,7 +3781,7 @@ int32_t llama_tokenize(
|
|||||||
return vocab->tokenize(text, text_len, tokens, n_tokens_max, add_special, parse_special);
|
return vocab->tokenize(text, text_len, tokens, n_tokens_max, add_special, parse_special);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t llama_token_to_piece(
|
int32_t llama_vocab_token_to_piece(
|
||||||
const struct llama_vocab * vocab,
|
const struct llama_vocab * vocab,
|
||||||
llama_token token,
|
llama_token token,
|
||||||
char * buf,
|
char * buf,
|
||||||
|
|||||||
Reference in New Issue
Block a user