tiktoken-chatml
Adding support for ChatML chat template to tiktoken tokenizers:
- Remap or remove OpenAI special tokens to support only ChatML special tokens:
<|im_start|>,<|im_end|>; - Always maintain the original vocuabulary size if possible;
- Add
apply_chat_templatemethod known from HF tokenizers; - Maintain full functionality of tiktoken tokenizer.
Use for training models from scratch. For your model safety - recheck all changes before using.
Installation
pip install tiktoken-chatml
Quickstart
import tiktoken_chatml
enc = tiktoken_chatml.get_encoding("cl100k_base-chatml")
output = enc.apply_chat_template(
[
{"role": "system", "content": "This is a system message."},
{"role": "user", "content": "Hello!"},
],
tokenize=False,
)
print(output)
Output:
<|im_start|>system
This is a system message
<|im_end|>
<|im_start|>user
Hello!
<|im_end|>
Setting tokenize=True invokes tiktoken encoding.encode().
You can use this encoding as a drag and drop replacement for tiktoken.
Supported encodings:
SUPPORTED_ENCODINGS = ["o200k_base-chatml", "cl100k_base-chatml", "gpt2-chatml"]
The eot_token is now <|im_end|>:
>> enc.eot_token == enc.encode("<|im_end|>", allowed_special="all")[0]
True
Metadata
Release files for tiktoken-chatml 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tiktoken_chatml-0.1.0.tar.gz | 2.2 kB | Without provenance | Details for tiktoken_chatml-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tiktoken_chatml-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tiktoken_chatml-0.1.0-py3-none-any.whl |
Total release size: 5.0 kB
Release files / tiktoken_chatml-0.1.0.tar.gz
| Download URL | tiktoken_chatml-0.1.0.tar.gz |
|---|---|
| Size | 2.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90f0500160c35ff70417ae494748ea902e8bc0eb74ed7e60a00a496d0410a730
|
|
BLAKE2b-256 checksum How to use checksums |
000a253aea54cecb1e288298a992e08be7aeb81cf3347d9f2e7ec45f816f0cd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.13 Linux/5.15.0-1057-aws
|
Release files / tiktoken_chatml-0.1.0-py3-none-any.whl
| Download URL | tiktoken_chatml-0.1.0-py3-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
904575ef86313f7b5cc320a869acb51a48f1f9b8d803f3d4edd668a603130b5e
|
|
BLAKE2b-256 checksum How to use checksums |
c31fce3b50bf1789aebb79234c24fdb2e6e1f131acd61575bb3718d523371aab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.13 Linux/5.15.0-1057-aws
|
Security for tiktoken-chatml 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.