View source: R/tensor_parallel.R
| ggml_pp_dp_forward | R Documentation |
Runs data parallelism over the batch across replicas of a pipeline-parallel
model: the batch is split into contiguous shards, one per replica, and each
replica runs the whole model as a device-by-layer pipeline on its own
set of GPUs (via ggml_pp_forward). This is the pipeline
counterpart of ggml_tp_dp_forward — use it when the model is too
large for one card (split it by layers) and you also want to raise throughput
by replicating the pipeline across independent GPU sets.
ggml_pp_dp_forward(
make_stages,
x,
replicas,
out_ncol,
mem_per_stage = 16L * 1024L * 1024L
)
make_stages |
A function |
x |
Input activation matrix, |
replicas |
A list of integer vectors, each the GPU-index pipeline for one
replica, e.g. |
out_ncol |
Number of columns |
mem_per_stage |
Bytes of ggml context metadata per stage (see
|
On a 4-GPU box the natural layout is PP=2 x DP=2: replica A pipelines
its layers across GPUs c(0, 1), replica B across c(2, 3), and the
two replicas each handle half the batch with no cross-replica traffic.
The M x N result matrix, the batch-concatenation of each
replica's pipeline output.
ggml_pp_forward, ggml_tp_dp_forward.
if (ggml_vulkan_available() && ggml_vulkan_device_count() >= 4) {
K <- 64L
W1 <- matrix(rnorm(K * K), K); W2 <- matrix(rnorm(K * K), K)
make_stages <- function(devices, m) {
mk <- function(dev, Wt, relu) list(
device = dev, in_shape = c(K, m),
build = function(ctx, input) {
w <- ggml_new_tensor_2d(ctx, GGML_TYPE_F32, K, K)
z <- ggml_mul_mat(ctx, w, input)
list(output = if (relu) ggml_relu(ctx, z) else z,
set_weights = function() ggml_backend_tensor_set_data(w, as.numeric(Wt)))
})
list(mk(devices[1], W1, TRUE), mk(devices[2], W2, FALSE))
}
X <- matrix(rnorm(8 * K), nrow = 8) # batch of 8
Y <- ggml_pp_dp_forward(make_stages, X, replicas = list(c(0, 1), c(2, 3)),
out_ncol = K)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.