mirror of
https://github.com/huggingface/candle.git
synced 2025-06-17 02:58:50 +00:00
Fixing unsafe slow load (memcpy).
- Without the annotation, I think the rust compiler assumes it's all u8. It did segfault trying to load `Roberta`.
This commit is contained in:
@ -71,7 +71,7 @@ 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 {
|
||||
let mut c = Vec::with_capacity(elem_count);
|
||||
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.
|
||||
// We're downgrading the `c` pointer from T to u8, which removes alignment
|
||||
|
Reference in New Issue
Block a user