MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / prepare_imatrix

Function prepare_imatrix

smallthinker/tools/quantize/quantize.cpp:206–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

204}
205
206static int prepare_imatrix(const std::string & imatrix_file,
207 std::string & imatrix_dataset,
208 const std::vector<std::string> & included_weights,
209 const std::vector<std::string> & excluded_weights,
210 std::unordered_map<std::string, std::vector<float>> & imatrix_data) {
211 int m_last_call = -1;
212 if (!imatrix_file.empty()) {
213 m_last_call = load_imatrix(imatrix_file, imatrix_dataset, imatrix_data);
214 }
215 if (imatrix_data.empty()) {
216 return m_last_call;
217 }
218 if (!excluded_weights.empty()) {
219 for (auto& name : excluded_weights) {
220 for (auto it = imatrix_data.begin(); it != imatrix_data.end(); ) {
221 auto pos = it->first.find(name);
222 if (pos != std::string::npos) it = imatrix_data.erase(it);
223 else ++it;
224 }
225 }
226 }
227 if (!included_weights.empty()) {
228 std::unordered_map<std::string, std::vector<float>> tmp;
229 for (auto& name : included_weights) {
230 for (auto& e : imatrix_data) {
231 auto pos = e.first.find(name);
232 if (pos != std::string::npos) {
233 tmp.emplace(std::move(e));
234 }
235 }
236 }
237 imatrix_data = std::move(tmp);
238 }
239 if (!imatrix_data.empty()) {
240 printf("%s: have %d importance matrix entries\n", __func__, int(imatrix_data.size()));
241 }
242 return m_last_call;
243}
244
245static ggml_type parse_ggml_type(const char * arg) {
246 for (int i = 0; i < GGML_TYPE_COUNT; ++i) {

Callers 1

mainFunction · 0.85

Calls 7

load_imatrixFunction · 0.85
printfFunction · 0.85
findMethod · 0.80
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected