candle
candle copied to clipboard
feat: Return Cow on CpuStorage
Return a Cow from to_cpu_storage to avoid unnecessary copy.
Address one of the issues in https://github.com/huggingface/candle/issues/1699
@LaurentMazare Could I get a review on this small MR?
Would you mind adding some benchmarks to show how much this improves on GPU model loading, ideally with the details of the config this was run on? This would be helpful to check how much of an improvement this would actually bring.
@LaurentMazare Sure, I will work on that.
cargo build fails for me on
command: cargo build --features metal
error[E0053]: method `to_cpu_storage` has an incompatible type for trait
--> candle-core/src/metal_backend.rs:327:33
|
327 | fn to_cpu_storage(&self) -> Result<CpuStorage> {
| ^^^^^^^^^^^^^^^^^^
| |
| expected `Cow<'_, CpuStorage>`, found `CpuStorage`
| help: change the output type to match the trait: `std::result::Result<Cow<'_, CpuStorage>, error::Error>`
|
note: type in trait
--> candle-core/src/backend.rs:14:33
|
14 | fn to_cpu_storage(&self) -> Result<Cow<'_, CpuStorage>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected signature `fn(&metal_backend::MetalStorage) -> std::result::Result<Cow<'_, CpuStorage, >, _>`
found signature `fn(&metal_backend::MetalStorage) -> std::result::Result<CpuStorage, _>`
For more information about this error, try `rustc --explain E0053`.
error: could not compile `candle-core` (lib) due to previous error
perhaps the changes need to be also implemented in metal (and cude backends)?
@aorticweb Thanks. This is fixed now.