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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ for chunk in client.chat.completions.create(
4. llama.cpp's automatic fitting (`-fit`, on by default) places layers across all those devices according to their free memory. If loading fails, llmesh retries with a smaller context.
5. When someone joins or leaves, the head restarts `llama-server` with the new split. If the head disappears, the next-oldest node takes over, typically within 15 to 20 seconds.

All nodes use the same pinned llama.cpp release (currently `b12017`; override it with `LLMESH_LLAMA_TAG`) because the RPC protocol changes between versions. A node on a different release is left out of the split and flagged in the dashboard.
All nodes use the same pinned llama.cpp release (currently `b12017`; override it with `LLMESH_LLAMA_TAG`) because the RPC protocol changes between versions. A node on a different release is left out of the split and flagged in the dashboard. Recent releases ship the RPC server binary as `ggml-rpc-server` (older ones as `rpc-server`); llmesh accepts either name, also under `--llama-dir`.

## Performance: what to expect

Expand Down
37 changes: 31 additions & 6 deletions src/llama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,15 @@ fn find_bin(dir: &Path, name: &str) -> Option<PathBuf> {
None
}

/// Names the RPC server binary has had across llama.cpp releases (`ggml-rpc-server` since late 2026).
const RPC_SERVER_NAMES: [&str; 2] = ["ggml-rpc-server", "rpc-server"];

fn find_rpc_server(dir: &Path) -> Option<PathBuf> {
RPC_SERVER_NAMES.iter().find_map(|n| find_bin(dir, n))
}

fn find_install(dir: &Path) -> Option<(PathBuf, PathBuf)> {
let rpc = find_bin(dir, "rpc-server")?;
let rpc = find_rpc_server(dir)?;
let srv = find_bin(dir, "llama-server")?;
Some((rpc, srv))
}
Expand Down Expand Up @@ -232,15 +239,26 @@ async fn run_capture(mut c: Command, timeout: Duration) -> Result<String> {
Ok(text)
}

/// `llama-server --version` prints `version: 12017 (abcdef)`; that's release tag `b12017`.
/// The release tag from `llama-server --version`, which prints either
/// `version: 12017 (abcdef)` (older) or `version: 0.8.0-dev (build 12017, commit abcdef)`.
pub fn parse_version_tag(out: &str) -> Option<String> {
let line = out.lines().find(|l| l.trim_start().starts_with("version:"))?;
let rest = line.split_once(':')?.1;
if let Some((_, after)) = rest.split_once("build ") {
let n: String = after.chars().take_while(|c| c.is_ascii_digit()).collect();
if let Ok(n) = n.parse::<u64>() {
return Some(format!("b{n}"));
}
}
rest.split_whitespace().next()?.parse::<u64>().ok().map(|n| format!("b{n}"))
}

async fn detect_tag(bin_dir: &Path, server: &Path) -> Option<String> {
let mut c = Command::new(server);
c.arg("--version");
set_lib_env(&mut c, bin_dir);
let out = run_capture(c, Duration::from_secs(20)).await.ok()?;
let line = out.lines().find(|l| l.trim_start().starts_with("version:"))?;
let n = line.split(':').nth(1)?.split_whitespace().next()?;
n.parse::<u64>().ok().map(|n| format!("b{n}"))
parse_version_tag(&out)
}

async fn probe(bin_dir: &Path, server: &Path, backend: Backend) -> Result<Vec<GpuDevice>> {
Expand Down Expand Up @@ -367,7 +385,7 @@ pub async fn setup(paths: &crate::config::Paths, opts: &LlamaOpts) -> Result<Ins
}

// A system install (e.g. Homebrew) of the pinned version is used as-is.
let system = match (on_path("rpc-server"), on_path("llama-server")) {
let system = match (RPC_SERVER_NAMES.iter().find_map(|n| on_path(n)), on_path("llama-server")) {
(Some(r), Some(s)) => Some((r, s)),
_ => None,
};
Expand Down Expand Up @@ -771,6 +789,13 @@ mod tests {
assert!(assets(t, "macos", "aarch64", Backend::Cuda).is_none());
}

#[test]
fn version_tags() {
assert_eq!(parse_version_tag("version: 0.8.0-dev (build 12017, commit 5047748f1)\nbuilt with GNU 11.4.0").as_deref(), Some("b12017"));
assert_eq!(parse_version_tag("version: 6000 (abc1234)\n").as_deref(), Some("b6000"));
assert_eq!(parse_version_tag("nothing useful"), None);
}

#[test]
fn device_parsing() {
let out = "ggml_cuda_init: found 1 CUDA devices:\nAvailable devices:\n CUDA0: NVIDIA GeForce RTX 3060 (12288 MiB, 11234 MiB free)\n Vulkan0: AMD Radeon (8192 MiB, 8000 MiB free)\n";
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ async fn run(cli: Cli) -> Result<()> {
None => start(paths, cli.start, false).await,
Some(Cmd::Start(a)) => start(paths, a, false).await,
Some(Cmd::Group(GroupCmd::Create { group_name: name, start: a })) => {
if let Some(m) = &a.model {
models::ModelRef::parse(m)?;
}
let key = paths.node_key()?;
let secret = GroupSecret::generate();
let mut cfg = GroupConfig::initial(a.model.as_deref().unwrap_or(DEFAULT_MODEL));
Expand Down Expand Up @@ -228,6 +231,9 @@ async fn start(paths: Paths, a: StartArgs, show_invite: bool) -> Result<()> {
let tag = g.secret().tag_hex();
paths.set_current_group(if g.is_lan() { None } else { Some(&tag) })?;
}
if let Some(b) = &a.backend {
llama::Backend::parse(b)?;
}
let group = paths.active_group()?;
let key = paths.node_key()?;
let opts = NodeOpts {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/fake_llama_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

args = sys.argv[1:]
if "--version" in args:
print("version: 12017 (fake)\nbuilt with fake for testing"); sys.exit(0)
print("version: 0.8.0-dev (build 12017, commit fake)\nbuilt with fake for testing"); sys.exit(0)
if "--list-devices" in args:
print("Available devices:\n (none)"); sys.exit(0)

Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/mock_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def release_tarball():
buf = io.BytesIO()
with tarfile.open(fileobj=buf, mode="w:gz") as t:
d = tarfile.TarInfo(f"llama-{TAG}"); d.type = tarfile.DIRTYPE; d.mode = 0o755; t.addfile(d)
for exe, script in (("rpc-server", "fake_rpc_server.py"), ("llama-server", "fake_llama_server.py")):
# llama.cpp releases since late 2026 ship the RPC server as `ggml-rpc-server` (older ones: `rpc-server`).
for exe, script in (("ggml-rpc-server", "fake_rpc_server.py"), ("llama-server", "fake_llama_server.py")):
body = f'#!/bin/sh\nexec "{sys.executable}" "{os.path.join(HERE, script)}" "$@"\n'.encode()
ti = tarfile.TarInfo(f"llama-{TAG}/{exe}"); ti.size = len(body); ti.mode = 0o755
t.addfile(ti, io.BytesIO(body))
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/run_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def chat(port, content="hi", **kw):

def main():
from openai import OpenAI
mock = subprocess.Popen([sys.executable, os.path.join(HERE, "mock_server.py"), str(MOCK_PORT)], stdout=open(os.path.join(WORK, "mock.log"), "w"), stderr=subprocess.STDOUT)
mock = subprocess.Popen([sys.executable, os.path.join(HERE, "mock_server.py"), str(MOCK_PORT)], stdout=open(os.path.join(WORK, "mock.log"), "w"), stderr=subprocess.STDOUT, start_new_session=True)
procs["mock"] = (mock, MOCK_PORT)
time.sleep(0.7)
log(f"work dir {WORK}")
Expand Down
Loading