Skip to content

Commit 06943a6

Browse files
danbevslaren
andauthored
ggml : move rope type enum to ggml.h (#8949)
* ggml : move rope type enum to ggml.h This commit moves the `llama_rope_type` enum from `llama.h` to `ggml.h` and changes its name to `ggml_rope_type`. The motivation for this change is to address the TODO in `llama.h` and use the enum in ggml. Note: This commit does not change the `mode` parameter to be of type `enum ggml_rope_type`. The name `mode` and its usage suggest that it might be more generic and possibly used as a bit field for multiple flags. Further investigation/discussion may be needed to determine if `mode` should be restricted to RoPE types. * squash! ggml : move rope type enum to ggml.h This commit removes GGML_ROPE_TYPE_NONE and GGML_ROPE_TYPE_GLM from ggml.h, and back the llama_rope_type enum. I've kept the assert for GGML_ROPE_TYPE_GLM as I'm not sure if it is safe to remove it yet. * squash! ggml : move rope type enum to ggml.h This commit removes the enum ggml_rope_type from ggml.h and replaces it with a define (GGML_ROPE_TYPE_NEOX). This define is used in the code to check if the mode is set to GPT-NeoX. Also the enum llama_rope_type has been updated to reflect this change. * squash! ggml : move rope type enum to ggml.h This commit contains a suggestion enable the GGML_ROPE_TYPE_NEOX macro/define to be passed to the shader compiler. * squash! ggml : move rope type enum to ggml.h This commit fixes the editorconfig-checker warnings. * squash! ggml : move rope type enum to ggml.h Update comment for ggml_rope function. * Revert "squash! ggml : move rope type enum to ggml.h" This reverts commit 6261222. * squash! ggml : move rope type enum to ggml.h Add GGML_ROPE_TYPE_NEOX to rope_common.comp. * remove extra line --------- Co-authored-by: slaren <slarengh@gmail.com>
1 parent 828d6ff commit 06943a6

File tree

11 files changed

+17
-16
lines changed

11 files changed

+17
-16
lines changed

ggml/include/ggml.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@
244244
#define GGML_EXIT_SUCCESS 0
245245
#define GGML_EXIT_ABORTED 1
246246

247+
#define GGML_ROPE_TYPE_NEOX 2
248+
247249
#define GGUF_MAGIC "GGUF"
248250

249251
#define GGUF_VERSION 3
@@ -1453,8 +1455,8 @@ extern "C" {
14531455
struct ggml_tensor * b);
14541456

14551457
// rotary position embedding
1456-
// if mode & 1 == 1, skip n_past elements (NOT SUPPORTED)
1457-
// if mode & 2 == 1, GPT-NeoX style
1458+
// if (mode & 1) - skip n_past elements (NOT SUPPORTED)
1459+
// if (mode & GGML_ROPE_TYPE_NEOX) - GPT-NeoX style
14581460
//
14591461
// b is an int32 vector with size a->ne[2], it contains the positions
14601462
GGML_API struct ggml_tensor * ggml_rope(

ggml/src/ggml-cann/aclnn_ops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ void ggml_cann_rope(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
28812881
ggml_rope_yarn_corr_dims(n_dims, n_ctx_orig, freq_base, beta_fast,
28822882
beta_slow, corr_dims);
28832883

2884-
const bool is_neox = mode & 2;
2884+
const bool is_neox = mode & GGML_ROPE_TYPE_NEOX;
28852885

28862886
// init cos/sin cache
28872887
ggml_cann_pool_alloc sin_allocator(

ggml/src/ggml-cuda/rope.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void ggml_cuda_op_rope(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
226226
memcpy(&beta_fast, (int32_t *) dst->op_params + 9, sizeof(float));
227227
memcpy(&beta_slow, (int32_t *) dst->op_params + 10, sizeof(float));
228228

229-
const bool is_neox = mode & 2;
229+
const bool is_neox = mode & GGML_ROPE_TYPE_NEOX;
230230

231231
const int32_t * pos = (const int32_t *) src1_d;
232232

ggml/src/ggml-metal.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,7 @@ static enum ggml_status ggml_metal_graph_compute(
23132313
memcpy(&beta_fast, (int32_t *) dst->op_params + 9, sizeof(float));
23142314
memcpy(&beta_slow, (int32_t *) dst->op_params + 10, sizeof(float));
23152315

2316-
const bool is_neox = mode & 2;
2316+
const bool is_neox = mode & GGML_ROPE_TYPE_NEOX;
23172317

23182318
id<MTLComputePipelineState> pipeline = nil;
23192319

ggml/src/ggml-sycl/rope.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void ggml_sycl_op_rope(
226226
memcpy(&beta_fast, (int32_t *) dst->op_params + 9, sizeof(float));
227227
memcpy(&beta_slow, (int32_t *) dst->op_params + 10, sizeof(float));
228228

229-
const bool is_neox = mode & 2;
229+
const bool is_neox = mode & GGML_ROPE_TYPE_NEOX;
230230

231231
const int32_t * pos = (const int32_t *) src1_dd;
232232

ggml/src/ggml-vulkan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4053,7 +4053,7 @@ static vk_pipeline ggml_vk_op_get_pipeline(ggml_backend_vk_context * ctx, const
40534053
case GGML_OP_ROPE:
40544054
{
40554055
const int mode = ((const int32_t *) dst->op_params)[2];
4056-
const bool is_neox = mode & 2;
4056+
const bool is_neox = mode & GGML_ROPE_TYPE_NEOX;
40574057

40584058
if (is_neox) {
40594059
if (src0->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_F32) {

ggml/src/ggml.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14094,7 +14094,7 @@ static void ggml_compute_forward_rope_f32(
1409414094
float corr_dims[2];
1409514095
ggml_rope_yarn_corr_dims(n_dims, n_ctx_orig, freq_base, beta_fast, beta_slow, corr_dims);
1409614096

14097-
const bool is_neox = mode & 2;
14097+
const bool is_neox = mode & GGML_ROPE_TYPE_NEOX;
1409814098

1409914099
const float * freq_factors = NULL;
1410014100
if (src2 != NULL) {
@@ -14219,7 +14219,7 @@ static void ggml_compute_forward_rope_f16(
1421914219
float corr_dims[2];
1422014220
ggml_rope_yarn_corr_dims(n_dims, n_ctx_orig, freq_base, beta_fast, beta_slow, corr_dims);
1422114221

14222-
const bool is_neox = mode & 2;
14222+
const bool is_neox = mode & GGML_ROPE_TYPE_NEOX;
1422314223

1422414224
const float * freq_factors = NULL;
1422514225
if (src2 != NULL) {

ggml/src/kompute-shaders/op_rope_f16.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void main() {
1111
const uint i2 = gl_WorkGroupID.y;
1212
const uint i1 = gl_WorkGroupID.x;
1313

14-
const bool is_neox = (pcs.mode & 2) != 0;
14+
const bool is_neox = (pcs.mode & GGML_ROPE_TYPE_NEOX) != 0;
1515

1616
float corr_dims[2];
1717
rope_yarn_corr_dims(pcs.n_dims, pcs.n_ctx_orig, pcs.freq_base, pcs.beta_fast, pcs.beta_slow, corr_dims);

ggml/src/kompute-shaders/op_rope_f32.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void main() {
1111
const uint i2 = gl_WorkGroupID.y;
1212
const uint i1 = gl_WorkGroupID.x;
1313

14-
const bool is_neox = (pcs.mode & 2) != 0;
14+
const bool is_neox = (pcs.mode & GGML_ROPE_TYPE_NEOX) != 0;
1515

1616
float corr_dims[2];
1717
rope_yarn_corr_dims(pcs.n_dims, pcs.n_ctx_orig, pcs.freq_base, pcs.beta_fast, pcs.beta_slow, corr_dims);

ggml/src/kompute-shaders/rope_common.comp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "common.comp"
22

3+
#define GGML_ROPE_TYPE_NEOX 2
4+
35
// TODO: use a local size of 32 or more (Metal uses 1024)
46
layout(local_size_x = 1) in;
57

0 commit comments

Comments
 (0)