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, drop-in 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
  • Drop-In Replacement: Full compatibility with OpenAI's TikToken tokenizer
  • Simplified BPE: Simplied algorithm to reduce performance impact of large special token vocabulary.

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.1.tar.gz (3.0 MB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: tokendagger-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 1087fbddec49a115c51a843f28f6b10dad51f42b61cdabbb3446321c4bd58f23
MD5 cadb4b625940f113213d30e35de5a66f
BLAKE2b-256 ffb75cc207d56a63e040c265c5eea1130be32b0622f681ce77f0b56eb6ddfa12

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