Repository navigation
Conversation
|
This was totally opportunistic while comparing CUDA and Metal for something else |
|
with -r 15:
|
ad6269a to
e924e7d
Compare
forforever73
left a comment
There was a problem hiding this comment.
LGTM :) clean mirror of the CUDA gdn cache fusion. Built and ran test-backend-ops locally on my M4 Max and new cases all pass, the existing GATED_DELTA_NET tests are unaffected.
|
Also ran llama-bench (-r 15)
|
e924e7d to
85a4663
Compare
|
@ggerganov is this better ? |
| // The cpy reads the gdn output through a view of a different shape, so ctx->can_fuse() cannot | ||
| // express it; the linkage and geometry are validated directly instead. |
There was a problem hiding this comment.
It's better, but still, I am not sure what to do about this part. Not being able to use can_fuse() required that you implement the "elision" logic, which is a duplication of the logic in can_fuse(). Does not seem right.
There was a problem hiding this comment.
Thanks, I have tried many things to not lose too much perf compared to the first iteration.
I’ll dig that when I come back
There was a problem hiding this comment.
Yes, this should not affect the performance. The goal is rather to avoid adding the dst_elide stuff. Having to add it means that the existing ggml_can_fuse_ext() is not general enough to capture such cases. So we should look to extend it in some way, or to formulate the graph in alternative way that would be compatible.
There was a problem hiding this comment.
Is it not possible to utilize the existing ggml_can_fuse_subgraph() in this case?
There was a problem hiding this comment.
I dont think so 🤔 The cpy is a view on an external cache tensor not really a subgraph and would require to patch ggml_can_fuse_subgraph. But I believe that the allow_view_consumer added is better as it matches the cuda pattern (kind of future proof) and is minimal. Or maybe i miss something?
There was a problem hiding this comment.
Ok, will take a look at the proposal tomorrow.
This comment was marked as off-topic.
This comment was marked as off-topic.
4509960 to
98d0d2f
Compare
|
I think there is some confusion here - the fusion never takes place. For example on M2 Ultra: CMAKE_OPTS="-DGGML_BLAS=OFF" scripts/compare-commits.sh master pr/25788 llama-bench -hf ggml-org/Qwen3.5-0.8B-GGUF:Q8_0 -fa 1 -ub 2048 -d 0,2048,4096,8192 -r 3 -n 32 -t 1
CMAKE_OPTS="-DGGML_BLAS=OFF" scripts/compare-commits.sh master pr/25788 llama-bench -hf ggml-org/Qwen3.8-27B-GGUF:Q8_0 -fa 1 -ub 2048 -d 0,2048,4096,8192 -r 3 -n 32 -t 1
The reason is because the Metal backend optimizes the graph by rearranging the ops to run concurrently. Here is how the graph looks for the Metal backend after the graph optimization is performed: make -j && GGML_METAL_GRAPH_DEBUG=1 ./bin/llama-completion -hf ggml-org/Qwen3.5-0.8B-GGUF:Q8_0 -p "I believe the meaning of life is" --top-k 1 -n 1 -st -no-cnv -lv 5So the fusion pattern is no longer This graph optimization can be disabled with the |
I guess i did too many changes 😅 let me check that |
Mirror the CUDA backend's ggml_cuda_try_gdn_cache_fusion: route the KV cache pointer into the kernel so it writes recurrent-state snapshots directly into the cache and skips the redundant per-layer cpy. Signed-off-by: Adrien Gallouët <[email protected]>
|
I confirm the current code is broken.. i'm going to revert to the last state and redo all benches |
98d0d2f to
c2e7c1c
Compare
| // a cpy that scatters gated_delta_net state snapshots into the cache must stay right after | ||
| // its gdn node, otherwise the gdn+copy fusion cannot apply. do not pull other nodes in front of it. | ||
| const bool pinned = node0.op() == GGML_OP_CPY && | ||
| node0.node->src[0] && node0.node->src[0]->view_src && | ||
| node0.node->src[0]->view_src->op == GGML_OP_GATED_DELTA_NET; | ||
|
|
There was a problem hiding this comment.
I wonder if we can avoid this extra logic. We already have related logic for preventing reorder of fusable nodes. Ideally it should be extended to cover this case and not need to add this new logic here.
Currently, the existing logic in ggml_graph_optimize() uses the ggml_can_fuse() to figure out which nodes could be fused, which we know does not work for this case because of the different shapes. I would try to replace it with ggml_can_fuse_subgraph() since it's more general. You mentioned earlier that ggml_can_fuse_subgraph() does not work, but I am not sure I understand why would that be.
gated_delta_net cache fusion
Overview
Mirror the CUDA backend's
ggml_cuda_try_gdn_cache_fusion: route the KV cache pointer into the kernel so it writes recurrent-state snapshots directly into the cache and skips the redundant per-layer cpy.Additional information
Requirements