feat(serve): backend-mode and Original options in the inference binary
--backend-mode auto|original|preview (default auto; an --experimental-* flag selects preview unless the mode is given), --original-prefill-capacity, --mtp-rt-dir, --spec-min-p, parsed first at tuple boundaries. The two binaries get the kar_expert_source initializer their runtime config already required. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
aed13f7583
commit
f1de06f425
@@ -80,6 +80,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.map(|(fd, provenance)| InheritedKarArchive::open(fd, provenance))
|
||||
.transpose()?,
|
||||
mtp_source: sources.mtp,
|
||||
kar_expert_source: None,
|
||||
};
|
||||
let policy = evaluation_measurement::EvaluationPolicy::from_environment()?;
|
||||
let observer = evaluation_measurement::observer(policy)?;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Linux CUDA inference process. Operator-owned artifact paths never enter RPCs.
|
||||
use leleka_runtime::backend::{
|
||||
InheritedKarArchive, NativeBackendConfig, RankedExpertProfileSource, spawn_backend,
|
||||
InheritedKarArchive, NativeBackendConfig, OriginalServeChoice, OriginalServeMode, OriginalServeOptions,
|
||||
RankedExpertProfileSource, original_serve_choice, spawn_backend, spawn_backend_original_serve,
|
||||
spawn_backend_experimental_native_integer_iq3_windowed256_retained_gr,
|
||||
spawn_backend_experimental_optimized_windowed256,
|
||||
spawn_backend_experimental_optimized_windowed256_queued_owners,
|
||||
@@ -23,13 +24,26 @@ const RESIDENT_OWNERS_FLAG: &str = "--experimental-optimized-windowed256-mtp-res
|
||||
const RETAINED_SCRATCH_FLAG: &str = "--experimental-optimized-windowed256-mtp-retained-scratch";
|
||||
const STREAMED_SPILL_FLAG: &str = "--experimental-optimized-windowed256-mtp-streamed-spill";
|
||||
const QUEUED_OWNERS_FLAG: &str = "--experimental-optimized-windowed256-mtp-queued-owners";
|
||||
const BACKEND_MODE_FLAG: &str = "--backend-mode";
|
||||
const ORIGINAL_PREFILL_CAPACITY_FLAG: &str = "--original-prefill-capacity";
|
||||
const MTP_RT_DIR_FLAG: &str = "--mtp-rt-dir";
|
||||
const SPEC_MIN_P_FLAG: &str = "--spec-min-p";
|
||||
const EXECUTION_FLAGS: [&str; 7] = [
|
||||
ADAPTIVE_SLOTS_FLAG,
|
||||
RESIDENT_OWNERS_FLAG,
|
||||
RETAINED_SCRATCH_FLAG,
|
||||
STREAMED_SPILL_FLAG,
|
||||
QUEUED_OWNERS_FLAG,
|
||||
OPTIMIZED_FLAG,
|
||||
INTEGER_WINDOWED_FLAG,
|
||||
];
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
if args.as_slice() == ["--help"] {
|
||||
println!(
|
||||
"leleka-inference --listen IP:PORT --token-env NAME --shard0 PATH --shard1 PATH --gpu ORDINAL --gpu-budget BYTES --context-tokens COUNT [--kar-archive PATH --kar-staging PATH | --kar-archive-fd N --kar-provenance PATH] [--mtp-pack PATH --mtp-staging PATH] [--experimental-native-integer-iq3-windowed256-retained-gr | --experimental-optimized-windowed256-mtp [--ranked-expert-profile PATH --expert-profile-sha256 DIGEST] | --experimental-optimized-windowed256-mtp-queued-owners --ranked-expert-profile PATH --expert-profile-sha256 DIGEST | --experimental-optimized-windowed256-mtp-streamed-spill --ranked-expert-profile PATH --expert-profile-sha256 DIGEST | --experimental-optimized-windowed256-mtp-retained-scratch --ranked-expert-profile PATH --expert-profile-sha256 DIGEST | --experimental-optimized-windowed256-mtp-strata-adaptive-slots --ranked-expert-profile PATH --expert-profile-sha256 DIGEST] [--public-evaluation-output /PRIVATE/measurements.jsonl (adaptive slots only; LELEKA_PUBLIC_EVALUATION=yes and LELEKA_EVALUATION_NONCE required)]"
|
||||
"leleka-inference --listen IP:PORT --token-env NAME --shard0 PATH --shard1 PATH --gpu ORDINAL --gpu-budget BYTES --context-tokens COUNT [--kar-archive PATH --kar-staging PATH | --kar-archive-fd N --kar-provenance PATH] [--mtp-pack PATH --mtp-staging PATH] [--experimental-native-integer-iq3-windowed256-retained-gr | --experimental-optimized-windowed256-mtp [--ranked-expert-profile PATH --expert-profile-sha256 DIGEST] | --experimental-optimized-windowed256-mtp-queued-owners --ranked-expert-profile PATH --expert-profile-sha256 DIGEST | --experimental-optimized-windowed256-mtp-streamed-spill --ranked-expert-profile PATH --expert-profile-sha256 DIGEST | --experimental-optimized-windowed256-mtp-retained-scratch --ranked-expert-profile PATH --expert-profile-sha256 DIGEST | --experimental-optimized-windowed256-mtp-strata-adaptive-slots --ranked-expert-profile PATH --expert-profile-sha256 DIGEST] [--public-evaluation-output /PRIVATE/measurements.jsonl (adaptive slots only; LELEKA_PUBLIC_EVALUATION=yes and LELEKA_EVALUATION_NONCE required)] [--backend-mode auto|original|preview (default auto; an --experimental-* flag selects preview unless the mode is given)] [--original-prefill-capacity 256..8192] [--mtp-rt-dir PATH] [--spec-min-p 0..1]"
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
@@ -38,7 +52,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
} else {
|
||||
return Err("invalid_inference_arguments".into());
|
||||
};
|
||||
let (public_evaluation_output, execution_args) = operator_public_evaluation_output(extra)?;
|
||||
let (requested_mode, mut original_options, extra) = operator_original_serve(extra)?;
|
||||
let (public_evaluation_output, execution_args) = operator_public_evaluation_output(&extra)?;
|
||||
let (adaptive_slots, adaptive_args) = operator_adaptive_slots_execution(&execution_args)?;
|
||||
if public_evaluation_output.is_some() && !adaptive_slots {
|
||||
return Err("public_evaluation_requires_adaptive_slots".into());
|
||||
@@ -109,11 +124,42 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.map(|(fd, provenance)| InheritedKarArchive::open(fd, provenance))
|
||||
.transpose()?,
|
||||
mtp_source: sources.mtp,
|
||||
// The routed-expert KAR source has no operator flag in this binary yet.
|
||||
kar_expert_source: None,
|
||||
};
|
||||
let observer = public_evaluation_output
|
||||
.map(evaluation_measurement::observer_adaptive_slots)
|
||||
.transpose()?;
|
||||
let backend = if let Some(observer) = observer {
|
||||
// An explicit experimental execution flag is an explicit preview choice unless the mode is also given.
|
||||
let explicit_preview = adaptive_slots
|
||||
|| resident_owners
|
||||
|| retained_scratch
|
||||
|| streamed_spill
|
||||
|| queued_owners
|
||||
|| optimized
|
||||
|| experimental_integer_windowed;
|
||||
let mode = match requested_mode {
|
||||
Some(mode) => mode,
|
||||
None if explicit_preview => OriginalServeMode::Preview,
|
||||
None => OriginalServeMode::Auto,
|
||||
};
|
||||
if mode == OriginalServeMode::Original && (explicit_preview || observer.is_some()) {
|
||||
return Err("conflicting_experimental_execution_flags".into());
|
||||
}
|
||||
original_options.mode = mode;
|
||||
let choice = original_serve_choice(mode, &config).map_err(|error| {
|
||||
// Fixed texts naming the missing assets or unsupported configuration; never operator paths.
|
||||
eprintln!("leleka-inference: {}", error.message);
|
||||
"original_serve_unavailable"
|
||||
})?;
|
||||
if let OriginalServeChoice::Preview { reason } = &choice {
|
||||
if mode == OriginalServeMode::Auto {
|
||||
eprintln!("leleka-inference: backend=preview ({reason})");
|
||||
}
|
||||
}
|
||||
let backend = if matches!(choice, OriginalServeChoice::Original) {
|
||||
spawn_backend_original_serve(config, original_options)
|
||||
} else if let Some(observer) = observer {
|
||||
spawn_backend_observed_experimental_optimized_windowed256_adaptive_slots(
|
||||
config, ranked_profile.ok_or("adaptive_slots_requires_ranked_expert_profile")?, observer,
|
||||
)
|
||||
@@ -145,7 +191,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
} else {
|
||||
spawn_backend(config)
|
||||
}
|
||||
.map_err(|_| "runtime_startup_failed")?;
|
||||
.map_err(|error| {
|
||||
eprintln!("leleka-inference: {}", error.message);
|
||||
"runtime_startup_failed"
|
||||
})?;
|
||||
let server = RuntimeServer::new(backend, token.clone())?;
|
||||
let listener = tokio::net::TcpListener::bind(address).await?;
|
||||
// Transport starts closed for model admission. Loading is an explicit typed
|
||||
@@ -721,6 +770,120 @@ fn operator_adaptive_slots_execution(args: &[String]) -> Result<(bool, Vec<Strin
|
||||
Ok((selected, ordinary))
|
||||
}
|
||||
|
||||
/// The Original-serve options. Consumed first, at tuple boundaries only: the known one-item execution
|
||||
/// flags and the fixture output pair are skipped as the later parsers read them, every other group is an
|
||||
/// opaque four-item source tuple, so no operand is ever scanned for a flag.
|
||||
fn operator_original_serve(
|
||||
args: &[String],
|
||||
) -> Result<(Option<OriginalServeMode>, OriginalServeOptions, Vec<String>), &'static str> {
|
||||
let mut mode = None;
|
||||
let mut options = OriginalServeOptions::default();
|
||||
let (mut capacity, mut directory, mut floor) = (false, false, false);
|
||||
let mut ordinary = Vec::with_capacity(args.len());
|
||||
let mut offset = 0usize;
|
||||
while offset < args.len() {
|
||||
let flag = args[offset].as_str();
|
||||
let value = || args.get(offset + 1).map(String::as_str).ok_or("original_serve_option_value_required");
|
||||
if flag == BACKEND_MODE_FLAG {
|
||||
if mode.is_some() {
|
||||
return Err("duplicate_backend_mode");
|
||||
}
|
||||
mode = Some(OriginalServeMode::parse(value()?).ok_or("invalid_backend_mode")?);
|
||||
offset += 2;
|
||||
} else if flag == ORIGINAL_PREFILL_CAPACITY_FLAG {
|
||||
if std::mem::replace(&mut capacity, true) {
|
||||
return Err("duplicate_original_prefill_capacity");
|
||||
}
|
||||
options.prefill_capacity = Some(value()?.parse().map_err(|_| "invalid_original_prefill_capacity")?);
|
||||
offset += 2;
|
||||
} else if flag == MTP_RT_DIR_FLAG {
|
||||
if std::mem::replace(&mut directory, true) {
|
||||
return Err("duplicate_mtp_rt_dir");
|
||||
}
|
||||
options.mtp_rt_directory = Some(PathBuf::from(value()?));
|
||||
offset += 2;
|
||||
} else if flag == SPEC_MIN_P_FLAG {
|
||||
if std::mem::replace(&mut floor, true) {
|
||||
return Err("duplicate_spec_min_p");
|
||||
}
|
||||
options.spec_min_p = value()?.parse().map_err(|_| "invalid_spec_min_p")?;
|
||||
offset += 2;
|
||||
} else if flag == PUBLIC_EVALUATION_OUTPUT_FLAG {
|
||||
let end = offset.checked_add(2).ok_or("public_evaluation_output_required")?;
|
||||
ordinary.extend_from_slice(args.get(offset..end).ok_or("public_evaluation_output_required")?);
|
||||
offset = end;
|
||||
} else if EXECUTION_FLAGS.contains(&flag) {
|
||||
ordinary.push(args[offset].clone());
|
||||
offset += 1;
|
||||
} else {
|
||||
let end = offset.checked_add(4).ok_or("invalid_operator_source_pairs")?;
|
||||
ordinary.extend_from_slice(args.get(offset..end).ok_or("invalid_operator_source_pairs")?);
|
||||
offset = end;
|
||||
}
|
||||
}
|
||||
if let Some(mode) = mode {
|
||||
options.mode = mode;
|
||||
}
|
||||
Ok((mode, options, ordinary))
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod original_serve_operator_tests {
|
||||
use super::*;
|
||||
fn args(items: &[&str]) -> Vec<String> {
|
||||
items.iter().map(|s| s.to_string()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_four_options_are_consumed_and_everything_else_passes_through_unchanged() {
|
||||
let input = args(&[
|
||||
"--backend-mode", "original", "--original-prefill-capacity", "1024", "--mtp-rt-dir", "/sanitized/mtp",
|
||||
"--spec-min-p", "0.25", OPTIMIZED_FLAG, "--kar-archive", "/sanitized/a", "--kar-staging", "/sanitized/s",
|
||||
PUBLIC_EVALUATION_OUTPUT_FLAG, "/sanitized/out",
|
||||
]);
|
||||
let (mode, options, rest) = operator_original_serve(&input).unwrap();
|
||||
assert_eq!(mode, Some(OriginalServeMode::Original));
|
||||
assert_eq!(options.mode, OriginalServeMode::Original);
|
||||
assert_eq!(options.prefill_capacity, Some(1024));
|
||||
assert_eq!(options.mtp_rt_directory, Some(PathBuf::from("/sanitized/mtp")));
|
||||
assert_eq!(options.spec_min_p, 0.25);
|
||||
assert_eq!(rest, args(&[OPTIMIZED_FLAG, "--kar-archive", "/sanitized/a", "--kar-staging", "/sanitized/s", PUBLIC_EVALUATION_OUTPUT_FLAG, "/sanitized/out"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nothing_given_means_no_mode_and_default_options() {
|
||||
let (mode, options, rest) = operator_original_serve(&[]).unwrap();
|
||||
assert_eq!(mode, None);
|
||||
assert_eq!(options.mode, OriginalServeMode::Auto);
|
||||
assert!(options.prefill_capacity.is_none() && options.mtp_rt_directory.is_none());
|
||||
assert!(rest.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn operands_are_never_scanned_for_options() {
|
||||
// a source operand that spells an option stays an operand of its tuple
|
||||
let opaque = args(&["--kar-archive", BACKEND_MODE_FLAG, "--kar-staging", "/sanitized/s"]);
|
||||
let (mode, _, rest) = operator_original_serve(&opaque).unwrap();
|
||||
assert_eq!(mode, None);
|
||||
assert_eq!(rest, opaque);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_and_duplicate_options_are_refused() {
|
||||
for bad in [
|
||||
args(&["--backend-mode"]),
|
||||
args(&["--backend-mode", "fast"]),
|
||||
args(&["--backend-mode", "auto", "--backend-mode", "auto"]),
|
||||
args(&["--original-prefill-capacity", "many"]),
|
||||
args(&["--original-prefill-capacity", "1", "--original-prefill-capacity", "2"]),
|
||||
args(&["--spec-min-p", "x"]),
|
||||
args(&["--mtp-rt-dir"]),
|
||||
args(&["--unpaired"]),
|
||||
] {
|
||||
assert!(operator_original_serve(&bad).is_err(), "{bad:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extract only the explicit fixture output pair. Existing source/profile pairs
|
||||
/// remain opaque four-item tuples; no operand can be interpreted as a flag.
|
||||
fn operator_public_evaluation_output(
|
||||
|
||||
Reference in New Issue
Block a user