diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h index c2ccd97253..3e0a852a38 100644 --- a/ggml/include/ggml.h +++ b/ggml/include/ggml.h @@ -1981,6 +1981,13 @@ extern "C" { float beta_fast, float beta_slow); + // set the offset dims for RoPE + // a must be GGML_OP_ROPE or GGML_OP_ROPE_BACK + // example: (marking: x = rotated, 0 = unrotated) + // n_embd = 10, n_dims = 4, offset = 2 --> [00xxxx0000] + GGML_API struct ggml_tensor * ggml_rope_set_offset( + struct ggml_tensor * a, + int n_offs); // clamp // in-place, returns view(a) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index d0d369c417..2355a1cc37 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -4200,7 +4200,7 @@ static struct ggml_tensor * ggml_rope_impl( struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a); - int32_t params[15] = { /*n_past*/ 0, n_dims, mode, /*n_ctx*/ 0, n_ctx_orig }; + int32_t params[16] = { /*n_past*/ 0, n_dims, mode, /*n_ctx*/ 0, n_ctx_orig }; memcpy(params + 5, &freq_base, sizeof(float)); memcpy(params + 6, &freq_scale, sizeof(float)); memcpy(params + 7, &ext_factor, sizeof(float)); @@ -4212,6 +4212,8 @@ static struct ggml_tensor * ggml_rope_impl( } else { memset(params + 11, 0, sizeof(int32_t) * GGML_MROPE_SECTIONS); } + params[15] = 0; // n_offs, set via ggml_rope_set_offset() + ggml_set_op_params(result, params, sizeof(params)); result->op = GGML_OP_ROPE; @@ -4422,6 +4424,15 @@ struct ggml_tensor * ggml_rope_multi_back( result->op = GGML_OP_ROPE_BACK; return result; } + +struct ggml_tensor * ggml_rope_set_offset( + struct ggml_tensor * a, + int n_offs) { + GGML_ASSERT(a->op == GGML_OP_ROPE || a->op == GGML_OP_ROPE_BACK); + ggml_set_op_params_i32(a, 15, n_offs); + return a; +} + // ggml_clamp struct ggml_tensor * ggml_clamp(