Repository navigation
CUDA: fix duplicate expert IDs - #30477
JohannesGaessler wants to merge 1 commit into
Conversation
|
I'm interested: #19182 |
|
My understanding is that duplicate IDs are also relevant for #26631 . The PoC in this particular PR is not what I would want to merge. I think I know the correct way to do it and it would be compatible with skipping computation in case of expert ID -1. Can you spin out the CPU implementation and the new tests into a separate PR so that I have something on master that I can use as a point of reference for my implementation? To be clear: from my end there is no urgency since I think I can handle duplicate IDs and skipping in separate PRs without issue. |
That would be tricky: we cannot tell if the op must run on CPU or CUDA without looking at tensor data. That's why I need to do all backend in one single PR, otherwise |
See #29998 (comment) .
The CUDA code on master is assuming that each expert is used either 0 or 1 times. This PR provides a proof-of-concept for the minimal changes needed to correctly handle duplicate expert IDs. This requires some algorithmic changes needed for
mmid.cuthat I think are quite doable and would not add meaningful amounts of complexity. However, there are 2 relevant issues for performance:mm_ids_helperkernel is launched with one CUDA block per expert. On master the amount of shared memory to store expert IDs is proportional ton_tokensbecause each expert can show up at most 1 time. With duplicate IDs this is now proportional ton_tokens*n_expert_usedand I think that can already become problematic for real-life use cases in llama.cpp.n_tokens, anything beyond that can be excluded from the loop bounds/CUDA grid in host code. With duplicate IDs the GPU code now needs to consider a width of up ton_tokens*n_expert_usedfor the worst case. IIRC that was a difference of something like 1.5x or 1.7x.To be clear: this PR is a PoC and is not in a state where it can be merged.
@am17an when you said in #26294 (review) that that PR fixes the issue, did you mean that you cherry-picked the commit and had a successful
test-backend-opsrun? When I cherry-picked it myself changes tommid.cuwere insufficient to fix the issue.Requirements