From 56dd0a09e6229bd4ce73f1f450886f8cde6af0d4 Mon Sep 17 00:00:00 2001 From: Tzu-Yu Lee Date: Sun, 18 May 2025 03:25:13 +0800 Subject: [PATCH] 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. --- backends/trtllm/src/errors.rs | 4 ++++ backends/trtllm/src/looper.rs | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/backends/trtllm/src/errors.rs b/backends/trtllm/src/errors.rs index 812fd6e3..3e6bd743 100644 --- a/backends/trtllm/src/errors.rs +++ b/backends/trtllm/src/errors.rs @@ -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), } diff --git a/backends/trtllm/src/looper.rs b/backends/trtllm/src/looper.rs index 6d7f30c3..17030b21 100644 --- a/backends/trtllm/src/looper.rs +++ b/backends/trtllm/src/looper.rs @@ -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, PP: AsRef>( 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());