-
Notifications
You must be signed in to change notification settings - Fork 5k
fix: eliminate hard-coded vocab definitions to make the Whisper model compatible with custom vocabularies and embedding layer lengths #3555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jaffe2718
wants to merge
4
commits into
ggml-org:master
Choose a base branch
from
Jaffe2718:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
79b0c01
Avoid hard-coding definition vocabulary to be compatible with differe…
Jaffe2718 43d873c
modify comment
Jaffe2718 ccd9b6e
fix num_language(): incorrect after loading special tokens
Jaffe2718 1ab1804
fix convert script: remove special token `<|endoftext|>`
Jaffe2718 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -453,7 +453,7 @@ struct whisper_vocab { | |
| } | ||
|
|
||
| int num_languages() const { | ||
| return n_vocab - 51765 - (is_multilingual() ? 1 : 0); | ||
| return token_translate - token_sot - 1; | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -1621,22 +1621,19 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con | |
| //printf("%s: vocab[%d] = '%s'\n", __func__, i, word.c_str()); | ||
| } | ||
|
|
||
| vocab.n_vocab = model.hparams.n_vocab; | ||
| if (vocab.is_multilingual()) { | ||
| vocab.token_eot++; | ||
| vocab.token_sot++; | ||
| vocab.n_vocab = model.hparams.n_vocab; // all tokens, including special tokens | ||
|
|
||
| // account for variable number of language tokens | ||
| const int dt = vocab.num_languages() - 98; | ||
|
|
||
| vocab.token_translate += dt; | ||
| vocab.token_transcribe += dt; | ||
| vocab.token_solm += dt; | ||
| vocab.token_prev += dt; | ||
| vocab.token_nosp += dt; | ||
| vocab.token_not += dt; | ||
| vocab.token_beg += dt; | ||
| } | ||
| vocab.token_eot = n_vocab; // <|endoftext|> 50256 for en, 50257 for multilingual, others for custom model | ||
| vocab.token_sot = n_vocab + 1; // <|startoftext|> | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I make a mistake in comment. It should be |
||
| // [n_vocab + 2, vocab.n_vocab - 1507) are language tokens | ||
| // num_language = vocab.token_translate - vocab.token_sot - 1 = vocab.n_vocab - n_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_vocab < model.hparams.n_vocab) { | ||
| WHISPER_LOG_INFO("%s: adding %d extra tokens\n", __func__, model.hparams.n_vocab - n_vocab); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I use ggml-tiny.en.bin recognition, the result is also empty, the same reason why the tests fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the last commit was
Migrate from HG dataset into HG model, it is necessary that these models need to be reconverted if they were last generated with this script, otherwise,<|endoftext|>will be written into common tokens.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like the test model, the GGML models that are actually converted from OpenAI's official model should not record special tokens in the vocabulary, otherwise the ID of the subsequent special token will be positioned incorrectly.
