Skip to content

Commit

Permalink
llama : suppress conversion from 'size_t' to 'int'
Browse files Browse the repository at this point in the history
This commit makes updates llama-vocab.cpp llm_tokenizer_spm.tokenize
to suppress/remove the following warnings that are generated on
Windows when using MSVC:

```console
src\llama-vocab.cpp(211,1): warning C4267: 'argument':
    conversion from 'size_t' to 'int', possible loss of data
src\llama-vocab.cpp(517,1): warning C4267: 'argument':
    conversion from 'size_t' to 'int', possible loss of data
```

This is done by adding a cast for the size_t returned from
symbols.size(). I believe this is safe as it seems unlikely that
symbols, which stores an entry for each UTF8 character, would become
larger than INT_MAX.
  • Loading branch information
danbev committed Aug 15, 2024
1 parent d3ae0ee commit 88a51dc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/llama-vocab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ struct llm_tokenizer_spm {
}

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

Expand Down Expand Up @@ -511,7 +512,8 @@ struct llm_tokenizer_bpe {
index++;
symbols.emplace_back(sym);
}
for (size_t i = 1; i < symbols.size(); ++i) {
int symbols_size = static_cast<int>(symbols.size());
for (int i = 1; i < symbols.size(); ++i) {
add_new_bigram(i - 1, i);
}

Expand Down

0 comments on commit 88a51dc

Please sign in to comment.