Skip to main content

Tokenize your documents at GB/s

Project description

Gigatoken

400-1600x faster than HuggingFace's tokenizers, drop-in replacement.

Tokenize your text data at GB/s!

GPT-2 Speedup

Keep in mind that both HF tokenizers and tiktoken are already running multithreaded Rust!

What is Gigatoken?

Gigatoken is the fastest tokenizer for language modeling. It supports a wide range of CPU hardware, and nearly all commonly used tokenizers.

Installation

pip install gigatoken

Usage

Gigatoken can be used with its own API, or in compatibility mode with HuggingFace Tokenizers or Tiktoken.

Compatibility Mode (Easiest)

import gigatoken as gt

# Minimum change from existing HuggingFace tokenizers usage (compatibility mode)
hf_tokenizer = ...
tokenizer = gt.Tokenizer(hf_tokenizer).as_hf()

# tokenizer can be used in the same contexts as hf_tokenizer
tokens = tokenizer.encode_batch(["This is a tes runningt string", "And here is another"])

A substantial amount of effort has been put into making sure the outputs match exactly with what you would get with HuggingFace Tokenizers in this setting, but this is at a non-negligible cost to performance. You can still expect way faster performance across the board, but not quite the 1000x you will get with the Gigatoken API.

Gigatoken API (Fastest)

import gigatoken as gt

tokenizer = gt.Tokenizer("Qwen/Qwen3-8B")  # Accepts HF model names
file_source = gt.TextFileSource(["owt_train.txt"], separator=b"<|endoftext|>")
tokens = tokenizer.encode_files(file_source)

Using the Gigatoken API lets the Rust implementation read data directly, and skips as much overhead as possible while allowing for maximum parallelism. Keep in mind that passing Python data structures through this API still incurs the overhead of reading from Python.

AI Use Disclosure A majority of this code base was crafted by hand without any use of AI (which can be seen from the project's Git history). In the final stages of the project, AI was used to assist:
  • Implementing the user-facing API
  • Widening of compatibility, for instance generalizing and porting the pretokenizer implementations to support more tokenizers, less interesting features like padding/truncation/unicode normalization
  • Porting SIMD strategies between AVX512/AVX2/NEON
  • Final profiling stages and the last ~4x worth of performance from eliminating branch prediction and improving the pretoken cache hierarchy
  • Refactoring and code reuse

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

gigatoken-0.4.0.tar.gz (687.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gigatoken-0.4.0-cp310-abi3-win_arm64.whl (1.3 MB view details)

Uploaded CPython 3.10+Windows ARM64

gigatoken-0.4.0-cp310-abi3-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.10+Windows x86-64

gigatoken-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

gigatoken-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

gigatoken-0.4.0-cp310-abi3-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gigatoken-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file gigatoken-0.4.0.tar.gz.

File metadata

  • Download URL: gigatoken-0.4.0.tar.gz
  • Upload date:
  • Size: 687.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gigatoken-0.4.0.tar.gz
Algorithm Hash digest
SHA256 bc6df75e1275b9360d76ab079abeb964cd1f3fdf3595447b99f094eff07c89ca
MD5 3cb9f3e970a184100f2a753ec2033508
BLAKE2b-256 dc699188ec9d084189ccea114994d0615526b0851f1627ed259ebbdee9613408

See more details on using hashes here.

File details

Details for the file gigatoken-0.4.0-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: gigatoken-0.4.0-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gigatoken-0.4.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 6a72b2867c46ba592167c9ec8de98288a18db030a69ff479debb53a0e7d90443
MD5 fed5804dcf30e5ae5bd02ca6d1da936a
BLAKE2b-256 b9a7d649b040cffb11820c8273826e48df1717782a62665ae2f2c34530346b4c

See more details on using hashes here.

File details

Details for the file gigatoken-0.4.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: gigatoken-0.4.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gigatoken-0.4.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 99c1e4ddd5f5f2a00744dd12a9c262dbeff044a45ba01581dc02ac6cb75088b7
MD5 884523fe6a58236232ce6209361f086b
BLAKE2b-256 0ea43d794a89cfb3b9682b2e9dd8f162ca44800eed88497c4472e994f43167fd

See more details on using hashes here.

File details

Details for the file gigatoken-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: gigatoken-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gigatoken-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b729a1c1e78d63907e5ee57c5bdbcd176f4a498562a73ccae1f519472b252ae
MD5 e9cc901f472aae44d5981441f06cde2c
BLAKE2b-256 bf6633079574ea8f5e264e90567b6942f076817458277d4c4178205bbe24327b

See more details on using hashes here.

File details

Details for the file gigatoken-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: gigatoken-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gigatoken-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 17a1a05829e15b3bffe39b6b159144dff1f04a5b9319a4fbcd89d86743cc50da
MD5 787699764a9c289e42b4bf24aee78c58
BLAKE2b-256 46c993fbd743895ef1eb32da1932c1f735220be33fa51e52ece16373f89ee4b8

See more details on using hashes here.

File details

Details for the file gigatoken-0.4.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: gigatoken-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gigatoken-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6c948869865a5feba5af29d7cb4951a118974240855ef5fd72b73d293da447cc
MD5 48a15a43022293c5d4c6d81667372d00
BLAKE2b-256 dbf7bae066b3a6d2b43d54b94639521b29308ad5c16c0c2390c93f1a43f23aaf

See more details on using hashes here.

File details

Details for the file gigatoken-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: gigatoken-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gigatoken-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7dc354a147d07cfb8cf4a24250c69ae02434e6770a49f4be71e89096dd042b62
MD5 9210c810d90ff696dd8a265f08990859
BLAKE2b-256 9a8ae461953ed3266822c5fbf2db97405ae57b2fc0683985d50da18055376887

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