{"id":24407441,"url":"https://github.com/chonkie-ai/autotiktokenizer","last_synced_at":"2025-04-12T01:22:58.652Z","repository":{"id":261147258,"uuid":"883392022","full_name":"chonkie-ai/autotiktokenizer","owner":"chonkie-ai","description":"🧰 The AutoTokenizer that TikToken always needed -- Load any tokenizer with TikToken now! ✨ ","archived":false,"fork":false,"pushed_at":"2025-01-03T15:32:46.000Z","size":69,"stargazers_count":40,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-19T04:44:38.711Z","etag":null,"topics":["machine-learning","nlp","tiktoken","tokenizers","transformers"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/autotiktokenizer/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chonkie-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-04T22:11:11.000Z","updated_at":"2025-03-15T04:17:36.000Z","dependencies_parsed_at":"2024-12-11T21:35:38.148Z","dependency_job_id":null,"html_url":"https://github.com/chonkie-ai/autotiktokenizer","commit_stats":null,"previous_names":["bhavnicksm/autotiktokenizer","chonkie-ai/autotiktokenizer"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chonkie-ai%2Fautotiktokenizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chonkie-ai%2Fautotiktokenizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chonkie-ai%2Fautotiktokenizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chonkie-ai%2Fautotiktokenizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chonkie-ai","download_url":"https://codeload.github.com/chonkie-ai/autotiktokenizer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248502173,"owners_count":21114759,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["machine-learning","nlp","tiktoken","tokenizers","transformers"],"created_at":"2025-01-20T05:10:55.094Z","updated_at":"2025-04-12T01:22:58.458Z","avatar_url":"https://github.com/chonkie-ai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \n![AutoTikTokenizer Logo](./assets/AutoTikTokenizer%20Logo.png)\n\n# AutoTikTokenizer\n\n[![PyPI version](https://img.shields.io/pypi/v/autotiktokenizer.svg)](https://pypi.org/project/autotiktokenizer/)\n[![Downloads](https://static.pepy.tech/badge/autotiktokenizer)](https://pepy.tech/project/autotiktokenizer)\n![Package size](https://img.shields.io/badge/size-9.7MB-blue)\n[![License](https://img.shields.io/github/license/bhavnicksm/autotiktokenizer)](https://github.com/chonkie-ai/autotiktokenizer/blob/main/LICENSE)\n[![Documentation](https://img.shields.io/badge/docs-available-brightgreen.svg)](https://github.com/chonkie-ai/autotiktokenizer#readme)\n[![Last Commit](https://img.shields.io/github/last-commit/bhavnicksm/autotiktokenizer)](https://github.com/chonkie-ai/autotiktokenizer/commits/main)\n[![GitHub Stars](https://img.shields.io/github/stars/bhavnicksm/autotiktokenizer?style=social)](https://github.com/chonkie-ai/autotiktokenizer/stargazers)\n\n🚀 Accelerate your HuggingFace tokenizers by converting them to TikToken format with AutoTikTokenizer - get TikToken's speed while keeping HuggingFace's flexibility.\n\n[Features](#key-features) •\n[Installation](#installation) •\n[Examples](#examples) •\n[Supported Models](#supported-models) •\n[Benchmarks](#benchmarks) •\n[Sharp Bits](#sharp-bits) •\n[Citation](#citation)\n\n\u003c/div\u003e\n\n# Key Features\n\n- 🚀 **High Performance** - Built on TikToken's efficient tokenization engine\n- 🔄 **HuggingFace Compatible** - Seamless integration with the HuggingFace ecosystem\n- 📦 **Lightweight** - Minimal dependencies, just TikToken and Huggingface-hub\n- 🎯 **Easy to Use** - Simple, intuitive API that works out of the box\n- 💻 **Well Tested** - Comprehensive test suite across supported models\n\n# Installation\n\nInstall `autotiktokenizer` from PyPI via the following command:\n\n```bash\npip install autotiktokenizer\n```\n\nYou can also install it from _source_, by the following command:\n\n```bash\npip install git+https://github.com/chonkie-ai/autotiktokenizer\n```\n\n# Examples\n\nThis section provides a basic usage example of the project. Follow these simple steps to get started quickly.\n\n```python\n# step 1: Import the library\nfrom autotiktokenizer import AutoTikTokenizer\n\n# step 2: Load the tokenizer\ntokenizer = AutoTikTokenizer.from_pretrained(\"meta-llama/Llama-3.2-3B-Instruct\")\n\n# step 3: Enjoy the Inferenece speed 🏎️\ntext = \"Wow! I never thought I'd be able to use Llama on TikToken\"\nencodings = tokenizer.encode(text)\n\n# (Optional) step 4: Decode the outputs\ntext = tokenizer.decode(encodings)\n```\n\n# Supported Models\n\nAutoTikTokenizer should ideally support ALL models on HF Hub but because of the vast diversity of models out there, we _cannot_ test out every single model. These are the models we have already validated for, and know that AutoTikTokenizer works well for them. If you have a model you wish to see here, raise an issue and we would validate and add it to the list. Thanks :)\n\n- [x] GPT2\n- [x] GPT-J Family\n- [x] SmolLM Family: Smollm2-135M, Smollm2-350M, Smollm2-1.5B etc.\n- [x] LLaMa 3 Family: LLama-3.2-1B-Instruct, LLama-3.2-3B-Instruct, LLama-3.1-8B-Instruct etc.\n- [x] Deepseek Family: Deepseek-v2.5 etc \n- [x] Gemma2 Family: Gemma2-2b-It, Gemma2-9b-it etc\n- [x] Mistral Family: Mistral-7B-Instruct-v0.3 etc\n- [x] Aya Family: Aya-23B, Aya Expanse etc\n- [x] BERT Family: BERT, RoBERTa, MiniLM, TinyBERT, DeBERTa etc.\n\n**NOTE:** Some models use the _unigram_ tokenizers, which are not supported with TikToken and hence, 🧰 AutoTikTokenizer cannot convert the tokenizers for such models. Some models that use _unigram_ tokenizers include T5, ALBERT, Marian and XLNet. \n\n# Benchmarks\n\nBenchmarking results for tokenizing **1 billion tokens** from fineweb-edu dataset using **Llama 3.2 tokenizer** on CPU (Google colab)\n\n| Configuration | Processing Type | AutoTikTokenizer | HuggingFace | Speed Ratio | \n|--------------|-----------------|------------------|--------------|-------------|\n| Single Thread | Sequential | **14:58** (898s) | 40:43 (2443s) | 2.72x faster |\n| Batch x1 | Batched | 15:58 (958s) | **10:30** (630s) | 0.66x slower |\n| Batch x4 | Batched | **8:00** (480s) | 10:30 (630s) | 1.31x faster |\n| Batch x8 | Batched | **6:32** (392s) | 10:30 (630s) | 1.62x faster |\n| 4 Processes | Parallel | **2:34** (154s) | 8:59 (539s) | 3.50x faster |\n\nThe above table shows that AutoTikTokenizer's tokenizer (TikToken) is actually way faster than HuggingFace's Tokenizer by 1.6-3.5 times under fair comparison! While, it's not making the most optimal use of TikToken (yet), its still way faster than the stock solutions you might be getting otherwise.\n\n# Sharp Bits\n\nA known issue of the repository is that it does not do any pre-processing or post-processing, which means that if a certain tokenizer (like `minilm`) expect all lower-case letters only, then you would need to convert it to lower case manually. Similarly, any spaces added in the process are not removed during decoding, so they need to handle them on your own. \n\nThere might be more sharp bits to the repository which are unknown at the moment, please raise an issue if you encounter any!\n\n# Acknowledgement\n\nSpecial thanks to HuggingFace and OpenAI for making their respective open-source libraries that make this work possible. I hope that they would continue to support the developer ecosystem for LLMs in the future!\n\n**If you found this repository useful, give it a ⭐️! Thank You :)**\n\n# Citation\n\nIf you use `autotiktokenizer` in your research, please cite it as follows:\n\n```bibtex\n@misc{autotiktokenizer,\n    author = {Bhavnick Minhas},\n    title = {AutoTikTokenizer},\n    year = {2024},\n    publisher = {GitHub},\n    journal = {GitHub repository},\n    howpublished = {\\url{https://github.com/bhavnicksm/autotiktokenizer}},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchonkie-ai%2Fautotiktokenizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchonkie-ai%2Fautotiktokenizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchonkie-ai%2Fautotiktokenizer/lists"}