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.
Index ¶
- Constants
- Variables
- func AddLabel(labels map[string]string, labelKey, labelValue string) map[string]string
- func CheckRedisHealth(ctx context.Context, redisClient *redis.Client) error
- func CheckUser(ctx context.Context, u User, redisClient *redis.Client) bool
- func CloneAndAddLabel(labels map[string]string, labelKey, labelValue string) map[string]string
- func CloneAndRemoveLabel(labels map[string]string, labelKey string) map[string]string
- func CloneSelectorAndAddLabel(selector *metav1.LabelSelector, labelKey, labelValue string) *metav1.LabelSelector
- func CountReadyPods(podList *v1.PodList) (int64, error)
- func CountRoutablePods(pods []*v1.Pod) (cnt int)
- func CryptoShuffle[T any](slice []T)
- func DelUser(ctx context.Context, u User, redisClient *redis.Client) error
- func DeploymentNameFromPod(pod *v1.Pod) string
- func DetokenizeText(tokenIds []int) (string, error)
- func FilterActivePods(pods []v1.Pod) []v1.Pod
- func FilterPods(pods []v1.Pod, filterFn filterPod) []v1.Pod
- func FilterPodsByLabel(pods []*v1.Pod, labelKey, labelValue string) []*v1.Pod
- func FilterPodsByLabelSelector(pods []*v1.Pod, labelSelector string) ([]*v1.Pod, error)
- func FilterReadyPod(pod *v1.Pod) bool
- func FilterRoutablePods(pods []*v1.Pod) []*v1.Pod
- func FilterRoutablePodsInPlace(pods []*v1.Pod) []*v1.Pod
- func GVKCheckExists(cfg *rest.Config, gvk schema.GroupVersionKind) (bool, error)
- func GeneratePodKey(podNamespace, podName string) string
- func GetLLMEngine(pod *v1.Pod, labelName string, defaultValue string) string
- func GetModelPortForPod(requestID string, pod *v1.Pod) int64
- func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)
- func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)
- func GetPodEnv(pod *v1.Pod, envName, defaultValue string) string
- func GetPodListByLabelSelector(ctx context.Context, podLister client.Client, namespace string, ...) (*v1.PodList, error)
- func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition
- func GetPortAnnotationOrDefault(annotations map[string]string, key string, defaultValue int) int
- func GetPortsForPod(pod *v1.Pod) []int
- func GetPositiveIntAnnotationOrDefault(annotations map[string]string, key string, defaultValue int) int
- func GetRedisClient() *redis.Client
- func GetStringAnnotationOrDefault(annotations map[string]string, key string, defaultValue string) string
- func HasVolume(vols []v1.Volume, name string) bool
- func HasVolumeMount(mounts []v1.VolumeMount, name, path string) bool
- func IsDataParallelPod(pod *v1.Pod) bool
- func IsPodActive(p *v1.Pod) bool
- func IsPodDraining(p *v1.Pod) bool
- func IsPodPhaseTerminal(phase v1.PodPhase) bool
- func IsPodReady(pod *v1.Pod) bool
- func IsPodReadyConditionTrue(status v1.PodStatus) bool
- func IsPodTerminal(pod *v1.Pod) bool
- func IsPodTerminating(p *v1.Pod) bool
- func IsRayClusterAvailable(cluster *rayclusterv1.RayCluster, minReadySeconds int32, now metav1.Time) bool
- func IsRayClusterReady(cluster *rayclusterv1.RayCluster) bool
- func IsRayClusterStateReady(status rayclusterv1.RayClusterStatus) bool
- func LoadEnv(key, defaultValue string) string
- func LoadEnvBool(key string, defaultValue bool) bool
- func LoadEnvDuration(key string, defaultValue time.Duration) time.Duration
- func LoadEnvFloat(key string, defaultValue float64) float64
- func LoadEnvInt(key string, defaultValue int) int
- func LoadEnvNonNegativeInt(key string, defaultValue int) int
- func LookupEnv(key string) (string, bool)
- func ModelClaimBindingsFromPod(pod *v1.Pod) map[string]ModelClaimBinding
- func ModelClaimPortForPod(pod *v1.Pod, modelName string) (int, bool)
- func ModelClaimsFromPod(pod *v1.Pod) map[string]int
- func ModelRouterName(modelName string) string
- func OTELEnabled() bool
- func ParsePodKey(key string) (string, string, bool)
- func PathWithoutQuery(requestPath string) string
- func SelectRandomPod(pods []*v1.Pod, randomFn func(int) int) (*v1.Pod, error)
- func SetConditionInList(inputList []metav1.Condition, conditionType string, ...) []metav1.Condition
- func SetUser(ctx context.Context, u User, redisClient *redis.Client) error
- func Shuffle[T any](slice []T)
- func TokenizeInputText(text string) ([]int, error)
- func TrimMessage(message string) string
- func ValidateArtifactURL(artifactURL string) error
- func ValidateKVCacheBackend(kv *orchestrationv1alpha1.KVCache) error
- type CustomizedRegistry
- type Message
- type ModelClaimBinding
- type ModelClaimRoute
- type PodArray
- type Registry
- type SyncMap
- func (sm *SyncMap[K, V]) CompareAndDelete(key K, old V) (deleted bool)
- func (sm *SyncMap[K, V]) CompareAndSwap(key K, old V, new V) bool
- func (sm *SyncMap[K, V]) Delete(key K)
- func (sm *SyncMap[K, V]) Keys() []K
- func (sm *SyncMap[K, V]) Len() int
- func (sm *SyncMap[K, V]) Load(key K) (typedVal V, ok bool)
- func (sm *SyncMap[K, V]) LoadAndDelete(key K) (typedVal V, loaded bool)
- func (sm *SyncMap[K, V]) LoadOrStore(key K, value V) (V, bool)
- func (sm *SyncMap[K, V]) Range(f func(key K, value V) bool)
- func (sm *SyncMap[K, V]) Store(key K, value V)
- func (sm *SyncMap[K, V]) Swap(key K, value V) (V, bool)
- func (sm *SyncMap[K, V]) Values() []V
- type Telemetry
- type User
Constants ¶
const (
DefaultLLMEngine = "vllm"
)
https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken
const (
NAMESPACE = "aibrix-system"
)
Variables ¶
var ( ReplicaSetDeploymentFinder = regexp.MustCompile(`^(.*)-\w+$`) // Deployment-[random name] RayClusterFleetFinder = regexp.MustCompile(`^(.*)-\w+-\w+$`) // RayClusterFleet-[random name]-[random name] )
var ( RayClusterIdentifier string = "ray.io/is-ray-node" RayClusterIdentifierYes string = "yes" RayClusterNodeType string = "ray.io/node-type" ReyClusterFleetIdentifier string = getReyClusterFleetIdentifier() )
var AllowedSchemas = []string{"s3://", "gcs://", "tos://", "huggingface://", "hf://", "/"}
var DeploymentIdentifier string = getDeploymentIdentifier()
Functions ¶
func CheckRedisHealth ¶ added in v0.5.0
func CloneAndAddLabel ¶
Clones the given map and returns a new map with the given key and value added. Returns the given map, if labelKey is empty.
func CloneAndRemoveLabel ¶
CloneAndRemoveLabel clones the given map and returns a new map with the given key removed. Returns the given map, if labelKey is empty.
func CloneSelectorAndAddLabel ¶
func CloneSelectorAndAddLabel(selector *metav1.LabelSelector, labelKey, labelValue string) *metav1.LabelSelector
Use DeepCopy to clone the selector, or create new one if nil Returns the given selector, if labelKey is empty.
func CountRoutablePods ¶
CountRoutablePods filters and returns the number of pods that are routable. A pod is routable if it have a valid PodIP and not in terminating state.
func CryptoShuffle ¶ added in v0.6.0
func CryptoShuffle[T any](slice []T)
CryptoShuffle shuffles slice in place using crypto/rand. Every swap reads the OS entropy source, so it costs a getrandom syscall and several allocations per swap; use it where unpredictability matters, not on hot paths. See Shuffle.
func DeploymentNameFromPod ¶ added in v0.4.0
DeploymentNameFromPod extracts the deployment name from the pod using two methods: 1. If the pod has a label with the key "app.kubernetes.io/name", its value is considered the deployment name. 2. If the pod has an owner reference of kind "ReplicaSet", the deployment name is extracted from the owner reference's name. Alternatively, if the pod is a ray cluster node, we check: 1. If the pod has a label with the key "orchestration.aibrix.ai/raycluster-fleet-name", its value is considered the deployment name. 2. "app.kubernetes.io/name" is discared for ray cluster node identifid by the label "ray.io/is-ray-node" 3. If the pod has an owner reference of kind "RayCluster", the deployment name is extracted from the owner reference's name.
func DetokenizeText ¶
func FilterActivePods ¶
FilterActivePods returns active pods.
func FilterPods ¶
FilterPods returns replica sets that are filtered by filterFn (all returned ones should match filterFn).
func FilterPodsByLabel ¶ added in v0.5.0
FilterPodsByLabel filters pods that have a specific label key-value pair
func FilterPodsByLabelSelector ¶ added in v0.6.0
FilterPodsByLabelSelector filter pod by k8s labelSelector
func FilterReadyPod ¶
func FilterRoutablePods ¶
FilterRoutablePods filters and returns a list of pods that are routable. A pod is routable if it have a valid PodIP and not in terminating state.
func FilterRoutablePodsInPlace ¶
FilterRoutablePodsInPlace filters a list of pods that are routable. A pod is routable if it have a valid PodIP and not in terminating state.
func GVKCheckExists ¶ added in v0.6.0
GVKCheckExists check if gvk is support
func GeneratePodKey ¶
GeneratePodKey generates a key in the format "namespace/name" for a given pod. It concatenates rather than using fmt because routers call it for every candidate pod on the request path.
func GetLLMEngine ¶ added in v0.6.0
func GetModelPortForPod ¶ added in v0.4.0
func GetPodCondition ¶
func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)
GetPodCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.
func GetPodConditionFromList ¶
func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)
GetPodConditionFromList extracts the provided condition from the given list of condition and returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.
func GetPodReadyCondition ¶
func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition
GetPodReadyCondition extracts the pod ready condition from the given status and returns that. Returns nil if the condition is not present.
func GetPortsForPod ¶ added in v0.6.0
GetPortsForPod returns all ports for a pod based on its configuration. For distributed data-parallel (DP) inference, a pod may expose multiple ports: - Base port from pod labels (e.g., "model-port") - Additional ports for each DP rank (base_port + rank_index) Returns nil if the pod doesn't have the required configuration.
func GetRedisClient ¶
func HasVolumeMount ¶ added in v0.6.0
func HasVolumeMount(mounts []v1.VolumeMount, name, path string) bool
func IsDataParallelPod ¶ added in v0.6.0
IsDataParallelPod checks if the pod is configured for Distributed Data Parallel. It returns true if "data-parallel-size" environment variable is present and its value is greater than 1.
func IsPodActive ¶ added in v0.4.0
func IsPodDraining ¶ added in v0.8.0
func IsPodPhaseTerminal ¶ added in v0.4.0
IsPodPhaseTerminal returns true if the pod's phase is terminal.
func IsPodReady ¶
IsPodReady returns true if a pod is ready; false otherwise.
func IsPodReadyConditionTrue ¶
IsPodReadyConditionTrue returns true if a pod is ready; false otherwise.
func IsPodTerminal ¶ added in v0.4.0
IsPodTerminal returns true if a pod is terminal, all containers are stopped and cannot ever regress.
func IsPodTerminating ¶
IsPodTerminating check if pod is in terminating status via whether the deletion timestamp is set
func IsRayClusterAvailable ¶
func IsRayClusterAvailable(cluster *rayclusterv1.RayCluster, minReadySeconds int32, now metav1.Time) bool
func IsRayClusterReady ¶
func IsRayClusterReady(cluster *rayclusterv1.RayCluster) bool
IsRayClusterReady returns true if a RayCluster is ready; false otherwise.
func IsRayClusterStateReady ¶
func IsRayClusterStateReady(status rayclusterv1.RayClusterStatus) bool
func LoadEnvBool ¶ added in v0.4.0
LoadEnvBool loads a boolean environment variable or returns a default value if not set.
func LoadEnvDuration ¶ added in v0.4.0
LoadEnvDuration loads a duration environment variable or returns a default value if not set. Like LoadEnvInt and LoadEnvFloat, it rejects non-positive values. The result is used as a period, TTL or timeout, where zero or a negative value does not mean "off": it either makes a time.After-based loop spin without waiting or silently skips work gated on a positive period.
func LoadEnvFloat ¶
func LoadEnvInt ¶
func LoadEnvNonNegativeInt ¶ added in v0.8.0
LoadEnvNonNegativeInt loads an int environment variable that accepts 0 as a meaningful value, falling back to defaultValue when the variable is unset, empty, negative or unparseable.
It exists because LoadEnvInt cannot express an explicit 0: that helper treats every value <= 0 as invalid and silently falls back to its default. For some knobs 0 is a documented value in its own right - the off switch of the PD decode abort (AIBRIX_DECODE_ABORT_TIMEOUT) and the single-attempt setting of its retry (AIBRIX_DECODE_ABORT_RETRY_DELAY) - and an operator facing a misbehaving component must be able to switch it off from the environment without a new build. A negative or unparseable value is still refused, as there it means a typo rather than an intent.
LoadEnvInt keeps its positive-only behaviour: its other callers rely on it.
func LookupEnv ¶
LookupEnv retrieves an environment variable and returns whether it exists. It returns the value and a boolean indicating its existence.
func ModelClaimBindingsFromPod ¶ added in v0.8.0
func ModelClaimBindingsFromPod(pod *v1.Pod) map[string]ModelClaimBinding
ModelClaimBindingsFromPod parses route.claim.model.aibrix.ai/* annotations on a warm runtime pod. State is additive: legacy annotations infer active from a positive port and activating from port 0.
func ModelClaimPortForPod ¶ added in v0.8.0
ModelClaimPortForPod returns the serving port for a specific served model on a warm runtime pod. It is called on the routing hot path, so it avoids the map allocation of ModelClaimsFromPod: it pre-filters annotation values with a cheap substring check and only unmarshals the matching claim.
func ModelClaimsFromPod ¶ added in v0.8.0
ModelClaimsFromPod is the routing compatibility view of ModelClaim bindings.
func ModelRouterName ¶ added in v0.8.0
ModelRouterName returns the deterministic HTTPRoute name used for a served model. Existing DNS-safe model names keep the historical <model>-router form.
func OTELEnabled ¶ added in v0.7.0
func OTELEnabled() bool
func ParsePodKey ¶
ParsePodKey parses a key in the format "namespace/podName". Returns (namespace, podName, success).
func PathWithoutQuery ¶ added in v0.8.0
PathWithoutQuery strips the query string from an Envoy/HTTP :path value. HTTP/2 :path includes both path and query (RFC 7540), so exact/prefix matchers on the request path must cut on '?' before comparing.
func SelectRandomPod ¶
SelectRandomPod selects a random pod from the provided list, ensuring it's routable. It returns an error if no ready pods are available.
func SetConditionInList ¶
func SetConditionInList(inputList []metav1.Condition, conditionType string, status metav1.ConditionStatus, reason, message string, args ...interface{}) []metav1.Condition
SetConditionInList sets the specific condition type on the given PodAutoscaler to the specified value with the given reason and message. The message and args are treated like a format string. The condition will be added if it is not present. The new list will be returned.
func Shuffle ¶ added in v0.8.0
func Shuffle[T any](slice []T)
Shuffle shuffles slice in place using math/rand/v2's process-wide generator, which is safe for concurrent use and neither allocates nor enters the kernel. It is the right choice for tie-breaking on request hot paths, where the order only needs to be unbiased, not unpredictable.
func TokenizeInputText ¶
func TrimMessage ¶
func ValidateArtifactURL ¶
ValidateArtifactURL checks if the ArtifactURL has a valid schema (s3://, gcs://, tos://, huggingface://, hf://, /)
func ValidateKVCacheBackend ¶ added in v0.4.0
func ValidateKVCacheBackend(kv *orchestrationv1alpha1.KVCache) error
ValidateKVCacheBackend validates that the backend specified in annotations is valid.
Types ¶
type CustomizedRegistry ¶
type CustomizedRegistry[V any, A comparable] struct { Registry[V] // contains filtered or unexported fields }
CustomizedRegistry extends Registry to provide a customized array provider.
func NewRegistryWithArrayProvider ¶
func NewRegistryWithArrayProvider[V any, A comparable](provider func([]V) A) *CustomizedRegistry[V, A]
func (*CustomizedRegistry[V, A]) Array ¶
func (reg *CustomizedRegistry[V, A]) Array() (arr A)
func (*CustomizedRegistry[V, A]) Delete ¶
func (reg *CustomizedRegistry[V, A]) Delete(key string)
func (*CustomizedRegistry[V, A]) Len ¶
func (reg *CustomizedRegistry[V, A]) Len() int
func (*CustomizedRegistry[V, A]) Store ¶
func (reg *CustomizedRegistry[V, A]) Store(key string, value V)
type ModelClaimBinding ¶ added in v0.8.0
type ModelClaimBinding struct {
Model string
Port int
State string
// Claim is the ModelClaim the binding belongs to, named by the
// annotation key.
Claim string
// WakeByRequest says that the controller wakes this engine when asked.
// A request for it while it sleeps is then written on the pod as a wake
// request, rather than sent to the runtime. An older controller does not
// set it, and wakes nothing itself.
WakeByRequest bool
// Reason says more than State about why the model is not served, such as
// WaitingForRoom while a wake waits for room, or Moving while the claim
// moves to another pod. It is empty when the state says it all.
Reason string
}
ModelClaimBinding is the runtime-observed route state carried by one warm pod annotation. Port 0 is known but non-routable.
type ModelClaimRoute ¶ added in v0.8.0
type ModelClaimRoute struct {
Model string `json:"model"`
Port int `json:"port"`
State string `json:"state,omitempty"`
WakeByRequest bool `json:"wakeByRequest,omitempty"`
Reason string `json:"reason,omitempty"`
}
ModelClaimRoute is the value of a warm pod's annotation for one claim, as the controller writes it and the gateway reads it.
type PodArray ¶
PodArray is a simple implementation of types.PodList indexed by deployment names
func (*PodArray) ListPortsForPod ¶ added in v0.6.0
ListPortsForPod returns each pod's ports keyed by pod key (namespace/name, see GeneratePodKey).
type Registry ¶
type Registry[V any] struct { // contains filtered or unexported fields }
Registry is a generic hash set focus on storing values with string keys. Array output is optimized by offering a cached copy. The cached copy is published as an immutable snapshot, so readers can load it without the lock: a snapshot is never modified once published, writers always replace it with a new one.
func NewRegistry ¶
type SyncMap ¶
func (*SyncMap[K, V]) CompareAndDelete ¶
func (*SyncMap[K, V]) CompareAndSwap ¶
func (*SyncMap[K, V]) LoadAndDelete ¶
func (*SyncMap[K, V]) LoadOrStore ¶
type Telemetry ¶ added in v0.7.0
type Telemetry struct {
// contains filtered or unexported fields
}
func InitOpenTelemetry ¶ added in v0.7.0
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package syncable defines the interface for state that can be synced across replicas (e.g.
|
Package syncable defines the interface for state that can be synced across replicas (e.g. |