| 4544 | } |
| 4545 | |
| 4546 | static struct ggml_tensor * llm_build_sparse_mul_mat( |
| 4547 | struct ggml_context * ctx, |
| 4548 | struct ggml_tensor * up, |
| 4549 | struct ggml_tensor * inp, |
| 4550 | struct ggml_tensor * idx, |
| 4551 | struct ggml_tensor * up_gpu, |
| 4552 | struct ggml_tensor * gpu_index, |
| 4553 | struct ggml_tensor * gpu_bucket, |
| 4554 | const llm_build_cb_short & cb, |
| 4555 | const char * name, |
| 4556 | bool full_gpu) { |
| 4557 | std::string full_name = "ffn_" + std::string(name) + "_sparse"; |
| 4558 | ggml_tensor * out = nullptr; |
| 4559 | |
| 4560 | #ifdef GGML_USE_HIPBLAS |
| 4561 | // WARNING: THIS IS A HACK! |
| 4562 | // if up_gpu->data is null |
| 4563 | // inference fails when model exceeds 40B on rocm device |
| 4564 | // so we just let up_gpu->data point to itself |
| 4565 | |
| 4566 | up_gpu->data = up_gpu; |
| 4567 | |
| 4568 | #endif |
| 4569 | |
| 4570 | #ifdef GGML_USE_CUBLAS |
| 4571 | // Full offloading fast path |
| 4572 | if (full_gpu) { |
| 4573 | GGML_ASSERT(up_gpu && "full_gpu but no up_gpu"); |
| 4574 | out = ggml_mul_mat_idx(ctx, up_gpu, inp, idx, NULL); |
| 4575 | ggml_cuda_assign_buffers_no_alloc(out); |
| 4576 | cb(out, (full_name).c_str()); |
| 4577 | return out; |
| 4578 | } |
| 4579 | #endif |
| 4580 | |
| 4581 | out = ggml_mul_mat_idx(ctx, up, inp, idx, gpu_index); |
| 4582 | cb(out, full_name.c_str()); |
| 4583 | |
| 4584 | #ifdef GGML_USE_CUBLAS |
| 4585 | if (up_gpu) { |
| 4586 | ggml_tensor * out_gpu = ggml_mul_mat_idx_upscale(ctx, up_gpu, inp, idx, gpu_bucket, out->ne[0]); |
| 4587 | ggml_cuda_assign_buffers_no_alloc(out_gpu); |
| 4588 | cb(out_gpu, (full_name + "_gpu").c_str()); |
| 4589 | out = ggml_add(ctx, out, out_gpu); |
| 4590 | // We don't need to assign buffers here, as the output will be passed into Axpy, |
| 4591 | // which in this case, is also a hybrid operation. |
| 4592 | cb(out, (full_name + "_merged").c_str()); |
| 4593 | } |
| 4594 | #endif |
| 4595 | |
| 4596 | return out; |
| 4597 | } |
| 4598 | |
| 4599 | static struct ggml_tensor * llm_build_sparse_axpy( |
| 4600 | struct ggml_context * ctx, |
no test coverage detected