Skip to content

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