Skip to content

Commit 1313b29

Browse files
feat(candle): better cuda error (huggingface#300)
1 parent a6f05a4 commit 1313b29

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

backends/candle/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::models::{
1818
use crate::models::{
1919
FlashBertModel, FlashDistilBertModel, FlashJinaBertModel, FlashNomicBertModel,
2020
};
21+
use anyhow::Context;
2122
use candle::{DType, Device};
2223
use candle_nn::VarBuilder;
2324
use models::BertConfig;
@@ -55,9 +56,11 @@ impl CandleBackend {
5556
) -> Result<Self, BackendError> {
5657
// Load config
5758
let config: String = std::fs::read_to_string(model_path.join("config.json"))
58-
.map_err(|err| BackendError::Start(err.to_string()))?;
59+
.context("Unable to read config file")
60+
.map_err(|err| BackendError::Start(format!("{err:?}")))?;
5961
let config: Config = serde_json::from_str(&config)
60-
.map_err(|err| BackendError::Start(format!("Model is not supported: {}", err)))?;
62+
.context("Model is not supported")
63+
.map_err(|err| BackendError::Start(format!("{err:?}")))?;
6164

6265
// Get candle device
6366
let device = if candle::utils::cuda_is_available() {
@@ -72,7 +75,7 @@ impl CandleBackend {
7275
)))
7376
}
7477
Err(err) => {
75-
tracing::warn!("Could not find a compatible CUDA device on host: {err}");
78+
tracing::warn!("Could not find a compatible CUDA device on host: {err:?}");
7679
tracing::warn!("Using CPU instead");
7780
Ok(Device::Cpu)
7881
}

0 commit comments

Comments
 (0)