Documentation
¶
Overview ¶
Package vtc implements the Virtual Token Counter routing algorithms focused on fairness and utilization
Index ¶
- Constants
- func EnvOverrides() types.VTCOverrides
- func EnvTokenTrackerKnobs() types.VTCTokenTrackerOverrides
- func NewVTCBasicRouter() (types.Router, error)
- func TimeUnitName(name string) string
- type BasicVTCRouter
- func (r *BasicVTCRouter) Polarity() types.Polarity
- func (r *BasicVTCRouter) Route(ctx *types.RoutingContext, readyPodList types.PodList) (string, error)
- func (r *BasicVTCRouter) ScoreAll(ctx *types.RoutingContext, readyPodList types.PodList) ([]float64, []bool, error)
- func (r *BasicVTCRouter) SubscribedMetrics() []string
- type InMemorySlidingWindowTokenTracker
- func (t *InMemorySlidingWindowTokenTracker) GetMaxTokenCount(ctx context.Context) (float64, error)
- func (t *InMemorySlidingWindowTokenTracker) GetMinTokenCount(ctx context.Context) (float64, error)
- func (t *InMemorySlidingWindowTokenTracker) GetTokenCount(ctx context.Context, user string) (float64, error)
- func (t *InMemorySlidingWindowTokenTracker) UpdateTokenCount(ctx context.Context, user string, inputTokens, outputTokens float64) error
- type SimpleTokenEstimator
- type TimeUnit
- type TokenEstimator
- type TokenTracker
- type TokenTrackerOption
- type VTCConfig
Constants ¶
const ( VTC_TOKEN_TRACKER_WINDOW_SIZE = "AIBRIX_ROUTER_VTC_TOKEN_TRACKER_WINDOW_SIZE" VTC_TOKEN_TRACKER_TIME_UNIT = "AIBRIX_ROUTER_VTC_TOKEN_TRACKER_TIME_UNIT" VTC_TOKEN_TRACKER_MIN_TOKENS = "AIBRIX_ROUTER_VTC_TOKEN_TRACKER_MIN_TOKENS" VTC_TOKEN_TRACKER_MAX_TOKENS = "AIBRIX_ROUTER_VTC_TOKEN_TRACKER_MAX_TOKENS" )
const ( VTC_MAX_POD_LOAD = "AIBRIX_ROUTER_VTC_BASIC_MAX_POD_LOAD" VTC_INPUT_TOKEN_WEIGHT = "AIBRIX_ROUTER_VTC_BASIC_INPUT_TOKEN_WEIGHT" VTC_OUTPUT_TOKEN_WEIGHT = "AIBRIX_ROUTER_VTC_BASIC_OUTPUT_TOKEN_WEIGHT" VTC_FAIRNESS_WEIGHT = "AIBRIX_ROUTER_VTC_BASIC_FAIRNESS_WEIGHT" VTC_UTILIZATION_WEIGHT = "AIBRIX_ROUTER_VTC_BASIC_UTILIZATION_WEIGHT" )
const RouterVTCBasic types.RoutingAlgorithm = "vtc-basic"
Variables ¶
This section is empty.
Functions ¶
func EnvOverrides ¶ added in v0.8.0
func EnvOverrides() types.VTCOverrides
EnvOverrides returns the VTC routing knob defaults the environment configures. The routing algorithm package folds them into the process default table at startup.
The token tracker's window, time unit, token floors and the two token weights are part of the table because a profile may override them: they are baked into a tracker instance rather than read per request, so a profile that sets any of them gets a tracker of its own (see TokenTrackerFor).
func EnvTokenTrackerKnobs ¶ added in v0.8.0
func EnvTokenTrackerKnobs() types.VTCTokenTrackerOverrides
EnvTokenTrackerKnobs returns the window, time unit and token floors the environment configures. The routing algorithm package folds them into the process default table at startup, and a request whose model config profile sets none of them shares the tracker built from them.
func NewVTCBasicRouter ¶
func TimeUnitName ¶ added in v0.8.0
TimeUnitName canonicalizes a time unit name the environment or a model config profile configures, so that callers carry the name of a unit the tracker has instead of an arbitrary string. An unknown name falls back to minutes, which is what the environment loader has always done.
Types ¶
type BasicVTCRouter ¶
type BasicVTCRouter struct {
// contains filtered or unexported fields
}
BasicVTCRouter implements the VTC routing algorithm
func NewBasicVTCRouter ¶
func NewBasicVTCRouter(tokenTracker TokenTracker, tokenEstimator TokenEstimator, config *VTCConfig) (*BasicVTCRouter, error)
NewBasicVTCRouter creates a new BasicVTCRouter with the provided token tracker and estimator
func (*BasicVTCRouter) Polarity ¶ added in v0.7.0
func (r *BasicVTCRouter) Polarity() types.Polarity
Polarity returns whether higher or lower score is better.
func (*BasicVTCRouter) Route ¶
func (r *BasicVTCRouter) Route(ctx *types.RoutingContext, readyPodList types.PodList) (string, error)
Route implements the VTC routing algorithm
func (*BasicVTCRouter) ScoreAll ¶ added in v0.7.0
func (r *BasicVTCRouter) ScoreAll(ctx *types.RoutingContext, readyPodList types.PodList) ([]float64, []bool, error)
ScoreAll computes the scores for all ready pods in a single batch operation.
func (*BasicVTCRouter) SubscribedMetrics ¶
func (r *BasicVTCRouter) SubscribedMetrics() []string
type InMemorySlidingWindowTokenTracker ¶
type InMemorySlidingWindowTokenTracker struct {
// contains filtered or unexported fields
}
InMemorySlidingWindowTokenTracker tracks tokens per user in a fixed-size sliding window (in-memory, thread-safe).
func (*InMemorySlidingWindowTokenTracker) GetMaxTokenCount ¶
func (t *InMemorySlidingWindowTokenTracker) GetMaxTokenCount(ctx context.Context) (float64, error)
Time: O(1) | Space: O(1)
func (*InMemorySlidingWindowTokenTracker) GetMinTokenCount ¶
func (t *InMemorySlidingWindowTokenTracker) GetMinTokenCount(ctx context.Context) (float64, error)
Time: O(1) | Space: O(1)
func (*InMemorySlidingWindowTokenTracker) GetTokenCount ¶
func (t *InMemorySlidingWindowTokenTracker) GetTokenCount(ctx context.Context, user string) (float64, error)
Time: Avg O(1) (amortized), Worst O(B_u) where B_u = buckets for user u | Space: O(1)
func (*InMemorySlidingWindowTokenTracker) UpdateTokenCount ¶
func (t *InMemorySlidingWindowTokenTracker) UpdateTokenCount(ctx context.Context, user string, inputTokens, outputTokens float64) error
Time: Avg O(1) (amortized), Worst O(B_u) where B_u = buckets for user u | Space: O(1)
type SimpleTokenEstimator ¶
func (*SimpleTokenEstimator) EstimateInputTokens ¶
func (e *SimpleTokenEstimator) EstimateInputTokens(message string) float64
func (*SimpleTokenEstimator) EstimateOutputTokens ¶
func (e *SimpleTokenEstimator) EstimateOutputTokens(message string) float64
type TokenEstimator ¶
type TokenEstimator interface {
EstimateInputTokens(message string) float64
EstimateOutputTokens(message string) float64
}
TokenEstimator estimates token counts for messages
func NewSimpleTokenEstimator ¶
func NewSimpleTokenEstimator() TokenEstimator
TODO: advanced token estimators
type TokenTracker ¶
type TokenTracker interface {
GetTokenCount(ctx context.Context, user string) (float64, error)
UpdateTokenCount(ctx context.Context, user string, inputTokens, outputTokens float64) error
GetMinTokenCount(ctx context.Context) (float64, error)
GetMaxTokenCount(ctx context.Context) (float64, error)
}
TokenTracker tracks token usage per user
func NewInMemorySlidingWindowTokenTracker ¶
func NewInMemorySlidingWindowTokenTracker(config *VTCConfig, opts ...TokenTrackerOption) TokenTracker
TODO: add redis token tracker so that state is shared across plugin instances NewInMemorySlidingWindowTokenTracker creates a new token tracker with configurable options
func NewScopedInMemorySlidingWindowTokenTracker ¶ added in v0.8.0
func NewScopedInMemorySlidingWindowTokenTracker(config *VTCConfig, knobs types.VTCTokenTrackerOverrides, opts ...TokenTrackerOption) TokenTracker
NewScopedInMemorySlidingWindowTokenTracker creates a tracker whose window, bucket size and token floors come from knobs instead of the process-wide environment variables. It backs the tracker a model config profile scopes to itself, so the profile's window, weights and floors are read from and written to that tracker alone.
type TokenTrackerOption ¶
type TokenTrackerOption func(*InMemorySlidingWindowTokenTracker)
TokenTrackerOption is a function that configures a token tracker
func WithTimeUnit ¶
func WithTimeUnit(unit TimeUnit) TokenTrackerOption
func WithWindowSize ¶
func WithWindowSize(size int) TokenTrackerOption
type VTCConfig ¶
type VTCConfig struct {
Variant types.RoutingAlgorithm
InputTokenWeight float64
OutputTokenWeight float64
}
func DefaultVTCConfig ¶
func DefaultVTCConfig() VTCConfig