Create a VarBuilder with the tensors loaded from the index.
(
tensor_index: PathBuf,
dtype: DType,
device: Device,
quant: &dyn Quantization,
)
| 249 | |
| 250 | /// Create a VarBuilder with the tensors loaded from the index. |
| 251 | pub 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, |
no test coverage detected