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: 2 additions & 0 deletions crates/mesh-llm-config/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ pub struct SkippyConfig {
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct SpeculativeConfig {
#[serde(default)]
pub strategy: Option<String>,
#[serde(default)]
pub mode: Option<String>,
#[serde(default)]
Expand Down
1 change: 1 addition & 0 deletions crates/mesh-llm-config/src/model/built_in_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ fn skippy_settings(prefix: &str) -> Vec<ConfigSettingSchema> {

fn speculative_settings(prefix: &str) -> Vec<ConfigSettingSchema> {
vec![
basic_setting(&format!("{prefix}.strategy"), ConfigValueSchema::String),
basic_setting(&format!("{prefix}.mode"), ConfigValueSchema::String),
basic_setting(
&format!("{prefix}.draft_model_path"),
Expand Down
28 changes: 28 additions & 0 deletions crates/mesh-llm-config/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,11 @@ fn validate_skippy(config: &SkippyConfig, base_path: &str) -> DiagnosticResult {
}

fn validate_speculative(config: &SpeculativeConfig, base_path: &str) -> DiagnosticResult {
validate_optional_enum(
config.strategy.as_deref(),
&["auto", "disabled", "native-mtp-n1"],
&format!("{base_path}.strategy"),
)?;
validate_optional_enum(
config.mode.as_deref(),
&["auto", "disabled", "draft", "ngram"],
Expand Down Expand Up @@ -1544,6 +1549,29 @@ gpu_id = "metal:0"
);
}

#[test]
fn speculative_strategy_rejects_unknown_values() {
let config: MeshConfig = toml::from_str(
r#"
[defaults.speculative]
strategy = "mystery-oracle"
"#,
)
.expect("config should parse before validation");

let diagnostics = validate_config_diagnostics(&config);
assert_eq!(diagnostics.len(), 1);
assert_eq!(
diagnostics[0].path.as_ref().map(ConfigPath::render),
Some("defaults.speculative.strategy".to_string())
);
assert!(
diagnostics[0]
.message
.contains("defaults.speculative.strategy must be one of")
);
}

#[test]
fn legacy_validation_errors_derive_compatible_string_messages() {
let config: MeshConfig = toml::from_str(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ mod tests {
source_model_bytes: Some(42),
layer_count: 2,
activation_width: 4096,
generation: None,
projector_path: None,
layers: vec![StagePackageLayerInfo {
layer_index: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) struct StageDeploymentContext<'a> {
pub(crate) kv_cache: KvCachePolicy,
pub(crate) flash_attn_type: FlashAttentionType,
pub(crate) projector_path: Option<String>,
pub(crate) native_mtp_enabled: bool,
}

pub(crate) fn remote_stage_load_request(
Expand Down Expand Up @@ -57,6 +58,7 @@ pub(crate) fn remote_stage_load_request(
cache_type_k: context.kv_cache.cache_type_k().to_string(),
cache_type_v: context.kv_cache.cache_type_v().to_string(),
flash_attn_type: context.flash_attn_type,
native_mtp_enabled: context.native_mtp_enabled,
shutdown_generation: 1,
coordinator_term: 0,
coordinator_id: None,
Expand Down Expand Up @@ -105,6 +107,7 @@ pub(crate) fn stage0_config(
filter_tensors_on_load: true,
selected_device,
kv_cache: None,
native_mtp_enabled: context.native_mtp_enabled,
load_mode: LoadMode::LayerPackage,
bind_addr: "127.0.0.1:0".to_string(),
upstream: None,
Expand Down Expand Up @@ -200,6 +203,7 @@ mod tests {
source_model_bytes: Some(100),
layer_count: 4,
activation_width: 1024,
generation: None,
projector_path: Some("/tmp/package/projectors/mmproj.gguf".to_string()),
layers: vec![StagePackageLayerInfo {
layer_index: 0,
Expand Down Expand Up @@ -230,6 +234,7 @@ mod tests {
kv_cache: KvCachePolicy::for_model_size(0),
flash_attn_type: FlashAttentionType::Auto,
projector_path: Some("/models/mmproj.gguf".to_string()),
native_mtp_enabled: false,
};
let request = remote_stage_load_request(
&context,
Expand All @@ -254,6 +259,7 @@ mod tests {
);
assert_eq!((request.layer_start, request.layer_end), (4, 8));
assert!(request.projector_path.is_none());
assert!(!request.native_mtp_enabled);

let stage0 = stage0_config(
&context,
Expand All @@ -280,5 +286,6 @@ mod tests {
stage0.projector_path.as_deref(),
Some("/models/mmproj.gguf")
);
assert!(!stage0.native_mtp_enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ mod tests {
filter_tensors_on_load: false,
selected_device: None,
kv_cache: None,
native_mtp_enabled: true,
load_mode: LoadMode::RuntimeSlice,
bind_addr: "127.0.0.1:0".to_string(),
upstream: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use hf_hub::progress::{DownloadEvent, Progress, ProgressEvent, ProgressHandler};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use skippy_protocol::{LoadMode, StageConfig};
use skippy_runtime::package::PackageGenerationInfo;
use skippy_runtime::package::{
self, LayerPackageInfo, PackageIntegrityOptions, PackageStageRequest,
};
Expand Down Expand Up @@ -92,6 +93,7 @@ pub struct StagePackageInfo {
pub source_model_bytes: Option<u64>,
pub layer_count: u32,
pub activation_width: u32,
pub generation: Option<PackageGenerationInfo>,
pub projector_path: Option<String>,
pub layers: Vec<StagePackageLayerInfo>,
}
Expand Down Expand Up @@ -1337,6 +1339,7 @@ fn stage_package_info(package_ref: &str, info: LayerPackageInfo) -> Result<Stage
source_model_bytes: info.source_model_bytes,
layer_count: info.layer_count,
activation_width,
generation: info.generation,
projector_path: info
.projectors
.first()
Expand Down Expand Up @@ -1576,6 +1579,7 @@ mod tests {
cache_type_k: "f16".to_string(),
cache_type_v: "f16".to_string(),
flash_attn_type: FlashAttentionType::Auto,
native_mtp_enabled: true,
shutdown_generation: 1,
coordinator_term: 0,
coordinator_id: None,
Expand Down Expand Up @@ -2085,6 +2089,7 @@ mod tests {
cache_type_k: "f16".to_string(),
cache_type_v: "f16".to_string(),
flash_attn_type: skippy_protocol::FlashAttentionType::Auto,
native_mtp_enabled: true,
shutdown_generation: 0,
coordinator_term: 0,
coordinator_id: None,
Expand Down
8 changes: 8 additions & 0 deletions crates/mesh-llm-host-runtime/src/inference/skippy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub(crate) struct SkippyModelLoadOptions {
pub(crate) projector_path: Option<PathBuf>,
pub(crate) telemetry: SkippyTelemetryOptions,
pub(crate) openai_guardrails: Option<OpenAiGuardrailsConfig>,
pub(crate) native_mtp_enabled: bool,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -238,6 +239,7 @@ impl SkippyModelLoadOptions {
projector_path: None,
telemetry: SkippyTelemetryOptions::off(),
openai_guardrails: Some(OpenAiGuardrailsConfig::disabled_for_skippy()),
native_mtp_enabled: true,
}
}

Expand Down Expand Up @@ -444,6 +446,7 @@ impl SkippyModelHandle {
speculative_window: embedded_args.speculative_window,
adaptive_speculative_window: embedded_args.adaptive_speculative_window,
draft_n_gpu_layers: embedded_args.draft_n_gpu_layers,
native_mtp_enabled: embedded_args.native_mtp_enabled,
activation_width: embedded_args.activation_width,
wire_dtype: embedded_args.wire_dtype,
reply_credit_limit: embedded_args.reply_credit_limit,
Expand Down Expand Up @@ -539,6 +542,7 @@ impl SkippyModelHandle {
speculative_window: embedded_args.speculative_window,
adaptive_speculative_window: embedded_args.adaptive_speculative_window,
draft_n_gpu_layers: embedded_args.draft_n_gpu_layers,
native_mtp_enabled: embedded_args.native_mtp_enabled,
activation_width: embedded_args.activation_width,
wire_dtype: embedded_args.wire_dtype,
reply_credit_limit: embedded_args.reply_credit_limit,
Expand Down Expand Up @@ -710,6 +714,7 @@ impl SkippyModelHandle {
speculative_window: embedded_args.speculative_window,
adaptive_speculative_window: embedded_args.adaptive_speculative_window,
draft_n_gpu_layers: embedded_args.draft_n_gpu_layers,
native_mtp_enabled: embedded_args.native_mtp_enabled,
activation_width: embedded_args.activation_width,
wire_dtype: embedded_args.wire_dtype,
reply_credit_limit: embedded_args.reply_credit_limit,
Expand Down Expand Up @@ -832,6 +837,7 @@ impl SkippyModelHandle {
speculative_window: embedded_args.speculative_window,
adaptive_speculative_window: embedded_args.adaptive_speculative_window,
draft_n_gpu_layers: embedded_args.draft_n_gpu_layers,
native_mtp_enabled: embedded_args.native_mtp_enabled,
activation_width: embedded_args.activation_width,
wire_dtype: embedded_args.wire_dtype,
reply_credit_limit: embedded_args.reply_credit_limit,
Expand Down Expand Up @@ -1054,6 +1060,7 @@ pub(crate) fn single_stage_config(options: &SkippyModelLoadOptions) -> Result<St
filter_tensors_on_load: false,
selected_device: options.selected_device.clone().map(Into::into),
kv_cache: None,
native_mtp_enabled: options.native_mtp_enabled,
load_mode: LoadMode::RuntimeSlice,
bind_addr: "127.0.0.1:0".to_string(),
upstream: None,
Expand Down Expand Up @@ -1236,6 +1243,7 @@ mod tests {
layer_count,
activation_width: 4096,
tensor_count: 100,
generation: None,
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/mesh-llm-host-runtime/src/inference/skippy/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
use anyhow::{Context, Result};
use serde::Serialize;
use sha2::{Digest, Sha256};
use skippy_runtime::package::PackageGenerationInfo;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SkippyPackageIdentity {
Expand All @@ -19,6 +20,7 @@ pub struct SkippyPackageIdentity {
pub layer_count: u32,
pub activation_width: u32,
pub tensor_count: u64,
pub generation: Option<PackageGenerationInfo>,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
Expand Down Expand Up @@ -109,6 +111,7 @@ pub fn synthetic_direct_gguf_package(
layer_count: compact.layer_count,
activation_width: compact.embedding_size,
tensor_count,
generation: None,
})
}

Expand Down Expand Up @@ -328,6 +331,7 @@ pub fn identity_from_layer_package(package_ref: &str) -> Result<SkippyPackageIde
layer_count: info.layer_count,
activation_width,
tensor_count: info.layers.iter().map(|l| l.tensor_count as u64).sum(),
generation: info.generation,
})
}

Expand Down
6 changes: 6 additions & 0 deletions crates/mesh-llm-host-runtime/src/inference/skippy/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ mod support;
mod translation;
mod types;

#[cfg(test)]
mod test_support;

#[cfg(test)]
mod native_mtp_tests;

#[cfg(test)]
mod tests;

Expand Down
Loading
Loading