MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / convert_model_names

Function convert_model_names

tokenizer/convert/convert.py:1179–1218  ·  view source on GitHub ↗
(model: LazyModel, params: Params, skip_unknown: bool)

Source from the content-addressed store, hash-verified

1177
1178
1179def convert_model_names(model: LazyModel, params: Params, skip_unknown: bool) -> LazyModel:
1180 tmap = gguf.TensorNameMap(ARCH, params.n_layer)
1181 should_skip: set[gguf.MODEL_TENSOR] = set(gguf.MODEL_TENSOR_SKIP.get(ARCH, []))
1182
1183 tmp = model
1184
1185 # HF models permut or pack some of the tensors, so we need to undo that
1186 for i in itertools.count():
1187 if f"model.layers.{i}.self_attn.q_proj.weight" in model:
1188 print(f"Permuting layer {i}")
1189 tmp[f"model.layers.{i}.self_attn.q_proj.weight"] = permute_lazy(model[f"model.layers.{i}.self_attn.q_proj.weight"], params.n_head, params.n_head)
1190 tmp[f"model.layers.{i}.self_attn.k_proj.weight"] = permute_lazy(model[f"model.layers.{i}.self_attn.k_proj.weight"], params.n_head, params.n_head_kv)
1191 # tmp[f"model.layers.{i}.self_attn.v_proj.weight"] = model[f"model.layers.{i}.self_attn.v_proj.weight"]
1192 elif f"model.layers.{i}.self_attn.W_pack.weight" in model:
1193 print(f"Unpacking and permuting layer {i}")
1194 tmp[f"model.layers.{i}.self_attn.q_proj.weight"] = permute_part_lazy(model[f"model.layers.{i}.self_attn.W_pack.weight"], 0, params.n_head, params.n_head)
1195 tmp[f"model.layers.{i}.self_attn.k_proj.weight"] = permute_part_lazy(model[f"model.layers.{i}.self_attn.W_pack.weight"], 1, params.n_head, params.n_head_kv)
1196 tmp[f"model.layers.{i}.self_attn.v_proj.weight"] = part_lazy (model[f"model.layers.{i}.self_attn.W_pack.weight"], 2)
1197 del tmp[f"model.layers.{i}.self_attn.W_pack.weight"]
1198 else:
1199 break
1200
1201 out: LazyModel = {}
1202 for name, lazy_tensor in model.items():
1203 tensor_type, name_new = tmap.get_type_and_name(name, try_suffixes = (".weight", ".bias")) or (None, None)
1204 if name_new is None:
1205 if skip_unknown:
1206 print(f"Unexpected tensor name: {name} - skipping")
1207 continue
1208 else:
1209 raise Exception(f"Unexpected tensor name: {name}. Use --skip-unknown to ignore it (e.g. LLaVA)")
1210
1211 if tensor_type in should_skip:
1212 print(f"skipping tensor {name_new}")
1213 continue
1214
1215 print(f"{name:48s} -> {name_new:40s} | {lazy_tensor.data_type.name:6s} | {lazy_tensor.shape}")
1216 out[name_new] = lazy_tensor
1217
1218 return out
1219
1220
1221def nth_multifile_path(path: Path, n: int) -> Path | None:

Callers 1

mainFunction · 0.85

Calls 3

permute_lazyFunction · 0.85
permute_part_lazyFunction · 0.85
part_lazyFunction · 0.85

Tested by

no test coverage detected