Add backtrace information to errors where relevant. (#166)

* Add backtrace information to errors where relevant.

* More backtrace information.

* Add to the FAQ.
This commit is contained in:
Laurent Mazare
2023-07-14 09:31:25 +01:00
committed by GitHub
parent a2f72edc0d
commit d88b6cdca9
11 changed files with 153 additions and 73 deletions

View File

@ -146,19 +146,28 @@ impl<'a> VarBuilder<'a> {
Tensors::Zeros => Tensor::zeros(&s, data.dtype, &data.device)?.contiguous()?,
Tensors::TensorMap(ts) => ts
.get(&path)
.ok_or_else(|| Error::CannotFindTensor {
path: path.to_string(),
.ok_or_else(|| {
Error::CannotFindTensor {
path: path.to_string(),
}
.bt()
})?
.clone(),
Tensors::Npz(npz) => npz.get(&path)?.ok_or_else(|| Error::CannotFindTensor {
path: path.to_string(),
Tensors::Npz(npz) => npz.get(&path)?.ok_or_else(|| {
Error::CannotFindTensor {
path: path.to_string(),
}
.bt()
})?,
Tensors::SafeTensorWithRouting {
routing,
safetensors,
} => {
let index = routing.get(&path).ok_or_else(|| Error::CannotFindTensor {
path: path.to_string(),
let index = routing.get(&path).ok_or_else(|| {
Error::CannotFindTensor {
path: path.to_string(),
}
.bt()
})?;
safetensors[*index]
.tensor(&path, &data.device)?
@ -170,7 +179,8 @@ impl<'a> VarBuilder<'a> {
msg: format!("shape mismatch for {path}"),
expected: s,
got: tensor.shape().clone(),
})?
}
.bt())?
}
Ok(tensor)
}