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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use regexp2cg for optimized code generation of regex patterns #54

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

odannyc
Copy link

@odannyc odannyc commented Oct 15, 2024

This change uses the new regexp2cg that is recommended for the extra performance boost as outlined here: https://github.com/dlclark/regexp2?tab=readme-ov-file#new-code-generation

If new regex patterns are added or updated this command needs to be ran:

regexp2cg -o regexp2_codegen.go

return nil, fmt.Errorf("error compiling regex: %s", err)
}

func NewCoreBPE(encoder map[string]int, specialTokensEncoder map[string]int, regex *regexp2.Regexp) (*CoreBPE, error) {
Copy link
Author

Choose a reason for hiding this comment

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

The regex compilation needs to be known at compile time, which means that we need to compile the regex higher up the stack, hence the reason why we pass regexp2.Regexp here instead of a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant