Skip to main content

RWKV Tokenizer

Project description

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 :-)

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

rwkv_tokenizer-0.11.0.tar.gz (806.1 kB view details)

Uploaded Source

Built Distribution

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

rwkv_tokenizer-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file rwkv_tokenizer-0.11.0.tar.gz.

File metadata

  • Download URL: rwkv_tokenizer-0.11.0.tar.gz
  • Upload date:
  • Size: 806.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.6.0

File hashes

Hashes for rwkv_tokenizer-0.11.0.tar.gz
Algorithm Hash digest
SHA256 3ee4861c4613908ab00c66caa952873d2d92108749e0edb60755b5885cbf82e7
MD5 ef2c1975168a198b8b5c27cd82b99002
BLAKE2b-256 880b55f681f8936d9c14057d9fb005eb0ddb1133d5ebae770bd07c24742546ff

See more details on using hashes here.

File details

Details for the file rwkv_tokenizer-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rwkv_tokenizer-0.11.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 169fad1e69f45150d754242d5a8e7b2e1516653841c450a1f7e922db0098965a
MD5 f40047a65190dbba9d024ab1f4e0e11d
BLAKE2b-256 b6b491aae96592264fdf8b1f6c037300cbe06a2a20edca8057bedf2f5f54c013

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