Skip to main content

High-Performance Implementation of OpenAI's TikToken - 2x Throughput, 4x Faster Code Tokenization

Project description

TokenDagger: High-Performance Implementation of OpenAI's TikToken

License: MIT Python 3.8+ PyPI version

A fast implementation of OpenAI's TikToken, designed for large-scale text processing. 2x Throughput and 4x faster on code sample tokenization.

Benchmarks

Performed on an AMD EPYC 4584PX - 16c/32t - 4.2 GHz.

Throughput Benchmark Results

  • Fast Regex Parsing: Optimized PCRE2 regex engine for efficient token pattern matching
  • Simplified BPE: Simplied algorithm to reduce performance impact of large special token vocabulary.
  • OpenAI Compatible: Full compatibility with OpenAI's TikToken tokenizer

Run Tests

make clean && make
pip3 install tiktoken
python3 tests/test_tokendagger_vs_tiktoken.py --tokenizer llama
python3 tests/test_tokendagger_vs_tiktoken.py --tokenizer mistral
python3 tests/performance_benchmark.py --tokenizer llama
python3 tests/performance_benchmark.py --tokenizer mistral
python3 tests/code_performance_benchmark.py --tokenizer llama
================================================================================
🎉 CONCLUSION: TokenDagger is 4.02x faster on code tokenization!
================================================================================

📦 Installation

From PyPI (Recommended)

pip install tokendagger

🛠️ Dev Install

git clone git@github.com:M4THYOU/TokenDagger.git
sudo apt install libpcre2-dev
git submodule update --init --recursive
sudo apt update && sudo apt install -y python3-dev

And optionally for running the tests:

pip3 install tiktoken

Dependencies

  • PCRE2: Perl Compatible Regular Expressions - GitHub

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tokendagger-0.1.0.tar.gz (3.0 MB view details)

Uploaded Source

File details

Details for the file tokendagger-0.1.0.tar.gz.

File metadata

  • Download URL: tokendagger-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for tokendagger-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e8b2042286ee7f3a54b5fab39328072ff76a4dc83483a0d03aa7fce83948fd3c
MD5 ae52120682a8653a7ba2922e965adc3d
BLAKE2b-256 0e79b3f11f0a9990d40302a5a178a20b42a9aaf104b58f13dff553b6df30b69f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page