Skip to content
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

binary search to get prompt tokens #26

Merged
merged 1 commit into from
Sep 20, 2023
Merged

Conversation

mikowals
Copy link
Contributor

  • added string_compare and quicksort to support sorting and binary search
  • moved tokenizer_init to an init in Tokenizer and removed the init to empty vars
  • removed unused str_lookup

Locally I confirmed this out put the same prompt_tokens as str_lookup.

In benchmarking in a Github codespace with 8 cores and 32 GB ram sorting took 6ms and getting prompt tokens of a few sentence prompt took 1ms. With old str_lookup getting the prompt tokens for the same prompt to 230ms.

The code can be cleaned up a lot when it becomes easier to have a pointer hold a locally defined struct with both the string and index.

@tairov
Copy link
Owner

tairov commented Sep 20, 2023

Look cool. I'll check this out a bit later .

Did you notice any tok/s performance improvement ?

@mikowals
Copy link
Contributor Author

The tok/s improvement was negligible for the size of prompts I was testing on. For longer prompts it probably is noticeable but would occur as the prompt be read a couple seconds faster and the change then being averaged over how many tokens the model went on to produce. So I focused on directly comparing the code being replaced.

@tairov tairov merged commit c6005ed into tairov:master Sep 20, 2023
@tairov
Copy link
Owner

tairov commented Sep 20, 2023

merged! @mikowals thanks for the clean implementation!

@mikowals mikowals deleted the b-search branch October 1, 2023 16:55
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.

2 participants