MCPcopy Create free account
hub / github.com/evilsocket/cake / load_var_builder_from_index

Function load_var_builder_from_index

cake-core/src/utils/mod.rs:251–267  ·  view source on GitHub ↗

Create a VarBuilder with the tensors loaded from the index.

(
    tensor_index: PathBuf,
    dtype: DType,
    device: Device,
    quant: &dyn Quantization,
)

Source from the content-addressed store, hash-verified

249
250/// Create a VarBuilder with the tensors loaded from the index.
251pub fn load_var_builder_from_index<'a>(
252 tensor_index: PathBuf,
253 dtype: DType,
254 device: Device,
255 quant: &dyn Quantization,
256) -> Result<VarBuilder<'a>> {
257 let filenames: Vec<std::path::PathBuf> = if tensor_index.exists() {
258 load_safetensors_paths_from_index(tensor_index)
259 .map_err(|e| anyhow!("can't load tensors index: {:?}", e))?
260 } else {
261 load_safetensors_from_model(tensor_index.parent().unwrap())
262 .map_err(|e| anyhow!("can't load tensors index: {:?}", e))?
263 };
264
265 prefetch_safetensors(&filenames)?;
266 unsafe { quant.load_var_builder(&filenames, dtype, &device) }
267}
268
269/// Create a VarBuilder that only loads safetensors shards needed for the given
270/// local layers. Shards containing only remote-worker tensors are excluded,

Callers 3

from_argsMethod · 0.85

Calls 4

prefetch_safetensorsFunction · 0.85
load_var_builderMethod · 0.80

Tested by

no test coverage detected