Keep runtime files inside application support
This commit is contained in:
@@ -2687,7 +2687,7 @@ impl Session {
|
||||
// `session` must release every Buffer before `_context` calls ds4_gpu_cleanup(),
|
||||
// and `_context` must drop before `model` unmaps memory wrapped without copying
|
||||
// by native/metal/ds4_metal.m:10329. This intentionally differs from
|
||||
// ../ds4/ds4.c:56287-56288; do not reorder these fields to match it.
|
||||
// DS4's `ds4.c` consumes this exact field order; do not reorder it.
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub(super) struct ExecutionStats {
|
||||
pub(super) speculative_mode: u8,
|
||||
@@ -7068,6 +7068,14 @@ mod tests {
|
||||
};
|
||||
use crate::engine::{FLASH, PRO};
|
||||
|
||||
fn installed_artifacts(
|
||||
model: crate::model::ModelChoice,
|
||||
legacy_mtp: bool,
|
||||
dspark: bool,
|
||||
) -> crate::model::EngineArtifacts {
|
||||
crate::model::engine_artifacts(model, legacy_mtp, dspark, &crate::app::models_path())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compression_schedule_tracks_the_deepseek_model_shape() {
|
||||
assert_eq!(compression_ratio(FLASH, 0), 0);
|
||||
@@ -7165,16 +7173,14 @@ mod tests {
|
||||
use crate::settings::{
|
||||
EngineSpeculativeSettings, EngineSsdSettings, EngineSteeringSettings,
|
||||
};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
let main_path = Path::new(
|
||||
"../ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf",
|
||||
);
|
||||
let artifacts = installed_artifacts(ModelChoice::DeepSeekV4Flash, true, false);
|
||||
let main_path = artifacts.model;
|
||||
configure_sources().unwrap();
|
||||
let support_path = Path::new("../ds4/gguf/DeepSeek-V4-Flash-MTP-Q4K-Q8_0-F32.gguf");
|
||||
let mut model = Model::open_main(main_path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let support = Gguf::open(support_path).unwrap();
|
||||
let support_path = artifacts.mtp.unwrap();
|
||||
let mut model = Model::open_main(&main_path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let support = Gguf::open(&support_path).unwrap();
|
||||
model.support_kind = Some(validate_support(&support, &model.shape).unwrap());
|
||||
model.support = Some(support);
|
||||
let prompt = model.render_conversation(
|
||||
@@ -7304,16 +7310,14 @@ mod tests {
|
||||
use crate::settings::{
|
||||
EngineSpeculativeSettings, EngineSsdSettings, EngineSteeringSettings,
|
||||
};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
configure_sources().unwrap();
|
||||
let main_path = Path::new(
|
||||
"../ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf",
|
||||
);
|
||||
let support_path = Path::new("../ds4/gguf/DeepSeek-V4-Flash-DSpark-support.gguf");
|
||||
let mut model = Model::open_main(main_path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let support = Gguf::open(support_path).unwrap();
|
||||
let artifacts = installed_artifacts(ModelChoice::DeepSeekV4Flash, false, true);
|
||||
let main_path = artifacts.model;
|
||||
let support_path = artifacts.mtp.unwrap();
|
||||
let mut model = Model::open_main(&main_path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let support = Gguf::open(&support_path).unwrap();
|
||||
model.support_kind = Some(validate_support(&support, &model.shape).unwrap());
|
||||
model.support = Some(support);
|
||||
let prompt = model.render_conversation(
|
||||
@@ -7446,24 +7450,19 @@ mod tests {
|
||||
use crate::settings::{
|
||||
EngineSpeculativeSettings, EngineSsdSettings, EngineSteeringSettings,
|
||||
};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
configure_sources().unwrap();
|
||||
let main_path = Path::new(
|
||||
"../ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf",
|
||||
);
|
||||
let legacy = installed_artifacts(ModelChoice::DeepSeekV4Flash, true, false);
|
||||
let dspark_artifacts = installed_artifacts(ModelChoice::DeepSeekV4Flash, false, true);
|
||||
let main_path = legacy.model;
|
||||
let cases = [
|
||||
(
|
||||
"../ds4/gguf/DeepSeek-V4-Flash-MTP-Q4K-Q8_0-F32.gguf",
|
||||
false,
|
||||
4,
|
||||
),
|
||||
("../ds4/gguf/DeepSeek-V4-Flash-DSpark-support.gguf", true, 1),
|
||||
(legacy.mtp.unwrap(), false, 4),
|
||||
(dspark_artifacts.mtp.unwrap(), true, 1),
|
||||
];
|
||||
for (support_path, dspark, draft_tokens) in cases {
|
||||
let mut model = Model::open_main(main_path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let support = Gguf::open(Path::new(support_path)).unwrap();
|
||||
let mut model = Model::open_main(&main_path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let support = Gguf::open(&support_path).unwrap();
|
||||
model.support_kind = Some(validate_support(&support, &model.shape).unwrap());
|
||||
model.support = Some(support);
|
||||
let prompt = model.render_conversation(
|
||||
@@ -7528,7 +7527,8 @@ mod tests {
|
||||
assert_eq!(
|
||||
generated,
|
||||
[19_923, 3, 1_730, 588, 342, 1_694, 440, 4_316],
|
||||
"SSD speculative output differed for {support_path}"
|
||||
"SSD speculative output differed for {}",
|
||||
support_path.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -7604,12 +7604,10 @@ mod tests {
|
||||
}
|
||||
|
||||
configure_sources().unwrap();
|
||||
let path = Path::new(
|
||||
"../ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf",
|
||||
);
|
||||
let resident = run(path, false);
|
||||
let path = installed_artifacts(ModelChoice::DeepSeekV4Flash, false, false).model;
|
||||
let resident = run(&path, false);
|
||||
assert_eq!(resident, [19_923, 3, 1_730, 588]);
|
||||
assert_eq!(resident, run(path, true));
|
||||
assert_eq!(resident, run(&path, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -7621,16 +7619,10 @@ mod tests {
|
||||
use crate::settings::{
|
||||
EngineSpeculativeSettings, EngineSsdSettings, EngineSteeringSettings,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
configure_sources().unwrap();
|
||||
let model = Model::open_main(
|
||||
Path::new(
|
||||
"../ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf",
|
||||
),
|
||||
ModelChoice::DeepSeekV4Flash,
|
||||
)
|
||||
.unwrap();
|
||||
let path = installed_artifacts(ModelChoice::DeepSeekV4Flash, false, false).model;
|
||||
let model = Model::open_main(&path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let prompt = model.render_conversation(
|
||||
"",
|
||||
&[crate::engine::ChatTurn {
|
||||
@@ -7690,16 +7682,10 @@ mod tests {
|
||||
use crate::settings::{
|
||||
EngineSpeculativeSettings, EngineSsdSettings, EngineSteeringSettings, ReasoningMode,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
configure_sources().unwrap();
|
||||
let model = Model::open_main(
|
||||
Path::new(
|
||||
"../ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf",
|
||||
),
|
||||
ModelChoice::DeepSeekV4Flash,
|
||||
)
|
||||
.unwrap();
|
||||
let path = installed_artifacts(ModelChoice::DeepSeekV4Flash, false, false).model;
|
||||
let model = Model::open_main(&path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let prompts = ["Reply with A.", "Reply with B."].map(|content| {
|
||||
model.render_conversation(
|
||||
"",
|
||||
@@ -7775,19 +7761,17 @@ mod tests {
|
||||
use crate::settings::{
|
||||
EngineSpeculativeSettings, EngineSsdSettings, EngineSteeringSettings,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
configure_sources().unwrap();
|
||||
let model_path = Path::new(
|
||||
"../ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf",
|
||||
);
|
||||
let steering_path = "../ds4/dir-steering/out/verbosity.f32";
|
||||
let model_path = installed_artifacts(ModelChoice::DeepSeekV4Flash, false, false).model;
|
||||
let steering_path = std::env::var("DS4_STEERING_FILE")
|
||||
.expect("set DS4_STEERING_FILE to the DS4 verbosity direction fixture");
|
||||
let cases = [
|
||||
(1.0, 0.0, [19_923, 3, 1_730, 588, 342, 8_233, 440, 4_316]),
|
||||
(0.0, 1.0, [19_923, 3, 1_730, 588, 342, 1_694, 440, 4_316]),
|
||||
];
|
||||
for (ffn_scale, attention_scale, expected) in cases {
|
||||
let model = Model::open_main(model_path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let model = Model::open_main(&model_path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let prompt = model.render_conversation(
|
||||
"",
|
||||
&[crate::engine::ChatTurn {
|
||||
@@ -7827,7 +7811,7 @@ mod tests {
|
||||
preload_experts: 0,
|
||||
},
|
||||
EngineSteeringSettings {
|
||||
file: Some(steering_path.into()),
|
||||
file: Some(steering_path.clone()),
|
||||
ffn_scale,
|
||||
attention_scale,
|
||||
},
|
||||
@@ -7853,18 +7837,15 @@ mod tests {
|
||||
use crate::settings::{
|
||||
EngineSpeculativeSettings, EngineSsdSettings, EngineSteeringSettings,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
configure_sources().unwrap();
|
||||
let path = std::env::var("DS4_PRO_MODEL").unwrap_or_else(|_| {
|
||||
"../ds4/models/DeepSeek-V4-Pro-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-Instruct-imatrix.gguf".into()
|
||||
});
|
||||
if !Path::new(&path).is_file() {
|
||||
eprintln!("skipping unavailable Pro fixture: {path}");
|
||||
let path = installed_artifacts(ModelChoice::DeepSeekV4Pro, false, false).model;
|
||||
if !path.is_file() {
|
||||
eprintln!("skipping unavailable Pro fixture: {}", path.display());
|
||||
return;
|
||||
}
|
||||
let run = |cache_experts| {
|
||||
let model = Model::open_main(Path::new(&path), ModelChoice::DeepSeekV4Pro).unwrap();
|
||||
let model = Model::open_main(&path, ModelChoice::DeepSeekV4Pro).unwrap();
|
||||
let prompt = model.render_conversation(
|
||||
"",
|
||||
&[crate::engine::ChatTurn {
|
||||
|
||||
@@ -3221,7 +3221,11 @@ mod tests {
|
||||
use crate::engine::{GLM, Model, ReasoningMode};
|
||||
use crate::model::ModelChoice;
|
||||
use crate::settings::EngineSsdSettings;
|
||||
use std::path::Path;
|
||||
|
||||
fn installed_glm_path() -> std::path::PathBuf {
|
||||
crate::model::engine_artifacts(ModelChoice::Glm52, false, false, &crate::app::models_path())
|
||||
.model
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dsa_indexer_schedule_matches_the_reference() {
|
||||
@@ -3258,16 +3262,14 @@ mod tests {
|
||||
#[test]
|
||||
#[ignore = "requires the 197 GiB GLM 5.2 checkpoint and Apple Metal"]
|
||||
fn resident_and_streamed_glm_match_ds4_decode_oracles() {
|
||||
let path = std::env::var("DS4_GLM_MODEL").unwrap_or_else(|_| {
|
||||
"../ds4/models/GLM-5.2-UD-IQ2_XXS_RoutedIQ2XXS_blk78Q2K.gguf".into()
|
||||
});
|
||||
if !Path::new(&path).is_file() {
|
||||
eprintln!("skipping unavailable GLM fixture: {path}");
|
||||
let path = installed_glm_path();
|
||||
if !path.is_file() {
|
||||
eprintln!("skipping unavailable GLM fixture: {}", path.display());
|
||||
return;
|
||||
}
|
||||
let prompt = b"Complete the C statement with the next exact token only:\nreturn snprintf(buf, sizeof(buf), \"%d\", value";
|
||||
for streamed in [false, true] {
|
||||
let model = Model::open_main(Path::new(&path), ModelChoice::Glm52).unwrap();
|
||||
let model = Model::open_main(&path, ModelChoice::Glm52).unwrap();
|
||||
let tokens = model.tokenize(std::str::from_utf8(prompt).unwrap());
|
||||
let executor = GlmExecutor::open(
|
||||
model,
|
||||
@@ -3329,15 +3331,13 @@ mod tests {
|
||||
#[test]
|
||||
#[ignore = "requires the 197 GiB GLM 5.2 checkpoint and Apple Metal"]
|
||||
fn streamed_glm_uses_ds4_indexed_prefill_for_long_prompts() {
|
||||
let path = std::env::var("DS4_GLM_MODEL").unwrap_or_else(|_| {
|
||||
"../ds4/models/GLM-5.2-UD-IQ2_XXS_RoutedIQ2XXS_blk78Q2K.gguf".into()
|
||||
});
|
||||
if !Path::new(&path).is_file() {
|
||||
eprintln!("skipping unavailable GLM fixture: {path}");
|
||||
let path = installed_glm_path();
|
||||
if !path.is_file() {
|
||||
eprintln!("skipping unavailable GLM fixture: {}", path.display());
|
||||
return;
|
||||
}
|
||||
let prompt = "Complete each C statement. Example: return snprintf(buf, sizeof(buf), \"%d\", value); Example: return snprintf(buf, sizeof(buf), \"%d\", value); Example: return snprintf(buf, sizeof(buf), \"%d\", value); Example: return snprintf(buf, sizeof(buf), \"%d\", value); Example: return snprintf(buf, sizeof(buf), \"%d\", value); Now complete exactly: return snprintf(buf, sizeof(buf), \"%d\", value";
|
||||
let model = Model::open_main(Path::new(&path), ModelChoice::Glm52).unwrap();
|
||||
let model = Model::open_main(&path, ModelChoice::Glm52).unwrap();
|
||||
let tokens =
|
||||
model.render_prompt("You are a helpful assistant", prompt, ReasoningMode::Direct);
|
||||
assert_eq!(tokens.len(), 102);
|
||||
@@ -3382,15 +3382,13 @@ mod tests {
|
||||
use crate::settings::EngineSpeculativeSettings;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
|
||||
let path = std::env::var("DS4_GLM_MODEL").unwrap_or_else(|_| {
|
||||
"../ds4/models/GLM-5.2-UD-IQ2_XXS_RoutedIQ2XXS_blk78Q2K.gguf".into()
|
||||
});
|
||||
if !Path::new(&path).is_file() {
|
||||
eprintln!("skipping unavailable GLM fixture: {path}");
|
||||
let path = installed_glm_path();
|
||||
if !path.is_file() {
|
||||
eprintln!("skipping unavailable GLM fixture: {}", path.display());
|
||||
return;
|
||||
}
|
||||
let run = |enabled| {
|
||||
let model = Model::open_main(Path::new(&path), ModelChoice::Glm52).unwrap();
|
||||
let model = Model::open_main(&path, ModelChoice::Glm52).unwrap();
|
||||
let tokens = model.tokenize("Write one short greeting.");
|
||||
let mut executor = GlmExecutor::open_profile(
|
||||
model,
|
||||
|
||||
@@ -1019,13 +1019,17 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn installed_ds4_fixture_opens_and_renders_a_prompt() {
|
||||
let path = Path::new(
|
||||
"../ds4/gguf/DeepSeek-V4-Flash-IQ2XXS-w2Q2K-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix.gguf",
|
||||
);
|
||||
let path = crate::model::engine_artifacts(
|
||||
ModelChoice::DeepSeekV4Flash,
|
||||
false,
|
||||
false,
|
||||
&crate::app::models_path(),
|
||||
)
|
||||
.model;
|
||||
if !path.exists() {
|
||||
return;
|
||||
}
|
||||
let model = Model::open_main(path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let model = Model::open_main(&path, ModelChoice::DeepSeekV4Flash).unwrap();
|
||||
let summary = model.summary();
|
||||
assert_eq!(summary.model, ModelChoice::DeepSeekV4Flash);
|
||||
assert_eq!(summary.vocabulary_size, 129_280);
|
||||
@@ -1223,18 +1227,32 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn installed_dspark_fixture_passes_the_target_layout() {
|
||||
let path = Path::new("../ds4/gguf/DeepSeek-V4-Flash-DSpark-support.gguf");
|
||||
let path = crate::model::engine_artifacts(
|
||||
ModelChoice::DeepSeekV4Flash,
|
||||
false,
|
||||
true,
|
||||
&crate::app::models_path(),
|
||||
)
|
||||
.mtp
|
||||
.unwrap();
|
||||
if path.exists() {
|
||||
validate_model_artifact(path, ModelChoice::DeepSeekV4Flash, true).unwrap();
|
||||
validate_model_artifact(&path, ModelChoice::DeepSeekV4Flash, true).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn installed_legacy_mtp_fixture_passes_the_target_layout() {
|
||||
let path = Path::new("../ds4/gguf/DeepSeek-V4-Flash-MTP-Q4K-Q8_0-F32.gguf");
|
||||
let path = crate::model::engine_artifacts(
|
||||
ModelChoice::DeepSeekV4Flash,
|
||||
true,
|
||||
false,
|
||||
&crate::app::models_path(),
|
||||
)
|
||||
.mtp
|
||||
.unwrap();
|
||||
if path.exists() {
|
||||
assert_eq!(
|
||||
validate_support(&Gguf::open(path).unwrap(), &FLASH).unwrap(),
|
||||
validate_support(&Gguf::open(&path).unwrap(), &FLASH).unwrap(),
|
||||
SupportKind::LegacyMtp
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user