-
Notifications
You must be signed in to change notification settings - Fork 102
feat: use tiktoken for tokenizing prompts #927
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Xunzhuo The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: bitliu <bitliu@tencent.com>
I think we should make tokenization a plugin in our framework |
@ahg-g how about adding an opt in pkg/epp/scheduling/config/config.go to let user to choose which tokenizer to use by passing envs? Plz see latest updates. |
Signed-off-by: bitliu <bitliu@tencent.com>
@@ -11,6 +11,8 @@ require ( | |||
github.com/google/uuid v1.6.0 | |||
github.com/onsi/ginkgo/v2 v2.23.4 | |||
github.com/onsi/gomega v1.37.0 | |||
github.com/pkoukk/tiktoken-go v0.1.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Xunzhuo it's great to see you getting involved in the project! Why use github.com/pkoukk/tiktoken-go
instead of github.com/tiktoken-go/tokenizer
? The latter seems to be better maintained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @danehans, just planning to get involved in this project deeper, would love to help.
QueueThresholdCritical: envutil.GetEnvInt("QUEUE_THRESHOLD_CRITICAL", commonconfig.DefaultQueueThresholdCritical, baseLogger), | ||
QueueingThresholdLoRA: envutil.GetEnvInt("QUEUING_THRESHOLD_LORA", defaultQueueingThresholdLoRA, baseLogger), | ||
LoraAffinityThreshold: envutil.GetEnvFloat("LORA_AFFINITY_THRESHOLD", defaultLoraAffinityThreshold, baseLogger), | ||
PrefixCacheTokenizerType: envutil.GetEnvString("PREFIX_CACHE_TOKENIZER_TYPE", "characters", baseLogger), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the tokenizer dependent on the prefix cache plugin being enabled?
cc @liu-cong @vMaroon @kfirtoledo |
@@ -224,7 +226,11 @@ func (m *Plugin) getPrefixState(cycleState *types.CycleState) (*schedulingContex | |||
// For block i, hash(i) = hash(block i content, hash(i-1)). | |||
func hashPrompt(ctx context.Context, request *types.LLMRequest, cacheBlockSize int, maxPrefixBlocks int) []BlockHash { | |||
loggerDebug := log.FromContext(ctx).V(logutil.DEBUG) | |||
prompt := []byte(request.Prompt) | |||
prompt, err := tokenizer.New(config.Conf.PrefixCacheTokenizerType).Tokenize(request.Prompt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why convert the prompts to tokens?
It doesn't provide any benefit in the prefix scorer and only increases the scorer's computation time. (@liu-cong)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
It was intentional not to tokenize the prompt since this is an estimated prefix cache indexer. Tokenization won't necessarily increase the accuracy. There are some ongoing investigations on whether to actually probe the cache indexes from the model servers and match the tokenizers. But that should be a separate discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
cool to see what an implementation of a tokenizer in the EPP may look like, but I'm not sure if we have a need quite yet.
I think tokenization doesn't define a standalone feature - tokenization should serve an end. Like @kfirtoledo said, prefix-cache locality estimation in the router does not require tokenization. My thoughts:
|
based on @kfirtoledo's and @vMaroon's comments, this change might cause performance degradation and additional negative implications with no significant advantages. |
Thanks for the input, let us hold for this PR for now and waiting for more feedbacks. |
@Xunzhuo: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
feat: use tiktoken for tokenizing prompts