Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
89 changes: 61 additions & 28 deletions crates/mesh-llm-host-runtime/src/inference/skippy/topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use std::collections::HashMap;

use anyhow::{anyhow, bail, Result};
use skippy_topology::{
infer_family_capability, plan_weighted_contiguous, BoundaryDecision, DiagnosticSeverity,
LayerSpec, NodeSpec, PlannerPolicy, TopologyPlanRequest,
infer_family_capability, plan_package_aware_contiguous_with_signals, BoundaryDecision,
DiagnosticSeverity, LayerSpec, NodePlacementSignal, NodeSpec, PlannerPolicy,
TopologyPlanRequest,
};

use super::materialization::StagePackageInfo;
Expand All @@ -12,6 +13,11 @@ use super::materialization::StagePackageInfo;
pub(crate) struct StageTopologyParticipant {
pub(crate) node_id: iroh::EndpointId,
pub(crate) vram_bytes: u64,
pub(crate) cached_slice_bytes: u64,
pub(crate) missing_artifact_bytes: u64,
pub(crate) rtt_ms: Option<u32>,
pub(crate) artifact_transfer_supported: bool,
pub(crate) availability_score: u32,
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -60,14 +66,25 @@ pub(crate) fn plan_package_topology(
.iter()
.map(|participant| NodeSpec {
node_id: participant.node_id.to_string(),
cached_slice_bytes: 0,
cached_slice_bytes: participant.cached_slice_bytes,
vram_bytes: participant.vram_bytes,
})
.collect(),
family,
policy: PlannerPolicy::default(),
};
let plan = plan_weighted_contiguous(&request)?;
let placement_signals = participants
.iter()
.map(|participant| NodePlacementSignal {
node_id: participant.node_id.to_string(),
cached_slice_bytes: participant.cached_slice_bytes,
missing_artifact_bytes: participant.missing_artifact_bytes,
rtt_ms: participant.rtt_ms,
artifact_transfer_supported: participant.artifact_transfer_supported,
availability_score: participant.availability_score,
})
.collect::<Vec<_>>();
let plan = plan_package_aware_contiguous_with_signals(&request, &placement_signals)?;

let rejected = plan
.boundaries
Expand Down Expand Up @@ -165,6 +182,18 @@ mod tests {
SecretKey::from_bytes(&bytes).public()
}

fn participant(node_id: iroh::EndpointId, vram_bytes: u64) -> StageTopologyParticipant {
StageTopologyParticipant {
node_id,
vram_bytes,
cached_slice_bytes: 0,
missing_artifact_bytes: 0,
rtt_ms: None,
artifact_transfer_supported: false,
availability_score: 0,
}
}

fn package(layer_count: u32) -> StagePackageInfo {
StagePackageInfo {
package_ref: "hf://Mesh-LLM/demo-package".to_string(),
Expand Down Expand Up @@ -198,18 +227,9 @@ mod tests {
"topology-a",
&package(12),
&[
StageTopologyParticipant {
node_id: id_a,
vram_bytes: 60,
},
StageTopologyParticipant {
node_id: id_b,
vram_bytes: 30,
},
StageTopologyParticipant {
node_id: id_c,
vram_bytes: 30,
},
participant(id_a, 60),
participant(id_b, 30),
participant(id_c, 30),
],
)
.unwrap();
Expand Down Expand Up @@ -251,18 +271,9 @@ mod tests {
"topology-a",
&package(2),
&[
StageTopologyParticipant {
node_id: id_a,
vram_bytes: 10,
},
StageTopologyParticipant {
node_id: id_b,
vram_bytes: 10,
},
StageTopologyParticipant {
node_id: id_c,
vram_bytes: 10,
},
participant(id_a, 10),
participant(id_b, 10),
participant(id_c, 10),
],
)
.unwrap();
Expand All @@ -289,4 +300,26 @@ mod tests {
.iter()
.all(|stage| stage.layer_start < stage.layer_end));
}

#[test]
fn topology_adapter_prefers_cached_peer_for_equal_capacity() {
let id_a = make_id(1);
let id_b = make_id(2);

let mut cold = participant(id_a, 40);
cold.missing_artifact_bytes = 32;
let mut warm = participant(id_b, 40);
warm.cached_slice_bytes = 64;
warm.artifact_transfer_supported = true;

let plan = plan_package_topology("topology-a", &package(8), &[cold, warm]).unwrap();

assert_eq!(plan.stages.len(), 2);
assert_eq!(plan.stages[0].node_id, id_b);
assert_eq!(
(plan.stages[0].layer_start, plan.stages[0].layer_end),
(0, 4)
);
assert_eq!(plan.stages[1].node_id, id_a);
}
}
4 changes: 2 additions & 2 deletions crates/mesh-llm-host-runtime/src/runtime/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::runtime_data::{
use anyhow::{Context, Result};
use skippy_protocol::{FlashAttentionType, LoadMode, PeerConfig, StageConfig};
use skippy_topology::{
infer_family_capability, plan_weighted_contiguous, BoundaryDecision, DiagnosticSeverity,
infer_family_capability, plan_package_aware_contiguous, BoundaryDecision, DiagnosticSeverity,
LayerSpec, NodeSpec, PlannerPolicy, TopologyPlanRequest,
};
use std::collections::HashMap;
Expand Down Expand Up @@ -1736,7 +1736,7 @@ fn plan_runtime_slice_topology(
layer_count = package.layer_count,
"planning split runtime topology"
);
let plan = plan_weighted_contiguous(&request)?;
let plan = plan_package_aware_contiguous(&request)?;
let rejected = plan
.boundaries
.iter()
Expand Down
Loading
Loading