-
Notifications
You must be signed in to change notification settings - Fork 292
Add explicit token-producer backend selector #1582
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
Open
zhouyou9505
wants to merge
6
commits into
llm-d:main
Choose a base branch
from
zhouyou9505:fix/1472-token-producer-backend-selector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfa3f2f
Add explicit token-producer backend selector
zhouyou9505 85de649
Merge upstream/main into fix/1472-token-producer-backend-selector
zhouyou9505 69526ed
docs: clarify tokenizer backend comments
zhouyou9505 742dd63
Merge branch 'main' into fix/1472-token-producer-backend-selector
sagearc 20b5372
Merge branch 'main' into fix/1472-token-producer-backend-selector
zhouyou9505 e13b2eb
Merge branch 'main' into fix/1472-token-producer-backend-selector
zhouyou9505 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,13 +58,23 @@ const ( | |
|
|
||
| var TokenizedPromptDataKey = plugin.NewDataKey(tokenizedPromptKeyID, PluginType) | ||
|
|
||
| type tokenizerBackend string | ||
|
|
||
| const ( | ||
| tokenizerBackendEstimate tokenizerBackend = "estimate" | ||
| tokenizerBackendVLLM tokenizerBackend = "vllm" | ||
| tokenizerBackendUDS tokenizerBackend = "uds" | ||
| ) | ||
|
|
||
| // tokenizerPluginConfig holds the configuration for the tokenizer plugin. | ||
| // | ||
| // Backend selection: `vllm` or `modelName` selects the vLLM HTTP /render | ||
| // backend; `udsTokenizerConfig` selects the deprecated gRPC-over-UDS backend; | ||
| // `estimate` selects the tokenizer-free byte-packing backend, which is also the | ||
| // zero-config default when no backend is set. | ||
| // Backend selection: `backend` explicitly selects the backend when set. When it | ||
| // is omitted, existing configs continue to infer the backend from `estimate`, | ||
| // `vllm`, `udsTokenizerConfig`, or `modelName`. | ||
| type tokenizerPluginConfig struct { | ||
| // Backend explicitly selects "estimate", "vllm", or "uds". When omitted, | ||
| // the plugin infers the backend from legacy config fields. | ||
| Backend tokenizerBackend `json:"backend,omitempty"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: duplicated explanation of the inferred backend path |
||
| // TokenizerConfig configures the deprecated gRPC-over-UDS backend. | ||
| // | ||
| // Deprecated: the UDS tokenizer backend is deprecated and will be removed | ||
|
|
@@ -128,29 +138,67 @@ func PluginFactory(name string, rawParameters *json.Decoder, handle plugin.Handl | |
| } | ||
| } | ||
|
|
||
| estimate := config.Estimate != nil | ||
| uds := config.TokenizerConfig.IsEnabled() | ||
| vllm := config.VLLM != nil || config.ModelName != "" | ||
| if (estimate && (uds || vllm)) || (uds && vllm) { | ||
| return nil, fmt.Errorf("invalid configuration for '%s' plugin: only one of 'estimate', 'vllm', or 'udsTokenizerConfig' may be set", PluginType) | ||
| p, err := NewPlugin(handle.Context(), name, &config) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| // modelName is required only by the real-tokenizer backends; the zero-config | ||
| // path selects the estimate backend, which needs none. | ||
| if (uds || vllm) && config.ModelName == "" { | ||
| return nil, fmt.Errorf("invalid configuration for '%s' plugin: 'modelName' must be specified", PluginType) | ||
|
|
||
| return p, nil | ||
| } | ||
|
|
||
| func (config *tokenizerPluginConfig) validateAndSelectBackend() (tokenizerBackend, error) { | ||
| selected, err := config.selectBackend() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if config.Estimate != nil && config.Estimate.Image != nil { | ||
| if m := config.Estimate.Image.Mode; m != "" && m != imageModeDynamic && m != imageModeStatic { | ||
| return nil, fmt.Errorf("invalid configuration for '%s' plugin: estimate.image.mode must be %q or %q", PluginType, imageModeDynamic, imageModeStatic) | ||
|
|
||
| switch selected { | ||
| case tokenizerBackendVLLM: | ||
| if config.ModelName == "" { | ||
| return "", fmt.Errorf("invalid configuration for '%s' plugin: 'modelName' must be specified", PluginType) | ||
| } | ||
| case tokenizerBackendUDS: | ||
| if config.ModelName == "" { | ||
| return "", fmt.Errorf("invalid configuration for '%s' plugin: 'modelName' must be specified", PluginType) | ||
| } | ||
| if !config.TokenizerConfig.IsEnabled() { | ||
| return "", fmt.Errorf("invalid configuration for '%s' plugin: 'udsTokenizerConfig' must be specified when backend is %q", PluginType, tokenizerBackendUDS) | ||
| } | ||
| case tokenizerBackendEstimate: | ||
| if config.Estimate != nil && config.Estimate.Image != nil { | ||
| if m := config.Estimate.Image.Mode; m != "" && m != imageModeDynamic && m != imageModeStatic { | ||
| return "", fmt.Errorf("invalid configuration for '%s' plugin: estimate.image.mode must be %q or %q", PluginType, imageModeDynamic, imageModeStatic) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| p, err := NewPlugin(handle.Context(), name, &config) | ||
| if err != nil { | ||
| return nil, err | ||
| return selected, nil | ||
| } | ||
|
|
||
| func (config *tokenizerPluginConfig) selectBackend() (tokenizerBackend, error) { | ||
| if config.Backend != "" { | ||
| switch config.Backend { | ||
| case tokenizerBackendEstimate, tokenizerBackendVLLM, tokenizerBackendUDS: | ||
| return config.Backend, nil | ||
| default: | ||
| return "", fmt.Errorf("invalid configuration for '%s' plugin: backend must be one of %q, %q, or %q", PluginType, tokenizerBackendEstimate, tokenizerBackendVLLM, tokenizerBackendUDS) | ||
| } | ||
| } | ||
|
|
||
| return p, nil | ||
| estimate := config.Estimate != nil | ||
| uds := config.TokenizerConfig.IsEnabled() | ||
| vllm := config.VLLM != nil || config.ModelName != "" | ||
| if (estimate && (uds || vllm)) || (uds && vllm) { | ||
| return "", fmt.Errorf("invalid configuration for '%s' plugin: only one of 'estimate', 'vllm', or 'udsTokenizerConfig' may be set", PluginType) | ||
| } | ||
| switch { | ||
| case uds: | ||
| return tokenizerBackendUDS, nil | ||
| case vllm: | ||
| return tokenizerBackendVLLM, nil | ||
| default: | ||
| return tokenizerBackendEstimate, nil | ||
| } | ||
| } | ||
|
|
||
| // LegacyPluginFactory wraps PluginFactory for the deprecated `tokenizer` type | ||
|
|
@@ -166,13 +214,20 @@ func LegacyPluginFactory(name string, rawParameters *json.Decoder, handle plugin | |
| return PluginFactory(name, rawParameters, handle) | ||
| } | ||
|
|
||
| // NewPlugin constructs the configured backend: udsTokenizerConfig (deprecated), | ||
| // vllm /render (selected by 'vllm' or 'modelName'), or estimate byte-packing | ||
| // (the default when no backend is set). | ||
| // NewPlugin constructs the configured backend. The explicit backend selector | ||
| // wins when set; otherwise legacy config inference is used. | ||
| func NewPlugin(ctx context.Context, name string, config *tokenizerPluginConfig) (*Plugin, error) { | ||
| if config == nil { | ||
| config = &tokenizerPluginConfig{} | ||
| } | ||
| selected, err := config.validateAndSelectBackend() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var backend tokenInputProducer | ||
| switch { | ||
| case config.TokenizerConfig.IsEnabled(): | ||
| switch selected { | ||
| case tokenizerBackendUDS: | ||
| log.FromContext(ctx).Info( | ||
| "DEPRECATION: the 'udsTokenizerConfig' parameter is deprecated and will be removed in a future release; set the 'vllm' parameter instead (see plugin README)", | ||
| "pluginType", PluginType, | ||
|
|
@@ -182,7 +237,7 @@ func NewPlugin(ctx context.Context, name string, config *tokenizerPluginConfig) | |
| return nil, fmt.Errorf("failed to initialize UDS tokenizer for '%s' plugin - %w", PluginType, err) | ||
| } | ||
| backend = renderBackend{tk: uds} | ||
| case config.VLLM != nil || config.ModelName != "": | ||
| case tokenizerBackendVLLM: | ||
| cfg := config.VLLM | ||
| if cfg == nil { | ||
| cfg = &vllmConfig{} | ||
|
|
@@ -192,7 +247,7 @@ func NewPlugin(ctx context.Context, name string, config *tokenizerPluginConfig) | |
| return nil, fmt.Errorf("failed to initialize vLLM HTTP renderer for '%s' plugin - %w", PluginType, err) | ||
| } | ||
| backend = renderBackend{tk: renderer} | ||
| default: | ||
| case tokenizerBackendEstimate: | ||
| backend = estimateBackend{img: newImageEstimator(config.Estimate)} | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The config fields themselves are not legacy, only the implicit inference logic, right?
Uh oh!
There was an error while loading. Please reload this page.
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.
Correct. Got it. The fields themselves are not legacy. Only the implicit backend inference behavior is legacy and kept for backward compatibility. I will refine the description.