Skip to content

Commit 4ad3eb2

Browse files
authored
skip imatrix entries with non-normal data
1 parent 0e36739 commit 4ad3eb2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

llama.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15231,19 +15231,25 @@ static void llama_model_quantize_internal(const std::string & fname_inp, const s
1523115231
if (params->only_copy) {
1523215232
ftype = model.ftype;
1523315233
}
15234-
const std::unordered_map<std::string, std::vector<float>> * imatrix_data = nullptr;
15234+
std::unordered_map<std::string, std::vector<float>> * imatrix_data = nullptr;
1523515235
if (params->imatrix) {
15236-
imatrix_data = static_cast<const std::unordered_map<std::string, std::vector<float>>*>(params->imatrix);
15236+
imatrix_data = static_cast<std::unordered_map<std::string, std::vector<float>>*>(params->imatrix);
1523715237
if (imatrix_data) {
1523815238
LLAMA_LOG_INFO("================================ Have weights data with %d entries\n",int(imatrix_data->size()));
1523915239
qs.has_imatrix = true;
1524015240
// check imatrix for nans or infs
15241-
for (const auto & kv : *imatrix_data) {
15242-
for (float f : kv.second) {
15243-
if (!std::isfinite(f)) {
15244-
throw std::runtime_error(format("imatrix contains non-finite value %f\n", f));
15241+
for (auto it = imatrix_data->begin(); it != imatrix_data->end();) {
15242+
bool remove_entry = false;
15243+
15244+
for (float f : it->second) {
15245+
if (!std::isnormal(f)) {
15246+
LLAMA_LOG_WARN("imatrix entry \"%s\" contains non-normal value %f, skipping!\n", it->first.c_str(), f);
15247+
remove_entry = true;
15248+
break;
1524515249
}
1524615250
}
15251+
15252+
it = remove_entry ? imatrix_data->erase(it) : ++it;
1524715253
}
1524815254
}
1524915255
}

0 commit comments

Comments
 (0)