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

Function create_new_metadata

cake-core/src/utils/split.rs:115–149  ·  view source on GitHub ↗
(
    data_path: &Path,
    reduced: &HashMap<String, Vec<String>>,
)

Source from the content-addressed store, hash-verified

113}
114
115fn 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///

Callers 1

split_modelFunction · 0.85

Calls 4

dtypeMethod · 0.80
to_vecMethod · 0.80
shapeMethod · 0.80
dataMethod · 0.80

Tested by

no test coverage detected