Skip to main content

RWKV Tokenizer

GitHub Actions Status Pypi.org Version Pypi.org Downloads License: Apache 2.0

A fast RWKV Tokenizer written in Rust that supports the World Tokenizer used by the RWKV v5 and v6 models.

Installation

Install the rwkv-tokenizer python module:

$ pip install pyrwkv-tokenizer

Usage

>>> import pyrwkv_tokenizer
>>> tokenizer = pyrwkv_tokenizer.RWKVTokenizer()
>>> tokenizer.encode("Today is a beautiful day. 今天是美好的一天。")
[33520, 4600, 332, 59219, 21509, 47, 33, 10381, 11639, 13091, 15597, 11685, 14734, 10250, 11639, 10080]
>>> tokenizer.decode([33520, 4600, 332, 59219, 21509, 47, 33, 10381, 11639, 13091, 15597, 11685, 14734, 10250, 11639, 10080])
'Today is a beautiful day. 今天是美好的一天。'

Performance and Validity Test

We compared the encoding results of the Rust RWKV Tokenizer and the original tokenizer using the English Wikipedia and Chinese poetries datasets. Both results are identical. The Rust RWKV Tokenizer also passes the original tokenizer's unit test. The following steps describe how to do the unit test:

$ pip install pytest pyrwkv-tokenizer
$ git clone https://github.com/cahya-wirawan/rwkv-tokenizer.git
$ cd rwkv-tokenizer
$ pytest

We did a performance comparison on the simple English Wikipedia dataset 20220301.en among following tokenizer:

  • The original RWKV tokenizer (BlinkDL)
  • Huggingface implementaion of RWKV tokenizer
  • Huggingface LLama tokenizer
  • Huggingface Mistral tokenizer
  • Bert tokenizer
  • OpenAI Tiktoken
  • The Rust RWKV tokenizer

The comparison is done using this jupyter notebook in a M2 Mac mini. The Rust RWKV tokenizer is around 17x faster than the original tokenizer and 9.6x faster than OpenAI Tiktoken.

performance-comparison

Changelog

  • Version 0.9.1
    • Added utf8 error handling to decoder
  • Version 0.9.0
    • Added multithreading for the function encode_batch()
    • Added batch/multithreading comparison
  • Version 0.3.0
    • Fixed the issue where some characters were not encoded correctly

This tokenizer is my very first Rust program, so it might still have many bugs and silly codes :-)

Metadata

Release files for rwkv-tokenizer 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rwkv-tokenizer 0.11.0
File Size Uploaded
rwkv_tokenizer-0.11.0.tar.gz 806.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rwkv-tokenizer 0.11.0
File Interpreter ABI Platform
rwkv_tokenizer-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details

Total release size: 2.2 MB

Release files / rwkv_tokenizer-0.11.0.tar.gz

Download URL rwkv_tokenizer-0.11.0.tar.gz
Size 806.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3ee4861c4613908ab00c66caa952873d2d92108749e0edb60755b5885cbf82e7
BLAKE2b-256 checksum
How to use checksums
880b55f681f8936d9c14057d9fb005eb0ddb1133d5ebae770bd07c24742546ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.6.0

Release files / rwkv_tokenizer-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL rwkv_tokenizer-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.4 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
169fad1e69f45150d754242d5a8e7b2e1516653841c450a1f7e922db0098965a
BLAKE2b-256 checksum
How to use checksums
b6b491aae96592264fdf8b1f6c037300cbe06a2a20edca8057bedf2f5f54c013
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.6.0

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files

0.5.2

67 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page