Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
97b026c
ggml-alloc : remove buffer_id from leaf_alloc (ggml/987)
danbev Oct 9, 2024
5b0a368
metal : single allocation of encode_async block (llama/9747)
ptsochantaris Oct 7, 2024
664ccb7
ggml : add metal backend registry / device (llama/9713)
ggerganov Oct 7, 2024
456016b
Update building for Android (llama/9672)
amqdn Oct 7, 2024
e9ed1a6
ggml : add backend registry / device interfaces to BLAS backend (llam…
slaren Oct 7, 2024
b1bd750
ggml : fix BLAS with unsupported types (llama/9775)
slaren Oct 8, 2024
e493b68
musa: add docker image support (llama/9685)
yeahdongcn Oct 10, 2024
5dde62c
rpc : add backend registry / device interfaces (llama/9812)
slaren Oct 10, 2024
dbb264b
ggml : move more prints to the ggml log system (llama/9839)
slaren Oct 11, 2024
fd7ba33
Vectorize load instructions in dmmv f16 CUDA kernel (llama/9816)
agray3 Oct 14, 2024
eed9509
Fix cann compilation error (llama/9891)
leo-pony Oct 16, 2024
3c1d3e4
CUDA: fix 1D im2col, add tests (ggml/993)
JohannesGaessler Oct 18, 2024
24b9e57
fix: use `vm_allocate` to allocate CPU backend buffer on macOS (llama…
giladgd Oct 16, 2024
3017ef0
fix: allocating CPU buffer with size `0` (llama/9917)
giladgd Oct 16, 2024
e2a2660
vulkan : add backend registry / device interfaces (llama/9721)
slaren Oct 17, 2024
4d49f58
add amx kernel for gemm (llama/8998)
mingfeima Oct 18, 2024
71d0e18
Add SYCL Backend registry, device and Event Interfaces (llama/9705)
OuadiElfarouki Oct 18, 2024
e6d7dbc
rpc : backend refactoring (llama/9912)
rgerganov Oct 18, 2024
cd24c26
fix mul_mat_vec_q and *_vec_q error (llama/9939)
NeoZhangJianyu Oct 21, 2024
1d0c577
rpc : pack only RPC structs (llama/9959)
rgerganov Oct 21, 2024
9b3a2da
ggml : add asserts for type conversion in fattn kernels (llama/9971)
ggerganov Oct 21, 2024
db26898
Adapt to dynamically loadable backends mechanism (llama/9970)
leo-pony Oct 22, 2024
3786b03
metal : add POOL2D and fix IM2COL (llama/9943)
junhee-yoo Oct 23, 2024
d7ea6cf
increase cuda_cpy block size (ggml/996)
bssrdf Oct 23, 2024
1ac1152
CUDA: fix MMQ for non-contiguous src0, add tests (llama/10021)
JohannesGaessler Oct 24, 2024
8a81531
CUDA: fix insufficient buffer clearing for MMQ (llama/10032)
JohannesGaessler Oct 24, 2024
3481ab5
metal : support permuted matrix multiplicaions (llama/10033)
ggerganov Oct 25, 2024
cc28564
ggml : add AMX backend (llama/8998)
mingfeima Oct 26, 2024
9c7653c
sync : ggml
ggerganov Oct 31, 2024
d17cdb3
talk-llama : sync llama.cpp
ggerganov Oct 31, 2024
bc763c1
whisper : backend registry init before model load
ggerganov Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
750 changes: 741 additions & 9 deletions examples/talk-llama/llama-sampling.cpp

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions examples/talk-llama/llama-sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include "llama-grammar.h"

#include <unordered_map>

struct llama_vocab;
struct llama_grammar;

Expand All @@ -27,3 +25,24 @@ struct llama_sampler * llama_sampler_init_grammar_impl(
const struct llama_vocab & vocab,
const char * grammar_str,
const char * grammar_root);

struct llama_sampler * llama_sampler_init_infill_impl(
const struct llama_vocab & vocab);

struct llama_sampler * llama_sampler_init_dry_impl(
const struct llama_vocab & vocab,
int32_t context_size,
float dry_multiplier,
float dry_base,
int32_t dry_allowed_length,
int32_t dry_penalty_last_n,
const char ** seq_breakers,
size_t num_breakers);

struct llama_sampler * llama_sampler_init_dry_testing(
int32_t context_size,
float dry_multiplier,
float dry_base,
int32_t dry_allowed_length,
int32_t dry_penalty_last_n,
const std::vector<std::vector<llama_token>>& seq_breakers);
58 changes: 49 additions & 9 deletions examples/talk-llama/llama-vocab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ struct llm_tokenizer_spm_session {
}

// seed the work queue with all possible 2-character tokens.
for (size_t i = 1; i < symbols.size(); ++i) {
for (int i = 1; i < (int) symbols.size(); ++i) {
try_add_bigram(i - 1, i);
}

Expand Down Expand Up @@ -563,7 +563,7 @@ struct llm_tokenizer_bpe_session {
index++;
symbols.emplace_back(sym);
}
for (size_t i = 1; i < symbols.size(); ++i) {
for (int i = 1; i < (int) symbols.size(); ++i) {
add_new_bigram(i - 1, i);
}

Expand Down Expand Up @@ -1663,6 +1663,14 @@ llama_token llama_token_eos_impl(const struct llama_vocab & vocab) {
return vocab.special_eos_id;
}

llama_token llama_token_eot_impl(const struct llama_vocab & vocab) {
return vocab.special_eot_id;
}

llama_token llama_token_eom_impl(const struct llama_vocab & vocab) {
return vocab.special_eom_id;
}

llama_token llama_token_cls_impl(const struct llama_vocab & vocab) {
return vocab.special_cls_id;
}
Expand All @@ -1688,23 +1696,39 @@ bool llama_add_eos_token_impl(const struct llama_vocab & vocab) {
}

llama_token llama_token_prefix_impl(const struct llama_vocab & vocab) {
return vocab.special_prefix_id;
return vocab.special_fim_pre_id;
}

llama_token llama_token_middle_impl(const struct llama_vocab & vocab) {
return vocab.special_middle_id;
return vocab.special_fim_mid_id;
}

llama_token llama_token_suffix_impl(const struct llama_vocab & vocab) {
return vocab.special_suffix_id;
return vocab.special_fim_suf_id;
}

llama_token llama_token_eot_impl(const struct llama_vocab & vocab) {
return vocab.special_eot_id;
llama_token llama_token_fim_pre_impl(const struct llama_vocab & vocab) {
return vocab.special_fim_pre_id;
}

llama_token llama_token_eom_impl(const struct llama_vocab & vocab) {
return vocab.special_eom_id;
llama_token llama_token_fim_suf_impl(const struct llama_vocab & vocab) {
return vocab.special_fim_suf_id;
}

llama_token llama_token_fim_mid_impl(const struct llama_vocab & vocab) {
return vocab.special_fim_mid_id;
}

llama_token llama_token_fim_pad_impl(const struct llama_vocab & vocab) {
return vocab.special_fim_pad_id;
}

llama_token llama_token_fim_rep_impl(const struct llama_vocab & vocab) {
return vocab.special_fim_rep_id;
}

llama_token llama_token_fim_sep_impl(const struct llama_vocab & vocab) {
return vocab.special_fim_sep_id;
}

int32_t llama_tokenize_impl(
Expand Down Expand Up @@ -1942,3 +1966,19 @@ int32_t llama_detokenize_impl(

return total <= text_len_max ? total : -total;
}

std::string llama_detokenize(const struct llama_vocab & vocab, const std::vector<llama_token> & tokens, bool special) {
std::string text;
text.resize(std::max(text.capacity(), tokens.size()));
int32_t n_chars = llama_detokenize_impl(vocab, tokens.data(), (int32_t)tokens.size(), &text[0], (int32_t)text.size(), false, special);
if (n_chars < 0) {
text.resize(-n_chars);
n_chars = llama_detokenize_impl(vocab, tokens.data(), (int32_t)tokens.size(), &text[0], (int32_t)text.size(), false, special);
GGML_ASSERT(n_chars <= (int32_t)text.size()); // whitespace trimming is performed after per-token detokenization
}

text.resize(n_chars);

// NOTE: the original tokenizer decodes bytes after collecting the pieces.
return text;
}
56 changes: 40 additions & 16 deletions examples/talk-llama/llama-vocab.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,26 @@ struct llama_vocab {
std::map<std::pair<std::string, std::string>, int> bpe_ranks;

// default LLaMA special tokens
// TODO: should we set all of these to LLAMA_TOKEN_NULL?
id special_bos_id = 1;
id special_eos_id = 2;
id special_eot_id = LLAMA_TOKEN_NULL;
id special_eom_id = LLAMA_TOKEN_NULL;
id special_unk_id = 0;
id special_sep_id = -1;
id special_pad_id = -1;
id special_cls_id = -1;
id special_mask_id = -1;

id linefeed_id = 13;
id special_prefix_id = -1;
id special_suffix_id = -1;
id special_middle_id = -1;
id special_eot_id = -1; // TODO: move above after "eos_id", and here add "file separator" token
id special_eom_id = -1;
id special_sep_id = LLAMA_TOKEN_NULL;
id special_pad_id = LLAMA_TOKEN_NULL;
id special_cls_id = LLAMA_TOKEN_NULL;
id special_mask_id = LLAMA_TOKEN_NULL;

id linefeed_id = 13;

// fim tokens
id special_fim_pre_id = LLAMA_TOKEN_NULL;
id special_fim_suf_id = LLAMA_TOKEN_NULL;
id special_fim_mid_id = LLAMA_TOKEN_NULL;
id special_fim_pad_id = LLAMA_TOKEN_NULL;
id special_fim_rep_id = LLAMA_TOKEN_NULL; // repo
id special_fim_sep_id = LLAMA_TOKEN_NULL; // file separator

// set of all tokens that cause "end of generation"
std::set<id> special_eog_ids;
Expand Down Expand Up @@ -104,19 +110,26 @@ bool llama_token_is_control_impl(const struct llama_vocab & vocab, llama_token t

llama_token llama_token_bos_impl(const struct llama_vocab & vocab);
llama_token llama_token_eos_impl(const struct llama_vocab & vocab);
llama_token llama_token_eot_impl(const struct llama_vocab & vocab);
llama_token llama_token_eom_impl(const struct llama_vocab & vocab);
llama_token llama_token_cls_impl(const struct llama_vocab & vocab);
llama_token llama_token_sep_impl(const struct llama_vocab & vocab);
llama_token llama_token_nl_impl (const struct llama_vocab & vocab);
llama_token llama_token_pad_impl(const struct llama_vocab & vocab);

bool llama_add_bos_token_impl(const struct llama_vocab & vocab);
bool llama_add_eos_token_impl(const struct llama_vocab & vocab);

llama_token llama_token_prefix_impl(const struct llama_vocab & vocab);
llama_token llama_token_middle_impl(const struct llama_vocab & vocab);
llama_token llama_token_suffix_impl(const struct llama_vocab & vocab);
llama_token llama_token_eot_impl (const struct llama_vocab & vocab);
llama_token llama_token_eom_impl (const struct llama_vocab & vocab);

llama_token llama_token_fim_pre_impl(const struct llama_vocab & vocab);
llama_token llama_token_fim_suf_impl(const struct llama_vocab & vocab);
llama_token llama_token_fim_mid_impl(const struct llama_vocab & vocab);
llama_token llama_token_fim_pad_impl(const struct llama_vocab & vocab);
llama_token llama_token_fim_rep_impl(const struct llama_vocab & vocab);
llama_token llama_token_fim_sep_impl(const struct llama_vocab & vocab);

bool llama_add_bos_token_impl(const struct llama_vocab & vocab);
bool llama_add_eos_token_impl(const struct llama_vocab & vocab);

int32_t llama_tokenize_impl(
const struct llama_vocab & vocab,
Expand All @@ -136,6 +149,12 @@ int32_t llama_token_to_piece_impl(
int32_t lstrip,
bool special);

// check if token0 is contained as a prefix in token1
bool llama_token_is_prefix_impl(
const struct llama_vocab & vocab,
llama_token token0,
llama_token token1);

int32_t llama_detokenize_impl(
const struct llama_vocab & vocab,
const llama_token * tokens,
Expand All @@ -144,3 +163,8 @@ int32_t llama_detokenize_impl(
int32_t text_len_max,
bool remove_special,
bool unparse_special);

std::string llama_detokenize(
const struct llama_vocab & vocab,
const std::vector<llama_token> & tokens,
bool special);
Loading
Loading