Skip to content

Commit 671bbee

Browse files
committed
Add layer remap logic
1 parent 971f245 commit 671bbee

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/llama-quant.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,30 @@ static void zeros(std::ofstream & file, size_t n) {
2121
}
2222
}
2323

24+
static std::string remap_layer(const std::string & orig_name, const std::vector<int>& prune, std::map<int, std::string>& mapped, int& next_id) {
25+
static const std::regex pattern(R"(blk\.(\d+)\.)");
26+
if (std::smatch match; std::regex_search(orig_name, match, pattern)) {
27+
const int blk = std::stoi(match[1]);
28+
std::string new_name = orig_name;
29+
30+
if (mapped.count(blk)) {
31+
// Already mapped, do nothing
32+
} else if (std::find(prune.begin(), prune.end(), blk) != prune.end()) {
33+
mapped[blk] = "X";
34+
} else if (blk < prune.front()) {
35+
mapped[blk] = std::to_string(blk);
36+
next_id = blk + 1;
37+
} else {
38+
mapped[blk] = std::to_string(next_id);
39+
++next_id;
40+
}
41+
42+
return new_name.replace(match.position(1), match.length(1), mapped[blk]);
43+
}
44+
45+
return orig_name;
46+
}
47+
2448
struct quantize_state_impl {
2549
const llama_model & model;
2650
const llama_model_quantize_params * params;

0 commit comments

Comments
 (0)