diff options
author | Laurent Mazare <laurent.mazare@gmail.com> | 2023-09-24 11:18:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-24 11:18:17 +0100 |
commit | 4aeb44901752022b0b22ee39fba146ece908ebe7 (patch) | |
tree | 2cb30a3a01126f4354ebf1b0b97bff27c653d4ff | |
parent | bcb0ed8f1c8982339ed78fe41dcd75521df90305 (diff) | |
download | candle-4aeb44901752022b0b22ee39fba146ece908ebe7.tar.gz candle-4aeb44901752022b0b22ee39fba146ece908ebe7.tar.bz2 candle-4aeb44901752022b0b22ee39fba146ece908ebe7.zip |
Depreate the VarBuilder::from_safetensors function. (#951)
-rw-r--r-- | candle-nn/src/var_builder.rs | 8 | ||||
-rw-r--r-- | candle-wasm-examples/segment-anything/src/bin/m.rs | 5 |
2 files changed, 8 insertions, 5 deletions
diff --git a/candle-nn/src/var_builder.rs b/candle-nn/src/var_builder.rs index 27cbb636..6e143615 100644 --- a/candle-nn/src/var_builder.rs +++ b/candle-nn/src/var_builder.rs @@ -1,6 +1,6 @@ //! A `VarBuilder` is used to retrieve variables used by a model. These variables can either come -//! from a pre-trained checkpoint, e.g. using `VarBuilder::from_safetensors`, or initialized for -//! training, e.g. using `VarBuilder::from_varmap`. +//! from a pre-trained checkpoint, e.g. using `VarBuilder::from_mmaped_safetensors`, or initialized +//! for training, e.g. using `VarBuilder::from_varmap`. use crate::VarMap; use candle::{safetensors::Load, DType, Device, Error, Result, Shape, Tensor}; use safetensors::{slice::IndexOp, tensor::SafeTensors}; @@ -414,6 +414,10 @@ impl<'a> VarBuilder<'a> { /// Initializes a `VarBuilder` that retrieves tensors stored in a collection of safetensors /// data. + #[deprecated( + since = "0.2.3", + note = "use from_mmaped_safetensors or from_buffered_safetensors instead" + )] pub fn from_safetensors(safetensors: Vec<SafeTensors<'a>>, dtype: DType, dev: &Device) -> Self { let mut routing = HashMap::new(); for (index, sf) in safetensors.iter().enumerate() { diff --git a/candle-wasm-examples/segment-anything/src/bin/m.rs b/candle-wasm-examples/segment-anything/src/bin/m.rs index 5140b979..acd903b0 100644 --- a/candle-wasm-examples/segment-anything/src/bin/m.rs +++ b/candle-wasm-examples/segment-anything/src/bin/m.rs @@ -21,11 +21,10 @@ pub struct Model { #[wasm_bindgen] impl Model { #[wasm_bindgen(constructor)] - pub fn new(weights: &[u8], use_tiny: bool) -> Result<Model, JsError> { + pub fn new(weights: Vec<u8>, use_tiny: bool) -> Result<Model, JsError> { console_error_panic_hook::set_once(); let dev = &Device::Cpu; - let weights = safetensors::tensor::SafeTensors::deserialize(weights)?; - let vb = VarBuilder::from_safetensors(vec![weights], DType::F32, dev); + let vb = VarBuilder::from_buffered_safetensors(weights, DType::F32, dev)?; let sam = if use_tiny { sam::Sam::new_tiny(vb)? // tiny vit_t } else { |