Skip to content

Commit 57819b8

Browse files
authored
llama : disable graph reuse with pipeline parallelism (ggml-org#20463)
1 parent 557fe2d commit 57819b8

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

ggml/src/ggml-backend.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,10 +1455,6 @@ static enum ggml_status ggml_backend_sched_compute_splits(ggml_backend_sched_t s
14551455
int split_backend_id = split->backend_id;
14561456
ggml_backend_t split_backend = sched->backends[split_backend_id];
14571457

1458-
if (sched->events[split_backend_id][sched->cur_copy] == NULL) {
1459-
ggml_backend_synchronize(split_backend);
1460-
}
1461-
14621458
// copy the input tensors to the split backend
14631459
for (int input_id = 0; input_id < split->n_inputs; input_id++) {
14641460
ggml_backend_t input_backend = ggml_backend_sched_get_tensor_backend(sched, split->inputs[input_id]);
@@ -1469,12 +1465,16 @@ static enum ggml_status ggml_backend_sched_compute_splits(ggml_backend_sched_t s
14691465
// inputs from the user must be copied immediately to prevent the user overwriting the data before the copy is done
14701466
if (sched->events[split_backend_id][sched->cur_copy] != NULL) {
14711467
ggml_backend_event_synchronize(sched->events[split_backend_id][sched->cur_copy]);
1468+
} else {
1469+
ggml_backend_synchronize(split_backend);
14721470
}
1473-
ggml_backend_tensor_copy_async(input_backend, split_backend, input, input_cpy);
1471+
ggml_backend_tensor_copy(input, input_cpy);
14741472
} else {
14751473
// wait for the split backend to finish using the input before overwriting it
14761474
if (sched->events[split_backend_id][sched->cur_copy] != NULL) {
14771475
ggml_backend_event_wait(split_backend, sched->events[split_backend_id][sched->cur_copy]);
1476+
} else {
1477+
ggml_backend_synchronize(split_backend);
14781478
}
14791479

14801480
// when offloading MoE weights, we can reduce the amount of data copied by copying only the experts that are used
@@ -1578,10 +1578,6 @@ static enum ggml_status ggml_backend_sched_compute_splits(ggml_backend_sched_t s
15781578
}
15791579
}
15801580

1581-
if (sched->events[split_backend_id][sched->cur_copy] == NULL) {
1582-
ggml_backend_synchronize(split_backend);
1583-
}
1584-
15851581
if (!sched->callback_eval) {
15861582
enum ggml_status ec = ggml_backend_graph_compute_async(split_backend, &split->graph);
15871583
if (ec != GGML_STATUS_SUCCESS) {

ggml/src/ggml-cuda/ggml-cuda.cu

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,14 +2823,11 @@ static bool ggml_backend_cuda_cpy_tensor_async(ggml_backend_t backend_src, ggml_
28232823
ggml_backend_buffer_t buf_src = src->view_src ? src->view_src->buffer : src->buffer;
28242824
ggml_backend_buffer_t buf_dst = dst->view_src ? dst->view_src->buffer : dst->buffer;
28252825

2826-
//enables async copies from CPU to CUDA, instead of only CUDA-to-CUDA
2827-
bool copy_from_host = ggml_backend_buffer_is_host(buf_src) && ggml_backend_dev_type(backend_src->device) == GGML_BACKEND_DEVICE_TYPE_CPU;
2828-
2829-
if (!(copy_from_host || ggml_backend_is_cuda(backend_src)) || !ggml_backend_is_cuda(backend_dst)) {
2826+
if (!ggml_backend_is_cuda(backend_src) || !ggml_backend_is_cuda(backend_dst)) {
28302827
return false;
28312828
}
28322829

2833-
if (!(copy_from_host || ggml_backend_buffer_is_cuda(buf_src)) || !ggml_backend_buffer_is_cuda(dst->buffer)) {
2830+
if (!ggml_backend_buffer_is_cuda(src->buffer) || !ggml_backend_buffer_is_cuda(dst->buffer)) {
28342831
return false;
28352832
}
28362833

@@ -2841,17 +2838,14 @@ static bool ggml_backend_cuda_cpy_tensor_async(ggml_backend_t backend_src, ggml_
28412838
ggml_backend_cuda_buffer_context * buf_ctx_src = (ggml_backend_cuda_buffer_context *)buf_src->context;
28422839
ggml_backend_cuda_buffer_context * buf_ctx_dst = (ggml_backend_cuda_buffer_context *)buf_dst->context;
28432840

2844-
if ((copy_from_host && cuda_ctx_dst->device != buf_ctx_dst->device) ||
2845-
!copy_from_host && (cuda_ctx_src->device != buf_ctx_src->device || cuda_ctx_dst->device != buf_ctx_dst->device)) {
2841+
if (cuda_ctx_src->device != buf_ctx_src->device || cuda_ctx_dst->device != buf_ctx_dst->device) {
28462842
#ifndef NDEBUG
28472843
GGML_LOG_DEBUG("%s: backend and buffer devices do not match\n", __func__);
28482844
#endif
28492845
return false;
28502846
}
28512847

2852-
if (copy_from_host) {
2853-
CUDA_CHECK(cudaMemcpyAsync(dst->data, src->data, ggml_nbytes(dst), cudaMemcpyHostToDevice, cuda_ctx_dst->stream()));
2854-
} else if (backend_src != backend_dst) {
2848+
if (backend_src != backend_dst) {
28552849
// copy on src stream
28562850
if (cuda_ctx_src->device == cuda_ctx_dst->device) {
28572851
CUDA_CHECK(cudaMemcpyAsync(dst->data, src->data, ggml_nbytes(dst), cudaMemcpyDeviceToDevice, cuda_ctx_src->stream()));

src/llama-context.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ llama_context::llama_context(
342342

343343
if (cparams.pipeline_parallel) {
344344
LLAMA_LOG_INFO("%s: pipeline parallelism enabled\n", __func__);
345+
346+
if (!graph_reuse_disable) {
347+
// TODO: figure out a way to make graph reuse work with pipeline parallelism
348+
// ref: https://github.com/ggml-org/llama.cpp/pull/20463
349+
LLAMA_LOG_WARN("%s: graph reuse is currently not compatible with pipeline parallelism - disabling\n", __func__);
350+
351+
graph_reuse_disable = true;
352+
}
345353
}
346354

347355
sched_reserve();

0 commit comments

Comments
 (0)