| 125 | } |
| 126 | |
| 127 | int main(int /*argc*/, const char ** /*argv*/) { |
| 128 | struct ggml_init_params params = { |
| 129 | /* .mem_size = */ 128*1024*1024, |
| 130 | /* .mem_buffer = */ NULL, |
| 131 | /* .no_alloc = */ false, |
| 132 | }; |
| 133 | |
| 134 | std::vector<uint8_t> work_buffer; |
| 135 | |
| 136 | struct ggml_context * ctx0 = ggml_init(params); |
| 137 | |
| 138 | struct ggml_tensor * x; |
| 139 | |
| 140 | // rope f32 |
| 141 | for (int m = 0; m < 5; ++m) { |
| 142 | const int ndims = 4; |
| 143 | |
| 144 | const int64_t n_rot = 128; |
| 145 | const int64_t ne[4] = { 2*n_rot, 32, 73, 1 }; |
| 146 | |
| 147 | const int n_past_0 = 100; |
| 148 | const int n_past_2 = 33; |
| 149 | |
| 150 | struct ggml_tensor * r0; |
| 151 | struct ggml_tensor * r1; |
| 152 | struct ggml_tensor * r2; |
| 153 | x = get_random_tensor_f32(ctx0, ndims, ne, -1.0f, 1.0f); |
| 154 | int mode = -1; |
| 155 | |
| 156 | if (m < 2) { |
| 157 | struct ggml_tensor * p0 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2]); |
| 158 | struct ggml_tensor * p1 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2]); |
| 159 | struct ggml_tensor * p2 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2]); |
| 160 | |
| 161 | for (int i = 0; i < ne[2]; ++i) { |
| 162 | ((int32_t *) p0->data)[i] = n_past_0 + i; |
| 163 | ((int32_t *) p1->data)[i] = n_past_2 - n_past_0; |
| 164 | ((int32_t *) p2->data)[i] = n_past_2 + i; |
| 165 | } |
| 166 | // test mode 0, 2 (standard, GPT-NeoX) |
| 167 | mode = m == 0 ? GGML_ROPE_TYPE_NORMAL : GGML_ROPE_TYPE_NEOX; |
| 168 | |
| 169 | // 100, 101, 102, ..., 172 |
| 170 | r0 = ggml_rope(ctx0, x, p0, n_rot, mode); |
| 171 | // -67, -67, -67, ..., -67 |
| 172 | r1 = ggml_rope(ctx0, r0, p1, n_rot, mode); // "context swap", i.e. forget n_past_0 - n_past_2 tokens |
| 173 | |
| 174 | // 33, 34, 35, ..., 105 |
| 175 | r2 = ggml_rope(ctx0, x, p2, n_rot, mode); |
| 176 | } else { |
| 177 | // testing multi-dimension rope position embedding mode |
| 178 | struct ggml_tensor * p0 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2] * 4); |
| 179 | struct ggml_tensor * p1 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2] * 4); |
| 180 | struct ggml_tensor * p2 = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, ne[2] * 4); |
| 181 | |
| 182 | int sections[4] = {16, 24, 24, 0}; |
| 183 | |
| 184 | mode = (m == 2) ? GGML_ROPE_TYPE_MROPE : (m == 3) ? GGML_ROPE_TYPE_VISION : GGML_ROPE_TYPE_IMROPE; |
nothing calls this directly
no test coverage detected