Archived
Gemma 4's template is one llama.cpp reads with a hand-written handler, so the template analysis
found no format in it: the server warned "this model's reply format cannot be described",
returned the thought channel as content and refused every request with tools (HTTP 400).
The plugin now states the format its tokenizer_config.json declares (`response_template`), in
gemma4_chat_format.h, exported through RAD_ARCH_CHAT_FORMAT:
thinking <|channel>thought\n ... <channel|>, reasoning_anywhere
calls <|tool_call>call:NAME{...}<tool_call|>, repeated, triggers on <|tool_call>
the object bare keys, strings between <|"|> and <|"|>, other values as JSON writes them
The template closes an empty channel in the generation prompt when thinking is off and opens one
after a tool response when it is on; RAD_CHAT_THINK_FROM_PROMPT reads both. llama.cpp's handler
records an extra thought channel after the answer and a lone <channel|>; reasoning_anywhere reads
the first as reasoning and drops the second, so neither reaches the content.
chatparse_gemma4_test, against the model's own template (tests/data/chat/gemma4) and llama.cpp's
Gemma 4 parser as the oracle (tests/legacy, which now takes a declared format): every reply the
template renders reads back as the message it rendered, byte for byte as llama.cpp reads it; the
shapes the model writes and the ways it leaves the format; thinking on, off, and after a tool
response; reasoning_format none; a conversation with role:tool results rendered into the open
turn and continued; every truncation, fuzzed replies and a 200 KB string under the streaming
contract; the call grammar against llama.cpp's on rendered calls, tool_choice required and a
response format; and the chat bridge serving it, with the decoder rendering <|"|>.
arch_test holds the export to the header.
End to end on the 31B QAT checkpoint, two R9700 at TP 2: 60 requests over greedy and
temperature 1.0 / top_k 64 / top_p 0.95, streaming and not, thinking on and off. Every request
with tools came back with finish_reason "tool_calls" and JSON arguments -- one call, two parallel
calls, integer and boolean arguments -- every follow-up with role:tool results as an answer with
finish_reason "stop", and no <|channel>, <channel|>, <|tool_call> or <|"|> reached any content or
reasoning_content. With thinking off the model writes <|channel>thought\n<channel|> itself
before its answer to a tool result; it is read as an empty thought.
290 lines
17 KiB
CMake
290 lines
17 KiB
CMake
# One executable per *_test.cpp, globbed, so adding a test is adding a file.
|
|
#
|
|
# arch_test is the exception and says why in its own header: "No GPU, no model file, no core." It
|
|
# supplies its OWN implementation of the declare-phase C ABI -- a recording fake -- so that a
|
|
# plugin cannot pass only against core/build/'s builder, which would be an undeclared dependency.
|
|
# Linking rad_core would put a second definition of every rad_decl_* symbol in the link, so it
|
|
# gets the two utility translation units it actually needs and nothing else.
|
|
#
|
|
# The failure mode this avoids is worth naming, because it is not obvious from the error: a static
|
|
# archive only yields an object file that resolves an undefined symbol, so the clash appears the
|
|
# moment the ABI grows a call the fake has not implemented yet. The linker pulls rad_builder.cpp.o
|
|
# to satisfy that one symbol and every other rad_decl_* in it collides. Adding the call to the fake
|
|
# is the real fix; not linking the archive is what stops the next one presenting as a wall of
|
|
# duplicate-definition errors instead of one honest "undefined reference".
|
|
set(RAD_TESTS_NO_CORE arch_test)
|
|
|
|
# fixture_test is about tools/kfixture.cpp and tools/opshapes.cpp -- the seeded draw, the
|
|
# reduction and the on-disk recording that every kernel correctness number in the project is
|
|
# relative to. Those two are compiled into each tool rather than made a library (tools/
|
|
# CMakeLists.txt says why), so a test of them compiles them too. The alternative is a test that
|
|
# shells out to rad-kbench, which can only observe the harness through whatever a kernel run says
|
|
# about it -- and the properties worth pinning here are ones a passing run is equally consistent
|
|
# with.
|
|
set(RAD_TESTS_WITH_TOOLS fixture_test)
|
|
|
|
# The tokenizer tests compare the encoder against tools/tokref, the reference encoder, which is a
|
|
# library of its own for exactly that (tools/CMakeLists.txt).
|
|
set(RAD_TESTS_WITH_TOKREF tokenizer_test tokenizer_perf_test)
|
|
|
|
# The GBNF oracle is upstream's candidate walk, which the mask engine is held to bit for bit. It is
|
|
# test code and is compiled into the tests that compare against it -- and into rad-gbnf-check,
|
|
# which runs the same comparison on a real vocabulary -- so that no serving binary contains it.
|
|
set(RAD_TESTS_WITH_GBNF_ORACLE sample_test gbnf_test)
|
|
|
|
# THE LEGACY REPLY PARSER, AS AN ORACLE. The engine reads replies with core/text/chatparse.h; a
|
|
# whole-reply path built on llama.cpp's PEG parser and a by-hand call lifter is kept in legacy/ so
|
|
# that the tests can compare the two on every input. Built as its own archive and linked into the
|
|
# tests that compare -- nothing in core/ can reach it. tools/ links it for the acceptance tool's
|
|
# side-by-side numbers.
|
|
add_library(rad_legacy_toolparse STATIC ${CMAKE_CURRENT_SOURCE_DIR}/legacy/toolparse_legacy.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/legacy/chatdiff.cpp)
|
|
target_link_libraries(rad_legacy_toolparse PUBLIC rad_core)
|
|
target_include_directories(rad_legacy_toolparse PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/legacy)
|
|
set(RAD_TESTS_WITH_LEGACY chatparse_test chatparse_gemma4_test)
|
|
|
|
# relayout_parity_test holds each kernel library's relayout of libquant's planes to the recorded
|
|
# hash of the bytes that library stores. libr4d needs a HIP toolchain to build and its layouts do
|
|
# not, so the test compiles their host sources in -- -ffp-contract=off, as libr4d compiles every
|
|
# unit, so a scale converted on the way through rounds here as it does in the plugin.
|
|
set(RAD_TESTS_WITH_R4D_HOST relayout_parity_test)
|
|
|
|
# The chat templates the reply-format tests render through, copied from the model repositories,
|
|
# and the media samples the decoder is held to. Passed by path so a test binary run from anywhere
|
|
# finds them.
|
|
set(RAD_CHAT_FIXTURES ${CMAKE_CURRENT_SOURCE_DIR}/data/chat)
|
|
set(RAD_MEDIA_FIXTURES ${CMAKE_CURRENT_SOURCE_DIR}/data/media)
|
|
|
|
file(GLOB RAD_TESTS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*_test.cpp)
|
|
foreach(t ${RAD_TESTS})
|
|
get_filename_component(n ${t} NAME_WE)
|
|
if(n IN_LIST RAD_TESTS_NO_CORE)
|
|
add_executable(${n} ${t} ${CMAKE_SOURCE_DIR}/core/util/rad_util.cpp)
|
|
elseif(n IN_LIST RAD_TESTS_WITH_TOKREF)
|
|
add_executable(${n} ${t})
|
|
target_link_libraries(${n} PRIVATE rad_tokref rad_core)
|
|
elseif(n IN_LIST RAD_TESTS_WITH_TOOLS)
|
|
add_executable(${n} ${t} ${CMAKE_SOURCE_DIR}/tools/kfixture.cpp
|
|
${CMAKE_SOURCE_DIR}/tools/opshapes.cpp)
|
|
target_link_libraries(${n} PRIVATE rad_core)
|
|
target_include_directories(${n} PRIVATE ${CMAKE_SOURCE_DIR}/tools)
|
|
elseif(n IN_LIST RAD_TESTS_WITH_R4D_HOST)
|
|
add_executable(${n} ${t} ${CMAKE_SOURCE_DIR}/libr4d/r4d_layout.cpp
|
|
${CMAKE_SOURCE_DIR}/libr4d/r4d_fp8_layout.cpp)
|
|
target_link_libraries(${n} PRIVATE rad_core ${CMAKE_DL_LIBS})
|
|
target_include_directories(${n} PRIVATE ${CMAKE_SOURCE_DIR}/libr4d)
|
|
target_compile_options(${n} PRIVATE -ffp-contract=off)
|
|
elseif(n IN_LIST RAD_TESTS_WITH_GBNF_ORACLE)
|
|
add_executable(${n} ${t} ${CMAKE_CURRENT_SOURCE_DIR}/gbnf_oracle.cpp)
|
|
target_link_libraries(${n} PRIVATE rad_core)
|
|
# The chat templates whose tool-call grammars the engine is held to the oracle on. Checked
|
|
# in, because a template is a few kilobytes and the tokenizer beside it is not.
|
|
target_compile_definitions(${n} PRIVATE
|
|
RAD_GBNF_TEST_DATA="${CMAKE_CURRENT_SOURCE_DIR}/data/gbnf")
|
|
else()
|
|
add_executable(${n} ${t})
|
|
target_link_libraries(${n} PRIVATE rad_core)
|
|
endif()
|
|
if(n IN_LIST RAD_TESTS_WITH_LEGACY)
|
|
target_link_libraries(${n} PRIVATE rad_legacy_toolparse)
|
|
endif()
|
|
target_compile_definitions(${n} PRIVATE RAD_CHAT_FIXTURES="${RAD_CHAT_FIXTURES}"
|
|
RAD_MEDIA_FIXTURES="${RAD_MEDIA_FIXTURES}")
|
|
# include/ normally arrives through rad_core's PUBLIC interface; a test that does not link it
|
|
# still needs the ABI headers, since that is the whole surface it is testing against.
|
|
target_include_directories(${n} PRIVATE ${CMAKE_SOURCE_DIR}/core ${CMAKE_SOURCE_DIR}/abi
|
|
${CMAKE_BINARY_DIR}/rad_include)
|
|
set_target_properties(${n} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
|
# The tier transfer test loads a kernel plugin that waits on a stream through the device API, so
|
|
# the executable exports it the way the engine binary does for its plugins.
|
|
if(n STREQUAL "mem_test")
|
|
set_target_properties(${n} PROPERTIES ENABLE_EXPORTS ON)
|
|
endif()
|
|
add_test(NAME ${n} COMMAND ${n})
|
|
# AND mem_test NEEDS THE CARD TO ITSELF, which nothing about its name says. The KV pool is
|
|
# elastic on every run, so Pools::configure reserves and commits through the driver whatever
|
|
# allocators the fixture injects -- the host-allocator seam is real for the weight pool and
|
|
# dead for this one. Beside a server holding the card the pool cannot be backed and the whole
|
|
# file fails with "the card would not back it", which reads as a regression and is contention.
|
|
# The `gpu` label is how the rest of the tree already says that, and `ctest -LE gpu` still runs
|
|
# everything else on a machine that is busy.
|
|
if(${n} STREQUAL "mem_test")
|
|
set_tests_properties(${n} PROPERTIES LABELS "gpu")
|
|
endif()
|
|
# A TEST THAT SKIPPED IS NOT A TEST THAT PASSED, and a test that FAILED must not read as one
|
|
# either. Several files here guard cases on a model file, a vocabulary or a backend and print a
|
|
# " SKIP " line when it is absent; ctest swallows output on success, so without a skip signal
|
|
# those cases report Passed having asserted nothing.
|
|
#
|
|
# SKIP_REGULAR_EXPRESSION cannot be that signal. CMake evaluates it BEFORE the return code, so a
|
|
# binary that prints one skip line and then fails is reported Skipped and counted toward "100%
|
|
# tests passed" -- and a partly-skipped binary is exactly the one that prints skip lines.
|
|
#
|
|
# So the skip signal is the RETURN CODE, and rad_test.h derives it rather than declaring it:
|
|
# every CHECK increments a counter and main returns 77 only when nothing failed and nothing was
|
|
# checked at all. A file where some cases ran and others skipped passes on the ones that ran,
|
|
# which is the honest answer, and a failure anywhere is a failure.
|
|
set_tests_properties(${n} PROPERTIES SKIP_RETURN_CODE 77)
|
|
set_tests_properties(${n} PROPERTIES ENVIRONMENT
|
|
"RADIANCE_HOME=${CMAKE_BINARY_DIR}/radiance_home")
|
|
endforeach()
|
|
|
|
# ================================================================== the device selftest
|
|
#
|
|
# r4d_selftest IS THE ONLY THING THAT CHECKS THE FUSION CLAIMS, so it is a registered test.
|
|
#
|
|
# Sixteen rows in libr4d's registry say things like "byte-identical to the two ops it replaces",
|
|
# and that claim is what makes a fused kernel SUBSTITUTABLE rather than a second numerical path --
|
|
# it is the difference between a fusion and a fork. Six of those claims are verified, by memcmp,
|
|
# against the unfused kernels run on the same inputs. Every one of those verifications lives in
|
|
# r4d_selftest.cpp, which libr4d/CMakeLists.txt builds; a binary built and registered with nothing
|
|
# leaves `ctest` green without executing a single one of them.
|
|
#
|
|
# It needs a card, so it is guarded on the HIP backend; it forks a child per row and takes about
|
|
# two minutes, against 1.2 seconds for everything else, so it carries a `slow` label and
|
|
# `ctest -LE slow` is the fast inner loop. The default `ctest` runs it.
|
|
if(RAD_HIP_FOUND AND TARGET r4d_selftest)
|
|
add_test(NAME r4d_selftest
|
|
COMMAND r4d_selftest ${RAD_PLUGIN_OUT}/kernels/libr4d.so)
|
|
set_tests_properties(r4d_selftest PROPERTIES
|
|
LABELS "slow;gpu"
|
|
TIMEOUT 900
|
|
ENVIRONMENT "RADIANCE_HOME=${CMAKE_BINARY_DIR}/radiance_home")
|
|
endif()
|
|
|
|
# ================================================================== the device layer without SVM
|
|
#
|
|
# A KERNEL DRIVER WITHOUT THE SVM API PINS HOST MEMORY ANOTHER WAY, and a machine with it never
|
|
# takes that way. ROCr's thunk maps a locked range in place only through the KFD's SVM API; without
|
|
# it (a KVM guest whose amdgpu registered no device memory with HMM) the backend allocates a pinned
|
|
# range whole from the host pool (core/device/aql.cpp, "pinned host memory, in pieces"). HSA_USE_SVM=0
|
|
# is the thunk's own switch for that driver, so device_test runs a second time under it and the
|
|
# path is held on every machine with a card. On the host backend both runs are the same run.
|
|
if(RAD_HIP_FOUND AND TARGET device_test)
|
|
add_test(NAME device_test_nosvm COMMAND device_test)
|
|
set_tests_properties(device_test_nosvm PROPERTIES
|
|
SKIP_RETURN_CODE 77
|
|
ENVIRONMENT "RADIANCE_HOME=${CMAKE_BINARY_DIR}/radiance_home;HSA_USE_SVM=0")
|
|
endif()
|
|
|
|
# ================================================================== the host kernels
|
|
#
|
|
# rad-avx-check holds libavx to libref, op for op and at every ISA level the machine executes, and
|
|
# runs embed_lookup_q over a file-backed table with two ranks and the read-ahead racing: the path a
|
|
# model's host gather takes and that no geometry reaches. It writes its table beside itself, where
|
|
# the filesystem reports its direct-I/O alignment, and again in TMPDIR, where a tmpfs reports none
|
|
# and the gather aligns its reads by the block size, as it does on btrfs.
|
|
if(TARGET libavx AND TARGET rad-avx-check)
|
|
add_test(NAME avx_check
|
|
COMMAND rad-avx-check --ref ${RAD_PLUGIN_OUT}/kernels/libref.so
|
|
--avx ${RAD_PLUGIN_OUT}/kernels/libavx.so)
|
|
set_tests_properties(avx_check PROPERTIES TIMEOUT 600)
|
|
endif()
|
|
|
|
# ================================================================== the document as a test
|
|
#
|
|
# docs/OPS.md calls its resolved table "THE AUTHORITY FOR THE OPS IN IT" and says of itself that
|
|
# ref's op list is the conventional vocabulary and this file is that list. A hand-maintained table
|
|
# drifts from the registries -- dropped optional operands, a missing `:inout`, parameters that
|
|
# have moved into the `params` operand, a parameter no plugin declares -- so this test holds the
|
|
# document to what the plugins dump.
|
|
#
|
|
# The cost is named in OPS.md itself: a header written against a GUESS at a schema the document
|
|
# omits gets the schema wrong. A document that is WRONG is worse than one that is missing, because
|
|
# it is read instead of the source.
|
|
#
|
|
# It is cheap (a dlopen and an awk pass) so it carries no label and runs in the default ctest.
|
|
# libref alone would catch most of it; libr4d.so is added when there is a card to load it, and
|
|
# the script reports " SKIP " rather than green when a plugin will not dump.
|
|
set(RAD_OPSDOC_PLUGINS ${RAD_PLUGIN_OUT}/kernels/libref.so)
|
|
if(RAD_HIP_FOUND AND TARGET libr4d)
|
|
list(APPEND RAD_OPSDOC_PLUGINS ${RAD_PLUGIN_OUT}/kernels/libr4d.so)
|
|
endif()
|
|
add_test(NAME ops_doc
|
|
COMMAND ${CMAKE_SOURCE_DIR}/tools/ops_doc_check.sh
|
|
${CMAKE_SOURCE_DIR}/docs/OPS.md $<TARGET_FILE:rad-schemas>
|
|
${RAD_OPSDOC_PLUGINS})
|
|
set_tests_properties(ops_doc PROPERTIES SKIP_RETURN_CODE 77)
|
|
|
|
# ================================================================== the shipped plugins, out of tree
|
|
#
|
|
# Every plugin radiance ships is a plugin like any other, and this is what holds that to be true:
|
|
# the build is installed into a prefix, every plugin directory is configured ON ITS OWN against it
|
|
# with find_package(radiance), built and installed into a home of its own, and the result has to
|
|
# hold the same plugins, declare the same vocabulary and register the same way as the tree's build
|
|
# -- then serve rad-kbench's fixture from that home through the installed tools
|
|
# (tests/oot_plugins.sh). A first-party plugin that quietly depended on being built in the tree
|
|
# fails here; so does an installed package a third party could not build against.
|
|
#
|
|
# libr4d is included where the tree built it: the same HIP compiler, its own targets. Labelled
|
|
# `oot` because it rebuilds every plugin, which is minutes, not seconds.
|
|
set(RAD_OOT_HIP "")
|
|
if(RAD_HIP_FOUND AND TARGET libr4d)
|
|
get_target_property(RAD_OOT_R4D_ARCH libr4d HIP_ARCHITECTURES)
|
|
string(REPLACE ";" "\\;" RAD_OOT_R4D_ARCH "${RAD_OOT_R4D_ARCH}")
|
|
set(RAD_OOT_HIP ${CMAKE_HIP_COMPILER} "${RAD_OOT_R4D_ARCH}")
|
|
endif()
|
|
add_test(NAME oot_plugins
|
|
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/oot_plugins.sh
|
|
${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}/oot ${RAD_OOT_HIP})
|
|
set_tests_properties(oot_plugins PROPERTIES LABELS "oot" TIMEOUT 3600
|
|
ENVIRONMENT "CMAKE_GENERATOR=${CMAKE_GENERATOR}")
|
|
|
|
# ================================================================== the kernel library, as a test
|
|
#
|
|
# rad-kbench replaying data/kernels.rkb: every kernel every loaded library supplies, run against
|
|
# libref's recorded answers on seeded inputs, inside guarded allocations. No model, no oracle at
|
|
# run time, no network -- the fixture is checked in.
|
|
#
|
|
# r4d_selftest checks what its author wrote down and is compiled by the plugin; rad-kbench checks
|
|
# every row in every registry against an independent implementation, and the checked-in fixture
|
|
# lets it run without a model container.
|
|
#
|
|
# NOT GATED ON A CARD, because the reference library is under test in a replay too. The answers
|
|
# in the fixture were recorded by libref and checked in, so libref against them is a real
|
|
# comparison and the only regression test the oracle has -- which matters more than it sounds,
|
|
# since every correctness number this project reports about any kernel is defined relative to
|
|
# libref. It also means a build machine with no card still checks something, and a host
|
|
# implementation is exactly what regresses there.
|
|
#
|
|
# SLOW: libref is a straight-loop host implementation, so a full replay is minutes rather than the
|
|
# seconds the device libraries take. `ctest -LE slow` is the fast inner loop, as it is for
|
|
# r4d_selftest. `gpu` is added only where there is one, so `ctest -LE gpu` on a build machine
|
|
# still runs this.
|
|
#
|
|
# `--max-cases 1` because a fixture recorded at max-cases 1 has one case per point already and
|
|
# the cap is then only a guard against a future fixture that does not.
|
|
if(TARGET rad-kbench AND EXISTS ${CMAKE_SOURCE_DIR}/data/kernels.rkb)
|
|
add_test(NAME kbench
|
|
COMMAND rad-kbench --home ${RAD_PLUGIN_OUT} --max-cases 1)
|
|
set(RAD_KBENCH_LABELS "slow")
|
|
if(RAD_HIP_FOUND AND TARGET libr4d)
|
|
set(RAD_KBENCH_LABELS "slow;gpu")
|
|
endif()
|
|
# RESOURCE_LOCK, because the case budget each of these takes is a fraction of what the machine
|
|
# has FREE at the moment it starts. Two replays launched together both read the same number and
|
|
# both take their share of it, so the pair arrives at the total the budget exists to stay under.
|
|
# They also thrash a shared last-level cache against each other, which makes --bench meaningless.
|
|
set_tests_properties(kbench PROPERTIES
|
|
LABELS "${RAD_KBENCH_LABELS}"
|
|
TIMEOUT 1800
|
|
RESOURCE_LOCK kbench_memory
|
|
ENVIRONMENT "RADIANCE_HOME=${RAD_PLUGIN_OUT}")
|
|
endif()
|
|
|
|
# The same replay over the ROUTED fixture. A recording is of one container and no container in
|
|
# scope declares the whole vocabulary, so the MoE ops, the gqa 8 attention dispatch and the MTP
|
|
# head have no coverage in data/kernels.rkb at all -- see the note beside it in the root
|
|
# CMakeLists. Two tests rather than one merged fixture because a fixture names the container it
|
|
# was recorded from, and merging two would make that field a lie.
|
|
if(TARGET rad-kbench AND EXISTS ${CMAKE_SOURCE_DIR}/data/kernels_moe.rkb)
|
|
add_test(NAME kbench_moe
|
|
COMMAND rad-kbench --home ${RAD_PLUGIN_OUT} --max-cases 1
|
|
--fixture ${RAD_PLUGIN_OUT}/kernels_moe.rkb)
|
|
set_tests_properties(kbench_moe PROPERTIES
|
|
LABELS "${RAD_KBENCH_LABELS}"
|
|
TIMEOUT 1800
|
|
RESOURCE_LOCK kbench_memory
|
|
ENVIRONMENT "RADIANCE_HOME=${RAD_PLUGIN_OUT}")
|
|
endif()
|