snoozeml.models — Model Metadata & Lifecycle Management#
Model metadata, operational state representations, and lifecycle management for SnoozeML.
- class snoozeml.models.ModelState(*values)[source]#
-
Operational lifecycle state of a registered model within SnoozeML.
- IDLE = 'idle'#
Configuration registered, but weights are deallocated (scaled to zero).
- LOADING = 'loading'#
Model weights are currently being loaded into host RAM or device VRAM.
- READY = 'ready'#
Weights are resident in memory and ready for immediate inference.
- BUSY = 'busy'#
Inference forward pass is actively executing.
- classmethod from_str(value)[source]#
Parses a case-insensitive state string into a
ModelState.- Parameters:
value (str)
- Return type:
- class snoozeml.models.ModelInfo(id, state, onnx_path, idle_timeout_secs=300, max_batch_size=16, max_batch_delay_ms=10, last_accessed_secs_ago=0, description=None, pinned=False, memory_bytes=0)[source]#
Bases:
objectMetadata and live operational state for a registered model in SnoozeML.
- Parameters:
- state#
Operational status (
ModelState).
- state: ModelState#
- property is_loaded: bool#
Returns
Trueif model weights are currently resident in memory (readyorbusy).
- class snoozeml.models.ModelsManager(client)[source]#
Bases:
objectSynchronous manager for querying and controlling model lifecycles on a SnoozeML daemon.
Accessed via
snoozeml.SnoozeClient.models.- Parameters:
client (SnoozeClient)
- list()[source]#
Lists all registered models and their current lifecycle telemetry.
- Returns:
List of
ModelInfoobjects.- Raises:
SnoozeError – On authentication, permission, or connection errors.
- Return type:
- get(model_id)[source]#
Retrieves metadata and operational state for a specific model.
- Parameters:
model_id (str) – Unique identifier of the model to inspect.
- Returns:
Matching
ModelInfoinstance.- Raises:
ModelNotFoundError – If
model_idis not registered on the server.SnoozeError – On authentication or transport failures.
- Return type:
- pin(model_id)[source]#
Pins a model in memory so it is eagerly loaded and exempt from automatic eviction.
- unpin(model_id)[source]#
Unpins a model so it returns to normal scale-to-zero and LRU lifecycle management.
- get_stats(model_id)[source]#
Retrieves cumulative inference and batch execution statistics for a registered model.
Queries the OIP v2 statistics endpoint (
GET /v2/models/{model_id}/stats).- Parameters:
model_id (str) – Target model identifier.
- Returns:
ModelStatscontaining request counts, latencies, and execution metrics.- Raises:
ModelNotFoundError – If
model_idis not found or has no recorded statistics.SnoozeError – On network or server failure.
- Return type:
ModelStats
- stats()[source]#
Retrieves cumulative execution statistics across all registered models.
Queries the OIP v2 repository statistics endpoint (
GET /v2/models/stats).- Returns:
List of
ModelStatsinstances.- Raises:
SnoozeError – On network or server failure.
- Return type:
List[ModelStats]
- refresh()[source]#
Triggers runtime discovery and refresh of models on the SnoozeML daemon via HTTP.
Scans the daemon’s configured models directory for newly added or modified models.
- upload(file, *, filename=None, model_id=None, description=None, pinned=False, overwrite=False, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, device=None, provider=None)[source]#
Uploads a model file directly to the SnoozeML daemon via HTTP.
Supports passing custom runtime configuration (pinned memory, replica limits, batch sizes, idle timeouts, overwrite) without needing to mount local filesystem volumes.
- Parameters:
file (str | Path | bytes | Any) – Filesystem path (str or Path), raw bytes, or readable binary stream.
filename (str | None) – Optional explicit filename (e.g. “iris_classifier.onnx”).
model_id (str | None) – Optional unique identifier for the model (defaults to file stem).
description (str | None) – Optional custom human-readable description.
pinned (bool) – If True, eagerly loads model into memory and exempts it from scale-to-zero.
overwrite (bool) – If True, replaces an existing model weight file on the server if present.
max_batch_size (int | None) – Maximum batch size for dynamic Axis(0) micro-batching.
max_batch_delay_ms (int | None) – Maximum latency budget in ms before executing micro-batch.
idle_timeout_secs (int | None) – Inactivity threshold in seconds before scale-to-zero unload.
min_residency_secs (int | None) – Minimum duration in seconds model stays resident before LRU eviction.
autoscale_queue_threshold (int | None) – Queue backlog threshold to trigger replica autoscale.
max_replicas (int | None) – Upper limit on parallel replica instances.
routing_strategy (str | None) – Replica routing strategy (“least_queue”, “round_robin”, “random”).
device (str | None) – Hardware execution provider (“cpu”, “cuda”, “auto”).
provider (str | None)
- Returns:
ModelInforepresenting the newly registered model.- Return type:
- wait_for_ready(model_id, *, timeout=30.0, poll_interval=0.2, trigger_load=False)[source]#
Polls model metadata until the model reaches a loaded state (
ModelState.READYorModelState.BUSY).- Parameters:
- Returns:
Loaded
ModelInfoinstance.- Return type:
- deploy_sklearn(model, *, model_id, initial_types=None, sample_input=None, input_name='float_input', output_name='output', opset_version=17, overwrite=True, pinned=False, description=None, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, device=None, provider=None)[source]#
Converts a fitted scikit-learn estimator or
Pipelineto ONNX and deploys it to SnoozeML in one call.- Parameters:
model (Any)
model_id (str)
sample_input (Any | None)
input_name (str)
output_name (str)
opset_version (int)
overwrite (bool)
pinned (bool)
description (str | None)
max_batch_size (int | None)
max_batch_delay_ms (int | None)
idle_timeout_secs (int | None)
min_residency_secs (int | None)
autoscale_queue_threshold (int | None)
max_replicas (int | None)
routing_strategy (str | None)
device (str | None)
provider (str | None)
- Return type:
- deploy_torch(model, sample_input, *, model_id, input_names=None, output_names=None, dynamic_axes=None, opset_version=17, overwrite=True, pinned=False, description=None, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, device=None, provider=None)[source]#
Exports a PyTorch
nn.Moduleto ONNX and deploys it to SnoozeML in one call.- Parameters:
model (Any)
sample_input (Any)
model_id (str)
opset_version (int)
overwrite (bool)
pinned (bool)
description (str | None)
max_batch_size (int | None)
max_batch_delay_ms (int | None)
idle_timeout_secs (int | None)
min_residency_secs (int | None)
autoscale_queue_threshold (int | None)
max_replicas (int | None)
routing_strategy (str | None)
device (str | None)
provider (str | None)
- Return type:
- deploy_xgboost(model, *, model_id, overwrite=True, pinned=False, description=None, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, device=None, provider=None)[source]#
Exports an XGBoost model to
.xgb.jsonand deploys it to SnoozeML in one call.- Parameters:
model (Any)
model_id (str)
overwrite (bool)
pinned (bool)
description (str | None)
max_batch_size (int | None)
max_batch_delay_ms (int | None)
idle_timeout_secs (int | None)
min_residency_secs (int | None)
autoscale_queue_threshold (int | None)
max_replicas (int | None)
routing_strategy (str | None)
device (str | None)
provider (str | None)
- Return type:
- class snoozeml.models.AsyncModelsManager(client)[source]#
Bases:
objectAsynchronous manager for querying and controlling model lifecycles on a SnoozeML daemon.
Accessed via
snoozeml.AsyncSnoozeClient.models.- Parameters:
client (AsyncSnoozeClient)
- async get(model_id)[source]#
Asynchronously retrieves metadata and operational state for a specific model.
- async evict(model_id)[source]#
Alias for
unload()— asynchronously evicts/snoozes a model from memory.
- async get_stats(model_id)[source]#
Asynchronously retrieves cumulative inference and batch execution statistics for a registered model.
Queries the OIP v2 statistics endpoint (
GET /v2/models/{model_id}/stats).- Parameters:
model_id (str) – Target model identifier.
- Returns:
ModelStatscontaining request counts, latencies, and execution metrics.- Raises:
ModelNotFoundError – If
model_idis not found or has no recorded statistics.SnoozeError – On network or server failure.
- Return type:
ModelStats
- async stats()[source]#
Asynchronously retrieves cumulative execution statistics across all registered models.
Queries the OIP v2 repository statistics endpoint (
GET /v2/models/stats).- Returns:
List of
ModelStatsinstances.- Raises:
SnoozeError – On network or server failure.
- Return type:
List[ModelStats]
- async refresh()[source]#
Asynchronously triggers runtime discovery and refresh of models on the daemon.
Scans the daemon’s configured models directory for newly added or modified models.
- async upload(file, *, filename=None, model_id=None, description=None, pinned=False, overwrite=False, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, device=None, provider=None)[source]#
Asynchronously uploads a model file directly to the daemon via HTTP.
Supports passing custom runtime configuration (pinned memory, replica limits, batch sizes, idle timeouts, overwrite) without needing to mount local filesystem volumes.
- Parameters:
file (str | Path | bytes | Any) – Filesystem path (str or Path), raw bytes, or readable binary stream.
filename (str | None) – Optional explicit filename (e.g. “iris_classifier.onnx”).
model_id (str | None) – Optional unique identifier for the model (defaults to file stem).
description (str | None) – Optional custom human-readable description.
pinned (bool) – If True, eagerly loads model into memory and exempts it from scale-to-zero.
overwrite (bool) – If True, replaces an existing model weight file on the server if present.
max_batch_size (int | None) – Maximum batch size for dynamic Axis(0) micro-batching.
max_batch_delay_ms (int | None) – Maximum latency budget in ms before executing micro-batch.
idle_timeout_secs (int | None) – Inactivity threshold in seconds before scale-to-zero unload.
min_residency_secs (int | None) – Minimum duration in seconds model stays resident before LRU eviction.
autoscale_queue_threshold (int | None) – Queue backlog threshold to trigger replica autoscale.
max_replicas (int | None) – Upper limit on parallel replica instances.
routing_strategy (str | None) – Replica routing strategy (“least_queue”, “round_robin”, “random”).
device (str | None) – Hardware execution provider (“cpu”, “cuda”, “auto”).
provider (str | None)
- Returns:
ModelInforepresenting the newly registered model.- Return type:
- async wait_for_ready(model_id, *, timeout=30.0, poll_interval=0.2, trigger_load=False)[source]#
Asynchronously polls model metadata until the model reaches a loaded state.
- async deploy_sklearn(model, *, model_id, initial_types=None, sample_input=None, input_name='float_input', output_name='output', opset_version=17, overwrite=True, pinned=False, description=None, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, device=None, provider=None)[source]#
Asynchronously converts a fitted scikit-learn estimator or
Pipelineand deploys it.- Parameters:
model (Any)
model_id (str)
sample_input (Any | None)
input_name (str)
output_name (str)
opset_version (int)
overwrite (bool)
pinned (bool)
description (str | None)
max_batch_size (int | None)
max_batch_delay_ms (int | None)
idle_timeout_secs (int | None)
min_residency_secs (int | None)
autoscale_queue_threshold (int | None)
max_replicas (int | None)
routing_strategy (str | None)
device (str | None)
provider (str | None)
- Return type:
- async deploy_torch(model, sample_input, *, model_id, input_names=None, output_names=None, dynamic_axes=None, opset_version=17, overwrite=True, pinned=False, description=None, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, device=None, provider=None)[source]#
Asynchronously exports a PyTorch
nn.Moduleto ONNX and deploys it.- Parameters:
model (Any)
sample_input (Any)
model_id (str)
opset_version (int)
overwrite (bool)
pinned (bool)
description (str | None)
max_batch_size (int | None)
max_batch_delay_ms (int | None)
idle_timeout_secs (int | None)
min_residency_secs (int | None)
autoscale_queue_threshold (int | None)
max_replicas (int | None)
routing_strategy (str | None)
device (str | None)
provider (str | None)
- Return type:
- async deploy_xgboost(model, *, model_id, overwrite=True, pinned=False, description=None, max_batch_size=None, max_batch_delay_ms=None, idle_timeout_secs=None, min_residency_secs=None, autoscale_queue_threshold=None, max_replicas=None, routing_strategy=None, device=None, provider=None)[source]#
Asynchronously exports an XGBoost model to
.xgb.jsonand deploys it.- Parameters:
model (Any)
model_id (str)
overwrite (bool)
pinned (bool)
description (str | None)
max_batch_size (int | None)
max_batch_delay_ms (int | None)
idle_timeout_secs (int | None)
min_residency_secs (int | None)
autoscale_queue_threshold (int | None)
max_replicas (int | None)
routing_strategy (str | None)
device (str | None)
provider (str | None)
- Return type: