admission

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package admission provides resource-scoped, priority-aware admission for realtime model work.

Priority is explicit provenance supplied by the runtime (for example, interactive ASR versus speculative preparation versus background reasoning). The governor never inspects prompt or transcript content. Work is admitted at safe points, and preemption is cooperative through lease cancellation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPreempted is the cancellation cause used when higher-priority work
	// needs capacity held by a cooperative lower-priority lease.
	ErrPreempted = errors.New("resource lease preempted by higher-priority work")
	// ErrAdmissionDeadline indicates that work did not begin by its declared
	// admission deadline.
	ErrAdmissionDeadline = errors.New("resource admission deadline exceeded")
)

Functions

This section is empty.

Types

type Class

type Class uint8

Class is a runtime-declared scheduling class. The numeric ordering is part of the scheduler contract: larger values are admitted first.

const (
	ClassBackground Class = iota + 1
	ClassSpeculative
	ClassInteractive
	ClassUrgent
)

func (Class) String

func (class Class) String() string

type ClassTiming

type ClassTiming struct {
	Admitted                   uint64  `json:"admitted"`
	Released                   uint64  `json:"released"`
	Preemptions                uint64  `json:"preemptions"`
	WaitTotalMS                float64 `json:"wait_total_ms"`
	WaitMaxMS                  float64 `json:"wait_max_ms"`
	ServiceTotalMS             float64 `json:"service_total_ms"`
	ServiceMaxMS               float64 `json:"service_max_ms"`
	PreemptionToReleaseTotalMS float64 `json:"preemption_to_release_total_ms"`
	PreemptionToReleaseMaxMS   float64 `json:"preemption_to_release_max_ms"`
}

ClassTiming is fixed-memory admission telemetry. Wait covers request enqueue through lease grant. Service covers grant through the holder's Release safe point, so it includes provider work and cancellation acknowledgement.

type Config

type Config struct {
	Capacity            int
	ReservedInteractive int
	Clock               func() time.Time
}

Config defines one resource domain, such as a co-located GPU. Capacity and costs are abstract integer units. ReservedInteractive prevents background and speculative work from consuming all capacity, while interactive and urgent work may use the complete capacity.

type ContinuationProvider

type ContinuationProvider struct {
	Provider continuation.Provider
	Governor *Governor
	Request  Request
}

ContinuationProvider admits every model continuation through one resource governor. Class and cost come from deployment configuration, never prompt classification.

func (*ContinuationProvider) Continue

func (*ContinuationProvider) Descriptor

func (provider *ContinuationProvider) Descriptor() continuation.Descriptor

type Governor

type Governor struct {
	// contains filtered or unexported fields
}

Governor owns admission state for one bounded resource domain.

func NewGovernor

func NewGovernor(config Config) (*Governor, error)

NewGovernor creates a deterministic safe-point scheduler.

func (*Governor) Acquire

func (governor *Governor) Acquire(ctx context.Context, request Request) (*Lease, error)

Acquire waits until request can start. A returned lease owns its capacity until Release; cancellation only asks the holder to stop and never pretends GPU work has ended before the holder acknowledges the safe point.

func (*Governor) Snapshot

func (governor *Governor) Snapshot() Snapshot

Snapshot reports queue and capacity state without exposing request content.

type Lease

type Lease struct {
	// contains filtered or unexported fields
}

Lease is cooperative ownership of admitted capacity.

func (*Lease) Context

func (lease *Lease) Context() context.Context

Context is cancelled when the caller, its deadline, or higher-priority preemption asks the work to stop.

func (*Lease) Release

func (lease *Lease) Release()

Release acknowledges the provider's safe point and returns capacity. It is idempotent and must be called even after Context is cancelled.

func (*Lease) Request

func (lease *Lease) Request() Request

Request returns the immutable scheduling declaration.

type PerceptionProvider

type PerceptionProvider struct {
	Provider v1.PerceptionProvider
	Governor *Governor
	Request  Request
}

PerceptionProvider protects every stateful ASR boundary. Interactive ASR should normally be non-preemptible so a cancelled chunk cannot corrupt a provider session.

func (*PerceptionProvider) Descriptor

func (provider *PerceptionProvider) Descriptor() v1.Descriptor

func (*PerceptionProvider) Finalize

func (provider *PerceptionProvider) Finalize(ctx context.Context, finalSample uint64) (v1.PerceptionRevision, error)

func (*PerceptionProvider) PushFrame

func (provider *PerceptionProvider) PushFrame(ctx context.Context, frame v1.AudioFrame) ([]v1.PerceptionRevision, error)

type Request

type Request struct {
	Class       Class
	Cost        int
	Preemptible bool
	Deadline    time.Time
	Label       string
}

Request declares resource demand independently of semantic input. Deadline orders queued work and bounds admission. Callers should also put the same deadline on the parent context when it must bound execution.

type Snapshot

type Snapshot struct {
	Capacity            int                    `json:"capacity"`
	ReservedInteractive int                    `json:"reserved_interactive"`
	Used                int                    `json:"used"`
	LowerPriorityUsed   int                    `json:"lower_priority_used"`
	Running             map[string]int         `json:"running"`
	Waiting             map[string]int         `json:"waiting"`
	Admitted            uint64                 `json:"admitted"`
	Released            uint64                 `json:"released"`
	Preemptions         uint64                 `json:"preemptions"`
	CancelledWaiters    uint64                 `json:"cancelled_waiters"`
	DeadlineMisses      uint64                 `json:"deadline_misses"`
	Classes             map[string]ClassTiming `json:"classes,omitempty"`
}

Snapshot is safe operational telemetry; it contains no model input.

type SpeechProvider

type SpeechProvider struct {
	Provider v1.StreamingSpeechProvider
	Governor *Governor
	Request  Request
}

SpeechProvider admits one complete streaming synthesis lease. The lease is held until the terminal chunk or error so capacity reflects actual work.

func (*SpeechProvider) Descriptor

func (provider *SpeechProvider) Descriptor() v1.Descriptor

func (*SpeechProvider) Stream

func (provider *SpeechProvider) Stream(ctx context.Context, plan v1.SpeechPlan, emit func(v1.SpeechChunk) error) error

func (*SpeechProvider) Synthesize

func (provider *SpeechProvider) Synthesize(ctx context.Context, plan v1.SpeechPlan) ([]v1.SpeechChunk, error)

Synthesize preserves the stable non-streaming convenience surface while holding exactly the same one-request lease as Stream.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL