MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / build_graph

Method build_graph

external/ggml/tests/test-backend-ops.cpp:2435–2482  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2433 : type(type), type_idx(type_idx), ne_a(ne_a), mode(mode) {}
2434
2435 ggml_tensor * build_graph(ggml_context * ctx) override {
2436 ggml_tensor * a = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, ne_a[0], ne_a[1], ne_a[2], 1);
2437 ggml_set_name(a, "a");
2438
2439 const bool is_mrope = mode & GGML_ROPE_TYPE_MROPE;
2440 const bool is_vision = mode == GGML_ROPE_TYPE_VISION;
2441
2442 ggml_tensor * pos;
2443 if (is_mrope || is_vision) {
2444 pos = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, ne_a[2] * 4);
2445 } else {
2446 pos = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, ne_a[2]);
2447 }
2448 ggml_set_name(pos, "pos");
2449
2450 float fs = 1.4245f;
2451 float ef = 0.7465f;
2452 float af = 1.4245f;
2453 ggml_tensor * freq = nullptr;
2454
2455 ggml_tensor * rope = nullptr;
2456 if (is_mrope) {
2457 if (is_vision) {
2458 GGML_ASSERT(n_dims/4 > 0);
2459 int rope_sections[4] = {n_dims/4, n_dims/4, 0, 0}; // Vision-RoPE only use first two dimension for image (x, y) coordinate
2460 rope = ggml_rope_multi(ctx, a, pos, freq, n_dims/2, rope_sections, mode, 0, 10000.0f, fs, ef, af, 1.0f, 1.0f);
2461 } else {
2462 GGML_ASSERT(n_dims/3 > 0);
2463 int rope_sections[4] = {n_dims/3, n_dims/3, n_dims/3, 0};
2464 rope = ggml_rope_multi(ctx, a, pos, freq, n_dims, rope_sections, mode, 0, 10000.0f, fs, ef, af, 1.0f, 1.0f);
2465 }
2466 } else {
2467 rope = ggml_rope(ctx, a, pos, ne_a[0], mode);
2468 }
2469
2470 ggml_tensor * view = ggml_view_2d(ctx, rope, ne_a[0] * ne_a[1], ne_a[2], rope->nb[2], 0);
2471
2472 ggml_tensor * dst = ggml_new_tensor_4d(ctx, type, ne_a[0] * ne_a[1], ne_a[2] * ne_a[3], 1, 1);
2473 ggml_set_name(dst, "dst");
2474
2475 ggml_tensor * row_idxs = ggml_new_tensor_3d(ctx, type_idx, ne_a[2], 1, 1);
2476 ggml_set_name(row_idxs, "row_idxs");
2477
2478 ggml_tensor * out = ggml_set_rows(ctx, dst, view, row_idxs);
2479 ggml_set_name(out, "out");
2480
2481 return out;
2482 }
2483
2484 void initialize_tensors(ggml_context * ctx) override {
2485 for (ggml_tensor * t = ggml_get_first_tensor(ctx); t != NULL; t = ggml_get_next_tensor(ctx, t)) {

Callers

nothing calls this directly

Calls 8

ggml_new_tensor_4dFunction · 0.85
ggml_set_nameFunction · 0.85
ggml_new_tensor_1dFunction · 0.85
ggml_rope_multiFunction · 0.85
ggml_ropeFunction · 0.85
ggml_view_2dFunction · 0.85
ggml_new_tensor_3dFunction · 0.85
ggml_set_rowsFunction · 0.85

Tested by

no test coverage detected