@@ -297,6 +297,7 @@ enum llm_kv {
297
297
LLM_KV_ATTENTION_LAYERNORM_RMS_EPS,
298
298
LLM_KV_ATTENTION_CAUSAL,
299
299
300
+ LLM_KV_ROPE_TYPE,
300
301
LLM_KV_ROPE_DIMENSION_COUNT,
301
302
LLM_KV_ROPE_FREQ_BASE,
302
303
LLM_KV_ROPE_SCALE_LINEAR,
@@ -375,6 +376,7 @@ static const std::map<llm_kv, const char *> LLM_KV_NAMES = {
375
376
{ LLM_KV_ATTENTION_LAYERNORM_RMS_EPS, "%s.attention.layer_norm_rms_epsilon" },
376
377
{ LLM_KV_ATTENTION_CAUSAL, "%s.attention.causal" },
377
378
379
+ { LLM_KV_ROPE_TYPE, "%s.rope.type" },
378
380
{ LLM_KV_ROPE_DIMENSION_COUNT, "%s.rope.dimension_count" },
379
381
{ LLM_KV_ROPE_FREQ_BASE, "%s.rope.freq_base" },
380
382
{ LLM_KV_ROPE_SCALE_LINEAR, "%s.rope.scale_linear" },
@@ -1129,12 +1131,29 @@ struct LLM_TN {
1129
1131
// gguf helpers
1130
1132
//
1131
1133
1134
+ static const std::map<enum llama_rope_type, const char *> LLAMA_ROPE_TYPES = {
1135
+ { LLAMA_ROPE_TYPE_NONE, "none" },
1136
+ { LLAMA_ROPE_TYPE_NORM, "norm" },
1137
+ { LLAMA_ROPE_TYPE_NEOX, "neox" },
1138
+ { LLAMA_ROPE_TYPE_GLM, "glm" },
1139
+ };
1140
+
1132
1141
static const std::map<llama_rope_scaling_type, const char *> LLAMA_ROPE_SCALING_TYPES = {
1133
1142
{ LLAMA_ROPE_SCALING_TYPE_NONE, "none" },
1134
1143
{ LLAMA_ROPE_SCALING_TYPE_LINEAR, "linear" },
1135
1144
{ LLAMA_ROPE_SCALING_TYPE_YARN, "yarn" },
1136
1145
};
1137
1146
1147
+ static enum llama_rope_type llama_rope_type_from_string(const std::string & name) {
1148
+ for (const auto & kv : LLAMA_ROPE_TYPES) {
1149
+ if (kv.second == name) {
1150
+ return (enum llama_rope_type) kv.first;
1151
+ }
1152
+ }
1153
+
1154
+ return LLAMA_ROPE_TYPE_NONE;
1155
+ }
1156
+
1138
1157
static llama_rope_scaling_type llama_rope_scaling_type_from_string(const std::string & name) {
1139
1158
for (const auto & kv : LLAMA_ROPE_SCALING_TYPES) {
1140
1159
if (kv.second == name) {
@@ -4394,7 +4413,15 @@ static void llm_load_hparams(
4394
4413
hparams.use_alibi = true;
4395
4414
}
4396
4415
4397
- hparams.rope_type = llama_rope_type(&model);
4416
+ hparams.rope_type = llama_default_rope_type(&model);
4417
+
4418
+ const auto kv = LLM_KV(model.arch);
4419
+ const int rope_type_keyidx = gguf_find_key(ctx, kv(LLM_KV_ROPE_TYPE).c_str());
4420
+ if (rope_type_keyidx != -1) {
4421
+ std::string rope_type("none");
4422
+ ml.get_key(LLM_KV_ROPE_TYPE, rope_type);
4423
+ hparams.rope_type = llama_rope_type_from_string(rope_type);
4424
+ }
4398
4425
}
4399
4426
4400
4427
// TODO: This should probably be in llama.h
@@ -16216,7 +16243,7 @@ enum llama_vocab_type llama_vocab_type(const struct llama_model * model) {
16216
16243
return model->vocab.type;
16217
16244
}
16218
16245
16219
- enum llama_rope_type llama_rope_type (const struct llama_model * model) {
16246
+ enum llama_rope_type llama_default_rope_type (const struct llama_model * model) {
16220
16247
switch (model->arch) {
16221
16248
// these models do not use RoPE
16222
16249
case LLM_ARCH_GPT2:
0 commit comments