MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / load_legacy_imatrix

Function load_legacy_imatrix

tools/quantize/quantize.cpp:184–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184static int load_legacy_imatrix(const std::string & imatrix_file, std::vector<std::string> & imatrix_datasets, std::unordered_map<std::string, std::vector<float>> & imatrix_data) {
185 std::ifstream in(imatrix_file.c_str(), std::ios::binary);
186 if (!in) {
187 printf("%s: failed to open %s\n",__func__, imatrix_file.c_str());
188 exit(1);
189 }
190 int n_entries;
191 in.read((char *)&n_entries, sizeof(n_entries));
192 if (in.fail() || n_entries < 1) {
193 printf("%s: no data in file %s\n", __func__, imatrix_file.c_str());
194 exit(1);
195 }
196 for (int i = 0; i < n_entries; ++i) {
197 int len; in.read((char *)&len, sizeof(len));
198 std::vector<char> name_as_vec(len+1);
199 in.read((char *)name_as_vec.data(), len);
200 if (in.fail()) {
201 printf("%s: failed reading name for entry %d from %s\n", __func__, i+1, imatrix_file.c_str());
202 exit(1);
203 }
204 name_as_vec[len] = 0;
205 std::string name{name_as_vec.data()};
206 auto & e = imatrix_data[name];
207 int ncall;
208 in.read((char *)&ncall, sizeof(ncall));
209 int nval;
210 in.read((char *)&nval, sizeof(nval));
211 if (in.fail() || nval < 1) {
212 printf("%s: failed reading number of values for entry %d\n", __func__, i);
213 imatrix_data = {};
214 exit(1);
215 }
216 e.resize(nval);
217 in.read((char *)e.data(), nval*sizeof(float));
218 if (in.fail()) {
219 printf("%s: failed reading data for entry %d\n", __func__, i);
220 imatrix_data = {};
221 exit(1);
222 }
223 if (ncall > 0) {
224 for (auto & v : e) {
225 v /= ncall;
226 }
227 }
228
229 if (getenv("LLAMA_TRACE")) {
230 printf("%s: loaded data (size = %6d, ncall = %6d) for '%s'\n", __func__, int(e.size()), ncall, name.c_str());
231 }
232 }
233
234 // latest legacy imatrix version contains the dataset filename at the end of the file
235 int m_last_call = 0;
236 if (in.peek() != EOF) {
237 in.read((char *)&m_last_call, sizeof(m_last_call));
238 int dataset_len;
239 in.read((char *)&dataset_len, sizeof(dataset_len));
240 std::vector<char> dataset_as_vec(dataset_len);
241 in.read(dataset_as_vec.data(), dataset_len);

Callers 1

load_imatrixFunction · 0.85

Calls 9

failMethod · 0.80
peekMethod · 0.80
assignMethod · 0.80
endMethod · 0.80
readMethod · 0.45
dataMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected