Skip to content

hooks: move the fork code out of upstream files - #314

Open
gaetan-puleo wants to merge 38 commits into
masterfrom
strix-llama-hooks
Open

gaetan-puleo wants to merge 38 commits into
masterfrom
strix-llama-hooks

Conversation

@gaetan-puleo

@gaetan-puleo gaetan-puleo commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

The fork keeps its changes inside upstream files, so every upstream sync conflicts. This PR moves the fork code to
hooks/. The upstream files go back to 9048bad8d, plus 65 hook lines (56 hook points, 23 files, listed in
hooks/HOOKS.txt) and four files changed directly: 4 casts in ggml-cpu/arch/x86/quants.c that clang needs, and the linter
rules for hooks/ (.flake8, ty.toml, .ecrc). The fork code is compiled next to the upstream code and is selected at
run time.

The branch is on master 403dfcb03. The commits before "move the fork changes of upstream files into hooks/" only add
hooks/; that commit puts the upstream files back; the later ones are fixes and the port of newer master commits.
The diff is large because the fork files are kept complete: they are generated from the fork by
hooks/tools/import-*.py, with the adapted lines marked hooks:.

Nothing of the fork is dropped, except the rule to send general changes to halo-box/llama.cpp (archived), in the PR
template, AGENTS.md and CONTRIBUTING.md. hooks/PORT.txt records what happened to each fork change of an upstream
line.

The fork README, docs, CI workflows, Dockerfiles and agent files stay at their path.

What changes for users

On Linux the fork code runs by default. Each part is behind a switch that gives the upstream code back:

Switch (GGML_HOOKS=-name turns it off) Effect
cuda_node, vk_node the fork computes the GPU nodes that upstream refuses
cuda_graph the fork HIP backend: kernels, fusions, graph passes, buffers
vk_graph the fork Vulkan backend
sched the fork scheduler and graph allocator
llama the fork libllama
tools the fork server, llama-bench and quantize

GGML_HOOKS=none gives upstream at run time, -DLLAMA_HOOKS=OFF builds pure upstream.

Differences with master:

  • Windows and macOS builds have no fork code: the hooks need an ELF linker (--wrap), so these builds are upstream,
    plus the UI and build fixes.
  • The fork arguments and common code are in the server, llama-bench and quantize. The other programs (llama-cli,
    llama-completion, ...) run the fork libllama and backends with the upstream arguments; the server inside llama-cli is the
    upstream one.
  • The fork converter (EXL3, ...) is hooks/python/convert_hf_to_gguf.py; the one at the root is the upstream one.
  • cpu_mul_mat_id, the fork CPU row map of MUL_MAT_ID, is a variant that stays off (GGML_HOOKS=+cpu_mul_mat_id).
  • test-alloc, test-fp8, test-quantize-stats, test-ggml-hooks and test-llama-hooks check upstream internals, so
    they turn off the switches concerned. The fork versions of the upstream tests are the test-<name>-fork tests.
  • With the defaults, the Vulkan hook kernels and the hooks around the upstream libllama (hooks/llama) do not apply.

Measurements

Device:     Ryzen AI Max+ 395 (gfx1151), 128 GB
Power:      tuned profile "balanced"
Kernel:     7.2.4-200.fc44.x86_64
Backend:    ROCm 10.1, RADV (Mesa 26.0.3)
Branch:     0aed0b87d (speed and 84 comparisons), a18dda974 (tests, new defaults)
Fork:       403dfcb03, same machine and session
No hooks:   the same tree with -DLLAMA_HOOKS=OFF

Correctness: llama-perplexity, 6 chunks of 2048, every chunk compared. 84 of 84 comparisons are identical: the default
against no hooks, and the switches against the fork binary. Models: Qwen3.5-0.8B (Q8_0, BF16, EXL3), gpt-oss-20b MXFP4,
Gemma 4 26B Q4_K_M, North Mini Code Q4_K_XL. HIP and Vulkan (EXL3: HIP only, switches against the fork only), ubatch 256,
512, 1024, 2048. "Default" and "switches" in these two sections are 0aed0b87d, with the switches off
and on; they are on by default now. With the new defaults, gpt-oss and Qwen3.5 Q8_0 are identical to the fork on HIP and
Vulkan, EXL3 on HIP, and GGML_HOOKS=none is identical to the build without hooks (3 chunks, ubatch 512).
On HIP with the switches, 13 partial offload, CPU, KV type and flash attention settings are identical to the fork too,
and test-mtp-draft-vocab (38 checks).

Prompt speed, tokens/s, llama-bench -fa on -b 4096, first of two passes, 2 samples each:

Model Backend pp / ub no hooks switches off switches on fork
Qwen3.5-0.8B Q8_0 HIP 8192 / 2048 7726 7728 14269 14202
Qwen3.5-0.8B BF16 HIP 8192 / 2048 7620 7554 11262 11276
gpt-oss-20b MXFP4 HIP 8192 / 256 1120 1100 1927 1927
gpt-oss-20b MXFP4 Vulkan 8192 / 2048 2321 2317 2346 2349
Gemma 4 26B Q4_K_M HIP 8192 / 2048 1641 1641 1924 1920
Gemma 4 26B Q4_K_M Vulkan 8192 / 2048 1632 1627 2046 2041

The first binary run on a model is 2 to 3 % faster, so the comparisons below alternate the order (8 pairs, 4 pp/ub
settings, mean and 95 % interval; the interval uses 1.96, about 20 % narrow for 8 pairs):

Comparison Difference
control, gpt-oss HIP, no hooks against itself -0.3 % +/- 0.4
gpt-oss HIP, switches off against no hooks -0.1 % +/- 0.1
gpt-oss HIP, switches on against fork +0.2 % +/- 0.2
Qwen3.5 Q8_0 HIP, switches on against fork -0.3 % +/- 0.2
control, Qwen3.5 Q8_0 Vulkan, no hooks against itself +0.3 % +/- 0.4
Qwen3.5 Q8_0 Vulkan, switches on against fork -0.2 % +/- 0.3
Qwen3.5 Q8_0 Vulkan, switches off against no hooks -1.2 % +/- 1.0

Tests (strix-002, with the new defaults): ctest 96/100 on HIP and 94/98 on Vulkan; the 4 failures need git-lfs or Python
modules that this machine does not have. test-ggml-hooks, test-llama-hooks, check-port.py 65515/65515 lines,
check-hooks.sh, check-wraps.sh, check-ctest.py 91/91. The server tests not marked slow: 503 passed with the upstream
tests, 514 with the fork tests; one test (test_n_probs_post_backend_sampling) fails with the fork binary too. Same output
as the fork: completion, embedding, tokenize, eval-callback, imatrix, speculative-simple, lookup, gguf-split, and the
quantized files (Q4_K_M, IQ4_XS, Q8_0). Static and GGML_BACKEND_DL (Vulkan, HIP) builds run Qwen3.5 Q8_0.

CI (92d8e95ed): 22 of 22 jobs pass. The two commits after a18dda974 add a missing include in a test file and the
time limit below.

  • test-llama-context-fork has its own limit of 1800 s. On llvmpipe it took 911 s, over the job limit of 900 s. On the same
    CPU (EPYC 7763) test-llama-context outside this branch took 844 to 897 s in 7 runs, and 3 more runs, 2 of them on
    master, reached the limit. The message of 92d8e95ed blames a machine 9 % slower; that is wrong, it is the same CPU.
  • The llvmpipe tests take 1733 s against 1189 s on master, mostly because the upstream and the fork version of this test
    both run.

llvmpipe (strix-002, container with the environment of the CI job: Ubuntu 26.04, Mesa 26.0.8, LLVM 21.1.8, 4 cores,
92d8e95ed): ctest -L main passes with the defaults (37/37), with GGML_HOOKS=none (37/37), without hooks (19/19) and in
the fork (36/36). Time of the slow test alone, empty shader cache, alternated order, mean and 95 % interval (Student):

Comparison Runs each Times Difference
test-llama-context-fork, defaults against the fork test-llama-context 6 311.1 s, 310.6 s +0.1 % +/- 1.0
test-llama-context, GGML_HOOKS=none against no hooks 4 305.3 s, 305.5 s -0.1 % +/- 1.2

Known failures

  • The upstream test-backend-ops fails GATED_DELTA_NET cases with the defaults: 6 on ROCm0 (20450/20456), 9 on Vulkan0
    (22693/22702). They use the fork chunked prefill on fp16 operands, at 1.6e-7 to 2e-7 NMSE against the upstream bound of
    1e-7. The fork test (test-backend-ops-fork) has its own bounds for them and passes. ctest does not run these tests, but a CI lane
    that runs test-backend-ops directly (gfx1151) sees them.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: AGENT-AUTHORED. Claude (Opus) wrote the hooks code, the import tools, the tests, the docs and this
    description, and ran the builds and benchmarks, under review of the author.
  • What was NOT verified:
    • the new defaults on long or large runs: the speed matrix was not run again (the code is the same as with the switches);
    • models over 20 GB, multi-GPU, and the server under load with the switches;
    • depths over 8192 and llama-benchy;
    • the hosted CI does not run the HIP code: it only compiles it;
    • the Fedora llvmpipe of strix-002 (LLVM 22.1.1) crashes in LLVM, with the fork binary too;
    • the server tests that the fork changed are in hooks/apps/server/tests, which the CI does not run;
    • Qwen3.5 BF16 on Vulkan at small ubatch: the speed varies by 15 %, no conclusion;
    • no automatic test compares the branch with a fork build.

…files

Fork code lives in hooks/. It connects to upstream by run-time wrapping of
the backend interfaces, link-time wrapping and 52 marked hook points
(hooks/HOOKS.txt). See hooks/README.md and hooks/adr/.

Assisted-by: Claude Opus
Copied unchanged from master: these files are not built. tests/corpus and
tests/data are added with -f instead of changing the upstream tests/.gitignore.

Assisted-by: Claude Opus
…rnary)

The fork added them inside upstream files. They are now in hooks/ggml/types
and connect through the existing type hook points:
- rocmfp4/, rocmfpx/: the fork libraries, unchanged
- ggml-common-ext.h, ggml-quants-ext.h/.c, cpu/*-ext.*: the fork additions to
  ggml-common.h, ggml-quants.h/.c, ggml-cpu/quants.h/.c, arch/x86/quants.c and
  ggml-cpu.c, each block with its upstream file and line
- types.c, cpu/types-cpu.c: the trait wrappers, quantize and validate
The same type ids as the fork (GGUF files store them). The q4_0 prefetch casts
of arch/x86/quants.c are dropped: upstream code stays.

The upstream test-quantize-fns is built without GGML_HOOKS and tests the
upstream types; test-quantize-fns-hooks is the fork version of the test.
check-hooks.sh counts only files that exist upstream.

Assisted-by: Claude Opus
- the fork comments and ids of ggml.h, the ftype ids and their conversion
  (ggml_ftype_to_ggml_type, link-time wrap), arch-fallback.h verbatim
- hooks/tools/check-port.py and hooks/PORT.txt: every line the fork added must
  be in the branch, every fork change not kept as it is has a ledger entry
- server hooks: the HTTP side moves to llama-server-impl, which has
  server-http.cpp (test-server-component links server-context alone)

Assisted-by: Claude Opus
CPU (hooks/ggml/kernels/cpu): copies of the fork versions of upstream CPU
functions, as hook kernels, each with its upstream file and line:
- mul_mat with an F16 src1 into a quantized vec_dot_type (on)
- the compact MUL_MAT_ID row map (on for an F16 src1, a variant for F32)
- the src1 check of the fork tiled.cpp, before the tiled path
- the generic quantized paths of ADD, OUT_PROD, GET_ROWS for the fork types
- the f16 cases of binary_op
- the x86 q4_0 kernel with its two casts (variant, off)
CPU kernels can give their work size (cpu_work_size).

The public C functions of ggml and libllama are renamed in their upstream
file (hooks_rename, a compile definition) instead of link-time wrapped:
programs built outside the tree against the libraries get the hooks too.

Checked on strix-002: the fork equivalence programs give the same bytes as
the fork master, with the defaults and every variant; test-backend-ops CPU
(ADD SUB MUL DIV GET_ROWS OUT_PROD MUL_MAT MUL_MAT_ID) and the hooks tests pass.

Assisted-by: Claude Opus
The fork EXL3 library under hooks/ggml/exl3, its builders as GGML_OP_CUSTOM
nodes (ggml-exl3-ops.c), the fork CPU kernels as hook kernels with the fork
work sizes, the GGML_EXL3 option and test-exl3. Backends created directly
(ggml_backend_cpu_init, _cuda_init, _vk_init) install the wrapper.

exl3-equiv (39 cases) and the 305 test-exl3 output digests match the fork.

Assisted-by: Claude Opus
…nd allocator

- the fork builders that upstream lacks (FA causal prefix and top-k hints, the f16
  DSV4 hc_pre gated form) in ggml-fork-ops.c, the upstream hc_pre builders renamed;
- CPU hook kernels: the fork flash attention for nodes with selected keys and the
  f16 hc_pre, with the fork work size;
- fork_sched switch (GGML_HOOKS=+fork_sched, off by default): the fork scheduler,
  graph allocator, tensor-list allocation and sanitizer, verbatim, beside the
  upstream ones; a dispatcher picks one side, upstream ggml-backend.cpp is built
  through ggml-backend-upstream.cpp; ggml_hook_switch() for such switches;
- HOOK(gguf-type): the fork check of unassigned type ids.

ops-equiv (57 cases) matches the fork; disabling the kernels changes the results.
With fork_sched, test-alloc fails at test_reallocation exactly as the fork does.
Default path: PPL and decode speed equal to pristine upstream on gfx1151.

Assisted-by: Claude Opus
- fork_cuda_graph: the fork answers supports_op and offload_op, and computes
  the segments between hook kernels (replace_graph_compute via base_compute)
- CPU: a hook kernel leaves nodes with srcs in an extra (repack) buffer type
  to upstream; fixes the EXL3 crash with -dev none
- fork libllama: build_rs and the QSA cache work with a meta device
  (test-llama-archs passes), marked hooks: in the import tool
- test-alloc: test_reallocation expects the 44 bytes the fork allocator keeps
- symbols.cmake: no stray ${syms} in LLAMA_FORK_HOOKED
- PR template: drop the archived halo-box/llama.cpp requirement
- docs: fork tests, GDN tolerance with fork_cuda_graph, EXL3 converter check

Assisted-by: Claude Opus
The upstream files go back to llama.cpp 9048bad, plus the HOOK(name)
lines listed in hooks/HOOKS.txt. Every fork line taken out of them is kept
in hooks/: hooks/tools/check-port.py 9048bad origin/master checks each
added line and each hunk (hooks/PORT.txt gives where every fork version
lives: a hook variant, a switch, or an adapted copy).

The commits before this one add hooks/ beside the fork code, which they do
not change: those trees build and run as the fork.

After a rebase on a newer fork master, run the hooks/tools/import-fork-*.py
tools on it and resolve the conflicts of this commit with the upstream
version of the files outside hooks/.

Assisted-by: Claude Opus
The fork README describes this repository: it is at the root again, and
hooks/fork-files no longer keeps a copy. import-fork-files.py writes it
(ACTIVE_FORK_FILES) and check-hooks.sh skips it, as documentation only.
hooks/README.md: the hook point count (54 entries, 63 lines, 21 files).

Assisted-by: Claude Opus
The CI workflows, issue and PR templates, docs, AGENTS.md, CONTRIBUTING.md,
.editorconfig and the agent skills describe and test this repository: they
are the fork version at their path again, with the archived halo-box rule
still dropped from the PR template. Upstream re-enabled the workflows the
fork disables and had none of the ROCm and gfx1151 jobs.

import-fork-files.py extracts them with git archive (modes and the skill
symlinks kept), check-hooks.sh skips them, check-port.py reads a symlink as
its target. hooks/fork-files keeps the UI sources, scripts, tools and
examples files only.

Assisted-by: Claude Opus
.devops/ is a repository file like the CI workflows: the fork
rocm.Dockerfile (Ubuntu 26.04, ROCm 10.1.0) is back at its path, and
hooks/fork-files no longer keeps a copy.

Assisted-by: Claude Opus
The READMEs of the server, cli, completion, llama-bench, gguf-py and the
chat UI are docs like docs/, and scripts/hip/gcn-cdna-vgpr-check.py is run
by the fork hip-quality-check workflow with the fork arguments: both are
the fork version at their path (ACTIVE_FORK_PATHS), not copies in
hooks/fork-files. The fork additions of the server README describe server
features of fork_tools.

Assisted-by: Claude Opus
The fork tests read their corpus from tests/corpus and tests/data, which the
upstream tests/.gitignore ignores: a new corpus file would not be added. The
import tool skipped the file with the rest of tests/; it is now an active
fork path.

Assisted-by: Claude Opus
The fork tests were built (test-<name>-fork) but not registered: ctest -L
main and -L behavior, which the fork CI runs, ran none of them, and the
ROCmFPx codec tests were not built at all. With LLAMA_BUILD_TESTS they are
now built and registered as tests/CMakeLists.txt of the fork does: the
fork names, arguments, labels and conditions, with the fork switches of
the backends of the build; the fork versions of upstream tests as
<name>-fork. test-exl3 gets the main label.

On HIP the build registers the 91 tests of a fork build (check-ctest.py)
and ctest -L main passes 38/38 as the fork; -L behavior -LE model|backend
has the same 4 failures as the fork on this machine (git-lfs vocabs, the
python modules).

check-port.py counts and lists the lines of adapted hunks that are not
found as they are (ADAPTED in --missing): that is how a part of an adapted
hunk, the ctest rules, went missing.

Assisted-by: Claude Opus
Directories, files, switches, kernel names, CMake options and targets, and
the fork tests no longer carry "fork":
- hooks/ggml/{cuda,vulkan}, hooks/ggml/src/sched, hooks/llama/lib and
  lib-include, hooks/apps/{common,server,mtmd,tests,...}, hooks/files,
  hooks/tests/equiv, hooks/tools/import-{cuda,vulkan,llama,apps,files}.py;
- the switches cuda_node, vk_node, cuda_graph, vk_graph, sched, llama and
  tools, the CPU kernels cpu_*; GGML_HOOKS_CUDA, GGML_HOOKS_VULKAN and
  LLAMA_HOOKS_LIB; the targets hooks-common, hooks-tests, ...;
- the tests new in the fork are test-<name>; test-<name>-fork stays for the
  9 tests that upstream also has.

The namespace ggml_fork, the fork_* C symbols of the fork scheduler and the
internal identifiers of the bridges keep it: they name the objects of the
fork code next to the upstream ones. The text of the fork code is
unchanged. An old fork_* name in GGML_HOOKS is reported, with the new name.

The import tools regenerate this tree. Same results as before: gpt-oss-20b
PPL HIP 5.4736 / 5.4741 (+llama,+cuda_graph,+sched), Vulkan 5.4882 /
5.4699 (+vk_graph); EXL3 7.4162 / 7.4148 / 7.4151; check-ctest 91/91;
ctest -L main 38/38 on HIP. On Vulkan test-llama-context fails by default
as upstream alone does (state restore), and passes with +vk_graph,+sched.

Assisted-by: Claude Opus
…ters)

- The hooks build was only on with -DCMAKE_PROJECT_INCLUDE, which the CI
  does not pass: it built pure upstream. HOOK(hooks) in CMakeLists.txt
  includes hooks/hooks.cmake after project(); -DLLAMA_HOOKS=OFF builds
  pure upstream.
- UI: the prebuilt archive the build downloads is a split build, which the
  upstream asset check refuses. HOOK(ui-assets) now includes the fork
  functions directly: the file that llama-hooks.cmake wrote was missing
  on a fresh configure, and there is no hooks build on Windows and macOS.
- ggml-cpu/arch/x86/quants.c: the 4 (const char *) casts of the fork, as
  the recent clang refuses the implicit pointer conversion (Windows x64).
  A hook cannot fix a build error: the casts are in the upstream file, an
  exception listed in check-hooks.sh; the cpu_q4_0_prefetch_casts variant
  goes away.
- Linters: the copies in hooks/ get the rules of their originals (.flake8,
  ty.toml, .ecrc, listed in check-hooks.sh); the import tools strip the
  trailing whitespace that hooks: markers left; asserts in import-llama.py.

Locally: a fresh configure without options builds with the hooks and the
UI, ctest -L main 36/36; flake8 and editorconfig-checker pass, ty has only
the missing-module errors of the packages the CI installs, as the fork.

Assisted-by: Claude Opus
A section "Where fork code goes": upstream files change only by HOOK lines
(the exceptions are in check-hooks.sh), new fork code goes in hooks/,
upstream behavior is the default with the fork versions behind switches,
the copies are generated by the import tools, PORT.txt records every fork
change, the test names, LLAMA_HOOKS=OFF for the pure upstream baseline,
and the checks to run before a push. The rule to send general changes to
halo-box/llama.cpp is gone: that repository is archived. The changes are
applied by import-files.py, so a new import keeps them.

Assisted-by: Claude Opus
The repository map, "Where does my change go?", "Before you start", the
reasons to close a PR and the resources no longer send changes to
halo-box/llama.cpp: that repository is archived. "Before you start" points
to the hooks layout. Applied by import-files.py, recorded in PORT.txt.

Assisted-by: Claude Opus
The branch is on the fork master 25b1c17. The import tools regenerate
hooks/ from it: common/sampling and speculative, the server, the CUDA mmb
and fused Gated DeltaNet decode of #297, src/llama-context.cpp, the CI
workflows and the tests. The AMX mmq flags of the fork for clang 22 come
through HOOK(cpu-amx) in ggml/src/ggml-cpu/CMakeLists.txt, with or without
the hooks build (hooks/ggml/cpu-amx.cmake). test-backend-sampler-fork is
registered in ctest with the fork labels. PORT.txt lists the 46 new hunks.

check-port against 25b1c17: 64385/64385 lines, 514/514 files. Same as
the fork binary: gpt-oss-20b PPL 5.4741 (HIP +llama,+cuda_graph,+sched),
EXL3 7.4162 / 7.4148 / 7.4151, GATED_DELTA_NET 69/69 with cuda_graph.
check-ctest 91/91, ctest -L main 38/38, the sampler tests pass.

Assisted-by: Claude Opus
… init race, server test)

- Windows: no hooks build on WIN32, whatever the compiler. lld-link and
  link.exe have no --wrap (duplicate ggml_backend_init, __real_* missing);
  the HOOK points stay inert there.
- Warnings as errors (LLAMA_FATAL_WARNINGS, HIP -Werror): -Wno-switch on
  the ggml targets (the hook types raise GGML_TYPE_COUNT, so the switches
  that list the upstream types are no longer complete), and
  -Wno-missing-declarations -Wno-deprecated-declarations on the sources of
  hooks/ only (__wrap_* functions, the dispatchers of the fork batch API);
  one cast in mul-mat.c. hooks_warning_options in hooks.cmake.
- Vulkan, CUDA bridges: the first fork node initializes the fork Vulkan
  instance, which has no lock; contexts created in parallel
  (test-thread-safety) raced on it. The fork registry is taken once and
  the device tables under a mutex.
- import-apps.py: no copy of the Python files the fork did not change; the
  server grep test found its marker in the copy too.

Locally with the CI options: the CPU build with LLAMA_FATAL_WARNINGS has
only the errors that the same build without the hooks has (GCC 16), the
HIP build with -Werror builds. Same results as the fork binary: gpt-oss
5.4741, EXL3 7.4162 / 7.4148 / 7.4151, GATED_DELTA_NET 69/69, check-ctest
91/91, ctest -L main 38/38. Windows and llvmpipe are not tested here.

Assisted-by: Claude Opus
The branch is on the fork master 3b76dee (#180, context checkpoints
written to unlinked files beyond a RAM cap). The import tools regenerate
common, the server and its tests. test-llama-context is built from
several files: import-apps.py copies the whole test when the fork changes
one of them, built as test-llama-context-fork and registered in ctest as
the upstream one (labels, --models, generate-models, the reallocation
check), with the fork switches. PORT.txt lists the 9 new hunks.

check-port against 3b76dee: 64730/64730 lines, 516/516 files. Same as
the fork binary: gpt-oss 5.4741, EXL3 7.4162 / 7.4148 / 7.4151,
GATED_DELTA_NET 69/69; check-ctest 91/91, ctest -L main 39/39,
test-llama-context-fork passes.

Assisted-by: Claude Opus
- scripts/hip/gcn-cdna-vgpr-check.py (applied by import-files.py): the fork
  kernels are in namespace ggml_fork, so their symbols did not match the
  baseline, which has the fork names (new SGPR spills and missing kernels
  in the HIP quality check). _ZN9ggml_forkL<name><args>E<params> counts as
  _ZL<name><args><params>, with the substitutions of the parameters one
  lower; the upstream and fork versions of a kernel take the maximum, as
  two translation units do. test_vgpr_check.py passes; on a local metrics
  build the check passes (7224 kernels, the 11 baseline entries found).
- hooks/ggml/types/cpu/x86-quants-ext.c: not an empty translation unit off
  x86 (-pedantic in the behavior check).

Assisted-by: Claude Opus
The branch is on the fork master 403dfcb (#315: Inkling 2 Mini and its
attention mask fixes, the ffn_gate_up_exps scales, inkling2_loop). These
are fork commits, not in upstream master: the import tools regenerate
them into hooks/llama/lib and hooks/python; PORT.txt lists the 58 new
hunks.

check-port against 403dfcb: 65515/65515 lines, 521/521 files. Same as
the fork binary: gpt-oss 5.4741, EXL3 7.4162 / 7.4148 / 7.4151,
GATED_DELTA_NET 69/69; check-ctest 91/91, ctest -L main 39/39.

Assisted-by: Claude Opus
The include is in ggml_add_cpu_backend_variant_impl, which
ggml/src/CMakeLists.txt calls: CMAKE_CURRENT_LIST_DIR is ggml/src there,
so ../../../hooks left the tree and the OPTIONAL include did nothing. The
clang 22 flags of the fork for amx/mmq.cpp were never set, and the
Windows x64 build hung on that file for hours (as in the fork before
704c814). CMAKE_CURRENT_FUNCTION_LIST_DIR is the directory of the
function. cpu-amx.cmake marks its inclusion and hooks_setup stops the
configure when a CPU backend exists without it, so the Linux builds catch
a wrong path.

Assisted-by: Claude Opus
With cuda_graph the fork code ran on upstream buffers. It recognizes its
buffers by its own functions, so its in-place weight repacking (MMB R2:
dense Q8_0, routed Q5_1 and Q4_K) was skipped without a word, and the
allocation sizes were the upstream ones. On Qwen3.5-0.8B Q8_0 the branch
gave PPL 7.5111 and about 5 % less prompt speed than the fork (7.5119);
the models used before (gpt-oss MXFP4, EXL3) do not take these paths.

In this mode the device gives the fork buffer types, which keep the record
of the repacked weights (a write or a free drops it), and the asynchronous
copies of fork buffers go through the fork functions on the same stream.
Upstream buffers stay supported.

Qwen3.5-0.8B Q8_0: the same perplexity as the fork at ubatch 256, 512,
1024 and 2048. test-llama-archs-fork, ctest -L main 39/39 and
test-backend-ops-fork with cuda_graph 46621/46621 pass.

Assisted-by: Claude Opus
@gaetan-puleo gaetan-puleo changed the title hooks: base for moving the fork code out of upstream files (draft, do not merge) hooks: move the fork code out of upstream files Nov 23, 2026
@gaetan-puleo
gaetan-puleo marked this pull request as ready for review November 23, 2026 22:38
The switches cuda_graph, vk_graph, sched, llama and tools are on, as
cuda_node and vk_node: on Linux a build behaves as the fork. GGML_HOOKS=-name
gives the upstream code of one, GGML_HOOKS=none gives upstream. Windows and
macOS have no hooks build.

- The upstream tests that read upstream internals run upstream code
  (hooks_upstream_tests): test-alloc, test-fp8, test-quantize-stats,
  test-ggml-hooks, test-llama-hooks.
- llama-cli: the server it embeds has no command line to parse again, the
  tools switch broke it. It is the upstream server, on the fork libllama.
- GGML_BACKEND_DL: the fork CUDA and Vulkan copies exported a second module
  entry point (ggml_backend_init), these builds did not link.
- Static builds: stb_image and miniaudio of the fork mtmd-helper.cpp are
  local to the file, they clashed with the upstream ones.
- The trellis and EXL3 directory tests are not built with GGML_BACKEND_DL,
  as in the fork.

Same as the fork by default: gpt-oss and Qwen3.5 Q8_0 on HIP and Vulkan,
EXL3 on HIP; GGML_HOOKS=none is the build without hooks. The server tests
give the result of the fork binary. The upstream test-backend-ops fails 6
(ROCm0) and 9 (Vulkan0) GATED_DELTA_NET cases on its bound, the fork test
has its own.

Assisted-by: Claude Opus
Older libstdc++ versions (the CI) do not include it through other headers.

Assisted-by: Claude Opus
With the fork code on by default the test is the test-llama-context of the
fork. On llvmpipe it takes 863 s on master on a slow CI machine, with a
limit of 900 s; here the machine was 9 % slower and the test was stopped
while it passed. Nothing is disabled.

Assisted-by: Claude Opus

@dzannotti dzannotti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this, but i'd like a large approval status quo migrating to this @LaurentZuijdwijk @Nathanw1014 @pwilkin ?

@pwilkin

pwilkin commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Here's what my Untrusty Assistant says:

My recommendation is don't merge in its current form. The extension mechanism is good work. The blocker is what ships on top of it: by default the fork now runs frozen copies of whole subsystems, so future upstream syncs would quietly stop reaching the code that actually runs.

What I covered: the PR body and ADR, the full non-hooks/ diff against upstream 9048bad8d, hooks/README.md, hooks.cmake, the type hook header, the import tools, the CI workflows, and the commit trailers. I did not read the ~500k lines of copied code inside hooks/ line by line, and I built and ran nothing.

Blocking

1. The fork code that runs by default is a frozen copy, so upstream syncs stop taking effect.

  • The switches llama, cuda_graph, vk_graph, sched and tools are all on by default. They send execution to full copies of the fork's src/, ggml-cuda, ggml-vulkan, the scheduler, the server and common.

  • Most of each copy is just upstream code. Measured against upstream 9048bad8d:

    Copy About this much is plain upstream
    hooks/llama/lib 119k of 130k lines
    hooks/ggml/cuda ~52k of 78k
    hooks/ggml/vulkan ~51k of 71k
  • On the next sync, git merge will update src/, ggml/src/ggml-cuda and the rest cleanly, and none of that code runs. New model architectures, bug fixes and security fixes (vocab, model loader, server request handling) would land only in the upstream copy, which is compiled but unused.

  • The copies can't be refreshed either. import-*.py defaults to REF='origin/master', which only has the old layout until this merges. No tool replays an upstream diff into the namespaced copies.

  • So the PR swaps visible merge conflicts for silent drift, which works against its own goal. The ADR describes the other design: "upstream's version stays in place … a benchmark decides the default", plus "copied kernels drift … need manual updates". That is now true of entire subsystems, not single kernels.

  • You can see it already: master has moved 5 commits past the PR base (Vulkan get_rows, llama-memory-recurrent.cpp), and each one needs a hand-port. Three of the 38 commits are already "port the fork commits …".

  • A fair ask before anything else: a dry run of the next upstream sync on top of this branch, showing what actually reaches the code that runs.

2. The required checks don't run in CI. check-wraps.sh, check-hooks.sh and check-port.py appear in no workflow under .github/. The ADR says outright that "the wrap check must run in CI". --wrap fails silently: if a call moves into the file that defines the symbol, the wrapper is just skipped, with no link error.

3. This would turn a CI lane red, as the PR says itself. With the new defaults, the upstream test-backend-ops fails GATED_DELTA_NET cases (6 on ROCm, 9 on Vulkan), and the gfx1151 lane runs that test directly. That has to be settled before merge. Leaving it red, or loosening a bound to get green, conflicts with AGENTS.md ("must not bypass CI").

4. Verification is INCOMPLETE under the AGENTS.md correctness flow.

  • Missing: top-1 and full-logit comparisons on the four tests/corpus/* texts, and a deterministic multi-step decode comparison.
  • The evidence is llama-perplexity on 6 chunks. For a refactor that claims no behaviour change, identical full logits are the right test and cost little next to the rest of the work.
  • The speed runs are pp8192 with 2 samples. The required depths 0/12000/32000/64000 at PP2048 with -r 4 were not run.
  • The speed matrix was not re-run on the new-defaults commit a18dda97.

5. Process and scope.

  • Size: 1699 files, +527k lines, 38 commits.
  • The ADR is "Status: proposed" and dated the same day the PR opened. AGENTS.md asks for an issue first for a change this large or one that adds a new subsystem.
  • It also changes the rules: it drops the halo-box/llama.cpp routing rule from AGENTS.md, CONTRIBUTING.md and the PR template. That belongs in its own PR.

6. Windows and macOS lose all fork code. hooks.cmake returns early on WIN32 OR APPLE. If anyone uses fork builds there, that's a regression against master and needs an explicit sign-off.

Will slow the review

  • Warnings switched off: -Wno-switch is added to every ggml* target (hooks_warning_options). That permanently hides real missing-case warnings in upstream code as well. It should be limited to the files that need it.
  • Docs disagree with the code:
    • hooks/README.md says "Upstream stays the default" in one section and "the fork code runs by default" in another.
    • The ADR describes small hooks around upstream, not swapping out whole subsystems. The ADR should record the design that actually ships.
  • Sync docs not updated: SYNC.md and skills/upstream-sync/* are unchanged, so the sync process and the sync agent skill still assume the old layout.
  • Build cost not reported: every build compiles two HIP backends, two Vulkan backends and two copies of libllama. There are no build-time or binary-size numbers. The llvmpipe CI time goes from 1189 s to 1733 s.
  • Installed headers: ggml.h pulls in the type hooks via __has_include("../../hooks/..."), and that path won't resolve from an installed include directory. Programs built against installed headers would see the upstream GGML_TYPE_COUNT and none of the hook type IDs. I haven't tested this.

Nits

  • server_hooks_public_paths lets any hook take API-key auth off a route. Today only the example handler uses it. It would be worth logging each such path at startup.

What's good

  • The AI disclosure is thorough, and all 38 commits use Assisted-by:, not Co-authored-by:.
  • The PR is unusually honest about its gaps. It even corrects its own wrong commit message about the CI machine.
  • The 84/84 identical perplexity comparisons and the GGML_HOOKS=none equivalence check are solid.
  • The hook-point count is small and checked against HOOKS.txt.
  • The runtime backend wrapping and kernel registry layer is a sound basis.

A possible way forward: land the mechanism (hook points, backend wrapping, kernel registry, hook types) with upstream as the default. Then move fork features onto real hooks a few at a time. Keep whole-subsystem copies only where there is a tested tool to replay upstream diffs into them, plus a CI check that flags upstream changes not yet copied over.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants