d6f3030047
* ggml: backend-agnostic tensor parallelism * support for GPT-OSS, Qwen 3 MoE * partial Vulkan fix * add support for 4/8 GPUs * unconditional peer access * re-use buffers + ggml contexts * fix output pattern * NCCL support * GGML: HIP: add RCCL support * Remove shfl and AllReduce from backend interface * move allocation workaround out of ggml-alloc.c * 2d tensor set/get support * Fix the seg fault without NCCL * Apply suggestion from JohannesGaessler * support for tensor dims % n_devs != 0 * fix view_offs scaling * arbitrary num. of GPUs/tensor split * fix compilation * better granularity estimate * Support device-specific host buffer types if all underlying backends expose the same type. This allows using pinned memory instead of pageable memory for CUDA. Fix compilation errors. * partial Qwen 3 Next support * Fix qwen3 30b (#8) * Fix crash with Qwen-30B-A3B Q4_0 Qwen-30B-A3B Q4_0 has an intermediate dimension of 768. Using a granularity of 256 forces an uneven split between GPUs, which is not supported by the current implementation. * Decide block size based on tensor quantization type * Fix crashes due to KV cache serialization (#9) KV cache serialization requires non-zero offsets on the tensor. Add support in the meta backend to set/get a tensor with a non-zero offset. * metal : fix build (#7) * static memory allocations, fix usage count * fix tensor granularity * more even memory distribution * use BF16 for allreduce * rebase fixup * better error message for unsupported architectures * Fix device mismatch during scatter of allReduce. (#11) There is a mismatch between the dst buffer device and the backend device, causing the use of sync copies * Enable the previous allreduce implementation. It is better in both perf and stability (#12) * delay AllReduce for Moe for less I/O * build : clean-up compile warnings * backend : move most of the meta backend API to ggml-backend-impl.h * cont : hide unused public API in the implementation * llama : use llama_device + remove ggml_backend_dev_is_meta() * ggml-backend : remove unused alloc include * minor : remove regex include * ggml : introduce ggml-ext.h for staging new APIs * rebase fixup * fix tests * llama : more robust logic for determining Meta devices (#16) * llama : more robust logic for determining Meta devices * cont : fix devs size check Co-authored-by: Johannes Gäßler <johannesg@5d6.de> * cont : fix log type Co-authored-by: Johannes Gäßler <johannesg@5d6.de> --------- Co-authored-by: Johannes Gäßler <johannesg@5d6.de> * disable roundtrip for meta backend * fix arch selection * Qwen 3.5 support * fix Gemma 4 MoE * fix OpenVino, SYCL * fix test-llama-archs for CPU-only builds * Fix Qwen 3.5 MoE * disable meta backend tests for WebGPU * tests : filter CPU-based devices from the Meta backend tests (#17) * meta : formatting, naming, indentation (#18) * formatting : llama-model.cpp * formatting : ggml-ext.h * formatting : ggml-backend-meta.cpp * meta : add TODO * add documentation * better error messages * fix GPT-OSS --------- Co-authored-by: Carl Philipp Klemm <carl@uvos.xyz> Co-authored-by: Gaurav Garg <gaugarg@nvidia.com> Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
57 lines
2.6 KiB
C
57 lines
2.6 KiB
C
#pragma once
|
|
|
|
#include "ggml.h"
|
|
#include "ggml-backend.h"
|
|
|
|
// This is a "staging" header for new ggml API
|
|
// It is not publicly available and it should not be used by 3rd party projects
|
|
//
|
|
// When the API matures enough, it will be moved to the official public API
|
|
|
|
//
|
|
// Meta backend
|
|
//
|
|
|
|
#define GGML_BACKEND_META_MAX_DEVICES 16
|
|
|
|
enum ggml_backend_meta_split_axis {
|
|
// tensor split by tensor dimensions:
|
|
GGML_BACKEND_SPLIT_AXIS_0 = 0,
|
|
GGML_BACKEND_SPLIT_AXIS_1 = 1,
|
|
GGML_BACKEND_SPLIT_AXIS_2 = 2,
|
|
GGML_BACKEND_SPLIT_AXIS_3 = 3,
|
|
|
|
GGML_BACKEND_SPLIT_AXIS_MIRRORED = 10, // all values on all backends
|
|
GGML_BACKEND_SPLIT_AXIS_PARTIAL = 11, // each backend has a partial sum
|
|
|
|
// for internal bookkeeping only:
|
|
GGML_BACKEND_SPLIT_AXIS_NONE = 98,
|
|
GGML_BACKEND_SPLIT_AXIS_UNKNOWN = 99,
|
|
};
|
|
GGML_API const char * ggml_backend_meta_split_axis_name(enum ggml_backend_meta_split_axis split_axis);
|
|
|
|
struct ggml_backend_meta_split_state {
|
|
enum ggml_backend_meta_split_axis axis;
|
|
|
|
// for tensors with axis >= 0 && axis < GGML_MAX_DIMS:
|
|
// - each device has a slice of the tensor along the split axis
|
|
// - most tensors have n_segments == 1 and a contiguous slice of the tensor data
|
|
// - some tensors have an inhomogenenous data layout along the split axis,
|
|
// those tensors are divided into segments which are each individually split across devices
|
|
// - ne has one entry per segment and device that add up to ggml_tensor::ne for that axis,
|
|
// the outer/inner loops are over segments/devices like [seg0_dev0, seg0_dev1, seg1_dev0, seg1_dev1],
|
|
// - for example, a transformer may have a fused QKV matrix rather than 3 matrices, those would be 3 separate segments
|
|
// that each need to be split individually across devices so that each device gets a slice of Q, K, and V
|
|
int64_t ne[16*GGML_BACKEND_META_MAX_DEVICES];
|
|
uint32_t n_segments;
|
|
};
|
|
|
|
// function to assign split states for statically allocated tensors, compute tensor split states will be assigned to be compatible:
|
|
typedef struct ggml_backend_meta_split_state(*ggml_backend_meta_get_split_state_t)(const struct ggml_tensor * tensor, void * userdata);
|
|
|
|
// create a new meta device from "simple" devices, meta buffer type/buffer/backend is then derived from this:
|
|
// TODO: this looks a bit strange - a backend API creates a device. I think we should try
|
|
// express this as a backend registry functionality instead
|
|
GGML_API ggml_backend_dev_t ggml_backend_meta_device(
|
|
ggml_backend_dev_t * devs, size_t n_devs, ggml_backend_meta_get_split_state_t get_split_state, void * get_split_state_ud);
|