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

Approximate tokens len #9546

Merged
merged 1 commit into from Jan 19, 2024
Merged

Approximate tokens len #9546

merged 1 commit into from Jan 19, 2024

Conversation

MichaReiser
Copy link
Member

Summary

The parser benchmark has become flaky after merging #9466.
A possible reason for the flakiness could be some non-determinism in jemalloc that makes it execute different branches while collecting the tokens into a Vec.

The idea of this PR is to approximate the size of the tokens Vec based on the source code length. The approximation used here is based on an analysis of the CPython code base and our ecosystem projects (including aiflow, black, django, transformers, twine, warehouse, zulip). I added a console output that prints the source code length and resulting tokens vec size for each file and piped it into a CSV. I then used a small python script to paint the $buffer/source$ distribution and picked 0.15 as a lower bound for the size of the tokens vec.

Ecosystem
ecosystem

CPython
python

Note: The 1 looks suspicious. It is due to empty files. I'm not sure why there are so many empty files

Source

Test Plan

I expected some real world perf improvements from this work but neither our hyperfine benchmarks nor the parser's microbenchmarks show any real improvement 🤷

@MichaReiser MichaReiser force-pushed the approximate-tokens-len branch 2 times, most recently from 7bf7760 to cbd2c19 Compare January 16, 2024 08:13
@MichaReiser MichaReiser marked this pull request as ready for review January 16, 2024 08:46
@MichaReiser MichaReiser added the internal An internal refactor or improvement label Jan 16, 2024
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

Neat idea.

@MichaReiser MichaReiser merged commit 47ad7b4 into main Jan 19, 2024
17 checks passed
@MichaReiser MichaReiser deleted the approximate-tokens-len branch January 19, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants