Comments (7)
I have a branch using RegexOptions.Compiled in several places. I think this will improve performance in long-lived instances of the GptEncoding class, but it actually runs the extant unit tests slightly slower than the main branch. I'm still playing with it and have several MB of public domain novels to crunch. Maybe a consumer-level option to use RegexOptions.Compiled in a couple places at least would be called for. I will let you know when I have finished.
from sharptoken.
Ran a quick encode benchmark with 5500 words input:
BenchmarkDotNet=v0.13.5, OS=Windows 10 (10.0.19045.3086/22H2/2022Update)
AMD Ryzen 7 1700, 1 CPU, 16 logical and 8 physical cores
.NET SDK=7.0.203
[Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2
Method | Mean | Error | StdDev |
---|---|---|---|
TokenizerEncode | 450.5 us | 4.61 us | 4.31 us |
TikTokenEncode | 504.1 us | 3.82 us | 2.99 us |
SharpTokenEncode | 2,704.0 us | 21.60 us | 20.20 us |
from sharptoken.
Here is an updated benchmarks that I calclulated. Will check what can be improved
Method | Categories | Data | Mean | Median | Ratio |
---|---|---|---|---|---|
SharpTokenV1_0_28_Encode | Encode | 1. (...)57. [19866] | 3,374,121.7 ns | 3,227,934.8 ns | 1.00 |
TiktokenSharpV1_0_5_Encode | Encode | 1. (...)57. [19866] | 3,415,080.4 ns | 3,399,812.1 ns | 1.11 |
TokenizerLibV1_3_2_Encode | Encode | 1. (...)57. [19866] | 2,060,565.1 ns | 2,027,039.6 ns | 0.63 |
Tiktoken_Encode | Encode | 1. (...)57. [19866] | 921,540.6 ns | 895,316.2 ns | 0.28 |
from sharptoken.
There is a new version that has a significant improvements thanks to @r-Larch 086544d
from sharptoken.
Hi @lofcz !
Thanks for reaching out!
I planned to implement some performance improvements and compare it with other libs. But not yet. If you have any ideas of improvements, please let me know and I will use them for improvement :)
from sharptoken.
Hey @UX-Ayoma !
THanks a lot for sharing!
I will explore what can be improved in the lib. I would say that there are lot of stuff to be done.
I started with some easy and added some optimisation for Decoding (#9).
I will explore and implement fixes for Encoding as well.
from sharptoken.
Fixed encoding here: PR #11.
Will update with benchmarks and more improvements later.
from sharptoken.
Related Issues (13)
- outdated lib Newtonsoft HOT 1
- gpt-3.5-turbo-16k Not Supported HOT 1
- Implement MODEL_PREFIX_FOR_ENCODING HOT 2
- New embedding models not recognized HOT 11
- Add Microsoft.SourceLink.GitHub to publish repo info/commit to nuget.org HOT 1
- GptEncoding thread-safe? HOT 4
- Anthropic (claude) support HOT 5
- cohere support
- o200k_base support HOT 1
- Gbt4o support
- Missing model name for 3.5 turbo Azure Deployment model HOT 5
- Incorrect token count with Cyrillic HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharptoken.