Skip to content
Open
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
24 changes: 18 additions & 6 deletions docs/prefix-cache-offload.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ retains source windows through the last rank's copy fence.
as a checkpoint are never offloaded.
- Every model contract is covered through the core's runtime-sized
allocation groups. The offload path contains no model-specific code.
- Offload work never blocks the model worker thread or the model stream.
- Offload work never blocks the model stream, and never blocks the model worker
thread except for the bounded Copy Engine drain before launching a graph that
contains in-graph peer-to-peer Copy Engine nodes (`Node::Copy` with a
`Memory::Peer` endpoint). Single-GPU and non-peer-copy models stay ungated.
Section 2.10 states the isolation mechanisms and section 4 the measurements
that gate derived defaults.

Expand Down Expand Up @@ -911,8 +914,15 @@ Offload limits interference through bounded work and explicit ownership:
offload streams are created at the least stream priority. Every other Helios
stream uses the default priority, which CUDA defines as the least priority
as well, so stream priority does not separate offload work from model work.
Creating the model and copy streams at a greater priority requires the
section 4 measurements to show a benefit. Measure delays to
When a loaded model contains CUDA graphs with in-graph peer-to-peer Copy Engine
nodes (`Node::Copy` referencing `Memory::Peer`), Helios coordinates offload
batches against those graphs through a per-model `CopyEngineGate`: new offload
batches pause between 16 MiB windows while a peer-copy graph executes, waiting
peer-copy graphs bound their drain wait at 120 seconds, and continuous pipelined
peer-copy execution yields bounded fairness turns to waiting offload workers.
Models without peer-copy graphs omit the gate and keep one synchronization per
transfer window. Creating the model and copy streams at a greater priority
requires the section 4 measurements to show a benefit. Measure delays to
input uploads, completion downloads, and Engram row copies on shared copy
engines through per-token latency. Batch size and stream priority alone do
not bound those delays.
Expand Down Expand Up @@ -1012,9 +1022,11 @@ Offload limits interference through bounded work and explicit ownership:
- In the composite, memory contents are a subset of disk contents, counting
writes in flight, and memory evicts only durable records.
- Slab allocation never blocks; an unsatisfiable request fails its job.
- The model worker thread never waits for offload work, and the model stream
never waits on an offload stream. A peer connection that stops accepting
frames fails the job; it never delays the worker.
- The model stream never waits on an offload stream, and the model worker
thread waits on offload only for a bounded in-flight 16 MiB batch drain
before launching a graph that contains in-graph peer-to-peer Copy Engine
nodes. A peer connection that stops accepting frames fails the job; it never
delays the worker.
- A transfer whose completion can no longer be reported stops the store and the
worker, so its ids and pins are neither reused nor released.
- Offload copies are bounded per issue, and offload threads run below the
Expand Down
3 changes: 2 additions & 1 deletion flare-cli/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ pub fn peer(
rendezvous::report_connected(&mut stream)?;
phase.finish(connected(&transport));
let phase = progress.phase("Join host prefix stores", None);
let records = flare_helios::offload::shard::join_peer(
let records = flare_helios::offload::shard::join_peer_with_gate(
owner.offload(),
owner.gpu_codec_cubins().to_vec(),
owner.copy_gate(),
&mut stream,
cluster.rank,
cluster.world,
Expand Down
1 change: 1 addition & 0 deletions heliopause/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ pub(crate) fn execution_manifest(value: &Bound<'_, PyAny>) -> PyResult<Execution
input_frame_bytes: field!(value, "input_frame_bytes", usize),
buffers,
graphs,
peer_copy_graphs: Vec::new(),
tuning_graphs,
persistent_workers,
})
Expand Down
10 changes: 10 additions & 0 deletions helios/src/execution/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ pub struct ExecutionManifest {
pub input_frame_bytes: usize,
pub buffers: Vec<BufferDescriptor>,
pub graphs: Vec<GraphDescriptor>,
/// True for each graph index whose reconstructed CUDA graph contains at least
/// one `Node::Copy` endpoint in peer memory (`Memory::Peer`). Empty when not
/// populated (e.g. non-core manifests); absent entries default to `false`.
pub peer_copy_graphs: Vec<bool>,
pub tuning_graphs: Vec<TuningGraphDescriptor>,
/// Optional dedicated persistent worker graphs launched once after startup tuning.
pub persistent_workers: Vec<PersistentWorkerDescriptor>,
Expand Down Expand Up @@ -831,6 +835,12 @@ impl ExecutionManifest {
}
}
self.validate_tuning()?;
if !self.peer_copy_graphs.is_empty() && self.peer_copy_graphs.len() != self.graphs.len() {
return Err(Error::execution(
ExecutionError::Manifest,
"peer_copy_graphs length must match graphs when populated",
));
}
let mut names = HashSet::new();
let mut host_spans = HashMap::<&str, (usize, usize)>::new();
for graph in &self.graphs {
Expand Down
13 changes: 11 additions & 2 deletions helios/src/execution/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ pub unsafe fn serve_rank(
if let Err(error) = manifest.validate().and_then(|_| wire::validate_completion_packet(&manifest)) {
return Shutdown { drained: true, error: Some(error) };
}
let mut leases = crate::offload::PeerGraphLeases::new(
manifest.offload.as_ref().and_then(|b| b.copy_gate()),
manifest.peer_copy_graphs.clone(),
);
let mut executor = match unsafe { GraphExecutor::new_unstarted(manifest) } {
Ok(executor) => executor,
Err(error) => {
Expand Down Expand Up @@ -645,15 +649,18 @@ pub unsafe fn serve_rank(
let uploads: Vec<_> = owned.iter().map(|upload| Upload {
buffer: &upload.buffer, offset: upload.offset, bytes: &upload.bytes,
}).collect();
let guard = leases.enter(graph)?;
if executor.submit(graph, &uploads, grammar)? != Some(fence) {
return Err(invalid("rank lost its prepared submission"));
}
leases.track(Some(fence), guard);
started.push_back(Instant::now());
}
_ => return Err(invalid("unexpected rank command")),
}
}
if let Some(completed) = executor.poll()? {
leases.release_through(completed.fence);
started.pop_front();
channel.send(COMPLETE, &completion(&completed))?;
}
Expand All @@ -678,8 +685,10 @@ pub unsafe fn serve_rank(
}
result
})();
match result {
let shutdown = match result {
Ok(()) => executor.close(),
Err(error) => executor.abandon(error),
}
};
leases.clear();
shutdown
}
174 changes: 141 additions & 33 deletions helios/src/execution/ranks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,21 @@
use super::{
ExecutionManifest, FrameCompletion, GraphExecutor, RankStream, TensorParallelExecutor, Upload,
};
use crate::{Result, Shutdown, cache::Fence};
use crate::{Result, Shutdown, cache::Fence, offload::PeerGraphLeases};

pub enum RankPeers {
Processes(Vec<RankStream>),
Threads(Vec<ExecutionManifest>),
}

pub(crate) enum RankExecutor {
enum RankExecutorInner {
Threaded(Box<super::threaded::ThreadedExecutor>),
Local(Box<GraphExecutor>),
Parallel(Box<TensorParallelExecutor>),
}

impl RankExecutor {
/// # Safety
/// Prepared graphs, contexts, buffers, and b12x IPC allocations must remain
/// retained until coordinated drain. Peer sockets identify ranks 1..world.
pub(crate) unsafe fn new(
manifest: ExecutionManifest,
peers: Option<RankPeers>,
) -> Result<Self> {
match peers {
Some(RankPeers::Threads(ranks)) => {
unsafe { super::threaded::ThreadedExecutor::new(manifest, ranks) }
.map(|executor| Self::Threaded(Box::new(executor)))
}
Some(RankPeers::Processes(peers)) => {
unsafe { TensorParallelExecutor::new(manifest, peers) }
.map(|executor| Self::Parallel(Box::new(executor)))
}
None => unsafe { GraphExecutor::new(manifest) }
.map(|executor| Self::Local(Box::new(executor))),
}
}

pub(crate) fn submit(
impl RankExecutorInner {
fn submit(
&mut self,
graph: usize,
uploads: &[Upload<'_>],
Expand All @@ -57,24 +36,23 @@ impl RankExecutor {
}
}

pub(crate) fn poll(&mut self) -> Result<Option<FrameCompletion>> {
fn poll(&mut self) -> Result<Option<FrameCompletion>> {
match self {
Self::Local(executor) => executor.poll(),
Self::Parallel(executor) => executor.poll(),
Self::Threaded(executor) => executor.poll(),
}
}

/// Wait briefly for this rank's running frame; false when the caller should keep polling.
pub(crate) fn park(&self) -> bool {
fn park(&self) -> bool {
match self {
Self::Local(executor) => executor.park(),
Self::Parallel(executor) => executor.park(),
Self::Threaded(_) => false,
}
}

pub(crate) fn outstanding(&self) -> usize {
fn outstanding(&self) -> usize {
match self {
Self::Local(executor) => executor.outstanding(),
Self::Parallel(executor) => executor.outstanding(),
Expand All @@ -83,7 +61,7 @@ impl RankExecutor {
}

#[cfg(feature = "server")]
pub(crate) fn manifest(&self) -> &ExecutionManifest {
fn manifest(&self) -> &ExecutionManifest {
match self {
Self::Local(executor) => executor.manifest(),
Self::Parallel(executor) => executor.manifest(),
Expand All @@ -92,7 +70,7 @@ impl RankExecutor {
}

#[cfg(feature = "server")]
pub(crate) fn can_submit(&self, grammar: bool) -> bool {
fn can_submit(&self, grammar: bool) -> bool {
match self {
Self::Local(executor) => executor.can_submit(grammar),
Self::Parallel(executor) => executor.can_submit(grammar),
Expand All @@ -101,19 +79,149 @@ impl RankExecutor {
}

#[cfg(feature = "server")]
pub(crate) fn next_fence(&self) -> Result<Fence> {
fn next_fence(&self) -> Result<Fence> {
match self {
Self::Local(executor) => executor.next_fence(),
Self::Parallel(executor) => executor.next_fence(),
Self::Threaded(executor) => executor.next_fence(),
}
}

pub(crate) fn close(&mut self) -> Shutdown {
fn close(&mut self) -> Shutdown {
match self {
Self::Local(executor) => executor.close(),
Self::Parallel(executor) => executor.close(),
Self::Threaded(executor) => executor.close(),
}
}
}

pub(crate) struct RankExecutor {
inner: RankExecutorInner,
leases: PeerGraphLeases,
}

fn merge_peer_copy_graphs(manifest: &ExecutionManifest, peers: Option<&RankPeers>) -> Vec<bool> {
let mut merged = manifest.peer_copy_graphs.clone();
if let Some(RankPeers::Threads(ranks)) = peers {
for peer in ranks {
if peer.peer_copy_graphs.len() > merged.len() {
merged.resize(peer.peer_copy_graphs.len(), false);
}
for (dst, &src) in merged.iter_mut().zip(&peer.peer_copy_graphs) {
*dst |= src;
}
}
}
merged
}

impl RankExecutor {
/// # Safety
/// Prepared graphs, contexts, buffers, and b12x IPC allocations must remain
/// retained until coordinated drain. Peer sockets identify ranks 1..world.
pub(crate) unsafe fn new(
manifest: ExecutionManifest,
peers: Option<RankPeers>,
) -> Result<Self> {
let copy_gate = manifest.offload.as_ref().and_then(|b| b.copy_gate());
let peer_copy_graphs = merge_peer_copy_graphs(&manifest, peers.as_ref());
let inner = match peers {
Some(RankPeers::Threads(ranks)) => {
unsafe { super::threaded::ThreadedExecutor::new(manifest, ranks) }
.map(|executor| RankExecutorInner::Threaded(Box::new(executor)))?
}
Some(RankPeers::Processes(peers)) => {
unsafe { TensorParallelExecutor::new(manifest, peers) }
.map(|executor| RankExecutorInner::Parallel(Box::new(executor)))?
}
None => unsafe { GraphExecutor::new(manifest) }
.map(|executor| RankExecutorInner::Local(Box::new(executor)))?,
};
Ok(Self {
inner,
leases: PeerGraphLeases::new(copy_gate, peer_copy_graphs),
})
}

pub(crate) fn submit(
&mut self,
graph: usize,
uploads: &[Upload<'_>],
grammar: bool,
) -> Result<Option<Fence>> {
let guard = self.leases.enter(graph)?;
let submitted = self.inner.submit(graph, uploads, grammar)?;
self.leases.track(submitted, guard);
Ok(submitted)
}

pub(crate) fn poll(&mut self) -> Result<Option<FrameCompletion>> {
let completion = self.inner.poll()?;
if let Some(ref frame) = completion {
self.leases.release_through(frame.fence);
}
Ok(completion)
}

/// Wait briefly for this rank's running frame; false when the caller should keep polling.
pub(crate) fn park(&self) -> bool {
self.inner.park()
}

pub(crate) fn outstanding(&self) -> usize {
self.inner.outstanding()
}

#[cfg(feature = "server")]
pub(crate) fn manifest(&self) -> &ExecutionManifest {
self.inner.manifest()
}

#[cfg(feature = "server")]
pub(crate) fn can_submit(&self, grammar: bool) -> bool {
!self.leases.should_drain_for_offload() && self.inner.can_submit(grammar)
}

#[cfg(feature = "server")]
pub(crate) fn next_fence(&self) -> Result<Fence> {
self.inner.next_fence()
}

pub(crate) fn close(&mut self) -> Shutdown {
let shutdown = self.inner.close();
self.leases.clear();
shutdown
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::execution::tests::manifest;

#[test]
fn merge_peer_copy_graphs_unions_asymmetric_local_ranks() {
let mut root = manifest();
root.peer_copy_graphs = vec![false, true];
let mut peer = manifest();
peer.peer_copy_graphs = vec![true, false, true];
let peers = RankPeers::Threads(vec![peer]);

let merged = merge_peer_copy_graphs(&root, Some(&peers));
assert_eq!(merged, vec![true, true, true]);
}

#[test]
fn manifest_rejects_mismatched_peer_copy_graphs_length() {
let mut bad = manifest();
bad.peer_copy_graphs = vec![true, false];
let err = bad
.validate()
.expect_err("mismatched peer_copy_graphs length must fail validation");
assert!(
err.to_string().contains("peer_copy_graphs"),
"unexpected validation error: {err}"
);
}
}
1 change: 1 addition & 0 deletions helios/src/execution/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub(super) fn manifest() -> ExecutionManifest {
input_frame_bytes: 48,
buffers,
graphs: vec![graph],
peer_copy_graphs: vec![],
}
}

Expand Down
2 changes: 1 addition & 1 deletion helios/src/model/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ mod tests {
buffers: vec![BufferDescriptor {
name: "other".into(), shape: vec![], ..buffer.clone()
}, buffer],
graphs: vec![], tuning_graphs: vec![], persistent_workers: vec![],
graphs: vec![], peer_copy_graphs: vec![], tuning_graphs: vec![], persistent_workers: vec![],
};
view.validate(&manifest).unwrap();
let mut missing = view.clone();
Expand Down
Loading
Loading