(
data_path: &Path,
reduced: &HashMap<String, Vec<String>>,
)
| 113 | } |
| 114 | |
| 115 | fn create_new_metadata( |
| 116 | data_path: &Path, |
| 117 | reduced: &HashMap<String, Vec<String>>, |
| 118 | ) -> Result<HashMap<String, TensorStore>> { |
| 119 | let mut metadata: HashMap<String, TensorStore> = HashMap::new(); |
| 120 | |
| 121 | for (filename, tensor_names) in reduced { |
| 122 | let filepath = data_path.join(filename); |
| 123 | |
| 124 | log::info!("loading {} ...", filepath.display()); |
| 125 | |
| 126 | let file = File::open(&filepath)?; |
| 127 | let buffer = unsafe { memmap2::MmapOptions::new().map(&file)? }; |
| 128 | let tensors = SafeTensors::deserialize(&buffer)?; |
| 129 | |
| 130 | log::info!(" extracting {} tensors", tensor_names.len()); |
| 131 | |
| 132 | for tensor_name in tensor_names { |
| 133 | let tensor = tensors.tensor(tensor_name)?; |
| 134 | metadata.insert( |
| 135 | tensor_name.to_string(), |
| 136 | TensorStore { |
| 137 | dtype: tensor.dtype(), |
| 138 | shape: tensor.shape().to_vec(), |
| 139 | data: tensor.data().to_vec(), |
| 140 | }, |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | drop(tensors); |
| 145 | drop(buffer); |
| 146 | } |
| 147 | |
| 148 | Ok(metadata) |
| 149 | } |
| 150 | |
| 151 | /// Split a model into per-worker bundles. |
| 152 | /// |
no test coverage detected