feat(app): performance stages move the LLM between the normal and the game placement
- while the services run, game mode decides the stage (perf.rs): a game means the game stage at once (or pause with game.pauseInGame); its end brings the normal stage back after game.revertSeconds (default 30) - a change tells the voice worker the LLM switches (llm switching, with a notice), waits until the brain has written the answers in progress (llm_idle, at most 2 minutes), restarts the LLM in the stage and tells the worker it is ready or paused - the game stage runs at 16K context, one request at a time, half the engine's CPU threads and the game placement (reserve game.reserveGb, default 8, else 2 GiB, else 0 GiB, else pause), measured once at that context; every placement of a run counts other programs' memory as it was when the services started - the voice worker gates every LLM use: on switching new work waits (at most 180 s), the first spoken request that waits hears the notice once under its own id, on ready all go on, on paused nothing is answered - dashboard: "성능 단계: 게임 중 · 게임에 X GB" / 일시정지; game mode screen: game VRAM, revert wait, pause in game Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ use serde::Serialize;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use crate::install::{Ctx, Layout};
|
||||
use crate::perf::Stage;
|
||||
use crate::settings::Settings;
|
||||
|
||||
/// The one model v2 runs (M0: Qwen3.6-35B-A3B UD-Q4_K_XL; docs/v2/roadmap.md).
|
||||
@@ -49,12 +50,12 @@ pub fn parallel(settings: &Settings) -> u32 {
|
||||
/// `strata launch` for the services: the M0 kit's normal placement, models in `models/llm`, this
|
||||
/// computer only. No pictures yet (nothing in v2 sends one; reading them takes graphics memory).
|
||||
/// `--restart` replaces a server started with other choices; the same choices are reused.
|
||||
pub fn launch_args(layout: &Layout, settings: &Settings, sets: &[String]) -> Vec<String> {
|
||||
pub fn launch_args(layout: &Layout, settings: &Settings, conf: &Conf, sets: &[String]) -> Vec<String> {
|
||||
let models = layout.data.join("models").join("llm").to_string_lossy().into_owned();
|
||||
let mut a: Vec<String> = ["launch", "--family", FAMILY, "--model", MODEL, "--data-dir"].map(String::from).into();
|
||||
a.push(models);
|
||||
for (k, v) in [("--context", settings.llm.context.to_string()), ("--vision", "off".into()),
|
||||
("--parallel", parallel(settings).to_string()), ("--access", "local".into()),
|
||||
for (k, v) in [("--context", conf.context.to_string()), ("--vision", "off".into()),
|
||||
("--parallel", conf.parallel.to_string()), ("--access", "local".into()),
|
||||
("--port", settings.llm.port.to_string())] {
|
||||
a.push(k.into());
|
||||
a.push(v);
|
||||
@@ -67,6 +68,29 @@ pub fn launch_args(layout: &Layout, settings: &Settings, sets: &[String]) -> Vec
|
||||
a
|
||||
}
|
||||
|
||||
/// The context and requests at once of a stage: the settings' in the normal stage; in a game 16K
|
||||
/// (or less when the settings ask for less) and one request at a time.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Conf {
|
||||
pub context: u32,
|
||||
pub parallel: u32,
|
||||
}
|
||||
|
||||
pub fn conf(settings: &Settings, stage: Stage) -> Conf {
|
||||
match stage {
|
||||
Stage::Gaming => Conf { context: crate::placement::GAME_CONTEXT.min(settings.llm.context), parallel: 1 },
|
||||
_ => Conf { context: settings.llm.context, parallel: parallel(settings) },
|
||||
}
|
||||
}
|
||||
|
||||
/// The engine's CPU threads from its log ("... on 16 CPU threads ...").
|
||||
fn cpu_threads(log: &str) -> Option<u32> {
|
||||
log.lines().rev().find_map(|l| {
|
||||
let i = l.find(" CPU threads")?;
|
||||
l[..i].rsplit(' ').next()?.parse().ok()
|
||||
})
|
||||
}
|
||||
|
||||
/// The engine settings for an expert budget (`placement.rs`) and the M0 kit's prompt chunk.
|
||||
fn placement_sets(expert_gib: f64) -> Vec<String> {
|
||||
vec![format!("expert-vram={expert_gib}"), "prefill=2048".into()]
|
||||
@@ -228,6 +252,14 @@ pub struct Llm {
|
||||
stop_timeout: Duration,
|
||||
/// The graphics card's memory (none: Strata places the model itself).
|
||||
gpu: Option<GpuReader>,
|
||||
/// What other programs held when the services started (before the LLM and the STT worker):
|
||||
/// every later placement of this run counts from it, not from a card that then also holds the
|
||||
/// STT worker and a game.
|
||||
baseline: Mutex<Option<i64>>,
|
||||
/// The engine's CPU threads in the normal stage; a game gets half.
|
||||
threads: Mutex<Option<u32>>,
|
||||
/// The stage it runs in, and in a game the graphics memory the game gets.
|
||||
stage: Mutex<(Stage, Option<i64>)>,
|
||||
}
|
||||
|
||||
/// How long the model may take to answer after `strata launch` returned (it loads in about 15 s
|
||||
@@ -247,7 +279,14 @@ impl Llm {
|
||||
pub fn with_exe(layout: Layout, exe: std::path::PathBuf) -> Self {
|
||||
Self { layout, exe, status: Mutex::new(LlmStatus { state: LlmState::Off, managed: false, percent: None, note: None }),
|
||||
active: Mutex::new(None), cancel: Arc::new(AtomicBool::new(false)), port: Mutex::new(0),
|
||||
stop_timeout: Duration::from_secs(120), gpu: None }
|
||||
stop_timeout: Duration::from_secs(120), gpu: None, baseline: Mutex::new(None), threads: Mutex::new(None),
|
||||
stage: Mutex::new((Stage::Normal, None)) }
|
||||
}
|
||||
|
||||
/// `{stage, gameRoomMib}` for the dashboard.
|
||||
pub fn stage_view(&self) -> Value {
|
||||
let (stage, room) = *self.stage.lock().unwrap();
|
||||
json!({"stage": stage, "gameRoomMib": room})
|
||||
}
|
||||
|
||||
/// Place the model by the card's memory (`placement.rs`), read with `gpu`.
|
||||
@@ -272,19 +311,29 @@ impl Llm {
|
||||
/// counted as another program's memory (a stop that is not confirmed reads nothing: no
|
||||
/// experts). A measurement that fails is not kept: the model then starts without experts on
|
||||
/// the card.
|
||||
async fn placement(&self, settings: &Settings, ctx: &Ctx, base: &str) -> Result<Vec<String>, String> {
|
||||
async fn placement(&self, settings: &Settings, ctx: &Ctx, base: &str, stage: Stage) -> Result<Option<Vec<String>>, String> {
|
||||
let c = conf(settings, stage);
|
||||
let workers = |sets: &mut Vec<String>| if stage == Stage::Gaming {
|
||||
let half = self.threads.lock().unwrap().map(|n| n / 2)
|
||||
.unwrap_or_else(|| std::thread::available_parallelism().map(|n| n.get() as u32 / 4).unwrap_or(1));
|
||||
sets.push(format!("pool-workers={}", half.max(1)));
|
||||
};
|
||||
if self.gpu.is_none() {
|
||||
return Ok(vec![]);
|
||||
let mut sets = vec![];
|
||||
workers(&mut sets);
|
||||
return Ok(Some(sets));
|
||||
}
|
||||
// Whatever a server left from an earlier run does (answers, loads, stays silent), it holds
|
||||
// the card: stop it first and read the card only once the port is confirmed closed.
|
||||
if let Err(e) = self.stop_server_on(settings.llm.port).await {
|
||||
crate::warn_log!("llm", "Warning: a server left on the port did not stop ({e}); starting without experts on the card");
|
||||
return Ok(placement_sets(0.0));
|
||||
let mut sets = placement_sets(0.0);
|
||||
workers(&mut sets);
|
||||
return Ok(Some(sets));
|
||||
}
|
||||
let Some(card) = self.read_gpu().await else { return Ok(vec![]) };
|
||||
let (context, parallel) = (settings.llm.context, parallel(settings));
|
||||
let key = format!("{context}/{parallel}");
|
||||
let Some(card) = self.read_gpu().await else { return Ok(Some(vec![])) };
|
||||
let others = *self.baseline.lock().unwrap().get_or_insert(card.used_mib);
|
||||
let key = format!("{}/{}", c.context, c.parallel);
|
||||
let file = self.probe_file();
|
||||
let mut all: serde_json::Map<String, Value> = std::fs::read_to_string(&file).ok()
|
||||
.and_then(|t| serde_json::from_str(&t).ok()).unwrap_or_default();
|
||||
@@ -293,16 +342,18 @@ impl Llm {
|
||||
let probe = match known {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
crate::info_log!("llm", "measuring the model without experts once (context {context}, {parallel} at once)");
|
||||
self.launch(settings, ctx, base, &placement_sets(0.0)).await?;
|
||||
crate::info_log!("llm", "measuring the model without experts once (context {}, {} at once)", c.context, c.parallel);
|
||||
self.launch(settings, ctx, base, &c, &placement_sets(0.0)).await?;
|
||||
let warmed = warm_up(base).await;
|
||||
let after = self.read_gpu().await.filter(|g| g.id == card.id);
|
||||
let model_mib = after.map(|g| g.used_mib - card.used_mib).unwrap_or(0);
|
||||
if let Err(e) = warmed.and_then(|()| if model_mib > 0 { Ok(()) } else { Err("the card's memory could not be read".into()) }) {
|
||||
crate::warn_log!("llm", "Warning: the measurement failed ({e}); starting without experts on the card");
|
||||
return Ok(placement_sets(0.0));
|
||||
let mut sets = placement_sets(0.0);
|
||||
workers(&mut sets);
|
||||
return Ok(Some(sets));
|
||||
}
|
||||
let p = crate::placement::Probe { context, parallel, gpu: card.id.clone(), model_mib,
|
||||
let p = crate::placement::Probe { context: c.context, parallel: c.parallel, gpu: card.id.clone(), model_mib,
|
||||
staging_gib: crate::placement::staging_gib(&engine_log(&self.layout.strata_home())) };
|
||||
all.insert(key, json!(p));
|
||||
crate::datadir::write_atomic(&file, Value::Object(all).to_string().as_bytes())
|
||||
@@ -310,15 +361,28 @@ impl Llm {
|
||||
p
|
||||
}
|
||||
};
|
||||
let expert = crate::placement::normal(card.total_mib, card.used_mib, &probe, settings.game.other_room_mib());
|
||||
crate::info_log!("llm", "placement: experts {expert} GiB (card {} MiB, held by others {} MiB, model without experts {} MiB)",
|
||||
card.total_mib, card.used_mib, probe.model_mib);
|
||||
Ok(placement_sets(expert))
|
||||
let expert = match stage {
|
||||
Stage::Gaming => {
|
||||
let g = crate::placement::game(card.total_mib, others, &probe, settings.game.reserve_mib());
|
||||
if g.paused {
|
||||
crate::info_log!("llm", "placement: no room for a game beside the model; paused while the game runs");
|
||||
return Ok(None);
|
||||
}
|
||||
*self.stage.lock().unwrap() = (Stage::Gaming, Some(g.game_room_mib));
|
||||
g.expert_gib
|
||||
}
|
||||
_ => crate::placement::normal(card.total_mib, others, &probe, settings.game.other_room_mib()),
|
||||
};
|
||||
crate::info_log!("llm", "placement ({stage:?}): experts {expert} GiB (card {} MiB, held by others {others} MiB, model without experts {} MiB)",
|
||||
card.total_mib, probe.model_mib);
|
||||
let mut sets = placement_sets(expert);
|
||||
workers(&mut sets);
|
||||
Ok(Some(sets))
|
||||
}
|
||||
|
||||
/// `strata launch` with `sets`, then wait until the model answers.
|
||||
async fn launch(&self, settings: &Settings, ctx: &Ctx, base: &str, sets: &[String]) -> Result<String, String> {
|
||||
let args = launch_args(&self.layout, settings, sets);
|
||||
async fn launch(&self, settings: &Settings, ctx: &Ctx, base: &str, c: &Conf, sets: &[String]) -> Result<String, String> {
|
||||
let args = launch_args(&self.layout, settings, c, sets);
|
||||
let refs: Vec<&str> = args.iter().map(String::as_str).collect();
|
||||
ctx.run_in(&self.exe, &refs, Some(&self.layout.strata_home())).await?;
|
||||
wait_ready(base, READY_TIMEOUT, &self.cancel).await
|
||||
@@ -351,11 +415,47 @@ impl Llm {
|
||||
/// Start (or reuse) the LLM; returns its `/v1` address and model id.
|
||||
/// A cancel since the last `arm` (or before the first start) ends it before it runs anything.
|
||||
pub async fn start(&self, settings: &Settings) -> Result<(String, String), String> {
|
||||
// A new run: other programs' memory is read afresh.
|
||||
*self.baseline.lock().unwrap() = None;
|
||||
*self.stage.lock().unwrap() = (Stage::Normal, None);
|
||||
self.start_stage(settings, Stage::Normal).await.map(|r| r.expect("the normal stage never pauses"))
|
||||
}
|
||||
|
||||
/// Move the running LLM to `stage` (`perf.rs`): a restart with that stage's placement, or a stop
|
||||
/// when it pauses (also a game stage with no room for the game). Returns the stage it ended in.
|
||||
/// With `llm.url` nothing moves.
|
||||
pub async fn switch(&self, settings: &Settings, stage: Stage) -> Result<Stage, String> {
|
||||
if settings.llm.url.is_some() {
|
||||
return Ok(Stage::Normal);
|
||||
}
|
||||
if stage != Stage::Paused && self.start_stage(settings, stage).await?.is_some() {
|
||||
return Ok(stage);
|
||||
}
|
||||
*self.port.lock().unwrap() = settings.llm.port;
|
||||
self.stop().await?;
|
||||
*self.stage.lock().unwrap() = (Stage::Paused, None);
|
||||
self.set(LlmState::Off, Some("게임 중 일시정지".into()));
|
||||
Ok(Stage::Paused)
|
||||
}
|
||||
|
||||
async fn start_stage(&self, settings: &Settings, stage: Stage) -> Result<Option<(String, String)>, String> {
|
||||
let managed = settings.llm.url.is_none();
|
||||
*self.status.lock().unwrap() = LlmStatus { state: LlmState::Starting, managed, percent: None, note: None };
|
||||
let result = self.start_inner(settings).await;
|
||||
let result = self.start_inner(settings, stage).await;
|
||||
if stage == Stage::Normal && result.as_ref().is_ok_and(Option::is_some) && self.gpu.is_some() {
|
||||
if let Some(n) = cpu_threads(&engine_log(&self.layout.strata_home())) {
|
||||
*self.threads.lock().unwrap() = Some(n);
|
||||
}
|
||||
}
|
||||
if let Ok(Some(_)) = &result {
|
||||
let mut st = self.stage.lock().unwrap();
|
||||
if stage == Stage::Normal {
|
||||
*st = (Stage::Normal, None);
|
||||
}
|
||||
}
|
||||
match &result {
|
||||
Ok((base, model)) => {
|
||||
Ok(None) => {}
|
||||
Ok(Some((base, model))) => {
|
||||
crate::info_log!("llm", "ready: {base} model={model}");
|
||||
self.set(LlmState::Ready, None);
|
||||
}
|
||||
@@ -368,13 +468,14 @@ impl Llm {
|
||||
result
|
||||
}
|
||||
|
||||
async fn start_inner(&self, settings: &Settings) -> Result<(String, String), String> {
|
||||
/// None: the stage pauses (nothing started).
|
||||
async fn start_inner(&self, settings: &Settings, stage: Stage) -> Result<Option<(String, String)>, String> {
|
||||
if self.cancel.load(Ordering::SeqCst) {
|
||||
return Err("cancelled".into());
|
||||
}
|
||||
if let Some(url) = &settings.llm.url {
|
||||
let model = wait_ready(url, URL_TIMEOUT, &self.cancel).await?;
|
||||
return Ok((url.clone(), model));
|
||||
return Ok(Some((url.clone(), model)));
|
||||
}
|
||||
if !self.exe.exists() {
|
||||
return Err("Strata가 설치되어 있지 않습니다. 마법사의 모델 단계에서 설치해 주세요".into());
|
||||
@@ -383,13 +484,16 @@ impl Llm {
|
||||
*self.active.lock().unwrap() = Some(ctx.clone());
|
||||
*self.port.lock().unwrap() = settings.llm.port;
|
||||
let base = format!("http://127.0.0.1:{}/v1", settings.llm.port);
|
||||
let ready = match self.placement(settings, &ctx, &base).await {
|
||||
Ok(sets) => self.launch(settings, &ctx, &base, &sets).await,
|
||||
let c = conf(settings, stage);
|
||||
let ready = match self.placement(settings, &ctx, &base, stage).await {
|
||||
Ok(Some(sets)) => self.launch(settings, &ctx, &base, &c, &sets).await.map(Some),
|
||||
Ok(None) => Ok(None),
|
||||
Err(e) => Err(e),
|
||||
};
|
||||
*self.active.lock().unwrap() = None;
|
||||
match ready {
|
||||
Ok(model) => Ok((base, model)),
|
||||
Ok(Some(model)) => Ok(Some((base, model))),
|
||||
Ok(None) => Ok(None),
|
||||
// Nothing half-started stays on the graphics card; if it may have, say so.
|
||||
Err(e) => match self.stop_server().await {
|
||||
Ok(()) => Err(e),
|
||||
@@ -491,12 +595,12 @@ async fn wait_gone(base: &str, timeout: Duration) -> bool {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
use crate::datadir::temp_dir;
|
||||
use crate::settings::{parse_settings, ChatChannelSettings};
|
||||
|
||||
fn layout(tag: &str) -> Layout {
|
||||
pub(crate) fn layout(tag: &str) -> Layout {
|
||||
Layout { data: temp_dir(tag), src: std::path::PathBuf::from("src") }
|
||||
}
|
||||
|
||||
@@ -504,7 +608,7 @@ mod tests {
|
||||
fn the_launch_keeps_the_model_in_the_data_folder_and_follows_the_settings() {
|
||||
let l = layout("llm1");
|
||||
let s = parse_settings(&json!({"llm": {"context": 16384, "port": 8099}})).unwrap();
|
||||
let a = launch_args(&l, &s, &[]);
|
||||
let a = launch_args(&l, &s, &conf(&s, Stage::Normal), &[]);
|
||||
let after = |k: &str| a[a.iter().position(|x| x == k).unwrap() + 1].clone();
|
||||
assert!(Path::new(&after("--data-dir")).starts_with(&l.data));
|
||||
assert_eq!((after("--context"), after("--port"), after("--parallel")), ("16384".into(), "8099".into(), "1".into()));
|
||||
@@ -566,7 +670,7 @@ mod tests {
|
||||
|
||||
/// `mode`: "list" answers, "hang" keeps the connection and says nothing, "503" is a server still
|
||||
/// loading.
|
||||
async fn serve(id: &'static str, delay: Duration, gone: Option<std::path::PathBuf>, mode: Arc<Mutex<&'static str>>) -> u16 {
|
||||
pub(crate) async fn serve(id: &'static str, delay: Duration, gone: Option<std::path::PathBuf>, mode: Arc<Mutex<&'static str>>) -> u16 {
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
@@ -640,12 +744,12 @@ mod tests {
|
||||
/// A fake `strata`: `launch --stop` records itself and runs `stop_body` (by default it stops the
|
||||
/// server: the file `gone` appears); `launch ...` runs `launch_body`.
|
||||
#[cfg(unix)]
|
||||
fn fake_strata(l: &Layout, launch_body: &str) -> std::path::PathBuf {
|
||||
pub(crate) fn fake_strata(l: &Layout, launch_body: &str) -> std::path::PathBuf {
|
||||
fake_strata_stop(l, launch_body, &format!("touch '{}'", l.data.join("gone").display()))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn fake_strata_stop(l: &Layout, launch_body: &str, stop_body: &str) -> std::path::PathBuf {
|
||||
pub(crate) fn fake_strata_stop(l: &Layout, launch_body: &str, stop_body: &str) -> std::path::PathBuf {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let exe = l.data.join("fake-strata");
|
||||
std::fs::create_dir_all(l.strata_home()).unwrap();
|
||||
@@ -734,7 +838,7 @@ mod tests {
|
||||
/// server still left over, `leftover` MiB, until a `launch --stop`), and 9874 MiB more while a
|
||||
/// Strata server runs (the calls file shows the last launch and stop).
|
||||
#[cfg(unix)]
|
||||
fn card(l: &Layout, id: &'static str, leftover: i64) -> GpuReader {
|
||||
pub(crate) fn card(l: &Layout, id: &'static str, leftover: i64) -> GpuReader {
|
||||
let calls = l.data.join("calls");
|
||||
Arc::new(move || {
|
||||
let c = std::fs::read_to_string(&calls).unwrap_or_default();
|
||||
@@ -747,21 +851,21 @@ mod tests {
|
||||
|
||||
/// A fake Strata that serves on `port` again (removes `gone`) and writes the engine's staging line.
|
||||
#[cfg(unix)]
|
||||
fn fake_placed(l: &Layout) -> std::path::PathBuf {
|
||||
pub(crate) fn fake_placed(l: &Layout) -> std::path::PathBuf {
|
||||
let log = l.strata_home().join("x.engine.log");
|
||||
fake_strata(l, &format!("rm -f '{}'; echo 'strata-q36: hybrid experts: (1.10 GiB staging); 7.1 s' >> '{}'; echo 'Strata is serving.'",
|
||||
fake_strata(l, &format!("rm -f '{}'; echo 'strata-q36: hybrid experts: 5 of 256 per layer in VRAM, the rest of a batch on 16 CPU threads (1.10 GiB staging); 7.1 s' >> '{}'; echo 'Strata is serving.'",
|
||||
l.data.join("gone").display(), log.display()))
|
||||
}
|
||||
|
||||
/// A fake server on a free port that answers only once a launch serves (removes `gone`).
|
||||
#[cfg(unix)]
|
||||
async fn server_after_launch(l: &Layout, mode: &'static str) -> u16 {
|
||||
pub(crate) async fn server_after_launch(l: &Layout, mode: &'static str) -> u16 {
|
||||
std::fs::create_dir_all(&l.data).unwrap();
|
||||
std::fs::write(l.data.join("gone"), "").unwrap();
|
||||
serve("qwen-test", Duration::from_millis(0), Some(l.data.join("gone")), Arc::new(Mutex::new(mode))).await
|
||||
}
|
||||
|
||||
fn launches(l: &Layout) -> Vec<String> {
|
||||
pub(crate) fn launches(l: &Layout) -> Vec<String> {
|
||||
std::fs::read_to_string(l.data.join("calls")).unwrap_or_default().lines()
|
||||
.filter(|c| c.starts_with("launch --family")).map(str::to_owned).collect()
|
||||
}
|
||||
@@ -841,6 +945,60 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn a_game_moves_the_llm_to_the_game_placement_and_back() {
|
||||
let l = layout("llm-stage");
|
||||
let port = server_after_launch(&l, "list").await;
|
||||
let llm = Llm::with_exe(l.clone(), fake_placed(&l)).with_gpu(card(&l, "GPU-test", 0));
|
||||
let s = parse_settings(&json!({"llm": {"port": port}})).unwrap();
|
||||
llm.start(&s).await.unwrap();
|
||||
assert_eq!(llm.stage_view(), json!({"stage": "normal", "gameRoomMib": null}));
|
||||
std::fs::remove_file(l.data.join("calls")).unwrap();
|
||||
assert_eq!(tokio::time::timeout(Duration::from_secs(30), llm.switch(&s, Stage::Gaming)).await.unwrap().unwrap(), Stage::Gaming);
|
||||
let g = launches(&l);
|
||||
// Measured once at the game's context and one request, then the 2 GiB minimum (8 GB does not
|
||||
// fit on 16 GB) with half the engine's 16 CPU threads.
|
||||
assert_eq!(g.len(), 2, "{g:?}");
|
||||
assert!(g[0].contains("--context 16384") && g[0].contains("--parallel 1") && g[0].contains("--set expert-vram=0"), "{}", g[0]);
|
||||
assert!(g[1].ends_with("--set expert-vram=2 --set prefill=2048 --set pool-workers=8"), "{}", g[1]);
|
||||
let room = 16303 - 1460 - 9874 - crate::placement::STT_MIB - crate::placement::MARGIN_MIB - 921;
|
||||
assert_eq!(llm.stage_view(), json!({"stage": "gaming", "gameRoomMib": room}));
|
||||
assert_eq!(llm.status().state, LlmState::Ready);
|
||||
// Back to normal: the run's first reading of other programs, the normal placement again.
|
||||
std::fs::remove_file(l.data.join("calls")).unwrap();
|
||||
assert_eq!(llm.switch(&s, Stage::Normal).await.unwrap(), Stage::Normal);
|
||||
let n = launches(&l);
|
||||
assert_eq!(n.len(), 1, "{n:?}");
|
||||
assert!(n[0].contains("--context 32768") && n[0].ends_with("--set expert-vram=1.5 --set prefill=2048"), "{}", n[0]);
|
||||
assert_eq!(llm.stage_view(), json!({"stage": "normal", "gameRoomMib": null}));
|
||||
// Pause: the LLM stops.
|
||||
assert_eq!(llm.switch(&s, Stage::Paused).await.unwrap(), Stage::Paused);
|
||||
assert_eq!(llm.status().state, LlmState::Off);
|
||||
assert_eq!(llm.stage_view()["stage"], json!("paused"));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn a_game_with_no_room_beside_the_model_pauses_the_llm() {
|
||||
let l = layout("llm-stage-full");
|
||||
let port = server_after_launch(&l, "list").await;
|
||||
let calls = l.data.join("calls");
|
||||
// A 12 GB card: the model fits, but not with any room for a game.
|
||||
let llm = Llm::with_exe(l.clone(), fake_placed(&l)).with_gpu(Arc::new(move || {
|
||||
let c = std::fs::read_to_string(&calls).unwrap_or_default();
|
||||
let running = c.lines().last().is_some_and(|x| x.starts_with("launch --family"));
|
||||
Some(Gpu { id: "GPU-small".into(), used_mib: 1460 + if running { 9874 } else { 0 }, total_mib: 12288 })
|
||||
}));
|
||||
let s = parse_settings(&json!({"llm": {"port": port}})).unwrap();
|
||||
llm.start(&s).await.unwrap();
|
||||
assert_eq!(llm.switch(&s, Stage::Gaming).await.unwrap(), Stage::Paused);
|
||||
assert_eq!(llm.status().state, LlmState::Off);
|
||||
assert_eq!(llm.stage_view(), json!({"stage": "paused", "gameRoomMib": null}));
|
||||
let c = std::fs::read_to_string(l.data.join("calls")).unwrap();
|
||||
assert_eq!(c.lines().last(), Some("launch --stop"));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn a_left_server_that_does_not_stop_means_no_experts_and_nothing_measured() {
|
||||
|
||||
Reference in New Issue
Block a user