Skip to content

Commit 0518b0a

Browse files
committed
fix rope fail
1 parent 69e26ff commit 0518b0a

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

ggml/src/ggml-cpu/ops.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5514,6 +5514,8 @@ static void ggml_mrope_cache_init(
55145514
theta = theta_h;
55155515
} else if (sector % 3 == 2 && sector < 3 * sections[2]) {
55165516
theta = theta_w;
5517+
} else if (sector % 3 == 0 && sector < 3 * sections[0]) {
5518+
theta = theta_t;
55175519
} else {
55185520
theta = theta_e;
55195521
}

ggml/src/ggml-cuda/rope.cu

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ static __global__ void rope_multi(
157157
theta_base = pos[channel_x + ne2 * 1]*powf(theta_scale, i0/2.0f);
158158
} else if (sector % 3 == 2 && sector < 3 * sections.v[2]) { // w
159159
theta_base = pos[channel_x + ne2 * 2]*powf(theta_scale, i0/2.0f);
160-
} else { // t
160+
} else if (sector % 3 == 0 && sector < 3 * sections.v[0]) { // t
161161
theta_base = pos[channel_x]*powf(theta_scale, i0/2.0f);
162+
} else {
163+
theta_base = pos[channel_x + ne2 * 3]*powf(theta_scale, i0/2.0f);
162164
}
163165
} else {
164166
if (sector < sections.v[0]) {

tests/test-backend-ops.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7076,6 +7076,10 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
70767076
test_cases.emplace_back(new test_rope(type, {128, 28, 2, 1}, 128, GGML_ROPE_TYPE_MROPE, 512, fs, ef, af, ff, v, fw)); // rope_multi,m-rope (qwen2vl 7B)
70777077
test_cases.emplace_back(new test_rope(type, {128, 12, 2, 1}, 20, GGML_ROPE_TYPE_MROPE, 512, fs, ef, af, ff, v, fw));
70787078
test_cases.emplace_back(new test_rope(type, {128, 28, 2, 1}, 32, GGML_ROPE_TYPE_MROPE, 512, fs, ef, af, ff, v, fw));
7079+
test_cases.emplace_back(new test_rope(type, {128, 12, 2, 1}, 128, GGML_ROPE_TYPE_IMROPE, 512, fs, ef, af, ff, v, fw)); // rope_multi,imrope (qwen3vl 2B)
7080+
test_cases.emplace_back(new test_rope(type, {128, 28, 2, 1}, 128, GGML_ROPE_TYPE_IMROPE, 512, fs, ef, af, ff, v, fw)); // rope_multi,imrope (qwen3vl 7B)
7081+
test_cases.emplace_back(new test_rope(type, {128, 12, 2, 1}, 20, GGML_ROPE_TYPE_IMROPE, 512, fs, ef, af, ff, v, fw));
7082+
test_cases.emplace_back(new test_rope(type, {128, 28, 2, 1}, 32, GGML_ROPE_TYPE_IMROPE, 512, fs, ef, af, ff, v, fw));
70797083
test_cases.emplace_back(new test_rope(type, { 80, 16, 2, 1}, 80, GGML_ROPE_TYPE_VISION, 512, fs, ef, af, ff, v, fw)); // rope_multi,m-rope (qwen2vl ViT)
70807084
}
70817085

@@ -7092,7 +7096,7 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
70927096

70937097
// single inplace test per type/mode/ff
70947098
for (ggml_type type : {GGML_TYPE_F32, GGML_TYPE_F16}) {
7095-
for (int mode : {GGML_ROPE_TYPE_NORMAL, GGML_ROPE_TYPE_NEOX, GGML_ROPE_TYPE_MROPE, GGML_ROPE_TYPE_VISION}) {
7099+
for (int mode : {GGML_ROPE_TYPE_NORMAL, GGML_ROPE_TYPE_NEOX, GGML_ROPE_TYPE_MROPE, GGML_ROPE_TYPE_IMROPE, GGML_ROPE_TYPE_VISION}) {
70967100
for (bool ff : {false, true}) {
70977101
test_cases.emplace_back(new test_rope(type, {128, 32, 2, 1}, 128, mode, 512, 1.4245f, 0.7465f, 1.4245f, ff, 0, true, true));
70987102
}

tests/test-rope.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ int main(int /*argc*/, const char ** /*argv*/) {
138138
struct ggml_tensor * x;
139139

140140
// rope f32
141-
for (int m = 0; m < 5; ++m) {
141+
for (int m = 0; m < 6; ++m) {
142142
const int ndims = 4;
143143

144144
const int64_t n_rot = 128;
@@ -180,7 +180,7 @@ int main(int /*argc*/, const char ** /*argv*/) {
180180
struct ggml_tensor * p2 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2] * 4);
181181

182182
int sections[4] = {16, 24, 24, 0};
183-
mode = (m == 3) ? GGML_ROPE_TYPE_MROPE : GGML_ROPE_TYPE_VISION;
183+
mode = (m == 3) ? GGML_ROPE_TYPE_MROPE : (m == 4) ? GGML_ROPE_TYPE_VISION : GGML_ROPE_TYPE_IMROPE;
184184

185185
for (int i = 0; i < ne[2]; ++i) {
186186
for (int j = 0; j < 4; ++j) {

0 commit comments

Comments
 (0)