Documentation
¶
Overview ¶
Copyright 2024 The Aibrix Team.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2024 The Aibrix Team.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2024 The Aibrix Team.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func GetPodModelMetricsSimplePrometheusValue(cache cache.Cache, podname, namespace, modelname, metricname string) float64
- func GetPodModelMetricsSimpleValue(cache cache.Cache, podname, namespace, modelname, metricname string) float64
- func Init()
- func NewLeastBusyTimeRouter() (types.Router, error)
- func NewLeastExpectedLatencyRouter() (types.Router, error)
- func NewLeastGpuCacheRouter() (types.Router, error)
- func NewLeastKvCacheRouter() (types.Router, error)
- func NewLeastLoadPullingRouter(provider cache.CappedLoadProvider) (types.Router, error)
- func NewLeastLoadRouter(provider cache.LoadProvider) (types.Router, error)
- func NewLeastRequestRouter() (types.Router, error)
- func NewLeastUtilRouter() (types.Router, error)
- func NewPDRouter() (types.Router, error)
- func NewPackLoadRouter(provider cache.CappedLoadProvider) (types.Router, error)
- func NewPrefixCacheAndLoadRouter() (types.Router, error)
- func NewPrefixCacheRouter() (types.Router, error)
- func NewQueueRouter(backend types.Router, queue types.RouterQueue[*types.RoutingContext]) (types.QueueRouter, error)
- func NewRandomRouter() (types.Router, error)
- func NewSLORouter(modelName string) (types.QueueRouter, error)
- func NewSessionAffinityRouter() (types.Router, error)
- func NewThroughputRouter() (types.Router, error)
- func Register(algorithm types.RoutingAlgorithm, constructor types.RouterConstructor)
- func RegisterPowerOfTwoRouter(redisClient *redis.Client)
- func RegisterProvider(algorithm types.RoutingAlgorithm, provider types.RouterProviderFunc)
- func Select(ctx *types.RoutingContext) (types.Router, error)
- func SelectRandomPodAsFallback(ctx *types.RoutingContext, pods []*v1.Pod, randomFunc func(int) int) (*v1.Pod, error)
- func SetFallback(router types.Router, fallback types.RoutingAlgorithm) error
- func Validate(algorithms string) (types.RoutingAlgorithm, bool)
- type FallbackRouter
- type MultiRouterConfig
- type PowerOfTwoRouter
- func (p *PowerOfTwoRouter) AddRequestCount(ctx *types.RoutingContext, requestID string, modelName string) (traceTerm int64)
- func (p *PowerOfTwoRouter) DoneRequestCount(ctx *types.RoutingContext, requestID string, modelName string, traceTerm int64)
- func (p *PowerOfTwoRouter) DoneRequestTrace(ctx *types.RoutingContext, requestID string, modelName string, ...)
- func (p *PowerOfTwoRouter) Route(ctx *types.RoutingContext, readyPodList types.PodList) (string, error)
- func (p *PowerOfTwoRouter) SubscribedMetrics() []string
- type PrefillTimeParams
- type PrefixCacheMetrics
- type RouterItem
- type RouterManager
- func (rm *RouterManager) Init()
- func (rm *RouterManager) Register(algorithm types.RoutingAlgorithm, constructor types.RouterConstructor)
- func (rm *RouterManager) RegisterProvider(algorithm types.RoutingAlgorithm, provider types.RouterProviderFunc)
- func (rm *RouterManager) Select(ctx *types.RoutingContext) (types.Router, error)
- func (rm *RouterManager) SetFallback(router types.Router, fallback types.RoutingAlgorithm) error
- func (rm *RouterManager) Validate(algorithms string) (types.RoutingAlgorithm, bool)
- type SLORouter
- type Scores
- type SlidingWindowHistogram
- type TokenizerPool
- type TokenizerPoolConfig
- type TokenizerPoolInterface
- type TokenizerPoolMetrics
Constants ¶
const ( RouterPD types.RoutingAlgorithm = "pd" VLLMEngine string = "vllm" SGLangEngine string = "sglang" TensorRTLLM string = "trtllm" LLMEngineIdentifier string = constants.ModelLabelEngine PDRoleSetIdentifier string = "roleset-name" PDRoleIdentifier string = "role-name" RoleReplicaIndex string = "stormservice.orchestration.aibrix.ai/role-replica-index" PodGroupIndex string = "stormservice.orchestration.aibrix.ai/pod-group-index" PromptLenBucketMinLength string = "prompt-len-bucket-min-length" PromptLenBucketMaxLength string = "prompt-len-bucket-max-length" )
const ( // KVConnectorTypeIdentifier specifies the KV transfer backend for a PD pod. Supported values include "shfs", "nixl", and "mooncake". KVConnectorTypeIdentifier = "model.aibrix.ai/kv-connector-type" // KV connector types for different backends KVConnectorTypeSHFS = "shfs" // Default - AIBrix SHFS/KVCacheManager (GPU) KVConnectorTypeNIXL = "nixl" // NIXL for Neuron (uses disagg_prefill_resp wrapper) KVConnectorTypeMooncake = "mooncake" // Mooncake KV transfer backend HeaderPrefillTargetPodIP = "prefill-target-pod-ip" HeaderPrefillTargetPod = "prefill-target-pod" )
const ( PREBLE_TARGET_GPU = "AIBRIX_ROUTER_PREBLE_TARGET_GPU" PREBLE_DECODING_LENGTH = "AIBRIX_ROUTER_PREBLE_DECODING_LENGTH" PREBLE_SLIDING_WINDOW_PERIOD = "AIBRIX_ROUTER_PREBLE_SLIDING_WINDOW_PERIOD" PREBLE_EVICTION_LOOP_INTERVAL = "AIBRIX_ROUTER_PREBLE_EVICTION_LOOP_INTERVAL" )
const ( // Default routing algorithm for slo-family algorithms, setting to RouterSLOLeastLoadPulling. RouterSLO types.RoutingAlgorithm = "slo" // SLO-aware routing algorithm that using SLOQueue and packLoadRouter as the backend. RouterSLOPackLoad types.RoutingAlgorithm = "slo-pack-load" // SLO-aware routing algorithm that using SLOQueue and leastLoadRouter (push mode) as the backend. RouterSLOLeastLoad types.RoutingAlgorithm = "slo-least-load" // SLO-aware routing algorithm that using SLOQueue and leastLoadRouter (pull mode) as the backend. RouterSLOLeastLoadPulling types.RoutingAlgorithm = "slo-least-load-pulling" )
const DefaultFallbackAlgorithm types.RoutingAlgorithm = RouterRandom
const RouterLeastBusyTime types.RoutingAlgorithm = "least-busy-time"
const RouterLeastGpuCache types.RoutingAlgorithm = "least-gpu-cache"
const RouterLeastKvCache types.RoutingAlgorithm = "least-kv-cache"
const RouterLeastLatency types.RoutingAlgorithm = "least-latency"
const RouterLeastRequest types.RoutingAlgorithm = "least-request"
const (
RouterNotSet = ""
)
const (
RouterPowerOfTwo types.RoutingAlgorithm = "power-of-two"
)
const RouterPrefixCachePreble types.RoutingAlgorithm = "prefix-cache-preble"
const RouterRandom types.RoutingAlgorithm = "random"
const (
RouterSessionAffinity types.RoutingAlgorithm = "session-affinity"
)
const RouterThroughput types.RoutingAlgorithm = "throughput"
const RouterUtil types.RoutingAlgorithm = "least-utilization"
Variables ¶
var ( RandomRouter = &randomRouter{} RandomRouterProviderFunc = func(_ *types.RoutingContext) (types.Router, error) { return RandomRouter, nil } )
var ( ErrInitTimeout = errors.New("router initialization timeout") ErrFallbackNotSupported = errors.New("router not support fallback") ErrFallbackNotRegistered = errors.New("fallback router not registered") )
var DefaultFallbackRouter types.RouterProviderFunc = RandomRouterProviderFunc
var (
ErrorNoAvailablePod = fmt.Errorf("no pod available")
)
var ModelRouterFactory = NewSLORouter
var (
RouterPrefixCache types.RoutingAlgorithm = "prefix-cache"
)
Functions ¶
func GetPodModelMetricsSimplePrometheusValue ¶ added in v0.6.0
func GetPodModelMetricsSimpleValue ¶ added in v0.6.0
func NewLeastBusyTimeRouter ¶
func NewLeastGpuCacheRouter ¶ added in v0.4.0
func NewLeastKvCacheRouter ¶
func NewLeastLoadPullingRouter ¶ added in v0.4.0
func NewLeastLoadPullingRouter(provider cache.CappedLoadProvider) (types.Router, error)
NewLeastLoadRouter creates leastLoadRouter instance in the pull mode.
func NewLeastLoadRouter ¶ added in v0.4.0
func NewLeastLoadRouter(provider cache.LoadProvider) (types.Router, error)
NewLeastLoadRouter creates leastLoadRouter instance in the push mode.
func NewLeastRequestRouter ¶
func NewLeastUtilRouter ¶ added in v0.4.0
func NewPDRouter ¶ added in v0.4.0
func NewPackLoadRouter ¶ added in v0.4.0
func NewPackLoadRouter(provider cache.CappedLoadProvider) (types.Router, error)
NewPackLoadRouter creates packLoadRouter instance.
func NewPrefixCacheRouter ¶
func NewQueueRouter ¶ added in v0.4.0
func NewQueueRouter(backend types.Router, queue types.RouterQueue[*types.RoutingContext]) (types.QueueRouter, error)
func NewRandomRouter ¶
func NewSLORouter ¶ added in v0.4.0
func NewSLORouter(modelName string) (types.QueueRouter, error)
func NewSessionAffinityRouter ¶ added in v0.6.0
func NewThroughputRouter ¶
func Register ¶
func Register(algorithm types.RoutingAlgorithm, constructor types.RouterConstructor)
func RegisterPowerOfTwoRouter ¶ added in v0.7.0
func RegisterProvider ¶ added in v0.4.0
func RegisterProvider(algorithm types.RoutingAlgorithm, provider types.RouterProviderFunc)
func SelectRandomPodAsFallback ¶
func SelectRandomPodAsFallback(ctx *types.RoutingContext, pods []*v1.Pod, randomFunc func(int) int) (*v1.Pod, error)
SelectRandomPodAsFallback selects a pod randomly as a fallback. This method should only be used when all other selection mechanisms have failed.
func SetFallback ¶ added in v0.4.0
func SetFallback(router types.Router, fallback types.RoutingAlgorithm) error
Types ¶
type FallbackRouter ¶ added in v0.4.0
type FallbackRouter struct {
// contains filtered or unexported fields
}
func (*FallbackRouter) Route ¶ added in v0.4.0
func (r *FallbackRouter) Route(ctx *types.RoutingContext, pods types.PodList) (string, error)
func (*FallbackRouter) SetFallback ¶ added in v0.4.0
func (r *FallbackRouter) SetFallback(fallback types.RoutingAlgorithm, provider types.RouterProviderFunc)
type MultiRouterConfig ¶ added in v0.7.0
type MultiRouterConfig struct {
Items []RouterItem
}
MultiRouterConfig holds the parsed routing algorithms and their weight coefficients.
func ParseMultiRouterConfig ¶ added in v0.7.0
func ParseMultiRouterConfig(routerStr string) (*MultiRouterConfig, error)
ParseMultiRouterConfig parses a multi-router string into a MultiRouterConfig. Format example: "prefix-cache:2,least-latency:1,least-request" - Weight coefficients must be integers in range [0, 1000000]. - Default weight coefficient is 1 if omitted. - Weight coefficient 0 means the routing algorithm should be skipped.
type PowerOfTwoRouter ¶ added in v0.7.0
type PowerOfTwoRouter struct {
// contains filtered or unexported fields
}
func NewPowerOfTwoRouterWithRedis ¶ added in v0.7.0
func NewPowerOfTwoRouterWithRedis(redisClient *redis.Client, keyRotationSec ...int64) (*PowerOfTwoRouter, error)
NewPowerOfTwoRouterWithRedis creates a new Power of Two router with the given Redis client. This is useful for testing or when you want to provide a custom Redis configuration. Returns error if cache registration fails, as the router cannot function correctly without it.
func (*PowerOfTwoRouter) AddRequestCount ¶ added in v0.7.0
func (p *PowerOfTwoRouter) AddRequestCount(ctx *types.RoutingContext, requestID string, modelName string) (traceTerm int64)
AddRequestCount implements cache.RequestTracker.
func (*PowerOfTwoRouter) DoneRequestCount ¶ added in v0.7.0
func (p *PowerOfTwoRouter) DoneRequestCount(ctx *types.RoutingContext, requestID string, modelName string, traceTerm int64)
DoneRequestCount implements cache.RequestTracker.
func (*PowerOfTwoRouter) DoneRequestTrace ¶ added in v0.7.0
func (p *PowerOfTwoRouter) DoneRequestTrace(ctx *types.RoutingContext, requestID string, modelName string, inputTokens int64, outputTokens int64, traceTerm int64)
DoneRequestTrace implements cache.RequestTracker.
func (*PowerOfTwoRouter) Route ¶ added in v0.7.0
func (p *PowerOfTwoRouter) Route(ctx *types.RoutingContext, readyPodList types.PodList) (string, error)
Route implements types.Router using power of two choices algorithm. It randomly selects two candidates and routes to the one with fewer running requests.
func (*PowerOfTwoRouter) SubscribedMetrics ¶ added in v0.7.0
func (p *PowerOfTwoRouter) SubscribedMetrics() []string
SubscribedMetrics implements types.Router.
type PrefillTimeParams ¶
type PrefixCacheMetrics ¶ added in v0.4.0
type PrefixCacheMetrics struct {
// contains filtered or unexported fields
}
PrefixCacheMetrics holds all prefix cache metrics
type RouterItem ¶ added in v0.7.0
RouterItem represents a single routing algorithm and its weight coefficient for multi-router config.
type RouterManager ¶ added in v0.4.0
type RouterManager struct {
// contains filtered or unexported fields
}
func NewRouterManager ¶ added in v0.4.0
func NewRouterManager() *RouterManager
func (*RouterManager) Init ¶ added in v0.4.0
func (rm *RouterManager) Init()
func (*RouterManager) Register ¶ added in v0.4.0
func (rm *RouterManager) Register(algorithm types.RoutingAlgorithm, constructor types.RouterConstructor)
func (*RouterManager) RegisterProvider ¶ added in v0.4.0
func (rm *RouterManager) RegisterProvider(algorithm types.RoutingAlgorithm, provider types.RouterProviderFunc)
func (*RouterManager) Select ¶ added in v0.4.0
func (rm *RouterManager) Select(ctx *types.RoutingContext) (types.Router, error)
Select the user provided router provider supported by gateway, no error reported and fallback to random router Call Validate before this function to ensure expected behavior.
func (*RouterManager) SetFallback ¶ added in v0.4.0
func (rm *RouterManager) SetFallback(router types.Router, fallback types.RoutingAlgorithm) error
func (*RouterManager) Validate ¶ added in v0.4.0
func (rm *RouterManager) Validate(algorithms string) (types.RoutingAlgorithm, bool)
Validate validates if user provided routing routers is supported by gateway
type SLORouter ¶ added in v0.4.0
type SLORouter struct {
FallbackRouter
*queue.SLOQueue
}
SLORouter is a router that add FallbackRouter mechanism to the queue.
type SlidingWindowHistogram ¶
type SlidingWindowHistogram struct {
// contains filtered or unexported fields
}
type TokenizerPool ¶ added in v0.4.0
type TokenizerPool struct {
// contains filtered or unexported fields
}
TokenizerPool manages model-specific tokenizers with caching and health checking
func NewTokenizerPool ¶ added in v0.4.0
func NewTokenizerPool(config TokenizerPoolConfig, cache cache.Cache) *TokenizerPool
NewTokenizerPool creates a new TokenizerPool instance
func (*TokenizerPool) Close ¶ added in v0.4.0
func (p *TokenizerPool) Close() error
Close gracefully shuts down the TokenizerPool
func (*TokenizerPool) GetTokenizer ¶ added in v0.4.0
GetTokenizer returns a tokenizer for the specified model
type TokenizerPoolConfig ¶ added in v0.4.0
type TokenizerPoolConfig struct {
EnableVLLMRemote bool // Feature flag
EndpointTemplate string // "http://%s:8000"
HealthCheckPeriod time.Duration // Default: 30s
TokenizerTTL time.Duration // Default: 5m
MaxTokenizersPerPool int // Default: 100
DefaultTokenizer tokenizer.Tokenizer // Default when remote fails
ModelServiceMap map[string]string // Model -> Service endpoint mapping
Timeout time.Duration // Request timeout
}
TokenizerPoolConfig represents configuration for the TokenizerPool
type TokenizerPoolInterface ¶ added in v0.4.0
type TokenizerPoolInterface interface {
GetTokenizer(model string, pods []*v1.Pod) tokenizer.Tokenizer
Close() error
}
TokenizerPoolInterface defines the interface for tokenizer pools
type TokenizerPoolMetrics ¶ added in v0.4.0
type TokenizerPoolMetrics struct {
// contains filtered or unexported fields
}
TokenizerPoolMetrics contains Prometheus metrics for the pool
Source Files
¶
- fallback.go
- least_busy_time.go
- least_gpu_cache.go
- least_kv_cache.go
- least_latency.go
- least_load.go
- least_request.go
- least_util.go
- model_router_factory.go
- pack_load.go
- pd_disaggregation.go
- pd_prefill_request.go
- power_of_two.go
- prefix_cache.go
- prefix_cache_preble.go
- queue_router.go
- random.go
- router.go
- scorer.go
- simple_session_affinity.go
- slo.go
- throughput.go
- tokenizer_pool.go
- util.go
- vtc.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pd contains the scoring types used by the PD (prefill-decode) disaggregated-inference router.
|
Package pd contains the scoring types used by the PD (prefill-decode) disaggregated-inference router. |
|
selector
Package selector defines the PodSelector contract for PD-disaggregated routing.
|
Package selector defines the PodSelector contract for PD-disaggregated routing. |
|
Package vtc implements the Virtual Token Counter routing algorithms focused on fairness and utilization
|
Package vtc implements the Virtual Token Counter routing algorithms focused on fairness and utilization |