The CLI hands budget and preset changes to the supervisor through a request file; the supervisor checks them with the resource planner twice (before and after stopping the engine), restarts the engine with the sealed archive descriptor it holds, keeps the gateway and API processes and ports, and restores the previous settings when the planner or the new engine refuses. --persist writes the result into leleka.json (and strata.json for the context). leleka.json now records the profile before the preset changed it so that dedicated undoes workstation. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
558 lines
22 KiB
Rust
558 lines
22 KiB
Rust
//! Memory profiles: which GPU class gets which budget, context ceiling, KAR source and RAM floor.
|
|
//!
|
|
//! The built-in profiles are the JSON files in `deploy/rust-runtime/profiles/`, embedded at build time so the binary
|
|
//! needs no data directory. `--profile FILE` replaces them with an operator file of the same shape. A profile only
|
|
//! selects documented switches of `leleka-inference`; it never changes the model, the quantization or the backend
|
|
//! mode, so choosing one is not a quality decision.
|
|
use crate::facts::Gpu;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::{collections::BTreeMap, path::Path};
|
|
|
|
/// Bytes of the pinned level-2 KAR archive (`InheritedKarArchive` admits exactly this length).
|
|
pub const ARCHIVE_BYTES: u64 = 55_295_529_472;
|
|
/// SHA-256 of the pinned level-2 archive (`qwen4exp_kar_ple.rs` `ARCHIVE_DIGEST`): what the verification stamp of the
|
|
/// archive file is keyed by.
|
|
pub const ARCHIVE_SHA256_HEX: &str =
|
|
"536d612ca60eab460cb978f51748fc6fa4e9d611d4601e777884e8b51385afa5";
|
|
|
|
/// SHA-256 of the two pinned IQ3_S shards (`backend.rs` `SHARD0`, `SHARD1`).
|
|
pub const SHARD_SHA256_HEX: [&str; 2] = [
|
|
"4c1eb2ceb4915e1192f4f386021897bde56a97f40a0bb78bb86465e0f7d2aca3",
|
|
"316b46f3a2dbd68c900f43136ab9449f9dcc3725dfd8c794847c204bc161e113",
|
|
];
|
|
|
|
/// [`ARCHIVE_SHA256_HEX`] as bytes.
|
|
pub fn archive_sha256() -> [u8; 32] {
|
|
let mut out = [0u8; 32];
|
|
hex::decode_to_slice(ARCHIVE_SHA256_HEX, &mut out).expect("the pinned digest is 64 hex digits");
|
|
out
|
|
}
|
|
/// Bytes of the two pinned IQ3_S GGUF shards.
|
|
pub const SHARD_BYTES: [u64; 2] = [54_817_524_224, 28_800_138_432];
|
|
|
|
pub const BUILTIN: [(&str, &str); 2] = [
|
|
(
|
|
"rtx5090-32g",
|
|
include_str!("../../../deploy/rust-runtime/profiles/rtx5090-32g.json"),
|
|
),
|
|
(
|
|
"rtx3080-16g",
|
|
include_str!("../../../deploy/rust-runtime/profiles/rtx3080-16g.json"),
|
|
),
|
|
];
|
|
|
|
const PREFILL_CAPACITIES: [u32; 8] = [256, 512, 1024, 2048, 3072, 4096, 6144, 8192];
|
|
|
|
/// How the engine receives the KAR archive.
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum KarSource {
|
|
/// A sealed memfd made by the supervisor: the whole archive lives in RAM (shmem) while the service runs.
|
|
Memfd,
|
|
/// An ordinary read-only file (`--kar-archive-file`): only the pages that are read pass through the file cache.
|
|
File,
|
|
}
|
|
|
|
impl KarSource {
|
|
pub fn as_str(self) -> &'static str {
|
|
match self {
|
|
KarSource::Memfd => "memfd",
|
|
KarSource::File => "file",
|
|
}
|
|
}
|
|
}
|
|
|
|
/// How the routed experts are admitted (`leleka-inference --expert-source`).
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum ExpertSource {
|
|
/// A page-locked RAM copy of the routed experts (about 50 GB): the server form.
|
|
Resident,
|
|
/// Read-only mappings of shard 0, nothing copied: the low-RAM form.
|
|
Mapped,
|
|
}
|
|
|
|
impl ExpertSource {
|
|
pub fn as_str(self) -> &'static str {
|
|
match self {
|
|
ExpertSource::Resident => "resident",
|
|
ExpertSource::Mapped => "mapped",
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The memory-governor settings a profile carries (`docs/memory-safety.md`). Every field is optional: absent means the
|
|
/// engine's own default (floors from the host size, an `auto` cache sized from what is left, lock `try`). They become
|
|
/// `--prefix-cache-mib` and `LELEKA_MEMORY_*` / `LELEKA_ORIGINAL_SERVE_RESIDENT_BUDGET_GIB` for the engine.
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct MemoryBudget {
|
|
/// `--prefix-cache-mib`: `auto` (a share of what the governor leaves elastic), `0` (off) or MiB.
|
|
#[serde(default)]
|
|
pub prefix_cache_mib: Option<String>,
|
|
/// `--prefix-cache-tail`: `off`, `prompt` (a checkpoint at the end of the prefill) or `reply` (also one at the end of the decode,
|
|
/// where the agent's next turn resumes: the slot-equivalent resume, `docs/prefix-cache.md`). Absent: the engine's default (off).
|
|
#[serde(default)]
|
|
pub prefix_cache_tail: Option<String>,
|
|
/// `--prefix-cache-block`: tokens per prefix block and chunk-grid step (a multiple of 256, at most 8192; 0 = the prefill chunk).
|
|
/// Only passed while the prefix cache is on.
|
|
#[serde(default)]
|
|
pub prefix_cache_block: Option<u32>,
|
|
/// Minutes an idle cached session is kept (`LELEKA_PREFIX_RETENTION_S`; 0 = no time limit). Only passed while the cache is on.
|
|
#[serde(default)]
|
|
pub prefix_retention_min: Option<u64>,
|
|
/// Below this much available host memory the caches shed (`LELEKA_MEMORY_SOFT_FLOOR_MIB`).
|
|
#[serde(default)]
|
|
pub soft_floor_mib: Option<u64>,
|
|
/// Below this new requests are refused with 503 `memory_pressure` (`LELEKA_MEMORY_HARD_FLOOR_MIB`).
|
|
#[serde(default)]
|
|
pub hard_floor_mib: Option<u64>,
|
|
/// Slack kept above the soft floor after the fixed footprint (`LELEKA_MEMORY_RESERVE_MIB`).
|
|
#[serde(default)]
|
|
pub reserve_mib: Option<u64>,
|
|
/// Share of the elastic memory an `auto` cache takes, percent (`LELEKA_MEMORY_CACHE_SHARE_PERCENT`).
|
|
#[serde(default)]
|
|
pub cache_share_percent: Option<u64>,
|
|
/// Keep the sealed KAR memfd resident: `off`, `try` (lock when RLIMIT_MEMLOCK allows, else guard and heal) or `require`.
|
|
#[serde(default)]
|
|
pub lock: Option<String>,
|
|
/// Pull swapped memfd pages back in (`LELEKA_MEMORY_HEAL`).
|
|
#[serde(default)]
|
|
pub heal: Option<bool>,
|
|
/// `--resident-budget-gib` of the mapped expert source: GiB of experts page-locked in RAM (`LELEKA_ORIGINAL_SERVE_RESIDENT_BUDGET_GIB`).
|
|
#[serde(default)]
|
|
pub resident_budget_gib: Option<u32>,
|
|
}
|
|
|
|
impl MemoryBudget {
|
|
pub fn validate(&self) -> Result<(), String> {
|
|
if let Some(value) = &self.prefix_cache_mib
|
|
&& value != "auto"
|
|
&& value.parse::<u64>().ok().is_none_or(|mib| mib > (1 << 30))
|
|
{
|
|
return Err("memory.prefix_cache_mib must be \"auto\", \"0\" or a size in MiB".into());
|
|
}
|
|
if let Some(tail) = &self.prefix_cache_tail
|
|
&& !matches!(tail.as_str(), "off" | "prompt" | "reply")
|
|
{
|
|
return Err("memory.prefix_cache_tail must be off, prompt or reply".into());
|
|
}
|
|
if let Some(block) = self.prefix_cache_block
|
|
&& (block % 256 != 0 || block > 8192)
|
|
{
|
|
return Err("memory.prefix_cache_block must be a multiple of 256, at most 8192 (0 = the prefill chunk)".into());
|
|
}
|
|
if let (Some(soft), Some(hard)) = (self.soft_floor_mib, self.hard_floor_mib)
|
|
&& hard >= soft
|
|
{
|
|
return Err("memory.hard_floor_mib must be below memory.soft_floor_mib".into());
|
|
}
|
|
if let Some(percent) = self.cache_share_percent
|
|
&& !(1..=100).contains(&percent)
|
|
{
|
|
return Err("memory.cache_share_percent must be 1..=100".into());
|
|
}
|
|
if let Some(lock) = &self.lock
|
|
&& !matches!(lock.as_str(), "off" | "try" | "require")
|
|
{
|
|
return Err("memory.lock must be off, try or require".into());
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
/// The engine arguments this section adds.
|
|
pub fn args(&self) -> Vec<String> {
|
|
let mut args = Vec::new();
|
|
if let Some(value) = &self.prefix_cache_mib {
|
|
args.extend(["--prefix-cache-mib".to_owned(), value.clone()]);
|
|
}
|
|
if let Some(tail) = &self.prefix_cache_tail {
|
|
args.extend(["--prefix-cache-tail".to_owned(), tail.clone()]);
|
|
}
|
|
if let Some(block) = self.prefix_cache_block
|
|
&& self.prefix_cache_on()
|
|
{
|
|
args.extend(["--prefix-cache-block".to_owned(), block.to_string()]);
|
|
}
|
|
args
|
|
}
|
|
|
|
/// The prefix cache is configured and not switched off (`0`).
|
|
pub fn prefix_cache_on(&self) -> bool {
|
|
self.prefix_cache_mib.as_deref().is_some_and(|mib| mib != "0")
|
|
}
|
|
|
|
/// The engine environment this section adds.
|
|
pub fn env(&self) -> BTreeMap<String, String> {
|
|
let mut env = BTreeMap::new();
|
|
let mut put = |key: &str, value: Option<String>| {
|
|
if let Some(value) = value {
|
|
env.insert(key.to_owned(), value);
|
|
}
|
|
};
|
|
put(
|
|
"LELEKA_MEMORY_SOFT_FLOOR_MIB",
|
|
self.soft_floor_mib.map(|v| v.to_string()),
|
|
);
|
|
put(
|
|
"LELEKA_MEMORY_HARD_FLOOR_MIB",
|
|
self.hard_floor_mib.map(|v| v.to_string()),
|
|
);
|
|
put(
|
|
"LELEKA_MEMORY_RESERVE_MIB",
|
|
self.reserve_mib.map(|v| v.to_string()),
|
|
);
|
|
put(
|
|
"LELEKA_MEMORY_CACHE_SHARE_PERCENT",
|
|
self.cache_share_percent.map(|v| v.to_string()),
|
|
);
|
|
put("LELEKA_MEMORY_LOCK", self.lock.clone());
|
|
if self.prefix_cache_on() {
|
|
put("LELEKA_PREFIX_RETENTION_S", self.prefix_retention_min.map(|minutes| minutes.saturating_mul(60).to_string()));
|
|
}
|
|
put(
|
|
"LELEKA_MEMORY_HEAL",
|
|
self.heal.map(|v| if v { "1" } else { "0" }.to_owned()),
|
|
);
|
|
put(
|
|
"LELEKA_ORIGINAL_SERVE_RESIDENT_BUDGET_GIB",
|
|
self.resident_budget_gib.map(|v| v.to_string()),
|
|
);
|
|
env
|
|
}
|
|
}
|
|
|
|
/// Automatic selection window (`sm` is compute capability times ten; `sm_max` and `vram_mib_max` are exclusive).
|
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct Selector {
|
|
pub sm_min: u32,
|
|
pub sm_max: u32,
|
|
pub vram_mib_min: u64,
|
|
pub vram_mib_max: u64,
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
pub struct Profile {
|
|
pub name: String,
|
|
pub description: String,
|
|
#[serde(default)]
|
|
pub select: Selector,
|
|
pub gpu_budget_bytes: u64,
|
|
pub context_tokens: u32,
|
|
#[serde(default)]
|
|
pub prefill_capacity: Option<u32>,
|
|
#[serde(default)]
|
|
pub kv: Option<String>,
|
|
#[serde(default)]
|
|
pub kv_resident: Option<u32>,
|
|
#[serde(default)]
|
|
pub prompt_cache: Option<u32>,
|
|
/// MTP draft confidence floor (`--spec-min-p`, 0..=1). The reference agent runs used 0.5; unset keeps the engine default.
|
|
#[serde(default)]
|
|
pub spec_min_p: Option<f64>,
|
|
pub kar_source: KarSource,
|
|
pub expert_source: ExpertSource,
|
|
pub min_driver_major: u32,
|
|
pub min_vram_total_mib: u64,
|
|
/// Free VRAM required at start. Defaults to the budget; a profile whose budget is an upper bound that the
|
|
/// engine does not fully reach (the laptop: 15 GiB budget, 14.2 GiB measured peak) names the measured need.
|
|
#[serde(default)]
|
|
pub min_vram_free_mib: Option<u64>,
|
|
pub min_ram_total_bytes: u64,
|
|
pub min_ram_available_bytes: u64,
|
|
/// Advice only: the `memory=` value for `.wslconfig` when WSL2 gives the VM too little.
|
|
#[serde(default)]
|
|
pub wsl_memory_gib: Option<u32>,
|
|
/// Path relative to the assets directory of an optional ranked expert profile (VRAM expert tier).
|
|
#[serde(default)]
|
|
pub expert_profile: Option<String>,
|
|
#[serde(default)]
|
|
pub expert_profile_sha256: Option<String>,
|
|
/// Extra `LELEKA_ORIGINAL_SERVE_*` switches for the engine process.
|
|
#[serde(default)]
|
|
pub engine_env: BTreeMap<String, String>,
|
|
/// Memory budget settings (`docs/memory-safety.md`).
|
|
#[serde(default)]
|
|
pub memory: MemoryBudget,
|
|
}
|
|
|
|
impl Profile {
|
|
pub fn builtin(name: &str) -> Option<Profile> {
|
|
BUILTIN
|
|
.iter()
|
|
.find(|(candidate, _)| *candidate == name)
|
|
.map(|(_, text)| {
|
|
let profile: Profile =
|
|
serde_json::from_str(text).expect("built-in profile JSON is valid");
|
|
profile
|
|
})
|
|
}
|
|
|
|
pub fn builtins() -> Vec<Profile> {
|
|
BUILTIN
|
|
.iter()
|
|
.map(|(name, _)| Profile::builtin(name).expect("built-in"))
|
|
.collect()
|
|
}
|
|
|
|
pub fn from_file(path: &Path) -> Result<Profile, String> {
|
|
let bytes = std::fs::read(path)
|
|
.map_err(|error| format!("cannot read profile {}: {error}", path.display()))?;
|
|
if bytes.len() > 64 * 1024 {
|
|
return Err("profile file exceeds 64 KiB".into());
|
|
}
|
|
let profile: Profile = serde_json::from_slice(&bytes)
|
|
.map_err(|error| format!("invalid profile {}: {error}", path.display()))?;
|
|
profile.validate()?;
|
|
Ok(profile)
|
|
}
|
|
|
|
pub fn validate(&self) -> Result<(), String> {
|
|
if self.name.is_empty()
|
|
|| self.name.len() > 64
|
|
|| !self
|
|
.name
|
|
.bytes()
|
|
.all(|b| b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_' | b'.'))
|
|
{
|
|
return Err("profile name must be 1..64 characters of [A-Za-z0-9._-]".into());
|
|
}
|
|
if self.gpu_budget_bytes < (1 << 30) || self.gpu_budget_bytes > (1 << 40) {
|
|
return Err("gpu_budget_bytes must be between 1 GiB and 1 TiB".into());
|
|
}
|
|
if !(1..=262_144).contains(&self.context_tokens) {
|
|
return Err("context_tokens must be 1..=262144 for the Original serve path".into());
|
|
}
|
|
if let Some(capacity) = self.prefill_capacity
|
|
&& !PREFILL_CAPACITIES.contains(&capacity)
|
|
{
|
|
return Err(format!(
|
|
"prefill_capacity must be one of {PREFILL_CAPACITIES:?}"
|
|
));
|
|
}
|
|
if let Some(p) = self.spec_min_p
|
|
&& !(0.0..=1.0).contains(&p)
|
|
{
|
|
return Err("spec_min_p must be within 0..=1".into());
|
|
}
|
|
if let Some(kv) = &self.kv
|
|
&& kv != "int8"
|
|
{
|
|
return Err("kv must be int8 (the engine refuses other formats)".into());
|
|
}
|
|
if let Some(digest) = &self.expert_profile_sha256
|
|
&& (digest.len() != 64 || !digest.bytes().all(|b| b.is_ascii_hexdigit()))
|
|
{
|
|
return Err("expert_profile_sha256 must be 64 hex digits".into());
|
|
}
|
|
if let Some(path) = &self.expert_profile
|
|
&& (path.is_empty()
|
|
|| path.starts_with('/')
|
|
|| path.split('/').any(|part| part == ".." || part.is_empty()))
|
|
{
|
|
return Err(
|
|
"expert_profile must be a relative path inside the assets directory".into(),
|
|
);
|
|
}
|
|
self.memory.validate()?;
|
|
for (key, value) in &self.engine_env {
|
|
// LELEKA_CHAIN selects the chain-kernel group (docs/chain-kernels.md); every other switch is a serve-stack one
|
|
if !(key.starts_with("LELEKA_ORIGINAL_SERVE_") || key == "LELEKA_CHAIN")
|
|
|| !key
|
|
.bytes()
|
|
.all(|b| b.is_ascii_uppercase() || b.is_ascii_digit() || b == b'_')
|
|
{
|
|
return Err(format!(
|
|
"engine_env key {key} must be an upper-case LELEKA_ORIGINAL_SERVE_* name (or LELEKA_CHAIN)"
|
|
));
|
|
}
|
|
if value.is_empty() || value.len() > 1024 || value.chars().any(char::is_control) {
|
|
return Err(format!(
|
|
"engine_env value of {key} is empty or not printable"
|
|
));
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
/// True when the compute capability and VRAM of `gpu` fall inside the selection window.
|
|
pub fn matches(&self, gpu: &Gpu) -> bool {
|
|
let Some(sm) = gpu.sm else { return false };
|
|
(self.select.sm_min..self.select.sm_max).contains(&sm)
|
|
&& (self.select.vram_mib_min..self.select.vram_mib_max).contains(&gpu.vram_total_mib)
|
|
}
|
|
}
|
|
|
|
/// Resolve `--profile`: `auto` (or nothing), a built-in name, or a path to a JSON file.
|
|
pub fn resolve(spec: Option<&str>, gpu: Option<&Gpu>) -> Result<Profile, String> {
|
|
let spec = spec.unwrap_or("auto");
|
|
if spec != "auto" {
|
|
if let Some(profile) = Profile::builtin(spec) {
|
|
return Ok(profile);
|
|
}
|
|
if spec.contains('/') || spec.contains('\\') || spec.ends_with(".json") {
|
|
return Profile::from_file(Path::new(spec));
|
|
}
|
|
let names: Vec<_> = BUILTIN.iter().map(|(name, _)| *name).collect();
|
|
return Err(format!(
|
|
"unknown profile {spec:?}; built-in profiles: {}; or pass a JSON file (see `leleka profiles show NAME`)",
|
|
names.join(", ")
|
|
));
|
|
}
|
|
let gpu = gpu.ok_or(
|
|
"no NVIDIA GPU was detected, so no profile can be selected automatically; pass --profile NAME|FILE",
|
|
)?;
|
|
let matches: Vec<Profile> = Profile::builtins()
|
|
.into_iter()
|
|
.filter(|profile| profile.matches(gpu))
|
|
.collect();
|
|
match matches.len() {
|
|
1 => Ok(matches.into_iter().next().expect("one")),
|
|
0 => Err(format!(
|
|
"no built-in profile fits {} (sm_{}, {} MiB); built-in: {}; write a profile file from `leleka profiles show NAME` and pass --profile FILE",
|
|
gpu.name,
|
|
gpu.sm.map_or("?".into(), |sm| sm.to_string()),
|
|
gpu.vram_total_mib,
|
|
BUILTIN
|
|
.iter()
|
|
.map(|(name, _)| *name)
|
|
.collect::<Vec<_>>()
|
|
.join(", ")
|
|
)),
|
|
_ => Err("more than one built-in profile matches; pass --profile NAME".into()),
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
fn gpu(name: &str, sm: u32, mib: u64) -> Gpu {
|
|
Gpu {
|
|
index: 0,
|
|
name: name.into(),
|
|
driver: "595.99.02".into(),
|
|
vram_total_mib: mib,
|
|
vram_free_mib: mib,
|
|
sm: Some(sm),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn built_in_profiles_parse_and_validate() {
|
|
for profile in Profile::builtins() {
|
|
profile.validate().unwrap();
|
|
}
|
|
assert_eq!(Profile::builtins().len(), 2);
|
|
}
|
|
|
|
#[test]
|
|
fn auto_selection_picks_the_server_and_the_laptop_profile() {
|
|
let server = resolve(None, Some(&gpu("NVIDIA GeForce RTX 5090", 120, 32607))).unwrap();
|
|
assert_eq!(server.name, "rtx5090-32g");
|
|
assert_eq!(server.kar_source, KarSource::Memfd);
|
|
let laptop = resolve(
|
|
Some("auto"),
|
|
Some(&gpu("NVIDIA GeForce RTX 3080 Laptop GPU", 86, 16384)),
|
|
)
|
|
.unwrap();
|
|
assert_eq!(laptop.name, "rtx3080-16g");
|
|
assert_eq!(laptop.kar_source, KarSource::File);
|
|
assert_eq!(laptop.context_tokens, 8192);
|
|
}
|
|
|
|
#[test]
|
|
fn unmatched_gpu_and_missing_gpu_give_actionable_errors() {
|
|
let error = resolve(None, Some(&gpu("NVIDIA GeForce RTX 4090", 89, 24564))).unwrap_err();
|
|
assert!(error.contains("--profile FILE"), "{error}");
|
|
assert!(resolve(None, None).unwrap_err().contains("--profile"));
|
|
assert!(
|
|
resolve(Some("nope"), None)
|
|
.unwrap_err()
|
|
.contains("rtx5090-32g")
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn explicit_name_overrides_the_detected_gpu() {
|
|
let forced = resolve(
|
|
Some("rtx3080-16g"),
|
|
Some(&gpu("NVIDIA GeForce RTX 5090", 120, 32607)),
|
|
)
|
|
.unwrap();
|
|
assert_eq!(forced.name, "rtx3080-16g");
|
|
}
|
|
|
|
#[test]
|
|
fn validation_rejects_unsafe_values() {
|
|
let mut profile = Profile::builtin("rtx5090-32g").unwrap();
|
|
profile
|
|
.engine_env
|
|
.insert("LD_PRELOAD".into(), "/tmp/x.so".into());
|
|
assert!(profile.validate().unwrap_err().contains("LD_PRELOAD"));
|
|
let mut profile = Profile::builtin("rtx5090-32g").unwrap();
|
|
profile.context_tokens = 524_288;
|
|
assert!(profile.validate().is_err());
|
|
let mut profile = Profile::builtin("rtx5090-32g").unwrap();
|
|
profile.prefill_capacity = Some(1000);
|
|
assert!(profile.validate().is_err());
|
|
let mut profile = Profile::builtin("rtx3080-16g").unwrap();
|
|
profile.expert_profile = Some("../x".into());
|
|
assert!(profile.validate().is_err());
|
|
profile.expert_profile = Some("/etc/passwd".into());
|
|
assert!(profile.validate().is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn the_builtin_profiles_carry_the_memory_budget_into_engine_arguments_and_environment() {
|
|
let server = Profile::builtin("rtx5090-32g").unwrap();
|
|
assert_eq!(
|
|
server.memory.args(),
|
|
["--prefix-cache-mib", "auto", "--prefix-cache-tail", "reply"].map(str::to_owned).to_vec()
|
|
);
|
|
let mut bad = server.memory.clone();
|
|
bad.prefix_cache_tail = Some("always".into());
|
|
assert!(bad.validate().is_err());
|
|
let env = server.memory.env();
|
|
assert_eq!(env["LELEKA_MEMORY_SOFT_FLOOR_MIB"], "4096");
|
|
assert_eq!(env["LELEKA_MEMORY_HARD_FLOOR_MIB"], "2048");
|
|
assert_eq!(env["LELEKA_MEMORY_LOCK"], "try");
|
|
let laptop = Profile::builtin("rtx3080-16g").unwrap();
|
|
assert_eq!(
|
|
laptop.memory.env()["LELEKA_MEMORY_LOCK"],
|
|
"off",
|
|
"the laptop archive is a file, not a memfd"
|
|
);
|
|
for profile in Profile::builtins() {
|
|
profile.validate().unwrap();
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn memory_budget_validation_rejects_nonsense() {
|
|
let mut profile = Profile::builtin("rtx5090-32g").unwrap();
|
|
profile.memory.hard_floor_mib = Some(8192);
|
|
assert!(profile.validate().unwrap_err().contains("hard_floor"));
|
|
let mut profile = Profile::builtin("rtx5090-32g").unwrap();
|
|
profile.memory.lock = Some("maybe".into());
|
|
assert!(profile.validate().is_err());
|
|
let mut profile = Profile::builtin("rtx5090-32g").unwrap();
|
|
profile.memory.prefix_cache_mib = Some("lots".into());
|
|
assert!(profile.validate().is_err());
|
|
profile.memory.prefix_cache_mib = Some("0".into());
|
|
assert!(profile.validate().is_ok());
|
|
profile.memory.cache_share_percent = Some(0);
|
|
assert!(profile.validate().is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn unknown_fields_in_a_profile_file_are_refused() {
|
|
let text = BUILTIN[0]
|
|
.1
|
|
.replacen('{', "{\"typo\": 1,", 1);
|
|
assert!(serde_json::from_str::<Profile>(&text).is_err());
|
|
}
|
|
}
|