Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of GPT3Tokenizer #579

Merged
merged 3 commits into from
Apr 22, 2023
Merged

Conversation

stephentoub
Copy link
Member

Motivation and Context

Improve the performance of GPT3Tokenizer in both throughput and allocation.

Description

This primarily focuses on the path once the BPE cache has already been sufficiently warmed up. There's much more that can be done about the code path that warms it up, but I've only handled the low-hanging fruit there for now. This can all also be significantly improved once the project moves to target .NET Core instead of netstandard2.0.

Contribution Checklist

private string _input =
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
    "Blandit cursus risus at ultrices mi. Elementum facilisis leo vel fringilla est ullamcorper eget. Pellentesque sit amet porttitor " +
    "eget dolor morbi non arcu. Sed turpis tincidunt id aliquet. Sit amet luctus venenatis lectus magna fringilla urna. Eu turpis " +
    "egestas pretium aenean. Tempus quam pellentesque nec nam aliquam. Sagittis vitae et leo duis ut diam. Tempor orci eu lobortis " +
    "elementum. Placerat vestibulum lectus mauris ultrices eros in cursus. Tempus egestas sed sed risus pretium quam vulputate. Aliquam " +
    "faucibus purus in massa.";

[Benchmark(Baseline = true)]
public List<int> Old() => OldTokenizer.GPT3Tokenizer.Encode(_input);

[Benchmark]
public List<int> New() => NewTokenizer.GPT3Tokenizer.Encode(_input);
Method Mean Error StdDev Median Ratio RatioSD Allocated Alloc Ratio
Old 50.82 us 0.997 us 2.014 us 49.99 us 1.00 0.00 72.22 KB 1.00
New 26.52 us 0.199 us 0.155 us 26.50 us 0.50 0.02 31.55 KB 0.44

This primarily focuses on the path once the BPE cache has already been sufficiently warmed up.  There's much more that can be done about the code path that warms it up, but I've only handled the low-hanging fruit there for now.  This can all also be significantly improved once the project moves to target .NET Core instead of netstandard2.0.
@lemillermicrosoft lemillermicrosoft added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel PR: ready for review All feedback addressed, ready for reviews labels Apr 21, 2023
Copy link
Member

@lemillermicrosoft lemillermicrosoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks for the good lessons.

@lemillermicrosoft lemillermicrosoft added the PR: ready to merge PR has been approved by all reviewers, and is ready to merge. label Apr 21, 2023
@dluc dluc merged commit 5c4cd3f into microsoft:main Apr 22, 2023
10 checks passed
@stephentoub stephentoub deleted the gpt3perf branch April 22, 2023 10:41
dluc pushed a commit that referenced this pull request Apr 29, 2023
### Motivation and Context

Improve the performance of GPT3Tokenizer in both throughput and
allocation.

### Description

This primarily focuses on the path once the BPE cache has already been
sufficiently warmed up. There's much more that can be done about the
code path that warms it up, but I've only handled the low-hanging fruit
there for now. This can all also be significantly improved once the
project moves to target .NET Core instead of netstandard2.0.
dehoward pushed a commit to lemillermicrosoft/semantic-kernel that referenced this pull request Jun 1, 2023
### Motivation and Context

Improve the performance of GPT3Tokenizer in both throughput and
allocation.

### Description

This primarily focuses on the path once the BPE cache has already been
sufficiently warmed up. There's much more that can be done about the
code path that warms it up, but I've only handled the low-hanging fruit
there for now. This can all also be significantly improved once the
project moves to target .NET Core instead of netstandard2.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code PR: ready for review All feedback addressed, ready for reviews PR: ready to merge PR has been approved by all reviewers, and is ready to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants