Heap Allocation Bypass [BPE] #66
Answered
by
Eamon2009
eamonsippy
asked this question in
Q&A
|
Heap Allocation Bypass: When train_bpe encodes a raw text string into base character IDs, it avoids standard string memory allocations entirely. What specific data structure (char_to_id) does it use to achieve |
Answered by
Eamon2009
Jul 28, 2026
Replies: 1 comment
|
The code uses a fixed-size integer array: int char_to_id[256];. Instead of instantiating C++ std::string objects and running them through a hash map (which requires slow heap memory allocation and hashing algorithms), the tokenizer simply casts a character to its raw ASCII/byte value ((unsigned char)c) and uses it as a direct .\llm.exe data\input.txt |
0 replies
Answer selected by
eamonsippy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code uses a fixed-size integer array: int char_to_id[256];. Instead of instantiating C++ std::string objects and running them through a hash map (which requires slow heap memory allocation and hashing algorithms), the tokenizer simply casts a character to its raw ASCII/byte value ((unsigned char)c) and uses it as a direct$O(1)$ index to find the ID. this is when you pass a .txt file
like for eg: