Documentation
¶
Overview ¶
Package modelclaim implements the controller for the ModelClaim CRD: a model runtime claim that attaches to a selected GPU pod and is served as its own engine process through the aibrix-runtime sidecar. Multiple claims may share a GPU through kvcached.
Index ¶
- Constants
- func Add(mgr manager.Manager, _ config.RuntimeConfig) error
- type ActivateRequest
- type ActivateResponse
- type DeactivateMode
- type DeactivateRequest
- type LocalityProvider
- type ModelClaimReconciler
- type ModelClaimRef
- type ModelInfo
- type PodPlacementState
- type RuntimeAcceleratorSnapshot
- type RuntimeClient
- type RuntimeOperationResponse
- type RuntimeSnapshot
- type RuntimeSnapshotModel
- type SetKVLimitRequest
- type SleepRequest
- type WakeRequest
Constants ¶
const ( // ModelClaimFinalizer ensures attached engine processes are deactivated and // routing is deregistered before the ModelClaim object is removed. ModelClaimFinalizer = "model.aibrix.ai/modelclaim-finalizer" // ScheduledPodsAnnotationKey records the warm pods this model has been // bin-packed onto, mirroring the ModelAdapter scheduled-pods convention so a // binding survives controller restarts. N models may be recorded per pod. ScheduledPodsAnnotationKey = "model.aibrix.ai/scheduled-pods" // DefaultRequeueDuration paces periodic reconciliation (placement retries // and health checks). DefaultRequeueDuration = 10 * time.Second // ActivatingRequeueDuration paces a claim while an engine of it is // booting, so the engine is routed soon after it is ready, and not a // whole period later. ActivatingRequeueDuration = 2 * time.Second // ActivatingRequeueWindow is how long into a boot that faster pace lasts. // An engine still booting after this long is looked at every period. ActivatingRequeueWindow = 5 * time.Minute )
const ( // DefaultRuntimePort is the port the runtime sidecar (aibrix runtime sidecar) // listens on, matching the ModelAdapter runtime API port. DefaultRuntimePort = 8080 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActivateRequest ¶
type ActivateRequest struct {
ModelName string `json:"model_name"`
// ArtifactURL is the weight location (hf://, s3://, ...).
ArtifactURL string `json:"artifact_url"`
// Engine is "vllm" or "sglang".
Engine string `json:"engine"`
// Port is the engine port to serve on. 0 lets the runtime pick a free port,
// which it returns in ActivateResponse.Port.
Port int32 `json:"port,omitempty"`
// IPCName is the kvcached shared-memory segment name; must be unique per
// model on the GPU (KVCACHED_IPC_NAME). Empty lets the runtime derive one.
IPCName string `json:"ipc_name,omitempty"`
// Credentials and engine-specific startup settings.
Credentials map[string]string `json:"credentials,omitempty"`
EngineConfig *modelv1alpha1.ModelClaimEngineConfig `json:"engine_config,omitempty"`
ClaimRef *ModelClaimRef `json:"claim_ref,omitempty"`
}
ActivateRequest asks the runtime sidecar to bring a model online as its own kvcached-enabled engine process sharing the pod's GPU.
type ActivateResponse ¶
type ActivateResponse struct {
Status string `json:"status"` // "success" | "error"
ModelName string `json:"model_name"`
Port int32 `json:"port"`
IPCName string `json:"ipc_name"`
Message string `json:"message,omitempty"`
}
ActivateResponse reports the resulting engine instance.
type DeactivateMode ¶
type DeactivateMode string
DeactivateMode selects how a model is torn down.
const ( // DeactivateStop terminates the engine process entirely. DeactivateStop DeactivateMode = "stop" )
type DeactivateRequest ¶
type DeactivateRequest struct {
ModelName string `json:"model_name"`
Mode DeactivateMode `json:"mode"`
}
DeactivateRequest tears a model down per Mode.
type LocalityProvider ¶
LocalityProvider is an optional advisory estimate for bringing a model's weights onto a node. Runtime snapshots supply the authoritative per-pod artifact signal; this interface remains for future node-level hints. A zero cost means "already hot", and uniformLocality preserves load-only fallback.
type ModelClaimReconciler ¶
type ModelClaimReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
// Runtime drives the per-runtime sidecar (activate/deactivate). Injected so
// the reconcile loop is testable with an in-process fake.
Runtime RuntimeClient
// Locality scores how cheap it is to load a model's weights on a node (the
// Layer 2 node weight-cache signal). Phase 1 uses uniformLocality, so
// placement is load-only until node state reporting is added back.
Locality LocalityProvider
// PoolPolicy serializes controller-local policy ticks and retains only the
// request-counter deltas needed for conservative KV allocation. It is not a
// desired-state store; runtime snapshots remain authoritative after restart.
PoolPolicy *poolPolicyManager
// Divisions remembers when each card was last divided to follow its load,
// so that a card is divided once per round however many claims sit on it.
Divisions *cardDivisionState
// Backoff spaces out the tries of claims no card in the pool can hold. A
// model waiting for room then does not have every runtime read for it every
// round.
Backoff *placementBackoff
// Reservations remembers the cards held for claims that room is being
// made for, and Footprints what engines were seen to hold asleep.
Reservations *cardReservations
Footprints *sleepingFootprints
// APIReader reads ModelClaims straight from the API server for the GPU
// memory account, where an instance recorded moments ago and not yet in the
// informer would read as free memory. Falls back to the cached client when
// unset, which is how the unit tests run.
APIReader client.Reader
// Now is the controller's clock, for how long a wake request has waited.
// It falls back to time.Now when unset.
Now func() time.Time
// WakeRequests remembers when each wake request was first seen, so that
// its wait is timed on this clock. It is made on first use when unset.
WakeRequests *wakeRequestClock
// LimitWarnings remembers when each engine was last warned that its KV
// limit did not take. It is made on first use when unset.
LimitWarnings *limitWarningClock
}
ModelClaimReconciler reconciles a ModelClaim object.
func (*ModelClaimReconciler) Reconcile ¶
func (r *ModelClaimReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)
Reconcile drives a ModelClaim towards its desired state: select a warm pod, activate a runtime engine, hold routing at port 0 until ready, and stop the engine on scale-down or deletion.
type ModelClaimRef ¶
type ModelClaimRef struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
UID string `json:"uid"`
}
ModelClaimRef identifies the ModelClaim that owns a runtime engine without relying on the served model name, which may not be unique across namespaces.
type ModelInfo ¶
type ModelInfo struct {
ModelName string `json:"model_name"`
Port int32 `json:"port"`
IPCName string `json:"ipc_name"`
Phase string `json:"phase"`
// Ready reports whether the engine can serve right now (runtime /health
// probe). The controller gates routability on it: a model's annotation
// stays at the non-routable marker (port 0) until Ready, so requests never
// route to a still-booting engine.
Ready bool `json:"ready"`
KVUsedBytes int64 `json:"kv_used_bytes,omitempty"`
KVTotalBytes int64 `json:"kv_total_bytes,omitempty"`
}
ModelInfo is one entry returned by the runtime sidecar's model listing.
type PodPlacementState ¶
type PodPlacementState struct {
SnapshotKnown bool
ArtifactCached bool
MemoryKnown bool
HBMFreeBytes int64
KVUsedBytes int64
ModelCount int
// AwakeCount is how many of the pod's engines are awake, serving or
// starting. The engines on a card share its compute, and a sleeping one
// takes none.
AwakeCount int
// HBMUsableBytes is how much of this pod's GPU memory can ever hold an
// engine, and HBMUsableKnown separates a card with nothing left from a card
// nobody could measure. A pod with several cards is described by its
// smallest, since which card an engine lands on is the device plugin's
// decision rather than ours.
HBMUsableBytes int64
HBMUsableKnown bool
// MaximumRoomBytes is the most the account says this card could ever
// offer, and MaximumRoomKnown says whether it could be worked out at all.
// Ranking uses it in preference to free memory: free memory moves with
// traffic, so ordering two admitted pods by it would contradict the gate
// they just passed.
MaximumRoomBytes int64
MaximumRoomKnown bool
}
PodPlacementState is the scheduling-relevant summary of one warm pod. It is not persisted in a CRD because runtime sidecars are the authoritative source.
type RuntimeAcceleratorSnapshot ¶
type RuntimeAcceleratorSnapshot struct {
ID string `json:"id"`
HBMTotalBytes int64 `json:"hbm_total_bytes"`
HBMFreeBytes int64 `json:"hbm_free_bytes"`
// HBMUsableBytes is how much of this card an engine can ever take: the
// total less what the driver keeps for itself. Unlike HBMFreeBytes it does
// not move with traffic, so a card can be sized by it. Negative when the
// runtime could not measure the card.
HBMUsableBytes int64 `json:"hbm_usable_bytes"`
}
RuntimeAcceleratorSnapshot is one GPU visible to a warm runtime pod.
type RuntimeClient ¶
type RuntimeClient interface {
Activate(ctx context.Context, podIP string, port int, req *ActivateRequest) (*ActivateResponse, error)
Deactivate(ctx context.Context, podIP string, port int, req *DeactivateRequest) error
ListModels(ctx context.Context, podIP string, port int) ([]ModelInfo, error)
Snapshot(ctx context.Context, podIP string, port int) (*RuntimeSnapshot, error)
SetKVLimit(ctx context.Context, podIP string, port int, req *SetKVLimitRequest) (*RuntimeOperationResponse, error)
Sleep(ctx context.Context, podIP string, port int, req *SleepRequest) (*RuntimeOperationResponse, error)
Wake(ctx context.Context, podIP string, port int, req *WakeRequest) (*RuntimeOperationResponse, error)
}
RuntimeClient is the control-plane view of the per-runtime sidecar. The interface keeps the controller testable with an in-process fake.
func NewRuntimeClient ¶
func NewRuntimeClient() RuntimeClient
NewRuntimeClient returns the default HTTP-backed runtime client.
type RuntimeOperationResponse ¶
type RuntimeOperationResponse struct {
Status string `json:"status"`
ModelName string `json:"model_name"`
OperationID string `json:"operation_id"`
Applied bool `json:"applied"`
Phase string `json:"phase"`
}
RuntimeOperationResponse reports the result of an idempotent control action.
type RuntimeSnapshot ¶
type RuntimeSnapshot struct {
ObservedAt time.Time `json:"observed_at"`
Accelerators []RuntimeAcceleratorSnapshot `json:"accelerators"`
Models []RuntimeSnapshotModel `json:"models"`
CachedArtifacts []string `json:"cached_artifacts"`
}
RuntimeSnapshot is the point-in-time source for controller placement. It is cached in memory only; the runtime sidecar remains authoritative.
type RuntimeSnapshotModel ¶
type RuntimeSnapshotModel struct {
ModelName string `json:"model_name"`
ArtifactURL string `json:"artifact_url"`
ClaimRef *ModelClaimRef `json:"claim_ref,omitempty"`
Port int32 `json:"port"`
IPCName string `json:"ipc_name"`
Phase string `json:"phase"`
// Alive is process liveness, separate from readiness: a booting engine is
// alive but not routable, while a restarting or terminal engine is not.
Alive bool `json:"alive"`
Ready bool `json:"ready"`
RestartCount int `json:"restart_count"`
LastError string `json:"last_error,omitempty"`
LastTransition *time.Time `json:"last_transition,omitempty"`
// KVUsedBytes is the KV memory this engine has mapped, its pages in use and
// the ones it holds in reserve together. KVCapacityBytes is the limit its
// KV allocator currently holds, which is what the engine obeys and not
// necessarily what the controller last asked for. Both are negative while
// the engine has no KV allocator to read, which a starting engine and one
// that never built a segment have in common.
KVUsedBytes int64 `json:"kv_used_bytes"`
KVCapacityBytes int64 `json:"kv_capacity_bytes"`
HBMPeakBytes int64 `json:"hbm_peak_bytes"`
// SleepingFootprintBytes is the GPU memory a sleeping engine still held
// right after it went to sleep, as the runtime measured it then. Only a
// sleeping engine reports it. Nil means the runtime could not attribute
// a reading to the engine.
SleepingFootprintBytes *int64 `json:"sleeping_footprint_bytes,omitempty"`
// RequestMetricsObserved distinguishes a zero metric from an unavailable
// scrape. Pool policy must not infer idleness unless the completion counter
// is also present.
RequestMetricsObserved bool `json:"request_metrics_observed"`
RequestsRunning int64 `json:"requests_running"`
RequestsWaiting int64 `json:"requests_waiting"`
RequestSuccessTotal *int64 `json:"request_success_total,omitempty"`
}
RuntimeSnapshotModel is one engine reported by a runtime snapshot.
type SetKVLimitRequest ¶
type SetKVLimitRequest struct {
ModelName string `json:"model_name"`
LimitBytes int64 `json:"limit_bytes"`
OperationID string `json:"operation_id"`
}
SetKVLimitRequest applies a kvcached limit to a resident model through the runtime sidecar. OperationID makes retries idempotent at the runtime.
type SleepRequest ¶
type SleepRequest struct {
ModelName string `json:"model_name"`
Level int `json:"level"`
OperationID string `json:"operation_id"`
}
SleepRequest puts a vLLM engine to sleep through its runtime sidecar.
type WakeRequest ¶
type WakeRequest struct {
ModelName string `json:"model_name"`
OperationID string `json:"operation_id"`
}
WakeRequest wakes a vLLM engine through its runtime sidecar.