Skip to content

Commit 3d2907d

Browse files
committed
make gptneox and gptj work with extended context too
1 parent d6b47e6 commit 3d2907d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

otherarch/gptj_v3.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ ModelLoadResult gptj_model_load(const std::string & fname, gptj_model & model, g
6868
printf("%s: ftype = %d\n", __func__, hparams.ftype);
6969
printf("%s: qntvr = %d\n", __func__, qntvr);
7070

71+
hparams.n_ctx = std::max(origmaxctx,hparams.n_ctx);
72+
7173
hparams.ftype %= GGML_QNT_VERSION_FACTOR;
7274
}
7375

@@ -474,8 +476,8 @@ bool gptj_eval(
474476

475477
// self-attention
476478
{
477-
struct ggml_tensor * Qcur = ggml_rope_inplace(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model.layers[il].c_attn_q_proj_w, cur), n_embd/n_head, n_head, N), n_past, n_rot, 0, 0);
478-
struct ggml_tensor * Kcur = ggml_rope_inplace(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model.layers[il].c_attn_k_proj_w, cur), n_embd/n_head, n_head, N), n_past, n_rot, 0, 0);
479+
struct ggml_tensor * Qcur = ggml_rope_inplace(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model.layers[il].c_attn_q_proj_w, cur), n_embd/n_head, n_head, N), n_past, n_rot, 0, n_ctx);
480+
struct ggml_tensor * Kcur = ggml_rope_inplace(ctx0, ggml_reshape_3d(ctx0, ggml_mul_mat(ctx0, model.layers[il].c_attn_k_proj_w, cur), n_embd/n_head, n_head, N), n_past, n_rot, 0, n_ctx);
479481

480482
// store key and value to memory
481483
{

otherarch/neox_v3.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ ModelLoadResult gpt_neox_model_load(const std::string & fname, gpt_neox_model &
6868
printf("%s: ftype = %d\n", __func__, hparams.ftype);
6969
printf("%s: qntvr = %d\n", __func__, qntvr);
7070

71+
hparams.n_ctx = std::max(origmaxctx,hparams.n_ctx);
72+
7173
hparams.ftype %= GGML_QNT_VERSION_FACTOR;
7274
}
7375

@@ -502,8 +504,8 @@ bool gpt_neox_eval(
502504
struct ggml_tensor * Vcur = ggml_cont(ctx0, ggml_view_3d(ctx0, cur, n_embd/n_head, n_head, N, cur->nb[1]/n_head, cur->nb[1], 2*sizeof(float)*n_embd/n_head));
503505

504506
// using mode = 2 for GPT-NeoX mode
505-
Qcur = ggml_rope_inplace(ctx0, Qcur, n_past, n_rot, 2, 0);
506-
Kcur = ggml_rope_inplace(ctx0, Kcur, n_past, n_rot, 2, 0);
507+
Qcur = ggml_rope_inplace(ctx0, Qcur, n_past, n_rot, 2, n_ctx);
508+
Kcur = ggml_rope_inplace(ctx0, Kcur, n_past, n_rot, 2, n_ctx);
507509

508510
// store key and value to memory
509511
{

0 commit comments

Comments
 (0)