Skip to content

[Feat] eliminate hard-coded record special tokens to be compatible with some models with custom vocab#3616

Open
Jaffe2718 wants to merge 1 commit intoggml-org:masterfrom
Jaffe2718:master
Open

[Feat] eliminate hard-coded record special tokens to be compatible with some models with custom vocab#3616
Jaffe2718 wants to merge 1 commit intoggml-org:masterfrom
Jaffe2718:master

Conversation

@Jaffe2718
Copy link

Fix #3392

{
int32_t n_vocab = 0;
read_safe(loader, n_vocab);
int32_t n_common_vocab = 0;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some models, such as ggml-tiny.en.bin include special tokens such as <|endoftext|> in vocab, which is obviously incorrect, so these tokens should be excluded

Comment on lines +1630 to +1648
n_common_vocab -= n_special_token; // subtract the special tokens

vocab.n_vocab = model.hparams.n_vocab; // all tokens, including special tokens

vocab.token_eot = n_common_vocab; // <|endoftext|> 50256 for en, 50257 for multilingual, others for custom model
vocab.token_sot = n_common_vocab + 1; // <|startoftranscribe|>
// [n_common_vocab + 2, vocab.n_vocab - 1507) are language tokens
// num_language = vocab.token_translate - vocab.token_sot - 1 = vocab.n_vocab - n_common_vocab - 1509
vocab.token_translate = vocab.n_vocab - 1507; // <|translate|>
vocab.token_transcribe = vocab.n_vocab - 1506; // <|transcribe|>
vocab.token_solm = vocab.n_vocab - 1505; // <|startoflm|>
vocab.token_prev = vocab.n_vocab - 1504; // <|startofprev|>
vocab.token_nosp = vocab.n_vocab - 1503; // <|nospeech|>
vocab.token_not = vocab.n_vocab - 1502; // <|notimestamps|>
vocab.token_beg = vocab.n_vocab - 1501; // timestamps from <|0.00|> to <|30.00|>, 1501 tokens

if (n_common_vocab < model.hparams.n_vocab) {
WHISPER_LOG_INFO("%s: adding %d extra tokens\n", __func__, model.hparams.n_vocab - n_common_vocab);
for (int i = n_common_vocab; i < model.hparams.n_vocab; i++) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this modifies the algorithm for native whisper to define vocab, but native whisper is also hardcoded. For some Whisper models like whisper-ja-anime-v0.3 on HuggingFace, if the vocab size is modified, it is not compatible with whisper.cpp because the index is off-bounds when loading the vocab of these models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segment fault on custom model

1 participant