Files
leleka/crates/deploy/src/config/engine_launch.rs
T

152 lines
5.7 KiB
Rust

//! What the engine process is started with: arguments, verify arguments, archive argument, MTP profile and environment.
use super::*;
impl RunConfig {
/// Arguments of `leleka-inference`, in the order its parser requires (seven fixed pairs first, then the
/// operator-source tuples). `{FD}` stays literal for [`KarArg::Fd`].
pub fn engine_args(&self, kar: KarArg) -> Vec<String> {
let paths = self.paths();
let mut args = self.fixed_engine_args(&paths);
args.extend(archive_engine_args(&paths, kar));
args.extend([
"--mtp-pack".into(),
paths.mtp_pack().display().to_string(),
"--mtp-staging".into(),
paths.mtp_staging().display().to_string(),
"--backend-mode".into(),
"original".into(),
"--expert-source".into(),
self.profile.expert_source.as_str().into(),
// The Original drafts over the MTP pack's draft vocabulary (draft_vocab.bin, 106k rows); without this the engine
// drafts over the full 248k-row head, about 0.2 ms more per draft step.
"--mtp-rt-dir".into(),
paths.mtp_pack().display().to_string(),
]);
args.extend(self.optional_engine_args());
args.extend(self.profile.memory.args());
if self.verify_stamps {
args.extend([
"--verify-stamps".into(),
paths.engine_stamps().display().to_string(),
]);
}
args
}
/// The seven fixed pairs.
fn fixed_engine_args(&self, paths: &Paths) -> Vec<String> {
let profile = &self.profile;
vec![
"--listen".into(),
self.ports.engine.clone(),
"--token-env".into(),
RUNTIME_TOKEN_ENV.into(),
"--shard0".into(),
paths.shard(0).display().to_string(),
"--shard1".into(),
paths.shard(1).display().to_string(),
"--gpu".into(),
self.gpu.to_string(),
"--gpu-budget".into(),
profile.gpu_budget_bytes.to_string(),
"--context-tokens".into(),
profile.context_tokens.to_string(),
]
}
/// The pairs that appear only when the profile sets them.
fn optional_engine_args(&self) -> Vec<String> {
let profile = &self.profile;
let mut args = Vec::new();
if let Some(value) = profile.prefill_capacity {
args.extend(["--original-prefill-capacity".into(), value.to_string()]);
}
if let Some(value) = &profile.kv {
args.extend(["--kv".into(), value.clone()]);
}
if let Some(value) = profile.kv_resident {
args.extend(["--kv-resident".into(), value.to_string()]);
}
if let Some(value) = profile.prompt_cache {
args.extend(["--prompt-cache".into(), value.to_string()]);
}
if let Some(value) = profile.spec_min_p {
args.extend(["--spec-min-p".into(), value.to_string()]);
}
args
}
/// Arguments of `leleka-inference --verify-only --verify-rehash`: both shards hashed in full and the stamps renewed.
/// A file-backed archive is verified by the engine too; a sealed-memfd profile has no archive here (the
/// supervisor-side hash of the archive file is `leleka verify`'s other half).
pub fn verify_args(&self, rehash: bool) -> Vec<String> {
let paths = self.paths();
let mut args = self.engine_args(KarArg::File);
// Keep the seven fixed pairs, drop the archive, pack and backend switches the verification does not use.
args.truncate(14);
if self.profile.kar_source == KarSource::File {
args.extend([
"--kar-archive-file".into(),
paths.kar().display().to_string(),
"--kar-provenance".into(),
paths.kar_provenance().display().to_string(),
]);
}
args.push("--verify-only".into());
if rehash {
args.push("--verify-rehash".into());
}
args.extend([
"--verify-stamps".into(),
paths.engine_stamps().display().to_string(),
]);
args
}
pub fn kar_arg(&self) -> KarArg {
match self.profile.kar_source {
KarSource::Memfd => KarArg::Fd,
KarSource::File => KarArg::File,
KarSource::None => KarArg::None,
}
}
/// The typed load's profile id: the KAR PLE form, or `kar_source: none`'s native-PLE form (`qwen4exp-native-mtp-v1`).
pub fn mtp_profile(&self) -> &'static str {
if self.profile.kar_source == KarSource::None {
NATIVE_MTP_PROFILE
} else {
MTP_PROFILE
}
}
/// The engine's extra environment: profile switches, then the `up`-resolved ones (which win).
pub fn engine_environment(&self) -> BTreeMap<String, String> {
let mut env = self.profile.memory.env();
env.extend(self.profile.engine_env.clone());
env.extend(self.engine_env.clone());
env
}
}
/// The archive arguments: the descriptor or the file, and the provenance file that goes with an archive.
fn archive_engine_args(paths: &Paths, kar: KarArg) -> Vec<String> {
let mut args = Vec::new();
match kar {
KarArg::Fd => args.extend(["--kar-archive-fd".into(), "{FD}".into()]),
KarArg::File => args.extend([
"--kar-archive-file".into(),
paths.kar().display().to_string(),
]),
KarArg::None => {}
}
if kar != KarArg::None {
args.extend([
"--kar-provenance".into(),
paths.kar_provenance().display().to_string(),
]);
}
args
}