Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/cli/tests/model_deploy_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use dotcore_proto::{
parameter_value,
},
deployment::v1::{ExactPlacement, MemoryFit},
inference::v1::{FallbackGroup, InferenceRoute, InferenceRouteView},
inference::v1::{FallbackGroup, InferenceRoute, InferenceRouteView, SleepingMemberPolicy},
model::v1::{
ByContextMemoryMode, ByContextMemoryModeOffer, ContextBound, ContextBoundReason,
ContextOvercommit, ContextOvercommitConsequence, CreateLocalModelDeploymentRequest,
Expand Down Expand Up @@ -1986,6 +1986,7 @@ fn wait_site() -> FakeState {
model_deployment_ids: vec!["qwen-1".to_owned()],
..FallbackGroup::default()
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
generation: 1,
}),
..InferenceRouteView::default()
Expand Down
5 changes: 4 additions & 1 deletion backend/core/src/composition/local_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use dotcore_proto::dotcore::{
deployment::v1::{ArtifactPreparationPolicy, ExactPlacement},
inference::v1::{
CreateRouteRequest, FallbackGroup, FallbackGroupSelection, InferenceRoute,
ReplaceRouteRequest, route_service_server::RouteService as RouteServiceContract,
ReplaceRouteRequest, SleepingMemberPolicy,
route_service_server::RouteService as RouteServiceContract,
},
model::v1::{
CreateLocalModelDeploymentRequest, CreateModelDeploymentRequest, DeploymentLogHistoryState,
Expand Down Expand Up @@ -420,6 +421,7 @@ async fn a_manager_node_application_relaunches_when_its_linked_route_is_renamed(
name: "chat-renamed".to_owned(),
enabled: true,
fallback_groups: route.fallback_groups.clone(),
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
}),
)
.await
Expand Down Expand Up @@ -684,6 +686,7 @@ impl LocalNodeHarness {
selection: FallbackGroupSelection::Single as i32,
model_deployment_ids: vec![model_deployment_id.to_owned()],
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
}),
)
.await
Expand Down
6 changes: 5 additions & 1 deletion backend/core/src/composition/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ mod tests {
use dotcore_proto::dotcore::{
inference::v1::{
CreateRouteRequest, FallbackGroup, FallbackGroupSelection, InferenceRouteView,
SleepingMemberPolicy,
},
model::v1::model_deployment_snapshot::Source,
};
Expand Down Expand Up @@ -217,6 +218,7 @@ mod tests {
model_deployment_ids: vec![(*member).to_owned()],
})
.collect(),
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
})
.expect("created route")
};
Expand Down Expand Up @@ -253,7 +255,7 @@ mod tests {
},
inference::v1::{
CreateRouteRequest, DeleteRouteRequest, FallbackGroup, FallbackGroupSelection,
ReplaceRouteRequest,
ReplaceRouteRequest, SleepingMemberPolicy,
},
};
use dotcore_site::view::desired::ApplicationNodeViewOwner as _;
Expand Down Expand Up @@ -293,6 +295,7 @@ mod tests {
name: "chat".to_owned(),
enabled: true,
fallback_groups: vec![group("model-one")],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
})
.expect("created route")
.route
Expand Down Expand Up @@ -327,6 +330,7 @@ mod tests {
name: name.to_owned(),
enabled,
fallback_groups: vec![group(member)],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
})
.expect("replaced route");
};
Expand Down
4 changes: 3 additions & 1 deletion backend/core/src/composition/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ async fn composed_route_manager_changes_are_shared_by_route_application_and_rout
use dotcore_proto::dotcore::{
inference::v1::{
CreateRouteRequest, DeleteRouteRequest, FallbackGroup, FallbackGroupSelection,
GetRouteRequest, ListRoutesRequest, ReplaceRouteRequest,
GetRouteRequest, ListRoutesRequest, ReplaceRouteRequest, SleepingMemberPolicy,
route_service_server::RouteService as RouteServiceContract,
},
model::v1::{
Expand Down Expand Up @@ -1078,6 +1078,7 @@ async fn composed_route_manager_changes_are_shared_by_route_application_and_rout
selection: FallbackGroupSelection::Single as i32,
model_deployment_ids: vec![deployment.model_deployment_id.clone()],
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
}),
)
.await
Expand Down Expand Up @@ -1130,6 +1131,7 @@ async fn composed_route_manager_changes_are_shared_by_route_application_and_rout
name: "route-two".to_owned(),
enabled: true,
fallback_groups: created.fallback_groups.clone(),
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
}),
)
.await
Expand Down
5 changes: 4 additions & 1 deletion backend/core/src/model/controller/node_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ mod tests {
use dotcore_proto::{
dotcore::{
deployment::v1::ExactPlacement,
inference::v1::{FallbackGroup, FallbackGroupSelection, InferenceRoute},
inference::v1::{
FallbackGroup, FallbackGroupSelection, InferenceRoute, SleepingMemberPolicy,
},
model::{
private::v1::ModelControllerStatusSection, v1::ModelDeploymentLifecycleTransition,
},
Expand Down Expand Up @@ -1200,6 +1202,7 @@ mod tests {
selection: FallbackGroupSelection::Single as i32,
model_deployment_ids: vec![deployment_id.to_owned()],
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
generation: 1,
});
Ok::<_, std::convert::Infallible>(())
Expand Down
5 changes: 4 additions & 1 deletion backend/core/src/model/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,9 @@ mod tests {
parameter_value::Value as EngineParameterValueKind,
},
deployment::v1::ExactPlacement,
inference::v1::{FallbackGroup, FallbackGroupSelection, InferenceRoute},
inference::v1::{
FallbackGroup, FallbackGroupSelection, InferenceRoute, SleepingMemberPolicy,
},
model::{
private::v1::{ModelAssignment, ModelDesiredViewSection},
v1::{
Expand Down Expand Up @@ -5429,6 +5431,7 @@ selector:
other.model_deployment_id,
],
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
generation: 1,
});
Ok::<(), std::convert::Infallible>(())
Expand Down
7 changes: 6 additions & 1 deletion backend/core/src/route_manager/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ fn modalities(supports_text: bool, supports_image: bool) -> Vec<i32> {
mod tests {
use dotcore_proto::dotcore::{
catalog::v1::parameter_value,
inference::v1::{FallbackGroup, FallbackGroupSelection, InferenceRoute},
inference::v1::{
FallbackGroup, FallbackGroupSelection, InferenceRoute, SleepingMemberPolicy,
},
model::v1::{
ModelDeploymentSnapshot, UpstreamModelDesiredConfiguration,
UpstreamModelInputCapabilities,
Expand All @@ -396,6 +398,7 @@ mod tests {
selection: FallbackGroupSelection::Single as i32,
model_deployment_ids: vec!["deployment".to_owned()],
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
generation: 7,
};
let docker_dispatch = FakeReadyTarget {
Expand Down Expand Up @@ -427,6 +430,7 @@ mod tests {
selection: FallbackGroupSelection::Single as i32,
model_deployment_ids: vec!["deployment".to_owned()],
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
generation: 7,
};
let availability = availability_for_eligible_targets(
Expand Down Expand Up @@ -682,6 +686,7 @@ mod tests {
model_deployment_ids: members.iter().map(|id| (*id).to_owned()).collect(),
})
.collect(),
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
generation: 1,
}
}
Expand Down
40 changes: 26 additions & 14 deletions backend/core/src/route_manager/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use std::{collections::BTreeSet, sync::Arc};
use dotcore_domain::inference_route::{RouteShapeError, is_valid_route_name, validate_route_shape};
use dotcore_domain::valid_id;
use dotcore_proto::dotcore::{
inference::v1::{FallbackGroup, FallbackGroupSelection, InferenceRoute},
inference::v1::{
CreateRouteRequest, FallbackGroup, FallbackGroupSelection, InferenceRoute,
ReplaceRouteRequest, SleepingMemberPolicy,
},
model::v1::{ModelDeploymentDeclaration, ModelDeploymentDesiredState},
site::v1::Site,
};
Expand Down Expand Up @@ -67,6 +70,7 @@ impl RouteDeclarationRepository {
selection: FallbackGroupSelection::Single as i32,
model_deployment_ids: vec![deployment.model_deployment_id.clone()],
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
generation: 1,
};
let transaction = RouteSiteTransaction {
Expand All @@ -82,17 +86,16 @@ impl RouteDeclarationRepository {
/// Persists one server-created complete route declaration.
pub(crate) fn create(
&self,
name: String,
enabled: bool,
fallback_groups: Vec<FallbackGroup>,
request: CreateRouteRequest,
) -> Result<InferenceRoute, RouteRepositoryError> {
self.site
.mutate_inference_routes(|transaction| {
let route = InferenceRoute {
inference_route_id: next_route_id(transaction.routes),
name,
enabled,
fallback_groups,
name: request.name,
enabled: request.enabled,
fallback_groups: request.fallback_groups,
sleeping_member_policy: request.sleeping_member_policy,
generation: 1,
};
validate_new_route(transaction, &route)?;
Expand All @@ -105,12 +108,16 @@ impl RouteDeclarationRepository {
/// Replaces a complete mutable route declaration at its exact generation.
pub(crate) fn replace(
&self,
inference_route_id: &str,
expected_generation: u64,
name: String,
enabled: bool,
fallback_groups: Vec<FallbackGroup>,
request: ReplaceRouteRequest,
) -> Result<InferenceRoute, RouteRepositoryError> {
let ReplaceRouteRequest {
inference_route_id,
expected_generation,
name,
enabled,
fallback_groups,
sleeping_member_policy,
} = request;
if expected_generation == 0 {
return Err(RouteRepositoryError::InvalidArgument(
"expected generation must be positive".to_owned(),
Expand All @@ -122,7 +129,7 @@ impl RouteDeclarationRepository {
.routes
.iter()
.position(|route| route.inference_route_id == inference_route_id)
.ok_or_else(|| RouteRepositoryError::NotFound(inference_route_id.to_owned()))?;
.ok_or_else(|| RouteRepositoryError::NotFound(inference_route_id.clone()))?;
let existing = &transaction.routes[index];
if existing.generation != expected_generation {
return Err(RouteRepositoryError::FailedPrecondition(
Expand All @@ -134,6 +141,7 @@ impl RouteDeclarationRepository {
name,
enabled,
fallback_groups,
sleeping_member_policy,
generation: existing.generation.checked_add(1).ok_or_else(|| {
RouteRepositoryError::FailedPrecondition(
"route generation cannot be incremented".to_owned(),
Expand Down Expand Up @@ -348,7 +356,9 @@ mod tests {
},
catalog::v1::{ModelParallelShape, OciPlatform},
deployment::v1::ExactPlacement,
inference::v1::{FallbackGroup, FallbackGroupSelection, InferenceRoute},
inference::v1::{
FallbackGroup, FallbackGroupSelection, InferenceRoute, SleepingMemberPolicy,
},
model::v1::{
ModelDeploymentDeclaration, ModelDeploymentDesiredState,
ModelDeploymentLifecycleTransition,
Expand Down Expand Up @@ -540,6 +550,7 @@ mod tests {
selection: FallbackGroupSelection::Single as i32,
model_deployment_ids: vec!["deployment-one".to_owned()],
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
generation: 1,
}],
..Default::default()
Expand Down Expand Up @@ -582,6 +593,7 @@ mod tests {
selection: FallbackGroupSelection::Single as i32,
model_deployment_ids: vec!["dep-1".to_owned()],
}],
sleeping_member_policy: SleepingMemberPolicy::Unspecified as i32,
generation: 1,
}
}
Expand Down
28 changes: 14 additions & 14 deletions backend/core/src/route_manager/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl RouteManager {
availability: Mutex::new(std::collections::BTreeMap::new()),
mutation: Mutex::new(()),
listener,
changes: tokio::sync::watch::Sender::new(()),
});
let observer_shared = Arc::downgrade(&shared);
shared
Expand Down Expand Up @@ -96,6 +97,12 @@ impl RouteManager {
)
}

/// Follows route snapshot changes: the receiver is marked changed whenever a new snapshot is
/// published.
pub(crate) fn changes(&self) -> tokio::sync::watch::Receiver<()> {
self.shared.changes.subscribe()
}

/// Lists the current desired routes with independently derived transient availability.
pub(crate) fn list(&self) -> Vec<InferenceRouteView> {
let snapshot = self.snapshot();
Expand Down Expand Up @@ -130,27 +137,15 @@ impl RouteManager {
&self,
request: CreateRouteRequest,
) -> Result<InferenceRouteView, RouteRepositoryError> {
self.mutate("create", || {
self.shared
.declarations
.create(request.name, request.enabled, request.fallback_groups)
})
self.mutate("create", || self.shared.declarations.create(request))
}

/// Replaces and publishes one complete route declaration.
pub(crate) fn replace(
&self,
request: ReplaceRouteRequest,
) -> Result<InferenceRouteView, RouteRepositoryError> {
self.mutate("replace", || {
self.shared.declarations.replace(
&request.inference_route_id,
request.expected_generation,
request.name,
request.enabled,
request.fallback_groups,
)
})
self.mutate("replace", || self.shared.declarations.replace(request))
}

/// Deletes one route declaration and publishes the complete resulting snapshot.
Expand Down Expand Up @@ -247,6 +242,8 @@ fn publish_snapshot(shared: &RouteManagerShared, snapshot: CompiledRouteSnapshot
if **current != snapshot {
let route_count = snapshot.routes().len();
*current = Arc::new(snapshot);
drop(current);
shared.changes.send_replace(());
info!(
event_kind = "route_snapshot_changed",
route_count, "inference route snapshot changed",
Expand Down Expand Up @@ -322,6 +319,9 @@ struct RouteManagerShared {
>,
mutation: Mutex<()>,
listener: Arc<tokio::sync::Notify>,

/// Marked changed after each published snapshot.
changes: tokio::sync::watch::Sender<()>,
}

/// Management API adapter for route-manager-owned declarations.
Expand Down
Loading