Skip to content
Merged
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
14 changes: 14 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,20 @@ uncommitted reservations for parked or in-flight writes
ranking estimates, leaving `flare_host_cache_inbound_bytes_per_second` for the
local store's measured restore rate.

When a loaded core declares `Execution.async_transfers` channels, `/metrics`
also exports lock-free per-channel gauges and counters labeled by `channel` and
`rank`: `flare_async_transfer_device_pool_bytes`,
`flare_async_transfer_host_pool_bytes`,
`flare_async_transfer_submitted_cmds_total`,
`flare_async_transfer_completed_cmds_total`,
`flare_async_transfer_canceled_cmds_total`,
`flare_async_transfer_rejected_cmds_total`,
`flare_async_transfer_bytes_disk_to_host_total`,
`flare_async_transfer_bytes_host_to_dev_total`,
`flare_async_transfer_bytes_disk_to_dev_total`, and
`flare_async_transfer_last_error`. Cores without async transfer channels omit
these series.

Dashboard DEPTH is the change in `verification_drafts` divided by the change in
`verification_rounds` over the sampling window. It averages each request's planned
draft-prefix length, including zero-draft rounds, rather than graph width or batch
Expand Down
2 changes: 2 additions & 0 deletions docs/cli-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ Help exits with status 0; usage errors go to stderr with status 2. Its options a
| `--max-concurrency N` | Reduce concurrency within captured batch capacities | Model/default configuration, otherwise core default |
| `--kv-cache-limit concurrency\|context\|memory` | Bound shared KV history by prepared context times selected concurrency, one prepared context, or available memory | `memory` |
| `--memory-limit LIMIT` | Per-GPU occupied size (`30G`), free-memory reserve (`-30G`, including `-0G`), or fraction of total memory (`0.8`) | `[memory] reserve`, otherwise core serving reserve |
| `--pool-vram-memory LIMIT` | Per-GPU ceiling for runtime-sized `Capacity::DEVICE_POOL` allocations on cores declaring async transfer pools: nonnegative size (`0`, `12G`), free-memory reserve (`-8G`), or fraction of total GPU memory (`0.25`); ignored on cores without `DEVICE_POOL` allocations | `[memory] pool_vram`, otherwise available VRAM above minimum KV reserve |
| `--pool-ram-memory LIMIT` | Per-rank ceiling for runtime-sized pinned `AsyncTransfer` host pools on cores declaring `Execution.async_transfers`: nonnegative size (`0`, `32G`), free-memory reserve (`-16G`), or fraction of total host RAM (`0.5`); ignored on cores without async transfer channels | `[memory] pool_ram`, otherwise available host RAM |
| `--mtp-draft-tokens N` | Reduce the maximum draft count; zero selects ordinary execution without draft generation, absorption, or draft-state maintenance | Core default |
| `--mtp-adaptive-verification` / `--no-mtp-adaptive-verification` | Adaptive or fixed selection among captured widths | Core default |
| `--mtp-adaptive-verification-alpha ALPHA` | Positive finite exponent on completed prefix-survival scheduling scores; below 1 favors longer verification prefixes | `1.0` |
Expand Down
3 changes: 2 additions & 1 deletion docs/core-format-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ not substitutes for identifiers.
| --- | --- |
| `CoreBody` | Format version, core identity, publisher identity, shared frontend contract and payload descriptors, deployment IDs and commitments to their serialized bodies. |
| `DeploymentBody` | Deployment ID, target architecture, TP topology, prepared contract and capacities, rank IDs and commitments to their serialized bodies. |
| `RankBody` | Rank ID, context and address reservations, allocations, initializers, modules, functions, graph catalog, events, peer/transport bindings, referenced payload descriptors, and optional prepared-weight catalog. |
| `RankBody` | Rank ID, context and address reservations, allocations, initializers, modules, functions, graph catalog, events, peer/transport bindings, referenced payload descriptors, optional prepared-weight catalog, and optional `external_extents` tables. |
| `PayloadDescriptor` | Content ID equal to SHA-256 of exact stored bytes and byte length. Conflicting lengths for one ID are rejected. |
| `PayloadSlice` | Payload ID, byte offset within the payload tensor, and byte length. |
| `PayloadUse` | One `PayloadSlice` and its use role: weights, tuned weights, initial state, kernels, graphs, or frontend. |
Expand All @@ -220,6 +220,7 @@ not substitutes for identifiers.
| `Module` / `Function` | Cubin resource reference; module reference, symbol, parameter layout and launch attributes. |
| `Graph` | Graph name, instantiation flags, compressed graph resource reference, node and edge counts, and function dependencies. Graph bytes encode nodes, edges, parameters, and dependencies. The rank's `flare.runtime.Execution` record carries each graph's operation kind, capacities, and input bindings. |
| `PreparedWeightView` | Semantic tensor name, stable group, dtype, shape, strides, allocation/view binding, source tensor identities and logical ranges, concatenation order, padding/fills, typed packing parameters and locality tile, and quantization statistic domain. |
| `ExternalExtentTable` | Channel name matching an `Execution.async_transfers` entry, one `Weights`-role `PayloadUse` directory, and ordered `Weights`-role `PayloadUse` segment slices entering the rank's authenticated payload set. Each directory entry is 24 little-endian bytes (`segment_index: u32`, `reserved: u32` which must be zero, `offset: u64`, `length: u64`), validated at export and load for channel direct-I/O alignment and segment bounds. |

Payload descriptors are authenticated wherever consumed, with equality enforced
across shared and rank bodies. Each body is signed over its exact serialized
Expand Down
24 changes: 24 additions & 0 deletions docs/runtime-core-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,30 @@ green context), virtual-address reservations, and the primary context.

Before CUDA initialization or serving worker threads, Flare restricts
`CUDA_VISIBLE_DEVICES` to `--gpus`, resolving indices within an inherited mask.

When a core declares `Capacity::DEVICE_POOL` allocations and
`Execution.async_transfers` channels, `allocate_caches` first reserves
`pinned_bytes.div_ceil(512) + 256 MiB` of VRAM per rank for `cuMemHostRegister_v2`
GPU MMU page tables and worker streams (covering each channel's planned pinned
`HOST_POOL` and bounded internal bounce pool, which is disabled when channel
alignment exceeds 32 MiB), then sizes and maps each `DEVICE_POOL` at its fixed
reserved CUDA virtual address before computing KV page capacity (leaving space
for execution state rows and the minimum KV cache requirement, bounded by
`--pool-vram-memory` / `[memory] pool_vram`). Across tensor-parallel ranks,
`DEVICE_POOL` physical byte capacity is agreed as the minimum across ranks, and
`Execution.buffers` views backed by that allocation are rewritten to
`floor(agreed_bytes / row_bytes)` leading rows (truncating any partial trailing
row). `NativeResources::prepare_async_transfers` authenticates and opens the
4 KiB-aligned `RankBody.external_extents` payload segments directly (`O_DIRECT`
on Linux), allocates each channel's runtime-sized pinned `HOST_POOL` (clamped to
the planned per-rank host ceiling from `allocate_caches`, with an internal
pinned bounce pool when enabled), writes immutable startup geometry into the
mapped-host `ControlHeader`, and starts the channel workers before executing
`Execution.tuning_graphs`. Shutdown stops and drains all async transfer
channels after compute streams drain and before unmapping device or mapped-host
storage; unconfirmed drain transitions the channel to `FailedDrain` and retains
pinned memory and CUDA handles until process exit. Cores without
`Execution.async_transfers` channels bypass this path completely.
When omitted, the list contains the first N visible GPUs for the core's N
local ranks, or one GPU per host for a multi-host core. Core loading finishes
its progress threads before setting visibility. Hub revision detection queries
Expand Down
87 changes: 86 additions & 1 deletion flare-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use flare_helios::{
KvCompression, PoolOptions, PrefixCacheOffload, parse_drain_on_shutdown, parse_max_age,
parse_pool_address, parse_size,
},
runtime_core::{KvCacheLimit, LoadOptions, MemoryLimit},
runtime_core::{KvCacheLimit, LoadOptions, MemoryLimit, PoolMemoryLimit},
};

/// The serving option that routes every peer over subnets every rank holds.
Expand Down Expand Up @@ -942,6 +942,26 @@ pub struct ServingOptions {
)]
pub memory_limit: Option<MemoryLimit>,

/// Per-GPU byte pool budget for runtime-sized device pools: size (12G), zero (0),
/// free reserve (-8G), or fraction of GPU memory (0.2).
#[arg(
long,
allow_hyphen_values = true,
value_name = "LIMIT",
help_heading = "Serving options"
)]
pub pool_vram_memory: Option<PoolMemoryLimit>,

/// Per-host pinned RAM pool budget for async extent transfers: size (32G), zero (0),
/// free reserve (-16G), or fraction of system RAM (0.5).
#[arg(
long,
allow_hyphen_values = true,
value_name = "LIMIT",
help_heading = "Serving options"
)]
pub pool_ram_memory: Option<PoolMemoryLimit>,

/// Route RoCE rails and fabric transfers only over subnets every rank holds, as on a switch
/// alone, leaving direct cables between ranks unused.
#[arg(long, help_heading = "Multi-host options")]
Expand Down Expand Up @@ -1150,6 +1170,12 @@ impl ServingOptions {
if let Some(limit) = self.memory_limit {
options.push(format!("--memory-limit={limit}"));
}
if let Some(limit) = self.pool_vram_memory {
options.push(format!("--pool-vram-memory={limit}"));
}
if let Some(limit) = self.pool_ram_memory {
options.push(format!("--pool-ram-memory={limit}"));
}
match shape {
Shape::Mesh => {}
Shape::Ring => options.push("--roce-ring".into()),
Expand Down Expand Up @@ -1267,6 +1293,8 @@ impl ServingOptions {
LoadOptions {
kv_cache_limit: self.kv_cache_limit,
memory_limit: self.memory_limit,
pool_vram_limit: self.pool_vram_memory,
pool_ram_limit: self.pool_ram_memory,
embedding_table_storage: self.embedding_table_storage,
embedding_table_cache_bytes: self.embedding_table_cache_size,
embedding_table_resident_scales: if self.embedding_table_resident_scales {
Expand Down Expand Up @@ -2418,6 +2446,63 @@ mod tests {
);
}

#[test]
fn pool_memory_limits_accept_zero_sizes_reserves_fractions_and_reach_every_rank() {
for (vram, ram) in [
("12G", "0"),
("0", "32G"),
("-8G", "0.5"),
("0.25", "-16G"),
("0G", "0G"),
] {
let args = run(&[
"flare",
"run",
"model.safetensors",
"--pool-vram-memory",
vram,
"--pool-ram-memory",
ram,
]);
assert_eq!(
args.load_options().pool_vram_limit,
Some(vram.parse().unwrap())
);
assert_eq!(
args.load_options().pool_ram_limit,
Some(ram.parse().unwrap())
);
let forwarded = args.rank_options();
let mut peer = vec!["flare", "run", "model.safetensors"];
peer.extend(forwarded.iter().map(String::as_str));
let peer = run(&peer).load_options();
assert_eq!(peer.pool_vram_limit, args.load_options().pool_vram_limit);
assert_eq!(peer.pool_ram_limit, args.load_options().pool_ram_limit);
}
for bad in ["-0.5", "1.5", "NaN", "1e-1"] {
assert!(
Cli::try_parse_from([
"flare",
"run",
"model.safetensors",
"--pool-vram-memory",
bad
])
.is_err()
);
assert!(
Cli::try_parse_from([
"flare",
"run",
"model.safetensors",
"--pool-ram-memory",
bad
])
.is_err()
);
}
}

#[test]
fn debian_man_page_documents_every_visible_subcommand() {
use clap::CommandFactory;
Expand Down
20 changes: 19 additions & 1 deletion flare-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::path::PathBuf;
use clap::{ArgMatches, parser::ValueSource};
use flare_helios::{
offload::{parse_drain_on_shutdown, parse_max_age},
runtime_core::MemoryLimit,
runtime_core::{MemoryLimit, PoolMemoryLimit},
};

use crate::cli;
Expand Down Expand Up @@ -78,6 +78,24 @@ impl Configuration {
serving.memory_limit = size(self.memory.reserve.as_deref(), "memory.reserve")?
.map(MemoryLimit::Reserve);
}
if serving.pool_vram_memory.is_none() {
serving.pool_vram_memory = nonempty(self.memory.pool_vram.as_deref())
.map(|value| {
value
.parse::<PoolMemoryLimit>()
.map_err(|error| format!("memory.pool_vram: {error}"))
})
.transpose()?;
}
if serving.pool_ram_memory.is_none() {
serving.pool_ram_memory = nonempty(self.memory.pool_ram.as_deref())
.map(|value| {
value
.parse::<PoolMemoryLimit>()
.map_err(|error| format!("memory.pool_ram: {error}"))
})
.transpose()?;
}
if serving.prefix_cache_memory.is_none() {
serving.prefix_cache_memory = size(
nonempty(self.prefix_cache.memory.as_deref()),
Expand Down
5 changes: 4 additions & 1 deletion flare-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,10 @@ fn serve(
peers,
)
} {
Ok(server) => server,
Ok(server) => {
server.attach_async_transfers(owner.async_transfer_handles());
server
}
Err(error) => {
if !error.drained {
std::mem::forget(transport);
Expand Down
17 changes: 15 additions & 2 deletions flare/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Typed host configuration independent of frontend argument parsing.
use flare_helios::offload::{
KvCompression, parse_drain_on_shutdown, parse_max_age, parse_size,
use flare_helios::{
offload::{KvCompression, parse_drain_on_shutdown, parse_max_age, parse_size},
runtime_core::PoolMemoryLimit,
};
use serde::Deserialize;
use std::{
Expand Down Expand Up @@ -46,6 +47,8 @@ pub struct Model {
#[serde(default)]
pub struct Memory {
pub reserve: Option<String>,
pub pool_vram: Option<String>,
pub pool_ram: Option<String>,
}

#[derive(Default, Deserialize)]
Expand Down Expand Up @@ -86,6 +89,16 @@ impl Configuration {
return Err("server.scheduler_checkpoint_extra_work_fraction must be finite and between zero and one".into());
}
size(configuration.memory.reserve.as_deref(), "memory.reserve")?;
if let Some(value) = nonempty(configuration.memory.pool_vram.as_deref()) {
value
.parse::<PoolMemoryLimit>()
.map_err(|error| format!("memory.pool_vram: {error}"))?;
}
if let Some(value) = nonempty(configuration.memory.pool_ram.as_deref()) {
value
.parse::<PoolMemoryLimit>()
.map_err(|error| format!("memory.pool_ram: {error}"))?;
}
size(
nonempty(configuration.prefix_cache.memory.as_deref()),
"prefix_cache.memory",
Expand Down
18 changes: 17 additions & 1 deletion flare/src/runtime_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use flare_helios::{
engram::Storage,
offload::{parse_drain_on_shutdown, parse_max_age, parse_size},
runtime_core::{KvCacheLimit, LoadOptions, MemoryLimit},
runtime_core::{KvCacheLimit, LoadOptions, MemoryLimit, PoolMemoryLimit},
};
use serde::{Deserialize, Serialize};
use std::{
Expand All @@ -15,6 +15,8 @@ use std::{
pub struct RuntimeSettings {
pub gpu: i32,
pub memory_limit: String,
pub pool_vram_memory: String,
pub pool_ram_memory: String,
pub kv_cache_limit: String,
pub host: String,
pub port: u16,
Expand All @@ -36,6 +38,8 @@ impl Default for RuntimeSettings {
Self {
gpu: 0,
memory_limit: String::new(),
pool_vram_memory: String::new(),
pool_ram_memory: String::new(),
kv_cache_limit: "context".into(),
host: "127.0.0.1".into(),
port: 8000,
Expand Down Expand Up @@ -84,6 +88,8 @@ impl RuntimeSettings {
self.bind()?;
for (name, value) in [
("memory limit", &self.memory_limit),
("VRAM pool memory", &self.pool_vram_memory),
("RAM pool memory", &self.pool_ram_memory),
("KV limit", &self.kv_cache_limit),
("prefix memory", &self.prefix_cache_memory),
("prefix disk limit", &self.prefix_cache_disk_limit),
Expand All @@ -105,6 +111,12 @@ impl RuntimeSettings {
if !self.memory_limit.trim().is_empty() {
base.memory_limit = Some(self.memory_limit.parse::<MemoryLimit>()?);
}
if !self.pool_vram_memory.trim().is_empty() {
base.pool_vram_limit = Some(self.pool_vram_memory.parse::<PoolMemoryLimit>()?);
}
if !self.pool_ram_memory.trim().is_empty() {
base.pool_ram_limit = Some(self.pool_ram_memory.parse::<PoolMemoryLimit>()?);
}
base.kv_cache_limit = self.kv_cache_limit.trim().parse::<KvCacheLimit>()?;
if let Some(n) = self.max_concurrency {
base.max_concurrency = Some(n);
Expand Down Expand Up @@ -166,6 +178,8 @@ pub(crate) struct RuntimeIdentity {
verify_weights: bool,
kv_cache_limit: KvCacheLimit,
memory_limit: Option<MemoryLimit>,
pool_vram_limit: Option<PoolMemoryLimit>,
pool_ram_limit: Option<PoolMemoryLimit>,
max_concurrency: Option<usize>,
mtp_draft_tokens: Option<usize>,
adaptive_verification: Option<bool>,
Expand All @@ -181,6 +195,8 @@ impl RuntimeIdentity {
verify_weights: runtime.verify_weights,
kv_cache_limit: options.kv_cache_limit,
memory_limit: options.memory_limit,
pool_vram_limit: options.pool_vram_limit,
pool_ram_limit: options.pool_ram_limit,
max_concurrency: options.max_concurrency,
mtp_draft_tokens: options.mtp_draft_tokens,
adaptive_verification: options.adaptive_verification,
Expand Down
Loading
Loading