-
Notifications
You must be signed in to change notification settings - Fork 112
feat: Add factory functions for all plugins #208
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // Package plugins provides plugins for the scheduler. | ||
| package plugins |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,18 @@ package profile | |
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/llm-d/llm-d-inference-scheduler/pkg/config" | ||
| "sigs.k8s.io/controller-runtime/pkg/log" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/types" | ||
| logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging" | ||
|
|
||
| "github.com/llm-d/llm-d-inference-scheduler/pkg/config" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -21,9 +25,37 @@ const ( | |
| prefill = "prefill" | ||
| ) | ||
|
|
||
| type pdProfileHandlerParameters struct { | ||
| prefix.Config | ||
| Threshold int `json:"threshold"` | ||
| } | ||
|
|
||
| // compile-time type assertion | ||
| var _ framework.ProfileHandler = &PdProfileHandler{} | ||
|
|
||
| // PdProfileHandlerFactory defines the factory function for the PdProfileHandler | ||
| func PdProfileHandlerFactory(name string, rawParameters json.RawMessage, _ plugins.Handle) (plugins.Plugin, error) { | ||
| parameters := pdProfileHandlerParameters{ | ||
| Config: prefix.Config{ | ||
| HashBlockSize: prefix.DefaultHashBlockSize, | ||
| MaxPrefixBlocksToMatch: prefix.DefaultMaxPrefixBlocks, | ||
| LRUCapacityPerServer: prefix.DefaultLRUCapacityPerServer, | ||
|
Comment on lines
+41
to
+42
Collaborator
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. is profile handler using these values? |
||
| }, | ||
|
Comment on lines
+38
to
+43
Collaborator
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. does it make sense that prefix config appear on profile handler plugin?
Collaborator
Author
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. This configuration is from the previous change to eliminate our own Prefix Scorer |
||
| Threshold: 100, | ||
| } | ||
| if rawParameters != nil { | ||
| if err := json.Unmarshal(rawParameters, ¶meters); err != nil { | ||
| return nil, fmt.Errorf("failed to parse the parameters of the '%s' profile handler - %w", PdProfileHandlerType, err) | ||
| } | ||
| } | ||
|
|
||
| cfg := &config.Config{ | ||
| PDThreshold: parameters.Threshold, | ||
| GIEPrefixConfig: ¶meters.Config, | ||
| } | ||
| return NewPdProfileHandler(cfg).WithName(name), nil | ||
| } | ||
|
|
||
|
Collaborator
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. comment on line 114 (I can't put the comment there cause it wasn't change in this PR): prefixState, err := types.ReadCycleStateKey[*prefix.SchedulingContextState](cycleState, prefix.PrefixCachePluginType)
if err != nil {
log.FromContext(ctx).Error(err, "unable to read prefix state")
return map[string]*framework.SchedulerProfile{}
}if this the expected behavior? if the prefix scorer failed to write the prefix we don't do PD?
Collaborator
Author
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. This code is from the previous change to eliminate our own Prefix Scorer |
||
| // NewPdProfileHandler initializes a new PdProfileHandler and returns its pointer. | ||
| func NewPdProfileHandler(cfg *config.Config) *PdProfileHandler { | ||
| return &PdProfileHandler{ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package plugins | ||
|
|
||
| import ( | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins" | ||
|
|
||
| "github.com/llm-d/llm-d-inference-scheduler/pkg/plugins/filter" | ||
| prerequest "github.com/llm-d/llm-d-inference-scheduler/pkg/plugins/pre-request" | ||
| "github.com/llm-d/llm-d-inference-scheduler/pkg/plugins/profile" | ||
| "github.com/llm-d/llm-d-inference-scheduler/pkg/plugins/scorer" | ||
| ) | ||
|
|
||
| // RegisterAllPlugins registers the factory functions of all plugins in this repository. | ||
| func RegisterAllPlugins() { | ||
| plugins.Register(filter.ByLabelFilterType, filter.ByLabelFilterFactory) | ||
| plugins.Register(filter.ByLabelSelectorFilterType, filter.ByLabelSelectorFactory) | ||
| plugins.Register(filter.DecodeFilterType, filter.DecodeFilterFactory) | ||
| plugins.Register(filter.PrefillFilterType, filter.PrefillFilterFactory) | ||
| plugins.Register(prerequest.PrefillHeaderHandlerType, prerequest.PrefillHeaderHandlerFactory) | ||
| plugins.Register(profile.PdProfileHandlerType, profile.PdProfileHandlerFactory) | ||
| plugins.Register(scorer.KvCacheAwareScorerType, scorer.KvCacheAwareScorerFactory) | ||
| plugins.Register(scorer.LoadAwareScorerType, scorer.LoadAwareScorerFactory) | ||
| plugins.Register(scorer.SessionAffinityScorerType, scorer.SessionAffinityScorerFactory) | ||
| } |
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 is it mandatory to specify name?
it's optional in all other plugins..
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.
cc @mayabar