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
107 changes: 48 additions & 59 deletions docs/orbit.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ processes to hosts and authenticates control and file-transfer requests.

| Command | Where | Effect |
| --- | --- | --- |
| `flare agent install [--join-code CODE] [--accept-first] [--listen ADDR]` | Node | Installs the executable copy and user unit, restarts the service, requests linger, and prints pairing details |
| `flare agent install [--join-code CODE] [--accept-first] [--listen ADDR] [--core-cache PATH]` | Node | Installs the executable copy and user unit, restarts the service, requests linger, and prints pairing details |
| `flare agent pair HOST... [--code CODE]` | Head or controller | Pairs the shared agent identities without a cluster definition |
| `flare agent reset` | Node | Removes authorized controllers; the node becomes unpaired |
| `flare agent --listen ADDR` | Node | Runs the service (the unit's command) |
| `flare agent [--listen ADDR] [--core-cache PATH]` | Node | Runs the service (the unit's command) |
| `flare orbit pair HOST... [--code CODE]` | Controller | Pairs and records nodes |
| `flare orbit controllers add NAME PUBLIC_KEY` / `remove KEY` | Controller | Writes and distributes the next controller-set revision |
| `flare orbit run [CORE] [--cluster NAME \| --nodes NODE,...] [--name GROUP] [--persistent] [--gpus N,...] [--dry-run] [--detach] ...` | Controller | Places a group on the candidate nodes' GPUs, starts it and attaches; `--persistent` saves its named definition; `--dry-run` prints the placement only |
Expand Down Expand Up @@ -465,80 +465,69 @@ selected rank order.

## Core caching

An agent stores the files it receives through PUT and TRANSFER under
`~/.cache/flare` in its account:
An agent stores uploaded executables and publisher profiles under `~/.cache/flare`
and stores verified model cores in the host's managed Flare model cache
(`--core-cache`, then `[paths].core_cache`, then `~/.cache/flare/cores`):

| Location | Contents |
| --- | --- |
| `cores/<export>-<primary-size>/` | Complete core for rank zero or single-host serving |
| `cores/<export>-<primary-size>-rank<R>/` | Files and ranges of a peer rank staged by `orbit push` |
| `blobs/<sha256>.safetensors` | Immutable payloads shared by core directories through hardlinks |
| `bin/flare-<digest-prefix>` | Uploaded executable overrides |
| `publishers/` | Public publisher profiles passed by controllers |

An agent starts every rank with `--core-cache` set to that directory, which
makes it the root of the rank's Flare model cache. A peer rank that receives
its data during serving bootstrap publishes it as a model-cache entry,
`models/<model-key>/<entry-id>/` with the primary named `model.safetensors`,
writes a `.flare-verified.json` marker there after verifying stored data, and
resolves that entry again on a later launch of the same export and rank. The
serving receiver does not read the agent's `cores/<export>-<primary-size>-rank<R>/`
directory. A manually started peer uses `--core-cache`, then `paths.core_cache`,
then `~/.cache/flare/cores` as its model-cache root, so it shares entries with
an agent-started peer only when given the agent's directory.
| `<core-cache>/models/<model-key>/<entry-id>/` | Published immutable complete cores and per-rank slices (`model.safetensors` plus companions) |
| `<core-cache>/sources/` | Lookup selectors shared between Orbit (`orbit:<dir>`, `<export>-complete`) and serving bootstrap (`<export>-rank<R>`) |
| `<core-cache>/staging/orbit/` | In-flight PUT and TRANSFER files prior to verification and publication |
| `~/.cache/flare/bin/flare-<digest-prefix>` | Uploaded executable overrides |
| `~/.cache/flare/publishers/` | Public publisher profiles passed by controllers |

An agent starts every rank with `--core-cache` set to that managed model-cache
root. Both `orbit push` and serving bootstrap publish verified rank slices into
`<core-cache>` under the shared `<export>-rank<R>` source reference with a
`.flare-verified.json` marker, so a peer rank started after `orbit push` or a
manual `flare run` reuses the cached entry without re-transferring payloads.

A packed core is one `.safetensors` file. A directory core has a primary and
companion files: payload-format companions have readable relative paths such as
`weights/layer-000.safetensors`, and legacy companions are named by their
SHA-256 beside the primary. No size threshold splits payloads. Peers receive
only the files and ranges their rank needs. An agent transfers a
digest-named companion whole, checks it against its filename hash, stores it
under `blobs/`, and hardlinks it into the core directory, so another core with
the same file reuses those bytes. Every other file receives its selected
ranges into a sparse file. Sparse logical lengths can greatly exceed allocated
disk space; use `du` to inspect allocation.
only the files and ranges their rank needs into sparse files; sparse logical
lengths can greatly exceed allocated disk space, so use `du` to inspect
allocation.

The source of `NODE:PATH` is read in place. A source outside the agent cache is
not copied merely to launch on that node. A repository core is acquired into the
downloading node's Flare model cache and read from that entry, while transfers
to other hosts populate each agent's own cache.
Keep source primaries, payloads, and symlink targets available while peers fetch
and ranks serve.

An agent verifies data fetched by TRANSFER before writing a `.verified` marker
in that `cores/` directory. New writes
invalidate the marker; a repeated transfer requiring no bytes can reuse it.
Verification failure removes the core directory. Data sent directly by an
authorized controller is not given that marker by PUT. `--verify-weights` asks
each serving rank to digest its stored data during loading as well.

Transfer sessions and running groups pin cache entries. Native receivers hold
file locks through serving, preventing agent eviction or concurrent replacement
of active rank cores. Receiving files can
evict unpinned executable overrides or core directories, but keeps reusable
blobs. Group-history pruning and `orbit rm` remove neither cores nor blobs.
The agent has no blob garbage-collection command; core-directory eviction
alone may reclaim little space when hardlinks still exist in the blob store.
downloading node's managed model cache and read from that entry, while transfers
to other hosts populate each agent's managed model cache. Keep source primaries,
payloads, and symlink targets available while peers fetch and ranks serve.

An agent verifies staged core data during TRANSFER—including controller-uploaded
cores on rank zero—before committing the entry into `<core-cache>` and writing
its `.verified` and `.flare-verified.json` markers. Verification failure removes
the staged directory without publishing an entry. `--verify-weights` asks each
serving rank to digest its stored data during loading as well.

Running groups and active controller sessions hold `flock` leases on published
model-cache entries. Receiving a core never sweeps or evicts published entries
inside `<core-cache>/models/`; abandoned unleased directories under
`<core-cache>/staging/orbit/` are reclaimed on agent startup, after subsequent
core transfers, and by `flare models gc`. Use `flare models remove` and
`flare models gc` to reclaim unleased published entries and unreachable blobs.
Receiving an executable override evicts only unpinned files in
`~/.cache/flare/bin/`. Flat rank directories left directly under
`<core-cache>/` (or `~/.cache/flare/cores/`) by older agents are not migrated
automatically and can be removed manually once unused.

## Prestaging

`flare orbit push CORE --to NODE,... [--roce-ring | --roce-chain]` places a core on nodes ahead of
any launch. It starts no ranks and sends no executable. With one node per
multi-host rank, the first node receives the complete core and each peer
receives its rank's data, in the
listed order. With any other number of nodes, each receives the complete core.
Single-host cores are always staged complete. A node that holds the core
outside its cache is skipped. Node-to-node fetches are verified; a direct upload
from the controller follows PUT's verification rules. `flare orbit cores` lists
every node's cache directories with their file counts, bytes on disk and
verification state. A launch whose rank zero runs on a node holding the staged
complete core reuses it. Peer ranks receive their data again through serving
bootstrap unless their model cache already holds the entry, because the serving
receiver does not read a per-rank directory staged by `orbit push`; placement
still prefers a node whose STATUS lists that directory as verified. An explicit
executable override may still need uploading. Pre-staged core directories are
unpinned
after transfer and can be evicted when another core arrives.
receives its rank's data, in the listed order. With any other number of nodes,
each receives the complete core. Single-host cores are always staged complete.
A node that holds the core outside its cache is skipped. Both rank zero and
peer nodes verify staged data and publish entries into their managed model cache
with `.verified` and `.flare-verified.json` markers. `flare orbit cores` lists
every node's published and staged entries with their file counts, bytes on disk,
and verification state. Subsequent launches reuse both the verified complete core
on rank zero and the verified per-rank entries on peers without re-transferring
payloads. An explicit executable override may still need uploading.

With `--roce-ring`, list exactly one node per multi-host rank in physical ring
order. Core bytes follow the fabric TCP paths described below, without
Expand Down
4 changes: 2 additions & 2 deletions docs/prefix-cache-offload.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ holds every rank's bytes in one process. Each disk peer uses its host's intake.
Automatic registered intake is additional to the warm budget whenever warm
memory or local disk is enabled. It needs no setting: its slot count is
`2 × max_active × row_slots + 2 × WINDOW_PAGES`, where `WINDOW_PAGES = 64`,
except for disk-only offload (`memory = 0` with local disk enabled) on an
except for local tiers (`memory > 0` or local disk enabled) on an
integrated-memory device (`CU_DEVICE_ATTRIBUTE_INTEGRATED`), where intake
targets two streaming windows and two continuation rows,
`2 × (WINDOW_PAGES + row_slots)` (`intake_slots(layout, 1)`).
The warm checkpoint budget rounds down to whole slots. If host headroom cannot
hold the full intake, it shrinks toward two complete windows,
`2 × (WINDOW_PAGES + row_slots)`, and one warning reports the memory needed for
full intake; on an integrated-memory disk-only host, the target already equals
full intake; on an integrated-memory host, the target already equals
that two-window floor, so host headroom neither shrinks it nor emits a warning.
Concurrent unique-prefix disk restores and concurrent outbound disk stores on an
integrated-memory disk-only host share and serialize window allocations through
Expand Down
13 changes: 9 additions & 4 deletions flare-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ pub struct AgentArgs {
/// Address and port to listen on.
#[arg(long, value_name = "IP:PORT", default_value = "0.0.0.0:29900")]
pub listen: String,

/// Prepared-model cache root shared by staged and served cores.
#[arg(long, alias = "model-cache", alias = "package-cache", value_name = "PATH")]
pub core_cache: Option<PathBuf>,
}

#[derive(Debug, Subcommand)]
Expand All @@ -399,6 +403,9 @@ pub enum AgentCommand {
/// Address and port the installed agent listens on.
#[arg(long, value_name = "IP:PORT", default_value = "0.0.0.0:29900")]
listen: String,
/// Prepared-model cache root passed to the installed agent service.
#[arg(long, alias = "model-cache", alias = "package-cache", value_name = "PATH")]
core_cache: Option<PathBuf>,
},
/// Remove this host's authorized controllers and pairing codes; keep its key and cache.
Reset,
Expand Down Expand Up @@ -655,11 +662,9 @@ pub struct OrbitRun {
}

impl OrbitRun {
/// Serving options every rank loads with.
/// Serving options every rank loads with. RoCE shape travels in Grant's dedicated fields.
pub fn rank_options(&self, matches: &clap::ArgMatches) -> Vec<String> {
let mut options = self
.serving
.rank_options(Shape::from_flags(self.roce_ring, self.roce_chain));
let mut options = self.serving.rank_options(Shape::Mesh);
// Explicit defaults must override saved values, while omitted defaults must not.
if self.serving.kv_cache_limit == KvCacheLimit::Memory
&& matches.value_source("kv_cache_limit")
Expand Down
116 changes: 116 additions & 0 deletions flare-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ impl Configuration {
_ => {}
}
}
cli::Command::Agent(args) => match &mut args.command {
None => {
args.core_cache.get_or_insert(cache);
}
Some(cli::AgentCommand::Install { core_cache, .. }) => {
if core_cache.is_none() {
*core_cache = args.core_cache.clone().or_else(|| self.core_cache(home));
}
}
_ => {}
},
cli::Command::Orbit(args) => match &mut args.command {
cli::OrbitCommand::Run(run) => {
run.serving.hub.core_cache.get_or_insert(cache);
Expand Down Expand Up @@ -755,4 +766,109 @@ namespace = "publisher"
assert!(Configuration::parse(&format!("[prefix_cache]\nmax_age='{invalid}'")).is_err());
}
}

#[test]
fn agent_core_cache_uses_config_and_flag_override_and_orbit_omits_roce_from_serving() {
let home = Path::new("/home/test-user");
let config = Configuration::parse("[paths]\ncore_cache = '/data/flare-cores'\n").unwrap();

let matches = cli::Cli::command()
.try_get_matches_from(["flare", "agent"])
.unwrap();
let mut parsed = cli::Cli::from_arg_matches(&matches).unwrap();
config.apply(&mut parsed, &matches, home).unwrap();
let cli::Command::Agent(agent) = parsed.command else {
panic!("expected agent command");
};
assert_eq!(agent.core_cache.as_deref(), Some(Path::new("/data/flare-cores")));

let matches = cli::Cli::command()
.try_get_matches_from(["flare", "agent", "--core-cache", "/override/cores"])
.unwrap();
let mut parsed = cli::Cli::from_arg_matches(&matches).unwrap();
config.apply(&mut parsed, &matches, home).unwrap();
let cli::Command::Agent(agent) = parsed.command else {
panic!("expected agent command");
};
assert_eq!(agent.core_cache.as_deref(), Some(Path::new("/override/cores")));

let matches = cli::Cli::command()
.try_get_matches_from([
"flare",
"orbit",
"run",
"model.safetensors",
"--roce-ring",
"--max-concurrency",
"8",
])
.unwrap();
let parsed = cli::Cli::from_arg_matches(&matches).unwrap();
let cli::Command::Orbit(orbit) = parsed.command else {
panic!("expected orbit command");
};
let cli::OrbitCommand::Run(run) = orbit.command else {
panic!("expected orbit run");
};
let run_matches = matches
.subcommand_matches("orbit")
.unwrap()
.subcommand_matches("run")
.unwrap();
let options = run.rank_options(run_matches);
assert!(run.roce_ring);
assert!(!options.iter().any(|arg| arg == "--roce-ring" || arg == "--roce-chain"));
assert!(options.iter().any(|arg| arg == "--max-concurrency"));
}

#[test]
fn agent_install_propagates_config_and_top_level_core_cache_with_subcommand_precedence() {
let home = Path::new("/home/test-user");
let configured =
Configuration::parse("[paths]\ncore_cache = '/data/flare-cores'\n").unwrap();
let empty = Configuration::default();

let parse_install = |args: &[&str], cfg: &Configuration| -> Option<PathBuf> {
let matches = cli::Cli::command().try_get_matches_from(args).unwrap();
let mut parsed = cli::Cli::from_arg_matches(&matches).unwrap();
cfg.apply(&mut parsed, &matches, home).unwrap();
let cli::Command::Agent(agent) = parsed.command else {
panic!("expected agent command");
};
let Some(cli::AgentCommand::Install { core_cache, .. }) = agent.command else {
panic!("expected agent install");
};
core_cache
};

assert_eq!(parse_install(&["flare", "agent", "install"], &empty), None);
assert_eq!(
parse_install(&["flare", "agent", "install"], &configured).as_deref(),
Some(Path::new("/data/flare-cores"))
);
assert_eq!(
parse_install(
&["flare", "agent", "--core-cache", "/top/cores", "install"],
&configured
)
.as_deref(),
Some(Path::new("/top/cores"))
);
assert_eq!(
parse_install(
&[
"flare",
"agent",
"--core-cache",
"/top/cores",
"install",
"--core-cache",
"/sub/cores"
],
&configured
)
.as_deref(),
Some(Path::new("/sub/cores"))
);
}
}
Loading
Loading