Update candle-core/src/safetensors.rs

This commit is contained in:
Nicolas Patry
2023-07-06 23:59:54 +02:00
committed by GitHub
parent 054717e236
commit ce27073feb

View File

@ -71,6 +71,8 @@ fn convert_<T: WithDType>(view: st::TensorView<'_>, device: &Device) -> Result<T
let data: &[T] = unsafe { std::slice::from_raw_parts(v.as_ptr() as *const T, elem_count) };
Tensor::from_slice(data, view.shape(), device)
} else {
// XXX: We need to specify `T` here, otherwise the compiler will infer u8 because of the following cast
// Making this vector too small to fit a full f16/f32/f64 weights, resulting in out-of-bounds access
let mut c: Vec<T> = Vec::with_capacity(elem_count);
// SAFETY: We just created c, so the allocated memory is necessarily
// contiguous and non overlapping with the view's data.