fix: resolve all P1 hardcoded model paths at runtime (A-4.2 P1)

Issues: 6 P1 locations with hardcoded model paths
- asr.rs:81 - whisper model
- scene_classification.rs:68 - resnet18 model
- qwen_vl_manager.rs:25,26 - Qwen model + mmproj
- rust_vad.rs:18 - silero_vad model
- facenet_embedding.swift:24 - already fixed (A-11)

Impact: Missing models cause silent degradation (A-12)
        No embeddings → TKG 0 nodes (020.mp4 root cause)

Solution: Use path_utils::resolve_asset_path for all model paths
- Resolves via MOMENTRY_MODELS_DIR env var
- Falls back to current_exe sibling
- Final fallback to models/ directory

Changes:
1. asr.rs: Resolve whisper model dir
2. scene_classification.rs: Resolve resnet18 model path
3. qwen_vl_manager.rs: Resolve Qwen model + mmproj paths
4. rust_vad.rs: Resolve silero_vad model via env or relative

Benefits:
- All P1 models now configurable via MOMENTRY_MODELS_DIR
- No more silent failures when models missing
- Models can be placed in release bundle

Verification:
- cargo check --lib passes
- cargo build --release --bin rust_vad passes

Next steps: Address P2 (41 locations) and P3 (35 locations)

References:
- A-4.2 P1 in Momentry_Release_Requirements_20261004.md v1.1
- A-11, A-12
- G-3 gate condition
This commit is contained in:
Accusys
2026-10-04 15:59:56 +08:00
parent 0d11c60163
commit 2f5e2c1314
4 changed files with 35 additions and 9 deletions
+20 -3
View File
@@ -15,7 +15,7 @@ struct Cli {
audio: String,
/// ONNX model path
#[arg(long, default_value = "/Users/accusys/models/silero_vad.onnx")]
#[arg(long, default_value = "")]
model: String,
/// Speech probability threshold
@@ -42,9 +42,26 @@ struct Cli {
fn main() -> Result<()> {
let cli = Cli::parse();
println!("[VAD] Loading model: {}", cli.model);
// Resolve model path if not provided
let model_path = if cli.model.is_empty() {
std::env::var("MOMENTRY_MODELS_DIR")
.map(|d| std::path::PathBuf::from(d).join("silero_vad.onnx"))
.unwrap_or_else(|_| {
// Try relative to current exe
std::env::current_exe()
.ok()
.and_then(|p| p.parent().map(|d| d.join("models/silero_vad.onnx")))
.unwrap_or_else(|| std::path::PathBuf::from("models/silero_vad.onnx"))
})
.to_string_lossy()
.to_string()
} else {
cli.model
};
println!("[VAD] Loading model: {}", model_path);
let start_load = Instant::now();
let mut vad = SileroVad::new(&cli.model)?;
let mut vad = SileroVad::new(&model_path)?;
println!("[VAD] Model loaded in {:.2}s", start_load.elapsed().as_secs_f32());
println!("[VAD] Loading audio: {}", cli.audio);
+5 -1
View File
@@ -74,11 +74,15 @@ pub async fn process_asr(
.parent()
.context("Invalid output path")?;
// Resolve whisper model directory
let models_dir = crate::core::path_utils::resolve_asset_path("MOMENTRY_MODELS_DIR", "models");
let whisper_model_dir = models_dir.join("whisper-small-mlx");
let output = tokio::process::Command::new(whisper_cli)
.args(&[
video_path,
"--model", "small",
"--model_dir", "/Users/accusys/models/whisper-small-mlx",
"--model_dir", whisper_model_dir.to_str().unwrap(),
"--output_dir", output_dir.to_str().unwrap(),
"--output_format", "json",
"--verbose", "False",
+6 -3
View File
@@ -65,11 +65,14 @@ pub async fn process_scene_classification(
});
}
let coreml_path = "/Users/accusys/models/resnet18_places365.mlpackage";
// Resolve scene classification model path
let models_dir = crate::core::path_utils::resolve_asset_path("MOMENTRY_MODELS_DIR", "models");
let coreml_path = models_dir.join("resnet18_places365.mlpackage");
let mut args = vec![video_path, output_path];
if std::path::Path::new(coreml_path).exists() {
if coreml_path.exists() {
args.push("--model");
args.push(coreml_path);
args.push(coreml_path.to_str().unwrap());
}
executor
+4 -2
View File
@@ -20,10 +20,12 @@ pub struct QwenVLManager {
impl QwenVLManager {
pub fn new() -> Self {
let models_dir = crate::core::path_utils::resolve_asset_path("MOMENTRY_MODELS_DIR", "models");
Self {
port: 8086,
model_path: PathBuf::from("/Users/accusys/models/Qwen3VL-8B-Instruct-Q8_0.gguf"),
mmproj_path: PathBuf::from("/Users/accusys/models/mmproj-Qwen3VL-8B-Instruct-F16.gguf"),
model_path: models_dir.join("Qwen3VL-8B-Instruct-Q8_0.gguf"),
mmproj_path: models_dir.join("mmproj-Qwen3VL-8B-Instruct-F16.gguf"),
log_file: PathBuf::from("logs/qwen3vl_8086.log"),
pid_file: PathBuf::from("/tmp/qwen3vl.pid"),
start_script: PathBuf::from("scripts/start_qwen3vl.sh"),