Repository navigation
Conversation
|
Hey @am17an! Sorry for a tanget, but I'm trying to learn more about running MoE models efficiently and noticed updated |
|
|
There was a problem hiding this comment.
did you forgot to include it in GGML_PUBLIC_HEADERS ?
There was a problem hiding this comment.
removed the public header
|
@zarbis Depends, |
@Green-Sky sorry again for hijacking this conversation, just wanna make sure if I need to file a bug report or not. Trying to load 60GB model on 16+32 VRAM+RAM system using If that is not expected behavior - I will open an issue with full details. |
- moe-cpu-misses: pass the width to the warp shuffles, the HIP macros need it, and a 64-bit mask to __ballot_sync for ROCm 7 - musa: map cudaHostAllocMapped, cudaHostAllocPortable and cudaHostGetDevicePointer - llama-moe-cache: const_cast the custom op userdata (-Wcast-qual) - test-llama-archs: only the backend tests use 4 layers for the host experts archs, the models written with -o keep the layer count of the fusion baselines - test-llama-archs: scale the layer split MoE cache budget by the number of GPUs, each GPU gets the budget of the single GPU tests
- libllama and the CUDA backend each keep a copy of the definitions (src/llama-moe-cpu-misses.h, ggml/src/ggml-cuda/moe-cpu-misses.cuh), no public ggml header - get_api takes GGML_MOE_CPU_MISSES_VERSION, a backend with another version returns NULL and the MoE cache uses the split path - the class count and the decay table size of the ClassLRU are fields of ggml_moe_cpu_layer, the CRF half-life stays in libllama
fcc88a6 to
fde147e
Compare
am17an
left a comment
There was a problem hiding this comment.
@ggerganov PTAL at the code structure, most of the complexity is behind the llama-moe-cache submodule and there are other minimal changes.
| // the MoE cache ops, obtained with ggml_backend_reg_get_proc_address(reg, "ggml_moe_cpu_misses_get_api") | ||
| // a copy of the definitions in src/llama-moe-cpu-misses.h: keep the two the same and bump GGML_MOE_CPU_MISSES_VERSION on a change |
There was a problem hiding this comment.
This is not acceptable - it couples the ggml backend with the llama.cpp code in some very convoluted way.
There was a problem hiding this comment.
I did this avoid new ggml ops, otherwise we would have to add 3 of them, is that okay?
There was a problem hiding this comment.
It would be better, but adding ops that have very narrow application generally should be avoided. I'm not sure if it is the case here - need to see what the ops look like and try to see if they would be useful to other projects.
Alternatively, we can try to think of some new ggml mechanism that would allow to inject custom ops with their backend implementations from user code. This way llama.cpp-specific ops could live in the project and do not pollute the ggml API. For Metal it's probably not difficult to come up with something since it can already compile code at runtime. But CUDA might be more complicated - not sure.
There was a problem hiding this comment.
The other way is to have a public header in ggml, src/ggml-ext.h which can avoid this coupling. I removed it earlier as I wanted minimal changes. If you're okay with that then it can be done this way. Later on we can come up with a solution to inject ops, but I don't think it's easy to do.
There was a problem hiding this comment.
I tried ggml-ext.h at some point and realized that it does not really work: #21869. It only works for the examples/tools that are inside the ggml repo. llama.cpp is technically a 3rd-party project for ggml so it does not fall in this category.
There was a problem hiding this comment.
I looked at the branch, but I don't think it's good enough. I find it a bit difficult to follow the idea. The mechanism has to be something like a plugin system, though I am not sure exactly how the interface should look like. It probably has to be able to expose different implementations for the different backends. And some generic scheduling information (i.e. number of threads / workgroups). The overlap/join logic is probably a second iteration of the design - it's not even clear to me if it should be supported. None of the existing ops support this. Including the backend headers directly in user code is also something that should be avoided - we want to keep the implementation backend-agnostic.
Atm I don't see a clear path how to implement this. Either try to start from scratch with some simple and small plugin system where we can discuss details and prototype gradually. Or try to express the logic of this PR in some generic ops that would make sense to be added to the library.
I am also not sure what exactly we want to implement. Is it just new ops, or is it an entirely new mechanism for running 2 backends? Are the new ops some sort of workaround for the actual goal? The diagram in the OP is not enough to understand completely.
There was a problem hiding this comment.
The idea is to run everything in the GPU. The cache, as well as the CPU experts to run are signalled via device memory. Instead of 2 syncs per layer we have 0. Introducing the ops would be an easy way to do this imo. The ops can be used by any ggml user who uses moe cache, it can be diffusion or audio models which utilize this feature and have MoE models.
There was a problem hiding this comment.
If you think the ops could find broader application, the best way would be to add a standalone example in https://github.com/ggml-org/ggml/tree/master/examples to demonstrate how they can be used. Something very basic - almost like the matrix multiplication example: https://github.com/ggml-org/ggml/tree/master/examples/simple.
There was a problem hiding this comment.
Actually since the MoE cache is based inside llama.cpp, it doesn't make a lot of sense if the ops are generic. So idk at this point, I don't want to leave this halfway but if we can't find a way to fit it into llama.cpp and so be it 🤷. @gaugarg-nv do you have ideas?
There was a problem hiding this comment.
@ggerganov I had AI spin-up a prototype like you asked am17an#73
|
Few rounds of greedy benchmarks with 2048 generated tokens on top of 71k context.
|
|
FWIW, I am seeing around 25% perf improvement with this PR on RTX 5090 + Windows with Qwen 3.6-35B with 8 GB cache and 0 CPU share. |
|
@gaugarg-nv what improvement do you see with non-zero CPU share? |
|
With 0.5 CPU share, I see 53% perf improvement with 4 GB cache. |
Overview
This is the most complex piece of the running the MoE cache on devices where the syncs are expensive. On Vulkan or Windows there should be a huge speed-up. On CUDA on linux I see something like 10%.
The architecture looks a bit like this:
I've used
GGML_OP_CUSTOMto do the signalling between host and the GPU.Additional information
Requirements