fix(build): add missing link recipes for llama-bench, quantize, imatrix and perplexity - #1034
fix(build): add missing link recipes for llama-bench, quantize, imatrix and perplexity#1034dexhunter wants to merge 1 commit into
Conversation
llama-bench, quantize, imatrix and perplexity each declared prerequisites in llama.cpp/BUILD.mk but had no link recipe, so make compiled their objects, printed "Nothing to be done", and exited 0 without producing any binary. The generic o/$(MODE)/%: o/$(MODE)/%.o rule could not link them either, because the object path (.../tools/llama-bench/llama-bench.cpp.o) does not match the pattern the target implies (.../llama-bench/llama-bench.o). Only llama-server had a recipe. Add a link recipe for each of the four tools, following the llama-server pattern and the generic link form in build/rules.mk. They need the same support objects as llama-server minus the server-only ones, because llama.cpp.a references them: TOOL_LLAMAFILE_OBJS for the llamafile_* calls patched into src/llama-mmap.cpp and ggml/src/gguf.cpp, and HTTPLIB_OBJS plus mbedtls.a for common/download.cpp, common/hf-cache.cpp and common/license.cpp, which are built with -DLLAMA_USE_HTTPLIB. Also add main.cpp to TOOL_BENCH_SRCS, TOOL_QUANTIZE_SRCS and TOOL_PERPLEXITY_SRCS. Upstream keeps main() in a separate main.cpp for those three tools, so without it they fail to link with an undefined reference to main. imatrix defines main() in imatrix.cpp and needs no change. llama-server is unaffected: rebuilt from the patched BUILD.mk it is byte-for-byte identical. Co-Authored-By: Aiden <aiden@weco.ai>
|
TYSM @dexhunter ! I appreciate this, I had not added them to the main build because I wanted to test the executables first. I appreciate you added a check that verifies that llama-server is not impacted 🙏 I am trying to wrap up a release by EOD, so I might not be able to merge this immediately, but I am planning to do that right afterwards so we'll have time to play with all the executables before the following release. I hope that's ok, and thanks again! |
|
Completely fine — merging after the release makes more sense than merging into it, and it gives the four tools a full cycle before they're in front of anyone. No rush from my side. On wanting to test the executables first: fair, and the PR description under-delivers there. It only showed
The two together — Two things those runs are not: the perplexity and imatrix values are meaningless, because a 5M-parameter toy model over an arbitrary text file will report whatever it likes — read them as "the code path runs to completion and terminates correctly", not as a quality signal. And this was a default- Still current, too: |
Description
o/$(MODE)/llama.cpplists five executables, but onlyllama-serveris everbuilt.
llama-bench,quantize,imatrixandperplexityare silently neverlinked:
makecompiles their objects, reports success and exits 0, and nobinary is produced.
Two things are missing in
llama.cpp.patches/llamafile-files/BUILD.mk:1. No link recipe. Each of the four tools declares prerequisites but has no
recipe:
A prerequisite-only rule adds dependencies; it does not build anything. The
generic link rule in
build/rules.mk(o/$(MODE)/%: o/$(MODE)/%.o) cannot fillthe gap either, because the paths do not line up — the target is
o/$(MODE)/llama.cpp/llama-bench/llama-bench, so the pattern looks foro/$(MODE)/llama.cpp/llama-bench/llama-bench.o, while the object that exists iso/$(MODE)/llama.cpp/tools/llama-bench/llama-bench.cpp.o. With no recipe and nomatching pattern rule, make treats the target as already satisfied and prints
Nothing to be done— so a missing binary looks exactly like a successfulbuild.
2.
main()is not compiled in. Upstream splits three of these tools into areusable implementation file plus a small
main.cpp. Only the implementationfile was listed:
main()*_SRCS?llama-benchtools/llama-bench/main.cppquantizetools/quantize/main.cppperplexitytools/perplexity/main.cppimatrixtools/imatrix/imatrix.cppSo even with a recipe added, three of the four would fail to link with
undefined reference to main.This has been the case since the v0.10.0 rewrite (
4cc1a5f7, "llamafilereloaded", #867), which gave
llama-servera recipe but not the other four.What this PR changes
One file,
llama.cpp.patches/llamafile-files/BUILD.mk:main.cpptoTOOL_BENCH_SRCS,TOOL_QUANTIZE_SRCSandTOOL_PERPLEXITY_SRCS.form (
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@, the same shape as thegeneric rule in
build/rules.mk), preceded by@mkdir -p $(dir $@)asllama-serverdoes.The tools take the same support objects as
llama-serverminus the server-onlyones, because
llama.cpp.aitself references them:$(TOOL_LLAMAFILE_OBJS)—src/llama-mmap.cppandggml/src/gguf.cpparepatched to call
llamafile_open_gguf(),llamafile_read(),llamafile_ref(), …$(HTTPLIB_OBJS)+o/$(MODE)/third_party/mbedtls/mbedtls.a—common/download.cpp,common/hf-cache.cppandcommon/license.cpparecompiled with
-DLLAMA_USE_HTTPLIB.No other build logic is touched, and nothing outside this file changes.
PR Type
Relevant issues
No issue is fixed by this PR. Context:
llama-benchis the standard reproducerfor the dense-model CPU performance gap being investigated in #980, and it
cannot currently be built from this repository — so this change is a
prerequisite for reproducing that comparison with llamafile's own build rather
than an upstream one. It does not address the performance gap itself.
Verification
All commands run on Linux x86-64 from a clean clone at
0ce2b877b22346ac11315425daf47448f73f3283(Update llama.cpp to b10103 (c588c4f) (#1030)), withmake setup(llama.cpp submodule atc588c4f47683e73ad2d69f50480bec6cc85fd0f7, b10103) and.cosmocc/4.0.2/bin/make.Before — build succeeds, binaries are absent:
The same
Nothing to be done/ exit 0 result holds forquantize,imatrixand
perplexity.After — all five build:
Each new binary runs:
quantizealso reaches the real quantization path rather than just printingusage:
llama-serveris unaffected. EditingBUILD.mkinvalidates every objectthat depends on it, so the server was fully recompiled (242 translation units)
and relinked from the patched makefile. The resulting binary is byte-for-byte
identical to the one built before the change:
(This comparison is an incremental rebuild in the same tree on purpose.
LLAMA_BUILD_NUMBER := $(shell date +%s)bakes a wall-clock timestamp intobuild-info.cpp, so binaries are not reproducible across a from-scratchrebuild;
build-info.cppdepends only onbuild-info.cpp.in, so keeping itfixed across the incremental rebuild is what makes the comparison isolate the
effect of the
BUILD.mkchange.)Test suite —
.cosmocc/4.0.2/bin/make checkexits 0:Checklist
targets as broken; none needed updating.)
llama.cpp/,whisper.cpp/, orstable-diffusion.cpp/, Ialso updated the matching
*.patches/files. — The change is made directly inllama.cpp.patches/llamafile-files/BUILD.mk, whichapply-patches.shcopies intollama.cpp/; nothing in the submodule itself is modified, so no new patch file isneeded.
AI Usage Information
AI Model used: Claude (Anthropic)
AI Developer Tool used: Claude Code
Any other info you'd like to share: An AI assistant was used to investigate the
build failure, draft the
BUILD.mkchange, write this description, and run theverification builds described above. The diagnosis and every command output above
were reproduced and checked on a real Linux x86-64 build of this repository at the
stated base commit.
I am an AI Agent filling out this form (check box if true)