Skip to content

common : only load backends when required#22290

Merged
angt merged 3 commits into
ggml-org:masterfrom
angt:common-only-load-backends-when-required
May 5, 2026
Merged

common : only load backends when required#22290
angt merged 3 commits into
ggml-org:masterfrom
angt:common-only-load-backends-when-required

Conversation

@angt
Copy link
Copy Markdown
Member

@angt angt commented Apr 23, 2026

Overview

Only load backends when required.

Additional information

This fixe the following issues: #20186, #21708 and maybe others.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES (kimi): I've asked the list of functions to modify for a minimal patch

@angt angt requested a review from a team as a code owner April 23, 2026 13:10
Comment thread ggml/src/ggml-backend-reg.cpp Outdated
Comment thread common/arg.cpp
@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Apr 23, 2026
@angt angt force-pushed the common-only-load-backends-when-required branch from 1952e4b to f2d4b06 Compare April 28, 2026 14:08
@ggerganov
Copy link
Copy Markdown
Member

The test-thread-safety is failing

@angt angt requested a review from ggerganov as a code owner April 28, 2026 15:09
@ggerganov
Copy link
Copy Markdown
Member

Hm, I don't see where we would call ggml_backend_load_all() for llama-cli, llama-server, etc. Building with -DGGML_BACKEND_DL=ON makes these binaries not load any backends.

@angt
Copy link
Copy Markdown
Member Author

angt commented Apr 28, 2026

Hm, I don't see where we would call ggml_backend_load_all() for llama-cli, llama-server, etc. Building with -DGGML_BACKEND_DL=ON makes these binaries not load any backends.

Damn, checking. I don’t use AI often (for llama.cpp!). Kimi is this bad ? 🤣

@github-actions github-actions Bot added the testing Everything test related label Apr 28, 2026
@angt angt force-pushed the common-only-load-backends-when-required branch from 9027fd9 to 37ac5d5 Compare April 28, 2026 16:26
@angt
Copy link
Copy Markdown
Member Author

angt commented Apr 28, 2026

The last call was missing...
Edit: So Kimi is fine, it was my fault 🙄

@angt
Copy link
Copy Markdown
Member Author

angt commented Apr 30, 2026

@ggerganov maybe I can take this PR as an opportunity to remove ggml_backend_load_all from common_params_parser_init and call it explicitly where it’s needed, instead of hiding it there?

@ggerganov
Copy link
Copy Markdown
Member

@ggerganov maybe I can take this PR as an opportunity to remove ggml_backend_load_all from common_params_parser_init and call it explicitly where it’s needed, instead of hiding it there?

Yes, let's do that.

angt added 3 commits April 30, 2026 12:11
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
@angt angt force-pushed the common-only-load-backends-when-required branch from 37ac5d5 to b967482 Compare April 30, 2026 12:25
@angt angt requested a review from a team as a code owner April 30, 2026 12:25
@angt
Copy link
Copy Markdown
Member Author

angt commented Apr 30, 2026

I finally have updated llama_backend_init() to call ggml_backend_load_all(). The name was a perfect fit, so I decided to try this, but I’m not yet 100% convinced too, and maybe we should just call ggml_backend_load_all() everywhere...

@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label May 4, 2026
@angt angt merged commit bf76ac7 into ggml-org:master May 5, 2026
44 of 46 checks passed
@rgerganov
Copy link
Copy Markdown
Member

rgerganov commented May 6, 2026

This patch broke RPC (issue #22721) and introduced obscure regressions (issue #22748). Having multiple calls to ggml_backend_load_all() is not how loading dynamic backends is supposed to work and breaks many implicit assumptions.

I suggest to revert this patch.

samuraieng pushed a commit to samuraieng/llama.cpp that referenced this pull request May 6, 2026
* common : only load backends when required

Signed-off-by: Adrien Gallouët <angt@huggingface.co>

* llama : call ggml_backend_load_all() directly from llama_backend_init()

Signed-off-by: Adrien Gallouët <angt@huggingface.co>

* Add ggml_backend_load_all() where llama_backend_init() is not used

Signed-off-by: Adrien Gallouët <angt@huggingface.co>

---------

Signed-off-by: Adrien Gallouët <angt@huggingface.co>
@angt
Copy link
Copy Markdown
Member Author

angt commented May 6, 2026

I think it’s just because of some missing calls it’s hard to track all of them

@angt
Copy link
Copy Markdown
Member Author

angt commented May 6, 2026

#22752 should fix both issues (and others)

cetarthoriphros pushed a commit to cetarthoriphros/llama.cpp that referenced this pull request May 9, 2026
* common : only load backends when required

Signed-off-by: Adrien Gallouët <angt@huggingface.co>

* llama : call ggml_backend_load_all() directly from llama_backend_init()

Signed-off-by: Adrien Gallouët <angt@huggingface.co>

* Add ggml_backend_load_all() where llama_backend_init() is not used

Signed-off-by: Adrien Gallouët <angt@huggingface.co>

---------

Signed-off-by: Adrien Gallouët <angt@huggingface.co>
meh pushed a commit to meh/llama.cpp that referenced this pull request May 10, 2026
* common : only load backends when required

Signed-off-by: Adrien Gallouët <angt@huggingface.co>

* llama : call ggml_backend_load_all() directly from llama_backend_init()

Signed-off-by: Adrien Gallouët <angt@huggingface.co>

* Add ggml_backend_load_all() where llama_backend_init() is not used

Signed-off-by: Adrien Gallouët <angt@huggingface.co>

---------

Signed-off-by: Adrien Gallouët <angt@huggingface.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants