feat(trtllm): check existence of config files

When the required config files are not present, nlohmann/json throws
parsing error, which does not help much for identifying what was wrong.
Check the existence of these files early and return specific error
messages.
This commit is contained in:
Tzu-Yu Lee 2025-05-18 03:25:13 +08:00
parent 987337bf31
commit 56dd0a09e6
2 changed files with 25 additions and 1 deletions

View File

@ -19,4 +19,8 @@ pub enum TensorRtLlmBackendError {
WebServer(#[from] server::WebServerError),
#[error("Tokio runtime failed to start: {0}")]
Tokio(#[from] std::io::Error),
#[error("config.json doesn't exist in engine folder {0}")]
ConfigNotFound(PathBuf),
#[error("generation_config.json doesn't exist in engine folder {0}")]
GenerationConfigNotFound(PathBuf),
}

View File

@ -3,7 +3,7 @@ use cxx::UniquePtr;
use hashbrown::HashMap;
use std::hint;
use std::ops::Deref;
use std::path::Path;
use std::path::{Path, PathBuf};
use tokenizers::Tokenizer;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
use tokio::sync::TryAcquireError;
@ -283,6 +283,26 @@ fn ensure_paths_exist<P: AsRef<Path>, PP: AsRef<Path>>(
return Err(err);
}
let mut config_path = PathBuf::from(engine_folder);
config_path.push("config.json");
if !config_path.exists() {
let err = TensorRtLlmBackendError::ConfigNotFound(engine_folder.to_path_buf());
error!("Path validation failed: {}", err,);
return Err(err);
}
let mut generation_config_path = PathBuf::from(engine_folder);
generation_config_path.push("generation_config.json");
if !generation_config_path.exists() {
let err = TensorRtLlmBackendError::GenerationConfigNotFound(engine_folder.to_path_buf());
error!("Path validation failed: {}", err,);
return Err(err);
}
// Ensure executor worker binary exists
if !executor_worker_path.exists() {
let err = TensorRtLlmBackendError::ExecutorWorkerNotFound(engine_folder.to_path_buf());