ggml: allow passing alloc dependencies in graph_optimize - #27301
Conversation
|
I tested #25952 locally with this PR, and this PR solves the lifetime issue cleanly. I registered experts, weights, and the optional expert_scale as allocation dependencies. |
|
@ggerganov: did you get chance to review this PR ? |
|
@anujj For my understanding, how did you test it? The PR currently does not provide any dependency information from the CUDA backend. |
ggerganov
left a comment
There was a problem hiding this comment.
Before merging, can we get a sample fusion implementation based on this mechanism to understand better how it would work in the a real case?
|
I've put them in the PR desc earlier, do you want to me actually add one here? |
|
Not needed to add to this PR. If you have a branch with #21897 for example using this new dependency information? |
|
@ggerganov in 56339ee I have made the changes to use this PR and enable concurrent streams |
|
cc @jeffbolznv if you have any thoughts before we merge |
max-krasnyansky
left a comment
There was a problem hiding this comment.
Looks good to me. We might have a use for this soon in ggml-hexagon
|
It's not immediately obvious to me in which situations graph_optimize should call it vs when we can get away without doing it, or if we should just be calling it for all fusions. I also think the new view nodes have a chance of breaking fusions if they're not carefully placed. e.g. vulkan's graph_optimize goes to some effort to bunch view nodes together into groups so they aren't interleaved with non-empty ops, and using this callback will potentially scatter more views in between real ops. Like, if I have fusions for both rms_norm+mul and rms_norm+mul+rope, then I don't want to make mul depend on rms_norm and end up with a graph of rms_norm+mul+view+rope that breaks my rms_norm+mul+rope fusion. I think when I had first suggested something like this in the past, my idea was to add the dependencies as additional operands to the existing nodes rather than additional nodes. That would avoid the issue of the additional views getting in the way. But it has drawbacks, too, like needing to modify tensors that should be treated as const. |
|
Maybe an alternative approach is to carry the dependencies as part of |
|
I think it can be refactored to do that if we find big issues with the current approach. For now as its opt-in I don't see issues doing this since it's already an established pattern in the scheduler. I plan to add this for big perf improvement fusions like topk-moe and some others and let the rest just be as they are today. |
Overview
Currently a backend doesn't have a good way to tell the allocator to not re-use memory for tensor operations which can be used for fusion or same-gpu parallelization (concurrent streams), this necessitates backends to work around this by implementing memory checks + also disabling fusion when memory checks fail. Some fusions never run because of this (e.g. #25952 (comment), #21897),
This PR introduces an extension to the
graph_optimizeAPI which can used by backends to add allocator dependencies ingraph_optimize, e.g.This can be also be used for fusion to avoid creating scratch buffers:
e.g. for MoE reduce in #25952
Additional information
Requirements