Build from a single safetensors file (non-sharded model).
(path: &Path)
| 365 | |
| 366 | /// Build from a single safetensors file (non-sharded model). |
| 367 | fn from_single_file(path: &Path) -> Result<Self> { |
| 368 | let f = File::open(path)?; |
| 369 | let shard_idx = 0u16; |
| 370 | |
| 371 | // mmap first, then parse header from mmap'd memory (avoids separate read + allocation) |
| 372 | #[cfg(unix)] |
| 373 | let shard = MappedShard::new(&f)?; |
| 374 | #[cfg(unix)] |
| 375 | let (header_len, header) = Self::parse_shard_header_mmap(&shard)?; |
| 376 | #[cfg(not(unix))] |
| 377 | let (header_len, header) = Self::parse_shard_header(path)?; |
| 378 | #[cfg(not(unix))] |
| 379 | let shard = MappedShard::new(f)?; |
| 380 | |
| 381 | let mut index = HashMap::with_capacity(header.len()); |
| 382 | for (name, entry) in header { |
| 383 | if name.starts_with("__") { |
| 384 | continue; |
| 385 | } |
| 386 | if let Some(tm) = Self::parse_tensor_meta(&name, &entry, shard_idx, header_len)? { |
| 387 | index.insert(name, tm); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | let shards = vec![shard]; |
| 392 | |
| 393 | log::info!("SafetensorsStorage: indexed {} tensors from single file", index.len()); |
| 394 | |
| 395 | Ok(Self { index, shards }) |
| 396 | } |
| 397 | |
| 398 | /// Parse a shard file's header from mmap'd data into typed entries. |
| 399 | #[cfg(unix)] |
nothing calls this directly
no outgoing calls
no test coverage detected