Archived
radiance 1.7.0
- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves every shipped container - Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime - /v1/messages works with Claude Code as it ships (gearwave00001) - a long agent conversation keeps its cached history when the client rewrites its last turn (manueloverride) - a stream's first event goes out with the first token, so llama-benchy measures prefill right - opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42) - four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b) - NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA adapters (baKon) - many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool arguments and the CPU's vision and audio encoders - plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
This commit is contained in:
1 parent
b068190326
commit
1e968f6e1d
739 files changed
+128447
-84632
No files matched your search
+462
-197
@@ -1,79 +1,168 @@
|
||||
# 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 tiers are labels (docs/GUIDE.md §1.3 lists them with their times):
|
||||
# unit a harness binary (rad_test.h) on the host backend
|
||||
# perf a binary's perf_ cases, which assert wall-clock costs; RUN_SERIAL
|
||||
# slow minutes: the kernel replays, the device selftest, the long sweeps
|
||||
# gpu needs a card; RESOURCE_LOCK card
|
||||
# oot rebuilds every bundled plugin out of tree against an install
|
||||
# r4d_emu libr4d's kernel sources run on the host by the SIMT emulator
|
||||
# fast every test with none of slow, gpu, oot and perf, set at the end of this file: the
|
||||
# inner loop (`ctest --preset fast`, or `ctest -L fast`)
|
||||
#
|
||||
# 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".
|
||||
# arch_test does not link rad_core: it supplies its own recording fake of the declare-phase C ABI,
|
||||
# so plugins are tested without depending on core/build/'s builder. With the archive linked, a new
|
||||
# ABI call missing from the fake would pull in rad_builder.cpp.o and collide on every rad_decl_*
|
||||
# symbol; without it the error is a single 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)
|
||||
# fixture_test tests tools/kfixture.cpp and tools/opshapes.cpp (the seeded draw, the reduction and
|
||||
# the on-disk recording) directly, kbench_test tools/kbench_core.cpp (rad-kbench's rules), and
|
||||
# kbench_mutant_test runs rad-kbench itself against known-bad kernel libraries. The tool sources are
|
||||
# not a library (tools/CMakeLists.txt), so the tests compile them in.
|
||||
set(RAD_TESTS_WITH_TOOLS fixture_test kbench_test kbench_mutant_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).
|
||||
# tools_test tests tools/iface.cpp, the command-line plumbing the tools share, which is compiled
|
||||
# into each tool rather than built as a library.
|
||||
set(RAD_TESTS_WITH_IFACE tools_test)
|
||||
|
||||
# The tokenizer tests compare the encoder against the reference encoder, tools/tokref.
|
||||
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.
|
||||
# The GBNF oracle (upstream's candidate walk), which the mask engine must match bit for bit. Test
|
||||
# code, compiled only into these tests and rad-gbnf-check, never into a serving binary.
|
||||
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.
|
||||
# The legacy reply parser as an oracle for core/text/chatparse.h: a whole-reply path built on
|
||||
# llama.cpp's PEG parser and a hand-written call lifter. Its own archive, linked only into the
|
||||
# comparing tests and rad-chatparse; core/ cannot reach it.
|
||||
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.
|
||||
# relayout_parity_test checks each kernel library's relayout of libquant's planes against a
|
||||
# recorded hash of the stored bytes. libr4d's layout sources are host-only, so they are compiled in,
|
||||
# with -ffp-contract=off as libr4d uses, so scale conversions round identically.
|
||||
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.
|
||||
# Chat templates (copied from the model repositories) and media samples, passed by absolute path so
|
||||
# test binaries can run from anywhere.
|
||||
set(RAD_CHAT_FIXTURES ${CMAKE_CURRENT_SOURCE_DIR}/data/chat)
|
||||
set(RAD_MEDIA_FIXTURES ${CMAKE_CURRENT_SOURCE_DIR}/data/media)
|
||||
|
||||
# libstdc++ AHEAD OF rad_core ON EVERY TEST'S LINK LINE. lld extracts an archive member to resolve
|
||||
# any undefined symbol, a shared library's imports included: ROCm 10.1's libamdhip64 imports
|
||||
# std::string::reserve, g++-14 emits that template weak in rad_graph.cpp.o, and what that object
|
||||
# needs in turn reaches dispatch.cpp.o, whose strong device calls replace the weak fakes sched_test,
|
||||
# ref_test and runtime_test run on -- with no link error, only a test on the wrong backend. With
|
||||
# libstdc++ first, the import resolves to it and no member is extracted for it.
|
||||
# libstdc++ before rad_core on every test's link line. lld extracts archive members to resolve a
|
||||
# shared library's imports too: ROCm 10.1's libamdhip64 imports std::string::reserve, which g++-14
|
||||
# emits weak in rad_graph.cpp.o, and that object pulls in dispatch.cpp.o, whose strong device calls
|
||||
# silently replace the weak fakes sched_test, ref_test and runtime_test rely on.
|
||||
set(RAD_TEST_CORE stdc++ rad_core)
|
||||
|
||||
# harness_test runs harness_fixture's cases through the harness's command line (rad_test.h).
|
||||
set(RAD_TESTS_HARNESS harness_test)
|
||||
add_executable(harness_fixture ${CMAKE_CURRENT_SOURCE_DIR}/harness_fixture.cpp)
|
||||
set_target_properties(harness_fixture PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
|
||||
# Binaries registered as several entries, <bin>_shard<k> running `<bin> --shard k/n`, so their
|
||||
# cases run in parallel and no entry is the fast tier's long pole.
|
||||
set(RAD_TEST_SHARDS_gbnf_test 4)
|
||||
|
||||
# ------------------------------------------------------------------ the environment of every test
|
||||
#
|
||||
# OMP_WAIT_POLICY=passive and a team of 4: libref, libquant and libavx open OpenMP regions over
|
||||
# small loops, and with libgomp's default wait every thread of a 32-thread team spins at each
|
||||
# barrier. Beside other processes that costs 10-100x (a 0.2 s binary takes a minute). Four threads
|
||||
# keep the multi-threaded paths, rows split across a team, under test.
|
||||
#
|
||||
# ROCR_VISIBLE_DEVICES=99 hides every card, so a unit test runs on the host backend on every
|
||||
# machine: the same code everywhere, and nothing touches a card a server is using. The _card
|
||||
# entries below run the device tests on a card.
|
||||
#
|
||||
# RAD_TEST_STRICT=1: a plugin or fixture this build makes is never legitimately absent, so a test
|
||||
# that cannot find one fails rather than skips. RAD_TEST_TMPDIR puts radtest::tmpdir() in the build
|
||||
# tree, on disk, where O_DIRECT works.
|
||||
#
|
||||
# RAD_TEST_CPU_BUDGET: a unit binary that spends more CPU seconds than this fails (rad_test.h), so
|
||||
# a slow case or a spinning thread pool is caught when it lands. Sanitised and Debug builds run
|
||||
# several times slower and have no budget.
|
||||
set(RAD_TEST_OMP_THREADS 4)
|
||||
set(RAD_TEST_TIMEOUT 120)
|
||||
set(RAD_TEST_CPU_BUDGET 10)
|
||||
set(RAD_TEST_SAN_ENV "")
|
||||
if(RAD_ASAN)
|
||||
list(APPEND RAD_TEST_SAN_ENV "ASAN_OPTIONS=detect_leaks=1" "UBSAN_OPTIONS=print_stacktrace=1")
|
||||
elseif(RAD_TSAN)
|
||||
# libgomp is not instrumented, so its synchronisation would read as races: one thread.
|
||||
set(RAD_TEST_OMP_THREADS 1)
|
||||
list(APPEND RAD_TEST_SAN_ENV "TSAN_OPTIONS=halt_on_error=1:second_deadlock_stack=1")
|
||||
endif()
|
||||
if(RAD_ASAN OR RAD_TSAN OR CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(RAD_TEST_TIMEOUT 600)
|
||||
set(RAD_TEST_CPU_BUDGET 0)
|
||||
endif()
|
||||
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tmp)
|
||||
set(RAD_TEST_OMP_ENV "OMP_WAIT_POLICY=passive" "OMP_NUM_THREADS=${RAD_TEST_OMP_THREADS}")
|
||||
set(RAD_TEST_CARD_ENV "RADIANCE_HOME=${CMAKE_BINARY_DIR}/radiance_home" ${RAD_TEST_OMP_ENV}
|
||||
"RAD_TEST_STRICT=1" "RAD_TEST_TMPDIR=${CMAKE_BINARY_DIR}/tmp"
|
||||
${RAD_TEST_SAN_ENV})
|
||||
set(RAD_TEST_ENV ${RAD_TEST_CARD_ENV} "ROCR_VISIBLE_DEVICES=99")
|
||||
|
||||
# Binaries that need more CPU than the default budget, and what costs it. Lower an entry when its
|
||||
# cost comes down, so the tripwire stays tight.
|
||||
set(RAD_TEST_CPU_BUDGET_quant_ggml_test 25) # llama.cpp's iq1_s and iq2_* grid searches, ~13 s
|
||||
set(RAD_TEST_CPU_BUDGET_tokenizer_test 20) # the reference encoder over every corpus: ~3 s built by GCC 16, ~10.5 s by GCC 14 (the image's Ubuntu)
|
||||
|
||||
# Binaries whose OpenMP team is busy for most of their run, so a parallel ctest counts them as a
|
||||
# team's worth of slots rather than one.
|
||||
set(RAD_TESTS_THREADED quant_ggml_test relayout_parity_test)
|
||||
|
||||
# A harness binary as a ctest entry, `<bin> -perf_ ARGS...`, labelled unit. Its perf_ cases run in
|
||||
# <bin>_perf instead (below).
|
||||
function(rad_unit_test name bin)
|
||||
set(budget ${RAD_TEST_CPU_BUDGET})
|
||||
if(budget AND DEFINED RAD_TEST_CPU_BUDGET_${bin})
|
||||
set(budget ${RAD_TEST_CPU_BUDGET_${bin}})
|
||||
endif()
|
||||
add_test(NAME ${name} COMMAND ${bin} -perf_ ${ARGN})
|
||||
# 77 is the harness's "nothing was checked" (rad_test.h).
|
||||
set_tests_properties(${name} PROPERTIES
|
||||
LABELS unit
|
||||
SKIP_RETURN_CODE 77
|
||||
TIMEOUT ${RAD_TEST_TIMEOUT}
|
||||
ENVIRONMENT "${RAD_TEST_ENV};RAD_TEST_CPU_BUDGET=${budget}")
|
||||
if(bin IN_LIST RAD_TESTS_THREADED)
|
||||
set_tests_properties(${name} PROPERTIES PROCESSORS ${RAD_TEST_OMP_THREADS})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# The script CTestTestfile.cmake includes to register the perf_ entries (below).
|
||||
set(RAD_PERF_SCRIPT "set(RAD_TEST_ENV [==[${RAD_TEST_ENV}]==])\nset(RAD_TEST_TIMEOUT ${RAD_TEST_TIMEOUT})\n")
|
||||
string(APPEND RAD_PERF_SCRIPT "include([==[${CMAKE_CURRENT_SOURCE_DIR}/perf_entries.cmake]==])\n")
|
||||
|
||||
# shipped_plugins_test loads the shipped architecture plugins, which bind the plugin-facing C ABI
|
||||
# back to the host at dlopen, so like the engine it carries all of rad_core and exports it.
|
||||
set(RAD_TESTS_WHOLE_CORE shipped_plugins_test)
|
||||
|
||||
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_HARNESS)
|
||||
add_executable(${n} ${t})
|
||||
add_dependencies(${n} harness_fixture)
|
||||
target_compile_definitions(${n} PRIVATE RAD_HARNESS_FIXTURE="$<TARGET_FILE:harness_fixture>")
|
||||
elseif(n IN_LIST RAD_TESTS_WITH_TOKREF)
|
||||
add_executable(${n} ${t})
|
||||
target_link_libraries(${n} PRIVATE rad_tokref ${RAD_TEST_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)
|
||||
${CMAKE_SOURCE_DIR}/tools/opshapes.cpp
|
||||
${CMAKE_SOURCE_DIR}/tools/kbench_core.cpp)
|
||||
target_link_libraries(${n} PRIVATE ${RAD_TEST_CORE} ${CMAKE_DL_LIBS})
|
||||
target_include_directories(${n} PRIVATE ${CMAKE_SOURCE_DIR}/tools)
|
||||
elseif(n IN_LIST RAD_TESTS_WITH_IFACE)
|
||||
add_executable(${n} ${t} ${CMAKE_SOURCE_DIR}/tools/iface.cpp)
|
||||
target_link_libraries(${n} PRIVATE ${RAD_TEST_CORE})
|
||||
target_include_directories(${n} PRIVATE ${CMAKE_SOURCE_DIR}/tools)
|
||||
elseif(n IN_LIST RAD_TESTS_WITH_R4D_HOST)
|
||||
@@ -82,11 +171,15 @@ foreach(t ${RAD_TESTS})
|
||||
target_link_libraries(${n} PRIVATE ${RAD_TEST_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_WHOLE_CORE)
|
||||
add_executable(${n} ${t})
|
||||
target_link_libraries(${n} PRIVATE stdc++ "$<LINK_LIBRARY:WHOLE_ARCHIVE,rad_core>")
|
||||
set_target_properties(${n} PROPERTIES ENABLE_EXPORTS ON)
|
||||
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_TEST_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.
|
||||
# Chat templates whose tool-call grammars are checked against the oracle (checked in; the
|
||||
# tokenizers are too large).
|
||||
target_compile_definitions(${n} PRIVATE
|
||||
RAD_GBNF_TEST_DATA="${CMAKE_CURRENT_SOURCE_DIR}/data/gbnf")
|
||||
else()
|
||||
@@ -98,59 +191,116 @@ foreach(t ${RAD_TESTS})
|
||||
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.
|
||||
# Normally inherited from rad_core; tests that do not link it still need the ABI headers.
|
||||
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.
|
||||
# mem_test loads a kernel plugin that calls back into the device API, so it exports it like the
|
||||
# engine binary.
|
||||
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")
|
||||
if(DEFINED RAD_TEST_SHARDS_${n})
|
||||
math(EXPR last "${RAD_TEST_SHARDS_${n}} - 1")
|
||||
foreach(k RANGE ${last})
|
||||
rad_unit_test(${n}_shard${k} ${n} --shard ${k}/${RAD_TEST_SHARDS_${n}})
|
||||
endforeach()
|
||||
else()
|
||||
rad_unit_test(${n} ${n})
|
||||
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")
|
||||
string(APPEND RAD_PERF_SCRIPT
|
||||
"rad_perf_entry(${n} [==[${t}]==] [==[${CMAKE_BINARY_DIR}/tests/${n}]==])\n")
|
||||
endforeach()
|
||||
|
||||
# ================================================================== perf_ cases
|
||||
#
|
||||
# A case named perf_... asserts a wall-clock cost, which tests running beside it would distort. The
|
||||
# unit entries leave those cases out, and <bin>_perf runs them alone (RUN_SERIAL, label perf).
|
||||
# Which binaries have one is read from their sources whenever ctest loads the tests
|
||||
# (perf_entries.cmake), so a new perf_ case is registered without reconfiguring.
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/rad_perf_tests.cmake "${RAD_PERF_SCRIPT}")
|
||||
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/rad_perf_tests.cmake)
|
||||
|
||||
# ================================================================== the device tests on a card
|
||||
#
|
||||
# The unit entries run on the host backend. These run the tests whose code differs on a card (the
|
||||
# AQL backend, the driver's elastic commit, the mover's copies) on the card, one at a time: a test
|
||||
# that commits device memory fails beside another holding it, or beside a server.
|
||||
if(RAD_HIP_FOUND)
|
||||
foreach(n device_test mem_test place_test runtime_test)
|
||||
add_test(NAME ${n}_card COMMAND ${n} -perf_)
|
||||
set_tests_properties(${n}_card PROPERTIES
|
||||
LABELS gpu
|
||||
SKIP_RETURN_CODE 77
|
||||
TIMEOUT ${RAD_TEST_TIMEOUT}
|
||||
ENVIRONMENT "${RAD_TEST_CARD_ENV}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
# ================================================================== whole models on the CPU
|
||||
#
|
||||
# engine_e2e_test runs the radiance binary on tiny synthetic checkpoints (tests/tiny_model.h) on
|
||||
# the host backend; convert_test runs rad-convert on the same checkpoints. Both start the built
|
||||
# binaries as children, so they depend on them and on every plugin the checkpoints select
|
||||
# (llama_fp8 for convert_test's --set of an fp8 quantization_config).
|
||||
set(RAD_E2E_DEPS radiance rad-convert libref libquant qwen35_bf16 lfm2_bf16 gemma4 llama_dense_fp8
|
||||
llama_fp8 qwenimage21)
|
||||
if(TARGET libavx)
|
||||
list(APPEND RAD_E2E_DEPS libavx)
|
||||
endif()
|
||||
foreach(t engine_e2e_test convert_test)
|
||||
if(TARGET ${t})
|
||||
target_compile_definitions(${t} PRIVATE
|
||||
RAD_E2E_SERVER="$<TARGET_FILE:radiance>" RAD_E2E_CONVERT="$<TARGET_FILE:rad-convert>"
|
||||
RAD_E2E_HOME="${RAD_PLUGIN_OUT}")
|
||||
add_dependencies(${t} ${RAD_E2E_DEPS})
|
||||
endif()
|
||||
endforeach()
|
||||
# 6 to 17 s by build type and load, mostly libref's GEMMs and decode steps and the engine's own
|
||||
# startups, so labelled `e2e` and kept out of the fast tier; the host and full tiers run it.
|
||||
if(TARGET engine_e2e_test)
|
||||
set_tests_properties(engine_e2e_test PROPERTIES LABELS "e2e" TIMEOUT 300)
|
||||
endif()
|
||||
|
||||
# abi_layout_test compares the ABI's struct layouts with a C translation unit's: abi_c_test.c
|
||||
# includes every abi/ header as strict C11, so a header only C++ accepts fails the build.
|
||||
if(TARGET abi_layout_test)
|
||||
target_sources(abi_layout_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/abi_c_test.c)
|
||||
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/abi_c_test.c PROPERTIES
|
||||
COMPILE_OPTIONS "-std=c11;-pedantic-errors;-Wall;-Wextra")
|
||||
endif()
|
||||
|
||||
# arch_test reads libref's vocabulary from $RADIANCE_HOME/kernels to check that each architecture
|
||||
# declares on it, so libref is built before it.
|
||||
if(TARGET libref AND TARGET arch_test)
|
||||
add_dependencies(arch_test libref)
|
||||
endif()
|
||||
|
||||
# kbench_mutant_test runs rad-kbench against the deliberately defective kernel libraries
|
||||
# (core/plugin/testplugin/kbmutant.cc) on the host backend, so it needs the tool, libref and the
|
||||
# mutants built.
|
||||
if(TARGET kbench_mutant_test AND TARGET rad-kbench AND TARGET libref)
|
||||
target_compile_definitions(kbench_mutant_test PRIVATE
|
||||
RAD_KBENCH_BIN="$<TARGET_FILE:rad-kbench>" RAD_PLUGIN_DIR="${RAD_PLUGIN_OUT}")
|
||||
# It also loads a mutant in process, whose device rows call back into the device API.
|
||||
set_target_properties(kbench_mutant_test PROPERTIES ENABLE_EXPORTS ON)
|
||||
add_dependencies(kbench_mutant_test rad-kbench libref radtest_kbarch)
|
||||
foreach(m ${RAD_KBM_MUTANTS})
|
||||
add_dependencies(kbench_mutant_test kbm_${m})
|
||||
endforeach()
|
||||
# One case replays libavx's sampler stages against libref; it is reported missing without it.
|
||||
if(TARGET libavx)
|
||||
add_dependencies(kbench_mutant_test libavx)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ================================================================== 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.
|
||||
# r4d_selftest is the only check of libr4d's fusion claims: rows declaring a fused kernel
|
||||
# byte-identical to the ops it replaces, verified by memcmp against the unfused kernels on the same
|
||||
# inputs. It needs a card and forks a child per row (about six minutes), so it is labelled `slow`;
|
||||
# the default `ctest` still runs it.
|
||||
if(RAD_HIP_FOUND AND TARGET r4d_selftest)
|
||||
add_test(NAME r4d_selftest
|
||||
COMMAND r4d_selftest ${RAD_PLUGIN_OUT}/kernels/libr4d.so)
|
||||
@@ -162,98 +312,164 @@ 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.
|
||||
# Without the KFD SVM API (e.g. a KVM guest whose amdgpu registered no device memory with HMM), ROCr
|
||||
# cannot lock host memory in place, and the backend allocates pinned ranges from the host pool
|
||||
# instead (core/device/aql.cpp, "pinned host memory, in pieces"). HSA_USE_SVM=0 forces that path, so
|
||||
# device_test runs a second time on the card under it.
|
||||
if(RAD_HIP_FOUND AND TARGET device_test)
|
||||
add_test(NAME device_test_nosvm COMMAND device_test)
|
||||
add_test(NAME device_test_nosvm COMMAND device_test -perf_)
|
||||
set_tests_properties(device_test_nosvm PROPERTIES
|
||||
LABELS gpu
|
||||
SKIP_RETURN_CODE 77
|
||||
ENVIRONMENT "RADIANCE_HOME=${CMAKE_BINARY_DIR}/radiance_home;HSA_USE_SVM=0")
|
||||
TIMEOUT ${RAD_TEST_TIMEOUT}
|
||||
ENVIRONMENT "${RAD_TEST_CARD_ENV};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.
|
||||
# rad-avx-check compares libavx with libref op by op at every ISA level the machine supports, and
|
||||
# runs embed_lookup_q over a file-backed table with two ranks racing the read-ahead. The table is
|
||||
# written beside the binary (filesystem reports a direct-I/O alignment) and in TMPDIR (a tmpfs
|
||||
# reports none, so reads align by block size, as 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)
|
||||
set(env ${RAD_TEST_OMP_ENV} "ROCR_VISIBLE_DEVICES=99" ${RAD_TEST_SAN_ENV})
|
||||
set_tests_properties(avx_check PROPERTIES TIMEOUT ${RAD_TEST_TIMEOUT} ENVIRONMENT "${env}")
|
||||
endif()
|
||||
|
||||
# The same checker on another host library (avx_subset_plugin.cpp: part of libref under another
|
||||
# name): the ops it lacks are listed rather than failed, cases go to the row whose constraints admit
|
||||
# them, and a declining row still fails.
|
||||
if(TARGET rad-avx-check AND TARGET libref)
|
||||
add_library(avx_subset_plugin MODULE avx_subset_plugin.cpp)
|
||||
target_link_libraries(avx_subset_plugin PRIVATE radiance::abi ${CMAKE_DL_LIBS})
|
||||
add_test(NAME avx_check_general
|
||||
COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/avx_check_general.sh
|
||||
$<TARGET_FILE:rad-avx-check> ${RAD_PLUGIN_OUT}/kernels/libref.so
|
||||
$<TARGET_FILE:avx_subset_plugin>)
|
||||
set(env ${RAD_TEST_OMP_ENV} "ROCR_VISIBLE_DEVICES=99" ${RAD_TEST_SAN_ENV})
|
||||
set_tests_properties(avx_check_general PROPERTIES TIMEOUT ${RAD_TEST_TIMEOUT} ENVIRONMENT "${env}")
|
||||
endif()
|
||||
|
||||
# ================================================================== libr4d's kernels, on the host
|
||||
#
|
||||
# libr4d builds for gfx12 only, and some of its ops (the sandwich-norm joins, expert_scale) have no
|
||||
# libref oracle by design (docs/OPS.md), so neither rad-kbench nor a no-card machine would ever run
|
||||
# those kernels. r4d_emu runs the SOURCE of four of libr4d's units on the host instead -- the
|
||||
# windowed paged attention, pair_argmax, the joins and expert_scale, the units written against
|
||||
# r4d_launch.h: emu/hip/hip_runtime.h supplies the HIP names, every GPU thread is a fiber,
|
||||
# __syncthreads and every cross-lane op a barrier (one not reached uniformly is reported as a
|
||||
# deadlock), and the units' launch macro is pointed at the emulator. Checked against a port of
|
||||
# libref's ref_attn_paged, against the host arithmetic in ref_host.cpp, and -- for the joins --
|
||||
# against the unfused chain, bit for bit.
|
||||
# Some libr4d ops (the sandwich-norm joins, expert_scale) have no libref oracle by design
|
||||
# (docs/OPS.md), so rad-kbench never checks them. r4d_emu runs the source of five units written
|
||||
# against r4d_launch.h on the host: the windowed paged attention, pair_argmax, the joins,
|
||||
# expert_scale and the QSA block selection, whose four kernels a card-less build otherwise never
|
||||
# runs. emu/hip/hip_runtime.h supplies the HIP names, each GPU thread is a fiber, and
|
||||
# __syncthreads and cross-lane ops are barriers (one not reached uniformly is reported as a
|
||||
# deadlock). Checked against ports of libref's ref_attn_paged and ref_qsa_select, the host
|
||||
# arithmetic in ref_host.cpp, and, for the joins, the unfused chain bit for bit.
|
||||
#
|
||||
# CLANG AND x86-64: the kernels use clang's ext_vector_type, and the fiber switch is x86-64 SysV
|
||||
# inline assembly. Under a clang C++ compiler they are ordinary targets here, the .hip files
|
||||
# compiled as C++ (`-x c++`, which is what makes them host code; the property is per directory, so
|
||||
# libr4d's own HIP build is untouched). Under g++ -- the docker image's -- a build with a card
|
||||
# still has a clang: its HIP compiler, ROCm's own clang++, and r4d_emu/run.sh builds and runs the
|
||||
# same tests with that. So wherever libr4d is built, this runs.
|
||||
# Requires clang (ext_vector_type) and x86-64 (SysV fiber switch in inline assembly). With a clang
|
||||
# C++ compiler the .hip files build here as C++ (`-x c++`; the property is per directory, so
|
||||
# libr4d's HIP build is unaffected). Otherwise a clang++ builds them through custom commands: the
|
||||
# HIP compiler (ROCm's clang++) when there is one, else RAD_EMU_CLANG, the clang++ on PATH. A
|
||||
# sanitised build also takes that route, since the emulator's fiber switches would confuse the
|
||||
# sanitiser. With no clang at all the tests are not registered.
|
||||
set(R4D_DIR ${CMAKE_SOURCE_DIR}/libr4d)
|
||||
set(R4D_EMU ${CMAKE_CURRENT_SOURCE_DIR}/r4d_emu)
|
||||
set(R4D_EMU_HIP ${R4D_DIR}/r4d_attn_paged_window.hip ${R4D_DIR}/r4d_pair_argmax_f32.hip
|
||||
${R4D_DIR}/r4d_norm_join_bf16.hip ${R4D_DIR}/r4d_expert_scale_bf16.hip
|
||||
${R4D_DIR}/r4d_qsa_select_bf16.hip)
|
||||
set(R4D_EMU_TESTS attn pick norm escale qsa)
|
||||
set(R4D_EMU_BUILT OFF)
|
||||
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
|
||||
# no fiber switch for this ISA: nothing to register
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(R4D_EMU_HIP ${R4D_DIR}/r4d_attn_paged_window.hip ${R4D_DIR}/r4d_pair_argmax_f32.hip
|
||||
${R4D_DIR}/r4d_norm_join_bf16.hip ${R4D_DIR}/r4d_expert_scale_bf16.hip)
|
||||
# No fiber switch for this ISA.
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT RAD_ASAN AND NOT RAD_TSAN)
|
||||
set_source_files_properties(${R4D_EMU_HIP} PROPERTIES LANGUAGE CXX COMPILE_OPTIONS "-x;c++")
|
||||
add_library(r4d_emu_kernels OBJECT ${R4D_EMU_HIP} ${R4D_EMU}/ref_host.cpp ${R4D_EMU}/emu/emu.cpp)
|
||||
target_include_directories(r4d_emu_kernels PUBLIC ${R4D_EMU}/emu ${R4D_EMU} ${R4D_DIR})
|
||||
target_link_libraries(r4d_emu_kernels PUBLIC rad_abi)
|
||||
# As libr4d compiles every unit: the joins are held to the chain bit for bit, and a contracted
|
||||
# multiply-add is a different rounding.
|
||||
# As in libr4d: the joins must match the unfused chain bit for bit, so no FMA contraction.
|
||||
target_compile_options(r4d_emu_kernels PRIVATE -ffp-contract=off -Wno-psabi)
|
||||
foreach(t attn pick norm escale)
|
||||
foreach(t ${R4D_EMU_TESTS})
|
||||
add_executable(r4d_emu_${t} ${R4D_EMU}/test_${t}.cpp)
|
||||
target_link_libraries(r4d_emu_${t} PRIVATE r4d_emu_kernels)
|
||||
target_compile_options(r4d_emu_${t} PRIVATE -ffp-contract=off -Wno-psabi)
|
||||
set_target_properties(r4d_emu_${t} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
add_test(NAME r4d_emu_${t} COMMAND r4d_emu_${t})
|
||||
endforeach()
|
||||
# The random sweep at a size the inner loop can afford; `r4d_emu_attn sweep 200` is the long one.
|
||||
add_test(NAME r4d_emu_attn_sweep COMMAND r4d_emu_attn sweep 40)
|
||||
set_tests_properties(r4d_emu_attn r4d_emu_pick r4d_emu_norm r4d_emu_escale r4d_emu_attn_sweep
|
||||
PROPERTIES LABELS "r4d_emu" TIMEOUT 600)
|
||||
elseif(RAD_HIP_FOUND AND CMAKE_HIP_COMPILER_ID MATCHES "Clang")
|
||||
add_test(NAME r4d_emu
|
||||
COMMAND sh ${R4D_EMU}/run.sh ${CMAKE_HIP_COMPILER} ${CMAKE_SOURCE_DIR}/abi ${R4D_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/r4d_emu 40)
|
||||
set_tests_properties(r4d_emu PROPERTIES LABELS "r4d_emu" TIMEOUT 900)
|
||||
set(R4D_EMU_BUILT ON)
|
||||
else()
|
||||
if(RAD_HIP_FOUND AND CMAKE_HIP_COMPILER_ID MATCHES "Clang")
|
||||
set(R4D_EMU_CXX ${CMAKE_HIP_COMPILER})
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(R4D_EMU_CXX ${CMAKE_CXX_COMPILER})
|
||||
else()
|
||||
find_program(RAD_EMU_CLANG NAMES clang++
|
||||
DOC "clang++ that builds tests/r4d_emu when the C++ compiler is not clang")
|
||||
set(R4D_EMU_CXX ${RAD_EMU_CLANG})
|
||||
endif()
|
||||
if(R4D_EMU_CXX)
|
||||
set(dir ${CMAKE_CURRENT_BINARY_DIR}/r4d_emu)
|
||||
file(MAKE_DIRECTORY ${dir})
|
||||
set(flags -std=c++20 -O2 -ffp-contract=off -Wno-psabi -I${R4D_EMU}/emu -I${R4D_EMU}
|
||||
-I${CMAKE_SOURCE_DIR}/abi -I${R4D_DIR})
|
||||
set(objs "")
|
||||
foreach(src ${R4D_EMU_HIP} ${R4D_EMU}/ref_host.cpp ${R4D_EMU}/emu/emu.cpp
|
||||
${R4D_EMU}/test_attn.cpp ${R4D_EMU}/test_pick.cpp ${R4D_EMU}/test_norm.cpp
|
||||
${R4D_EMU}/test_escale.cpp ${R4D_EMU}/test_qsa.cpp)
|
||||
get_filename_component(stem ${src} NAME_WE)
|
||||
set(lang "")
|
||||
if(src MATCHES "\\.hip$")
|
||||
set(lang -x c++)
|
||||
endif()
|
||||
add_custom_command(OUTPUT ${dir}/${stem}.o
|
||||
COMMAND ${R4D_EMU_CXX} ${flags} -MD -MF ${dir}/${stem}.o.d ${lang} -c ${src}
|
||||
-o ${dir}/${stem}.o
|
||||
DEPENDS ${src}
|
||||
DEPFILE ${dir}/${stem}.o.d
|
||||
COMMENT "Building r4d_emu ${stem}.o with ${R4D_EMU_CXX}"
|
||||
VERBATIM)
|
||||
if(NOT stem MATCHES "^test_")
|
||||
list(APPEND objs ${dir}/${stem}.o)
|
||||
endif()
|
||||
endforeach()
|
||||
set(exes "")
|
||||
foreach(t ${R4D_EMU_TESTS})
|
||||
set(exe ${CMAKE_BINARY_DIR}/tests/r4d_emu_${t})
|
||||
add_custom_command(OUTPUT ${exe}
|
||||
COMMAND ${R4D_EMU_CXX} ${dir}/test_${t}.o ${objs} -o ${exe}
|
||||
DEPENDS ${dir}/test_${t}.o ${objs}
|
||||
COMMENT "Linking r4d_emu_${t}"
|
||||
VERBATIM)
|
||||
list(APPEND exes ${exe})
|
||||
endforeach()
|
||||
add_custom_target(r4d_emu ALL DEPENDS ${exes})
|
||||
set(R4D_EMU_BUILT ON)
|
||||
endif()
|
||||
endif()
|
||||
if(R4D_EMU_BUILT)
|
||||
foreach(t pick norm escale qsa)
|
||||
add_test(NAME r4d_emu_${t} COMMAND ${CMAKE_BINARY_DIR}/tests/r4d_emu_${t})
|
||||
endforeach()
|
||||
# The attention cases take about 11 s, 7 of them in the two long prefills on the WMMA kernel,
|
||||
# which three shards put in different entries.
|
||||
foreach(k 0 1 2)
|
||||
add_test(NAME r4d_emu_attn_shard${k}
|
||||
COMMAND ${CMAKE_BINARY_DIR}/tests/r4d_emu_attn --shard ${k}/3)
|
||||
endforeach()
|
||||
set_tests_properties(r4d_emu_attn_shard0 r4d_emu_attn_shard1 r4d_emu_attn_shard2 r4d_emu_pick
|
||||
r4d_emu_norm r4d_emu_escale r4d_emu_qsa
|
||||
PROPERTIES LABELS "r4d_emu" TIMEOUT ${RAD_TEST_TIMEOUT})
|
||||
# A seeded random sweep, mostly prefill shapes on the WMMA kernel, which the emulator runs at
|
||||
# about 2 s a case: `slow`. `r4d_emu_attn sweep 200` is a longer run by hand, a superset of it.
|
||||
add_test(NAME r4d_emu_attn_sweep COMMAND ${CMAKE_BINARY_DIR}/tests/r4d_emu_attn sweep 40)
|
||||
set_tests_properties(r4d_emu_attn_sweep PROPERTIES LABELS "r4d_emu;slow" TIMEOUT 900)
|
||||
# QSA selection at serving sizes, seeded: about 15 s.
|
||||
add_test(NAME r4d_emu_qsa_sweep COMMAND ${CMAKE_BINARY_DIR}/tests/r4d_emu_qsa sweep 100)
|
||||
set_tests_properties(r4d_emu_qsa_sweep PROPERTIES LABELS "r4d_emu;slow" TIMEOUT 900)
|
||||
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.
|
||||
# docs/OPS.md is the authoritative op table, so this test checks it against what the plugins dump
|
||||
# (dropped optional operands, a missing `:inout`, parameters moved into `params`, undeclared
|
||||
# parameters). Cheap, so in the fast tier. libr4d.so is added when built; the script reports
|
||||
# " SKIP " rather than passing 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)
|
||||
@@ -262,20 +478,26 @@ 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)
|
||||
set_tests_properties(ops_doc PROPERTIES
|
||||
SKIP_RETURN_CODE 77
|
||||
TIMEOUT ${RAD_TEST_TIMEOUT}
|
||||
ENVIRONMENT "ROCR_VISIBLE_DEVICES=99")
|
||||
|
||||
# tools/rad-export. Its standard-library checks always run; the merge arithmetic runs where torch
|
||||
# and safetensors import, and the PEFT comparison where peft and transformers do too.
|
||||
find_program(RAD_PYTHON3 NAMES python3)
|
||||
if(RAD_PYTHON3)
|
||||
add_test(NAME rad_export_test COMMAND ${RAD_PYTHON3} ${CMAKE_CURRENT_SOURCE_DIR}/rad_export_test.py)
|
||||
set_tests_properties(rad_export_test PROPERTIES LABELS "unit;fast" TIMEOUT ${RAD_TEST_TIMEOUT})
|
||||
endif()
|
||||
|
||||
# ================================================================== 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.
|
||||
#
|
||||
# The device library (libr4d) is included where the tree built it: the same HIP compiler, libr4d's
|
||||
# targets. Labelled `oot` because it rebuilds every plugin, which is minutes, not seconds.
|
||||
# Installs the build into a prefix, then configures, builds and installs every plugin directory
|
||||
# standalone against it with find_package(radiance). The result must match the tree's plugins,
|
||||
# vocabulary and registration, and serve rad-kbench's fixture through the installed tools
|
||||
# (tests/oot_plugins.sh). libr4d is included when the tree built it, with the same HIP compiler and
|
||||
# targets. Labelled `oot`: it rebuilds every plugin and takes minutes.
|
||||
set(RAD_OOT_HIP "")
|
||||
if(RAD_HIP_FOUND AND TARGET libr4d)
|
||||
get_target_property(RAD_OOT_R4D_ARCH libr4d HIP_ARCHITECTURES)
|
||||
@@ -285,63 +507,106 @@ 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}")
|
||||
# RESOURCE_LOCK kbench_memory: its replay holds operands in host memory as the kbench entries do.
|
||||
set_tests_properties(oot_plugins PROPERTIES
|
||||
LABELS "oot"
|
||||
TIMEOUT 3600
|
||||
RESOURCE_LOCK kbench_memory
|
||||
ENVIRONMENT "CMAKE_GENERATOR=${CMAKE_GENERATOR};${RAD_TEST_OMP_ENV}")
|
||||
|
||||
# ================================================================== 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.
|
||||
# rad-kbench replays data/kernels.rkb: every kernel of every loaded library against libref's
|
||||
# recorded answers on seeded inputs, in guarded allocations. No model, oracle or network needed.
|
||||
#
|
||||
# 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.
|
||||
# kbench and kbench_moe check every library except the reference (--no-ref): its answers are what
|
||||
# the fixture holds. --strict fails a stale fixture, and --coverage fails when a row a fixture
|
||||
# reached (data/kbench_rows/) is no longer reached. Labelled `kbench`, which keeps them out of the
|
||||
# fast tier (a replay takes seconds to minutes), and `gpu` only when libr4d is built, so
|
||||
# `ctest -LE gpu` still runs them. `--max-cases 1` collapses a second seed of the same case; the
|
||||
# depth sweep's cases differ in their operand shapes and all run. OpenMP waits passively: the host
|
||||
# libraries' teams would otherwise spin between launches and starve what ctest -j runs beside them.
|
||||
set(RAD_KBENCH_LABELS "kbench")
|
||||
if(RAD_HIP_FOUND AND TARGET libr4d)
|
||||
set(RAD_KBENCH_LABELS "kbench;gpu")
|
||||
endif()
|
||||
set(RAD_KBENCH_ROWS ${CMAKE_SOURCE_DIR}/data/kbench_rows)
|
||||
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.
|
||||
COMMAND rad-kbench --home ${RAD_PLUGIN_OUT} --max-cases 1 --no-ref --strict
|
||||
--coverage ${RAD_KBENCH_ROWS})
|
||||
# RESOURCE_LOCK: each replay budgets a fraction of the memory available when it starts, so two
|
||||
# at once would together exceed it. They would also share the last-level cache and skew --bench.
|
||||
set_tests_properties(kbench PROPERTIES
|
||||
LABELS "${RAD_KBENCH_LABELS}"
|
||||
TIMEOUT 1800
|
||||
RESOURCE_LOCK kbench_memory
|
||||
ENVIRONMENT "RADIANCE_HOME=${RAD_PLUGIN_OUT}")
|
||||
PROCESSORS 4
|
||||
ENVIRONMENT "RADIANCE_HOME=${RAD_PLUGIN_OUT};OMP_WAIT_POLICY=passive")
|
||||
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.
|
||||
# The same replay over the routed fixture, which covers the MoE ops, the gqa 8 attention dispatch
|
||||
# and the MTP head (see the root CMakeLists). Separate tests, because a fixture records the one
|
||||
# container it came from.
|
||||
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
|
||||
COMMAND rad-kbench --home ${RAD_PLUGIN_OUT} --max-cases 1 --no-ref --strict
|
||||
--coverage ${RAD_KBENCH_ROWS}
|
||||
--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}")
|
||||
PROCESSORS 4
|
||||
ENVIRONMENT "RADIANCE_HOME=${RAD_PLUGIN_OUT};OMP_WAIT_POLICY=passive")
|
||||
endif()
|
||||
|
||||
# libref against its own recordings, both fixtures, at tolerance zero: it is deterministic and
|
||||
# machine-independent by construction, so any difference is a change in libref (or in the draw)
|
||||
# that would otherwise become the next recording's target. This is the oracle's regression test.
|
||||
# Its answers are cached under $RADIANCE_HOME/cache/kbench, keyed by libref's build-id and
|
||||
# everything it links, the input bytes and the case, so an unchanged libref replays in seconds and
|
||||
# a rebuilt one in full; the comparison runs either way. Labelled `slow` for the full run.
|
||||
if(TARGET rad-kbench AND TARGET libref AND EXISTS ${CMAKE_SOURCE_DIR}/data/kernels.rkb AND
|
||||
EXISTS ${CMAKE_SOURCE_DIR}/data/kernels_moe.rkb)
|
||||
add_test(NAME kbench_ref
|
||||
COMMAND rad-kbench --home ${RAD_PLUGIN_OUT} --kernels libref --max-cases 1 --strict
|
||||
--coverage ${RAD_KBENCH_ROWS}
|
||||
--fixture ${RAD_PLUGIN_OUT}/kernels.rkb
|
||||
--fixture ${RAD_PLUGIN_OUT}/kernels_moe.rkb)
|
||||
set_tests_properties(kbench_ref PROPERTIES
|
||||
LABELS "kbench;slow"
|
||||
TIMEOUT 3600
|
||||
RESOURCE_LOCK kbench_memory
|
||||
PROCESSORS 4
|
||||
ENVIRONMENT "RADIANCE_HOME=${RAD_PLUGIN_OUT};OMP_WAIT_POLICY=passive")
|
||||
endif()
|
||||
|
||||
# ================================================================== tiers
|
||||
#
|
||||
# `fast` goes on every test registered above that carries none of slow, gpu, oot, perf, e2e and
|
||||
# kbench, so the inner loop's membership is decided here alone. Every `gpu` test takes the card lock: two tests
|
||||
# that each commit device memory, or each time kernels, must not share a card. COST starts the
|
||||
# longest tests first in a parallel run, so they are not left on the critical path.
|
||||
get_property(RAD_ALL_TESTS DIRECTORY PROPERTY TESTS)
|
||||
foreach(t ${RAD_ALL_TESTS})
|
||||
get_test_property(${t} LABELS labels)
|
||||
if(NOT labels)
|
||||
set(labels "")
|
||||
endif()
|
||||
if(NOT labels MATCHES "(^|;)(slow|gpu|oot|perf|e2e|kbench)(;|$)")
|
||||
set_property(TEST ${t} APPEND PROPERTY LABELS fast)
|
||||
endif()
|
||||
if(labels MATCHES "(^|;)gpu(;|$)")
|
||||
set_property(TEST ${t} APPEND PROPERTY RESOURCE_LOCK card)
|
||||
endif()
|
||||
endforeach()
|
||||
foreach(cost IN ITEMS kbench_ref:500 r4d_selftest:350 r4d_emu_attn_sweep:80 kbench:20
|
||||
kbench_moe:15 engine_e2e_test:12 r4d_emu_attn_shard0:5 r4d_emu_attn_shard2:5)
|
||||
string(REPLACE ":" ";" cost ${cost})
|
||||
list(GET cost 0 t)
|
||||
list(GET cost 1 c)
|
||||
if(TEST ${t})
|
||||
set_tests_properties(${t} PROPERTIES COST ${c})
|
||||
endif()
|
||||
endforeach()
|
||||
@@ -0,0 +1,48 @@
|
||||
/* abi_c_test.c -- abi/ as a C plugin sees it.
|
||||
*
|
||||
* Every header is included in one translation unit compiled as strict C11 (-pedantic-errors, see
|
||||
* tests/CMakeLists.txt), so a header that only C++ accepts fails the build. The struct layouts a
|
||||
* C compiler gives them, and rad_yarn.h's C definitions, are handed to abi_layout_test.cpp, which
|
||||
* compares them with its own. */
|
||||
#include "rad_abi.h"
|
||||
#include "rad_builder.h"
|
||||
#include "rad_device.h"
|
||||
#include "rad_encoding.h"
|
||||
#include "rad_format.h"
|
||||
#include "rad_philox.h"
|
||||
#include "rad_planes.h"
|
||||
#include "rad_plugin.h"
|
||||
#include "rad_quant.h"
|
||||
#include "rad_runtime.h"
|
||||
#include "rad_sample.h"
|
||||
#include "rad_types.h"
|
||||
#include "rad_yarn.h"
|
||||
|
||||
#include "abi_layout.h"
|
||||
|
||||
const AbiRow abi_c_rows[] = {
|
||||
#define ABI_STRUCT(T) { #T, "", 0, sizeof(T) },
|
||||
#define ABI_FIELD(T, f) { #T, #f, offsetof(T, f), sizeof(((T*)0)->f) },
|
||||
#include "abi_layout_rows.h"
|
||||
#undef ABI_STRUCT
|
||||
#undef ABI_FIELD
|
||||
};
|
||||
const size_t abi_c_n_rows = sizeof abi_c_rows / sizeof abi_c_rows[0];
|
||||
|
||||
float abi_c_yarn_frequency(float factor, float low, float high, float magnitude, float inv, int i) {
|
||||
RadYarn y;
|
||||
y.factor = factor;
|
||||
y.low = low;
|
||||
y.high = high;
|
||||
y.magnitude = magnitude;
|
||||
return rad_yarn_frequency(&y, inv, i);
|
||||
}
|
||||
|
||||
int abi_c_yarn_valid(float factor, float low, float high, float magnitude) {
|
||||
RadYarn y;
|
||||
y.factor = factor;
|
||||
y.low = low;
|
||||
y.high = high;
|
||||
y.magnitude = magnitude;
|
||||
return rad_yarn_valid(&y);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/* abi_layout.h -- what abi_layout_test's C translation unit (abi_c_test.c) hands its C++ one: the
|
||||
* layout of every struct abi/ exports as a C compiler lays it out, and rad_yarn.h's C forms.
|
||||
*
|
||||
* A row is a struct's size (`field` empty) or one field's offset and size, in bytes. */
|
||||
#ifndef ABI_LAYOUT_H
|
||||
#define ABI_LAYOUT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct AbiRow {
|
||||
const char* type;
|
||||
const char* field;
|
||||
size_t offset;
|
||||
size_t size;
|
||||
} AbiRow;
|
||||
|
||||
extern const AbiRow abi_c_rows[];
|
||||
extern const size_t abi_c_n_rows;
|
||||
|
||||
/* rad_yarn_frequency and rad_yarn_valid as C sees them, over a RadYarn of these four values. */
|
||||
float abi_c_yarn_frequency(float factor, float low, float high, float magnitude, float inv, int i);
|
||||
int abi_c_yarn_valid(float factor, float low, float high, float magnitude);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ABI_LAYOUT_H */
|
||||
@@ -0,0 +1,566 @@
|
||||
/* abi_layout_rows.h -- every struct abi/ exports and each of its top-level fields, as
|
||||
* ABI_STRUCT(type) and ABI_FIELD(type, field) lines; the includer defines both. abi_c_test.c and
|
||||
* abi_layout_test.cpp include it, so the C and C++ translation units list the same rows.
|
||||
*
|
||||
* A struct or field added to abi/ is added here too: abi_layout_test fails on a struct whose
|
||||
* listed fields do not account for its size. Included once per table, so it has no include guard.
|
||||
*/
|
||||
ABI_STRUCT(RadArchProbe)
|
||||
ABI_FIELD(RadArchProbe, draft_depth)
|
||||
ABI_FIELD(RadArchProbe, draft_depth_fixed)
|
||||
ABI_FIELD(RadArchProbe, shape_probe_ok)
|
||||
ABI_FIELD(RadArchProbe, enc_merge)
|
||||
ABI_FIELD(RadArchProbe, audio_frames)
|
||||
ABI_FIELD(RadArchProbe, gen_rows)
|
||||
ABI_FIELD(RadArchProbe, gen_patches)
|
||||
ABI_STRUCT(RadArgs)
|
||||
ABI_FIELD(RadArgs, t)
|
||||
ABI_FIELD(RadArgs, n_t)
|
||||
ABI_FIELD(RadArgs, p)
|
||||
ABI_FIELD(RadArgs, n_p)
|
||||
ABI_FIELD(RadArgs, scratch)
|
||||
ABI_FIELD(RadArgs, scratch_bytes)
|
||||
ABI_FIELD(RadArgs, instance)
|
||||
ABI_FIELD(RadArgs, rank)
|
||||
ABI_FIELD(RadArgs, world_size)
|
||||
ABI_STRUCT(RadBatch)
|
||||
ABI_FIELD(RadBatch, phase)
|
||||
ABI_FIELD(RadBatch, step)
|
||||
ABI_FIELD(RadBatch, n_tok)
|
||||
ABI_FIELD(RadBatch, n_seq)
|
||||
ABI_FIELD(RadBatch, token_ids)
|
||||
ABI_FIELD(RadBatch, positions)
|
||||
ABI_FIELD(RadBatch, cu_seqlens)
|
||||
ABI_FIELD(RadBatch, seq_ids)
|
||||
ABI_FIELD(RadBatch, n_out)
|
||||
ABI_FIELD(RadBatch, out_ids)
|
||||
ABI_FIELD(RadBatch, q_lens)
|
||||
ABI_FIELD(RadBatch, ctx_lens)
|
||||
ABI_FIELD(RadBatch, max_q_len)
|
||||
ABI_FIELD(RadBatch, max_ctx_len)
|
||||
ABI_FIELD(RadBatch, n_kv_groups)
|
||||
ABI_FIELD(RadBatch, kv)
|
||||
ABI_FIELD(RadBatch, n_spec)
|
||||
ABI_FIELD(RadBatch, num_accepted)
|
||||
ABI_FIELD(RadBatch, spec_parent)
|
||||
ABI_FIELD(RadBatch, draft_pass)
|
||||
ABI_FIELD(RadBatch, n_checkpoints)
|
||||
ABI_FIELD(RadBatch, checkpoint_tok)
|
||||
ABI_FIELD(RadBatch, checkpoint_slot)
|
||||
ABI_FIELD(RadBatch, n_seq_decode)
|
||||
ABI_FIELD(RadBatch, n_tok_decode)
|
||||
ABI_FIELD(RadBatch, max_q_len_decode)
|
||||
ABI_FIELD(RadBatch, max_q_len_prefill)
|
||||
ABI_FIELD(RadBatch, n_draft_out)
|
||||
ABI_FIELD(RadBatch, draft_out_ids)
|
||||
ABI_FIELD(RadBatch, n_ahead)
|
||||
ABI_FIELD(RadBatch, rope_pos)
|
||||
ABI_FIELD(RadBatch, rope_mixed)
|
||||
ABI_FIELD(RadBatch, n_mm_rows)
|
||||
ABI_FIELD(RadBatch, mm_rows)
|
||||
ABI_FIELD(RadBatch, mm_embd)
|
||||
ABI_FIELD(RadBatch, enc)
|
||||
ABI_FIELD(RadBatch, enc_n_patch)
|
||||
ABI_FIELD(RadBatch, enc_pixels)
|
||||
ABI_FIELD(RadBatch, enc_coord)
|
||||
ABI_FIELD(RadBatch, enc_n_seg)
|
||||
ABI_FIELD(RadBatch, enc_cu)
|
||||
ABI_FIELD(RadBatch, enc_max_seg)
|
||||
ABI_FIELD(RadBatch, gen)
|
||||
ABI_FIELD(RadBatch, gen_b)
|
||||
ABI_STRUCT(RadBufDecl)
|
||||
ABI_FIELD(RadBufDecl, dtype)
|
||||
ABI_FIELD(RadBufDecl, rank)
|
||||
ABI_FIELD(RadBufDecl, shape)
|
||||
ABI_FIELD(RadBufDecl, kind)
|
||||
ABI_FIELD(RadBufDecl, domain)
|
||||
ABI_FIELD(RadBufDecl, derive)
|
||||
ABI_FIELD(RadBufDecl, kv)
|
||||
ABI_STRUCT(RadBuildCtx)
|
||||
ABI_FIELD(RadBuildCtx, rank)
|
||||
ABI_FIELD(RadBuildCtx, world_size)
|
||||
ABI_FIELD(RadBuildCtx, max_tok)
|
||||
ABI_FIELD(RadBuildCtx, max_seqs)
|
||||
ABI_FIELD(RadBuildCtx, max_ctx)
|
||||
ABI_FIELD(RadBuildCtx, max_spec)
|
||||
ABI_FIELD(RadBuildCtx, tp_wire_lossy)
|
||||
ABI_FIELD(RadBuildCtx, tp_wire_min_bytes)
|
||||
ABI_FIELD(RadBuildCtx, kv_dtype)
|
||||
ABI_FIELD(RadBuildCtx, is_draft)
|
||||
ABI_FIELD(RadBuildCtx, scope)
|
||||
ABI_FIELD(RadBuildCtx, shape_probe)
|
||||
ABI_FIELD(RadBuildCtx, max_enc_patches)
|
||||
ABI_FIELD(RadBuildCtx, max_out_rows)
|
||||
ABI_FIELD(RadBuildCtx, max_audio_frames)
|
||||
ABI_FIELD(RadBuildCtx, max_mixed_tok)
|
||||
ABI_STRUCT(RadAudioFormat)
|
||||
ABI_FIELD(RadAudioFormat, struct_size)
|
||||
ABI_FIELD(RadAudioFormat, audio_open)
|
||||
ABI_FIELD(RadAudioFormat, audio_close)
|
||||
ABI_FIELD(RadAudioFormat, transcribe_prompt)
|
||||
ABI_FIELD(RadAudioFormat, language_prompt)
|
||||
ABI_FIELD(RadAudioFormat, transcript_open)
|
||||
ABI_FIELD(RadAudioFormat, language_lead)
|
||||
ABI_FIELD(RadAudioFormat, languages)
|
||||
ABI_FIELD(RadAudioFormat, n_languages)
|
||||
ABI_STRUCT(RadChatFormat)
|
||||
ABI_FIELD(RadChatFormat, struct_size)
|
||||
ABI_FIELD(RadChatFormat, name)
|
||||
ABI_FIELD(RadChatFormat, reasoning_open)
|
||||
ABI_FIELD(RadChatFormat, reasoning_close)
|
||||
ABI_FIELD(RadChatFormat, reasoning_breaks)
|
||||
ABI_FIELD(RadChatFormat, n_reasoning_breaks)
|
||||
ABI_FIELD(RadChatFormat, reasoning_in_prompt)
|
||||
ABI_FIELD(RadChatFormat, section_open)
|
||||
ABI_FIELD(RadChatFormat, section_close)
|
||||
ABI_FIELD(RadChatFormat, call_separator)
|
||||
ABI_FIELD(RadChatFormat, call_open)
|
||||
ABI_FIELD(RadChatFormat, call_close)
|
||||
ABI_FIELD(RadChatFormat, name_prefix)
|
||||
ABI_FIELD(RadChatFormat, name_suffix)
|
||||
ABI_FIELD(RadChatFormat, call_end)
|
||||
ABI_FIELD(RadChatFormat, arg_prefix)
|
||||
ABI_FIELD(RadChatFormat, arg_name_suffix)
|
||||
ABI_FIELD(RadChatFormat, arg_value_prefix)
|
||||
ABI_FIELD(RadChatFormat, arg_value_suffix)
|
||||
ABI_FIELD(RadChatFormat, string_value)
|
||||
ABI_FIELD(RadChatFormat, other_value)
|
||||
ABI_FIELD(RadChatFormat, value_newlines)
|
||||
ABI_FIELD(RadChatFormat, triggers)
|
||||
ABI_FIELD(RadChatFormat, n_triggers)
|
||||
ABI_FIELD(RadChatFormat, args_form)
|
||||
ABI_FIELD(RadChatFormat, object_string_open)
|
||||
ABI_FIELD(RadChatFormat, object_string_close)
|
||||
ABI_FIELD(RadChatFormat, object_bare_keys)
|
||||
ABI_FIELD(RadChatFormat, reasoning_anywhere)
|
||||
ABI_STRUCT(RadConstraint)
|
||||
ABI_FIELD(RadConstraint, key)
|
||||
ABI_FIELD(RadConstraint, op)
|
||||
ABI_FIELD(RadConstraint, ival)
|
||||
ABI_FIELD(RadConstraint, sval)
|
||||
ABI_STRUCT(RadDeviceProps)
|
||||
ABI_FIELD(RadDeviceProps, name)
|
||||
ABI_FIELD(RadDeviceProps, arch)
|
||||
ABI_FIELD(RadDeviceProps, device_id)
|
||||
ABI_FIELD(RadDeviceProps, n_cu)
|
||||
ABI_FIELD(RadDeviceProps, warp_size)
|
||||
ABI_FIELD(RadDeviceProps, vram_bytes)
|
||||
ABI_FIELD(RadDeviceProps, vram_free)
|
||||
ABI_FIELD(RadDeviceProps, lds_bytes)
|
||||
ABI_FIELD(RadDeviceProps, supports_p2p)
|
||||
ABI_FIELD(RadDeviceProps, is_host_backend)
|
||||
ABI_STRUCT(RadDrafterDecl)
|
||||
ABI_FIELD(RadDrafterDecl, name)
|
||||
ABI_FIELD(RadDrafterDecl, kind)
|
||||
ABI_FIELD(RadDrafterDecl, depth)
|
||||
ABI_FIELD(RadDrafterDecl, proposal)
|
||||
ABI_FIELD(RadDrafterDecl, proposal_pitch)
|
||||
ABI_FIELD(RadDrafterDecl, mask_token)
|
||||
ABI_FIELD(RadDrafterDecl, window)
|
||||
ABI_FIELD(RadDrafterDecl, block)
|
||||
ABI_STRUCT(RadDtRow)
|
||||
ABI_FIELD(RadDtRow, dt)
|
||||
ABI_FIELD(RadDtRow, name)
|
||||
ABI_FIELD(RadDtRow, bits)
|
||||
ABI_STRUCT(RadEncPlane)
|
||||
ABI_FIELD(RadEncPlane, role)
|
||||
ABI_FIELD(RadEncPlane, dtype)
|
||||
ABI_FIELD(RadEncPlane, kind)
|
||||
ABI_FIELD(RadEncPlane, block)
|
||||
ABI_FIELD(RadEncPlane, extent)
|
||||
ABI_STRUCT(RadEncoderDecl)
|
||||
ABI_FIELD(RadEncoderDecl, name)
|
||||
ABI_FIELD(RadEncoderDecl, modalities)
|
||||
ABI_FIELD(RadEncoderDecl, patch_dim)
|
||||
ABI_FIELD(RadEncoderDecl, merge)
|
||||
ABI_FIELD(RadEncoderDecl, max_patches)
|
||||
ABI_FIELD(RadEncoderDecl, n_embd)
|
||||
ABI_FIELD(RadEncoderDecl, out)
|
||||
ABI_STRUCT(RadEncoding)
|
||||
ABI_FIELD(RadEncoding, scheme)
|
||||
ABI_FIELD(RadEncoding, transform)
|
||||
ABI_FIELD(RadEncoding, n_planes)
|
||||
ABI_FIELD(RadEncoding, reserved)
|
||||
ABI_FIELD(RadEncoding, plane)
|
||||
ABI_STRUCT(RadFileEntry)
|
||||
ABI_FIELD(RadFileEntry, name)
|
||||
ABI_FIELD(RadFileEntry, quantizer)
|
||||
ABI_FIELD(RadFileEntry, options)
|
||||
ABI_FIELD(RadFileEntry, enc)
|
||||
ABI_FIELD(RadFileEntry, rank)
|
||||
ABI_FIELD(RadFileEntry, shape)
|
||||
ABI_FIELD(RadFileEntry, layer)
|
||||
ABI_FIELD(RadFileEntry, expert)
|
||||
ABI_FIELD(RadFileEntry, slot)
|
||||
ABI_FIELD(RadFileEntry, n_planes)
|
||||
ABI_FIELD(RadFileEntry, plane_first)
|
||||
ABI_FIELD(RadFileEntry, offset)
|
||||
ABI_FIELD(RadFileEntry, bytes)
|
||||
ABI_FIELD(RadFileEntry, reserved)
|
||||
ABI_STRUCT(RadFileHeader)
|
||||
ABI_FIELD(RadFileHeader, magic)
|
||||
ABI_FIELD(RadFileHeader, version)
|
||||
ABI_FIELD(RadFileHeader, file_bytes)
|
||||
ABI_FIELD(RadFileHeader, arch_id)
|
||||
ABI_FIELD(RadFileHeader, model_name)
|
||||
ABI_FIELD(RadFileHeader, quant)
|
||||
ABI_FIELD(RadFileHeader, recipe)
|
||||
ABI_FIELD(RadFileHeader, created_by)
|
||||
ABI_FIELD(RadFileHeader, str_off)
|
||||
ABI_FIELD(RadFileHeader, str_bytes)
|
||||
ABI_FIELD(RadFileHeader, meta_off)
|
||||
ABI_FIELD(RadFileHeader, meta_count)
|
||||
ABI_FIELD(RadFileHeader, dir_off)
|
||||
ABI_FIELD(RadFileHeader, dir_count)
|
||||
ABI_FIELD(RadFileHeader, plane_off)
|
||||
ABI_FIELD(RadFileHeader, plane_count)
|
||||
ABI_FIELD(RadFileHeader, enc_off)
|
||||
ABI_FIELD(RadFileHeader, enc_count)
|
||||
ABI_FIELD(RadFileHeader, vocab_off)
|
||||
ABI_FIELD(RadFileHeader, vocab_bytes)
|
||||
ABI_FIELD(RadFileHeader, prof_off)
|
||||
ABI_FIELD(RadFileHeader, prof_count)
|
||||
ABI_FIELD(RadFileHeader, data_off)
|
||||
ABI_FIELD(RadFileHeader, data_bytes)
|
||||
ABI_FIELD(RadFileHeader, reserved)
|
||||
ABI_STRUCT(RadFileKV)
|
||||
ABI_FIELD(RadFileKV, key)
|
||||
ABI_FIELD(RadFileKV, type)
|
||||
ABI_FIELD(RadFileKV, pad)
|
||||
ABI_FIELD(RadFileKV, v)
|
||||
ABI_STRUCT(RadFilePlane)
|
||||
ABI_FIELD(RadFilePlane, offset)
|
||||
ABI_FIELD(RadFilePlane, bytes)
|
||||
ABI_STRUCT(RadFileProfile)
|
||||
ABI_FIELD(RadFileProfile, layer)
|
||||
ABI_FIELD(RadFileProfile, expert)
|
||||
ABI_FIELD(RadFileProfile, share)
|
||||
ABI_FIELD(RadFileProfile, reserved)
|
||||
ABI_STRUCT(RadFuseStep)
|
||||
ABI_FIELD(RadFuseStep, op)
|
||||
ABI_FIELD(RadFuseStep, p)
|
||||
ABI_FIELD(RadFuseStep, n_p)
|
||||
ABI_FIELD(RadFuseStep, from)
|
||||
ABI_FIELD(RadFuseStep, n_from)
|
||||
ABI_STRUCT(RadGenBatch)
|
||||
ABI_FIELD(RadGenBatch, rows)
|
||||
ABI_FIELD(RadGenBatch, src)
|
||||
ABI_FIELD(RadGenBatch, rope)
|
||||
ABI_FIELD(RadGenBatch, n_seg)
|
||||
ABI_FIELD(RadGenBatch, seg)
|
||||
ABI_FIELD(RadGenBatch, seg_h)
|
||||
ABI_FIELD(RadGenBatch, seg_bidi_h)
|
||||
ABI_FIELD(RadGenBatch, seg_cu)
|
||||
ABI_FIELD(RadGenBatch, seg_start)
|
||||
ABI_FIELD(RadGenBatch, slot_mapping)
|
||||
ABI_FIELD(RadGenBatch, n_px)
|
||||
ABI_FIELD(RadGenBatch, px)
|
||||
ABI_FIELD(RadGenBatch, px_h)
|
||||
ABI_FIELD(RadGenBatch, px_cu)
|
||||
ABI_FIELD(RadGenBatch, inpaint)
|
||||
ABI_FIELD(RadGenBatch, inp_mask)
|
||||
ABI_FIELD(RadGenBatch, n_lane)
|
||||
ABI_FIELD(RadGenBatch, lane_h)
|
||||
ABI_FIELD(RadGenBatch, sigma)
|
||||
ABI_FIELD(RadGenBatch, sigma_next)
|
||||
ABI_FIELD(RadGenBatch, cfg)
|
||||
ABI_FIELD(RadGenBatch, pair)
|
||||
ABI_FIELD(RadGenBatch, lane)
|
||||
ABI_FIELD(RadGenBatch, lane_dh)
|
||||
ABI_FIELD(RadGenBatch, flags)
|
||||
ABI_FIELD(RadGenBatch, seed)
|
||||
ABI_FIELD(RadGenBatch, dec_lane)
|
||||
ABI_FIELD(RadGenBatch, dec_height)
|
||||
ABI_FIELD(RadGenBatch, dec_width)
|
||||
ABI_FIELD(RadGenBatch, dec_preview)
|
||||
ABI_STRUCT(RadGeneratorDecl)
|
||||
ABI_FIELD(RadGeneratorDecl, name)
|
||||
ABI_FIELD(RadGeneratorDecl, layout)
|
||||
ABI_FIELD(RadGeneratorDecl, tmpl_text)
|
||||
ABI_FIELD(RadGeneratorDecl, tmpl_edit)
|
||||
ABI_FIELD(RadGeneratorDecl, tmpl_image)
|
||||
ABI_FIELD(RadGeneratorDecl, tmpl_image_sep)
|
||||
ABI_FIELD(RadGeneratorDecl, drop_prefix)
|
||||
ABI_FIELD(RadGeneratorDecl, tmpl_transparent)
|
||||
ABI_FIELD(RadGeneratorDecl, latent_channels)
|
||||
ABI_FIELD(RadGeneratorDecl, latent_scale)
|
||||
ABI_FIELD(RadGeneratorDecl, size_multiple)
|
||||
ABI_FIELD(RadGeneratorDecl, pixel_channels)
|
||||
ABI_FIELD(RadGeneratorDecl, slot_rows)
|
||||
ABI_FIELD(RadGeneratorDecl, max_tokens)
|
||||
ABI_FIELD(RadGeneratorDecl, max_refs)
|
||||
ABI_FIELD(RadGeneratorDecl, ref_area)
|
||||
ABI_FIELD(RadGeneratorDecl, default_width)
|
||||
ABI_FIELD(RadGeneratorDecl, default_height)
|
||||
ABI_FIELD(RadGeneratorDecl, default_steps)
|
||||
ABI_FIELD(RadGeneratorDecl, n_sigmas)
|
||||
ABI_FIELD(RadGeneratorDecl, sigmas)
|
||||
ABI_FIELD(RadGeneratorDecl, shift)
|
||||
ABI_FIELD(RadGeneratorDecl, dyn_shift)
|
||||
ABI_FIELD(RadGeneratorDecl, shift_exp)
|
||||
ABI_FIELD(RadGeneratorDecl, base_shift)
|
||||
ABI_FIELD(RadGeneratorDecl, max_shift)
|
||||
ABI_FIELD(RadGeneratorDecl, base_seq)
|
||||
ABI_FIELD(RadGeneratorDecl, max_seq)
|
||||
ABI_FIELD(RadGeneratorDecl, shift_terminal)
|
||||
ABI_FIELD(RadGeneratorDecl, default_cfg)
|
||||
ABI_FIELD(RadGeneratorDecl, max_lanes)
|
||||
ABI_FIELD(RadGeneratorDecl, image_out)
|
||||
ABI_STRUCT(RadKVGroupBatch)
|
||||
ABI_FIELD(RadKVGroupBatch, group)
|
||||
ABI_FIELD(RadKVGroupBatch, slot_mapping)
|
||||
ABI_FIELD(RadKVGroupBatch, block_table)
|
||||
ABI_FIELD(RadKVGroupBatch, block_table_pitch)
|
||||
ABI_FIELD(RadKVGroupBatch, seqused)
|
||||
ABI_FIELD(RadKVGroupBatch, state_index)
|
||||
ABI_FIELD(RadKVGroupBatch, state_index_pitch)
|
||||
ABI_FIELD(RadKVGroupBatch, block_size)
|
||||
ABI_FIELD(RadKVGroupBatch, max_blocks)
|
||||
ABI_STRUCT(RadKVGroupDecl)
|
||||
ABI_FIELD(RadKVGroupDecl, kind)
|
||||
ABI_FIELD(RadKVGroupDecl, dtype)
|
||||
ABI_FIELD(RadKVGroupDecl, window)
|
||||
ABI_FIELD(RadKVGroupDecl, n_head_kv)
|
||||
ABI_FIELD(RadKVGroupDecl, head_dim)
|
||||
ABI_FIELD(RadKVGroupDecl, state_dim)
|
||||
ABI_FIELD(RadKVGroupDecl, conv_width)
|
||||
ABI_STRUCT(RadKernelInfo)
|
||||
ABI_FIELD(RadKernelInfo, name)
|
||||
ABI_FIELD(RadKernelInfo, op)
|
||||
ABI_FIELD(RadKernelInfo, family)
|
||||
ABI_FIELD(RadKernelInfo, computes)
|
||||
ABI_FIELD(RadKernelInfo, shape)
|
||||
ABI_FIELD(RadKernelInfo, dtypes)
|
||||
ABI_FIELD(RadKernelInfo, domain)
|
||||
ABI_FIELD(RadKernelInfo, priority)
|
||||
ABI_FIELD(RadKernelInfo, constraints)
|
||||
ABI_FIELD(RadKernelInfo, n_constraints)
|
||||
ABI_FIELD(RadKernelInfo, tunables)
|
||||
ABI_FIELD(RadKernelInfo, n_tunables)
|
||||
ABI_FIELD(RadKernelInfo, tune_valid)
|
||||
ABI_FIELD(RadKernelInfo, init)
|
||||
ABI_FIELD(RadKernelInfo, fini)
|
||||
ABI_FIELD(RadKernelInfo, launch)
|
||||
ABI_FIELD(RadKernelInfo, scratch)
|
||||
ABI_FIELD(RadKernelInfo, layout)
|
||||
ABI_FIELD(RadKernelInfo, relayout)
|
||||
ABI_FIELD(RadKernelInfo, opd_shape)
|
||||
ABI_FIELD(RadKernelInfo, unrelayout)
|
||||
ABI_FIELD(RadKernelInfo, replaces)
|
||||
ABI_STRUCT(RadLayout)
|
||||
ABI_FIELD(RadLayout, tag)
|
||||
ABI_FIELD(RadLayout, dtype)
|
||||
ABI_FIELD(RadLayout, rank)
|
||||
ABI_FIELD(RadLayout, shape)
|
||||
ABI_FIELD(RadLayout, align)
|
||||
ABI_FIELD(RadLayout, bytes)
|
||||
ABI_STRUCT(RadModelMeta)
|
||||
ABI_FIELD(RadModelMeta, arch_id)
|
||||
ABI_FIELD(RadModelMeta, name)
|
||||
ABI_FIELD(RadModelMeta, quant)
|
||||
ABI_FIELD(RadModelMeta, n_layers)
|
||||
ABI_FIELD(RadModelMeta, n_embd)
|
||||
ABI_FIELD(RadModelMeta, n_head)
|
||||
ABI_FIELD(RadModelMeta, n_head_kv)
|
||||
ABI_FIELD(RadModelMeta, head_dim)
|
||||
ABI_FIELD(RadModelMeta, n_ff)
|
||||
ABI_FIELD(RadModelMeta, n_vocab)
|
||||
ABI_FIELD(RadModelMeta, n_ctx_train)
|
||||
ABI_FIELD(RadModelMeta, n_expert)
|
||||
ABI_FIELD(RadModelMeta, n_expert_used)
|
||||
ABI_FIELD(RadModelMeta, n_expert_shared)
|
||||
ABI_FIELD(RadModelMeta, rms_eps)
|
||||
ABI_FIELD(RadModelMeta, rope_theta)
|
||||
ABI_FIELD(RadModelMeta, rope_scale)
|
||||
ABI_FIELD(RadModelMeta, n_kv)
|
||||
ABI_FIELD(RadModelMeta, kv_key)
|
||||
ABI_FIELD(RadModelMeta, kv_val)
|
||||
ABI_STRUCT(RadNameMap)
|
||||
ABI_FIELD(RadNameMap, declared)
|
||||
ABI_FIELD(RadNameMap, mode)
|
||||
ABI_FIELD(RadNameMap, n_src)
|
||||
ABI_FIELD(RadNameMap, src)
|
||||
ABI_FIELD(RadNameMap, concat_dim)
|
||||
ABI_FIELD(RadNameMap, src_index)
|
||||
ABI_STRUCT(RadOpSchema)
|
||||
ABI_FIELD(RadOpSchema, op)
|
||||
ABI_FIELD(RadOpSchema, params)
|
||||
ABI_FIELD(RadOpSchema, n_params)
|
||||
ABI_FIELD(RadOpSchema, operands)
|
||||
ABI_FIELD(RadOpSchema, n_operands)
|
||||
ABI_FIELD(RadOpSchema, doc)
|
||||
ABI_STRUCT(RadOpdDesc)
|
||||
ABI_FIELD(RadOpdDesc, dtype)
|
||||
ABI_FIELD(RadOpdDesc, rank)
|
||||
ABI_FIELD(RadOpdDesc, shape)
|
||||
ABI_FIELD(RadOpdDesc, fill)
|
||||
ABI_FIELD(RadOpdDesc, fill_chunk)
|
||||
ABI_FIELD(RadOpdDesc, idx_max)
|
||||
ABI_FIELD(RadOpdDesc, idx_const)
|
||||
ABI_FIELD(RadOpdDesc, flags)
|
||||
ABI_STRUCT(RadOperand)
|
||||
ABI_FIELD(RadOperand, kind)
|
||||
ABI_FIELD(RadOperand, dtype)
|
||||
ABI_FIELD(RadOperand, handle)
|
||||
ABI_FIELD(RadOperand, raw)
|
||||
ABI_FIELD(RadOperand, offset)
|
||||
ABI_FIELD(RadOperand, rows)
|
||||
ABI_FIELD(RadOperand, cols)
|
||||
ABI_STRUCT(RadOperandSpec)
|
||||
ABI_FIELD(RadOperandSpec, name)
|
||||
ABI_FIELD(RadOperandSpec, role)
|
||||
ABI_FIELD(RadOperandSpec, optional)
|
||||
ABI_STRUCT(RadParam)
|
||||
ABI_FIELD(RadParam, key)
|
||||
ABI_FIELD(RadParam, kind)
|
||||
ABI_FIELD(RadParam, ival)
|
||||
ABI_FIELD(RadParam, ihi)
|
||||
ABI_FIELD(RadParam, sval)
|
||||
ABI_FIELD(RadParam, dval)
|
||||
ABI_STRUCT(RadParamSpec)
|
||||
ABI_FIELD(RadParamSpec, key)
|
||||
ABI_FIELD(RadParamSpec, type)
|
||||
ABI_FIELD(RadParamSpec, required)
|
||||
ABI_FIELD(RadParamSpec, role)
|
||||
ABI_STRUCT(RadPlanesEntry)
|
||||
ABI_FIELD(RadPlanesEntry, role)
|
||||
ABI_FIELD(RadPlanesEntry, dtype)
|
||||
ABI_FIELD(RadPlanesEntry, kind)
|
||||
ABI_FIELD(RadPlanesEntry, block)
|
||||
ABI_FIELD(RadPlanesEntry, rows)
|
||||
ABI_FIELD(RadPlanesEntry, cols)
|
||||
ABI_FIELD(RadPlanesEntry, row_bytes)
|
||||
ABI_FIELD(RadPlanesEntry, offset)
|
||||
ABI_STRUCT(RadPlanesHeader)
|
||||
ABI_FIELD(RadPlanesHeader, magic)
|
||||
ABI_FIELD(RadPlanesHeader, n_planes)
|
||||
ABI_FIELD(RadPlanesHeader, transform)
|
||||
ABI_FIELD(RadPlanesHeader, bytes)
|
||||
ABI_STRUCT(RadPluginInfo)
|
||||
ABI_FIELD(RadPluginInfo, kind)
|
||||
ABI_FIELD(RadPluginInfo, name)
|
||||
ABI_FIELD(RadPluginInfo, version)
|
||||
ABI_FIELD(RadPluginInfo, description)
|
||||
ABI_FIELD(RadPluginInfo, build_target)
|
||||
ABI_STRUCT(RadPrefetchNext)
|
||||
ABI_FIELD(RadPrefetchNext, layer)
|
||||
ABI_FIELD(RadPrefetchNext, router)
|
||||
ABI_FIELD(RadPrefetchNext, n_expert)
|
||||
ABI_FIELD(RadPrefetchNext, top_k)
|
||||
ABI_FIELD(RadPrefetchNext, n_parts)
|
||||
ABI_FIELD(RadPrefetchNext, parts)
|
||||
ABI_FIELD(RadPrefetchNext, count_at)
|
||||
ABI_STRUCT(RadQuantOption)
|
||||
ABI_FIELD(RadQuantOption, key)
|
||||
ABI_FIELD(RadQuantOption, type)
|
||||
ABI_FIELD(RadQuantOption, deflt)
|
||||
ABI_FIELD(RadQuantOption, doc)
|
||||
ABI_STRUCT(RadQuantWeight)
|
||||
ABI_FIELD(RadQuantWeight, name)
|
||||
ABI_FIELD(RadQuantWeight, rank)
|
||||
ABI_FIELD(RadQuantWeight, shape)
|
||||
ABI_FIELD(RadQuantWeight, rows)
|
||||
ABI_FIELD(RadQuantWeight, cols)
|
||||
ABI_FIELD(RadQuantWeight, layer)
|
||||
ABI_FIELD(RadQuantWeight, expert)
|
||||
ABI_FIELD(RadQuantWeight, importance)
|
||||
ABI_STRUCT(RadQuantizerInfo)
|
||||
ABI_FIELD(RadQuantizerInfo, name)
|
||||
ABI_FIELD(RadQuantizerInfo, doc)
|
||||
ABI_FIELD(RadQuantizerInfo, options)
|
||||
ABI_FIELD(RadQuantizerInfo, n_options)
|
||||
ABI_FIELD(RadQuantizerInfo, encoding)
|
||||
ABI_FIELD(RadQuantizerInfo, row_block)
|
||||
ABI_FIELD(RadQuantizerInfo, quantize)
|
||||
ABI_FIELD(RadQuantizerInfo, decode)
|
||||
ABI_STRUCT(RadRouting)
|
||||
ABI_FIELD(RadRouting, expert_ids)
|
||||
ABI_FIELD(RadRouting, expert_w)
|
||||
ABI_FIELD(RadRouting, expert_count)
|
||||
ABI_FIELD(RadRouting, sorted_tok)
|
||||
ABI_FIELD(RadRouting, expert_offset)
|
||||
ABI_FIELD(RadRouting, top_k)
|
||||
ABI_FIELD(RadRouting, n_expert)
|
||||
ABI_STRUCT(RadSampleParams)
|
||||
ABI_FIELD(RadSampleParams, seed)
|
||||
ABI_FIELD(RadSampleParams, pos)
|
||||
ABI_FIELD(RadSampleParams, temp)
|
||||
ABI_FIELD(RadSampleParams, top_p)
|
||||
ABI_FIELD(RadSampleParams, min_p)
|
||||
ABI_FIELD(RadSampleParams, typical_p)
|
||||
ABI_FIELD(RadSampleParams, rep_penalty)
|
||||
ABI_FIELD(RadSampleParams, freq_penalty)
|
||||
ABI_FIELD(RadSampleParams, pres_penalty)
|
||||
ABI_FIELD(RadSampleParams, xtc_probability)
|
||||
ABI_FIELD(RadSampleParams, xtc_threshold)
|
||||
ABI_FIELD(RadSampleParams, dry_multiplier)
|
||||
ABI_FIELD(RadSampleParams, dry_base)
|
||||
ABI_FIELD(RadSampleParams, top_k)
|
||||
ABI_FIELD(RadSampleParams, penalty_last_n)
|
||||
ABI_FIELD(RadSampleParams, dry_allowed_length)
|
||||
ABI_FIELD(RadSampleParams, dry_penalty_last_n)
|
||||
ABI_FIELD(RadSampleParams, hist_off)
|
||||
ABI_FIELD(RadSampleParams, hist_len)
|
||||
ABI_FIELD(RadSampleParams, mask_row)
|
||||
ABI_FIELD(RadSampleParams, flags)
|
||||
ABI_FIELD(RadSampleParams, dry_rep_limit)
|
||||
ABI_STRUCT(RadTensor)
|
||||
ABI_FIELD(RadTensor, data)
|
||||
ABI_FIELD(RadTensor, dtype)
|
||||
ABI_FIELD(RadTensor, rank)
|
||||
ABI_FIELD(RadTensor, shape)
|
||||
ABI_FIELD(RadTensor, stride)
|
||||
ABI_STRUCT(RadTunable)
|
||||
ABI_FIELD(RadTunable, key)
|
||||
ABI_FIELD(RadTunable, values)
|
||||
ABI_FIELD(RadTunable, n_values)
|
||||
ABI_FIELD(RadTunable, deflt)
|
||||
ABI_FIELD(RadTunable, doc)
|
||||
ABI_STRUCT(RadVocabHeader)
|
||||
ABI_FIELD(RadVocabHeader, kind)
|
||||
ABI_FIELD(RadVocabHeader, n_tokens)
|
||||
ABI_FIELD(RadVocabHeader, n_merges)
|
||||
ABI_FIELD(RadVocabHeader, n_steps)
|
||||
ABI_FIELD(RadVocabHeader, tok_text_off)
|
||||
ABI_FIELD(RadVocabHeader, tok_score_off)
|
||||
ABI_FIELD(RadVocabHeader, tok_type_off)
|
||||
ABI_FIELD(RadVocabHeader, merge_off)
|
||||
ABI_FIELD(RadVocabHeader, step_off)
|
||||
ABI_FIELD(RadVocabHeader, bos)
|
||||
ABI_FIELD(RadVocabHeader, eos)
|
||||
ABI_FIELD(RadVocabHeader, eot)
|
||||
ABI_FIELD(RadVocabHeader, pad_id)
|
||||
ABI_FIELD(RadVocabHeader, unk)
|
||||
ABI_FIELD(RadVocabHeader, sep)
|
||||
ABI_FIELD(RadVocabHeader, add_bos)
|
||||
ABI_FIELD(RadVocabHeader, add_eos)
|
||||
ABI_FIELD(RadVocabHeader, chat_template)
|
||||
ABI_FIELD(RadVocabHeader, flags)
|
||||
ABI_FIELD(RadVocabHeader, reserved)
|
||||
ABI_STRUCT(RadVocabStep)
|
||||
ABI_FIELD(RadVocabStep, kind)
|
||||
ABI_FIELD(RadVocabStep, flags)
|
||||
ABI_FIELD(RadVocabStep, arg0)
|
||||
ABI_FIELD(RadVocabStep, arg1)
|
||||
ABI_FIELD(RadVocabStep, iarg)
|
||||
ABI_STRUCT(RadWeightDecl)
|
||||
ABI_FIELD(RadWeightDecl, dtype)
|
||||
ABI_FIELD(RadWeightDecl, rank)
|
||||
ABI_FIELD(RadWeightDecl, shape)
|
||||
ABI_FIELD(RadWeightDecl, access)
|
||||
ABI_FIELD(RadWeightDecl, shard)
|
||||
ABI_FIELD(RadWeightDecl, group)
|
||||
ABI_FIELD(RadWeightDecl, optional)
|
||||
ABI_FIELD(RadWeightDecl, n_row_parts)
|
||||
ABI_FIELD(RadWeightDecl, row_parts)
|
||||
ABI_FIELD(RadWeightDecl, source)
|
||||
ABI_FIELD(RadWeightDecl, planes)
|
||||
ABI_STRUCT(RadWeightGroup)
|
||||
ABI_FIELD(RadWeightGroup, layer)
|
||||
ABI_FIELD(RadWeightGroup, expert)
|
||||
ABI_FIELD(RadWeightGroup, slot)
|
||||
ABI_STRUCT(RadYarn)
|
||||
ABI_FIELD(RadYarn, factor)
|
||||
ABI_FIELD(RadYarn, low)
|
||||
ABI_FIELD(RadYarn, high)
|
||||
ABI_FIELD(RadYarn, magnitude)
|
||||
@@ -0,0 +1,563 @@
|
||||
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 17 and
|
||||
* RAD_FORMAT_VER 2, as { type, field, offset, size } rows ("" is the struct itself). A snapshot
|
||||
* of the headers on x86-64 Linux, which abi_layout_test.cpp holds the layout to; regenerate it
|
||||
* from the test's printout only together with a version bump. */
|
||||
{ "RadArchProbe", "", 0, 48 },
|
||||
{ "RadArchProbe", "draft_depth", 0, 4 },
|
||||
{ "RadArchProbe", "draft_depth_fixed", 4, 4 },
|
||||
{ "RadArchProbe", "shape_probe_ok", 8, 4 },
|
||||
{ "RadArchProbe", "enc_merge", 16, 8 },
|
||||
{ "RadArchProbe", "audio_frames", 24, 8 },
|
||||
{ "RadArchProbe", "gen_rows", 32, 8 },
|
||||
{ "RadArchProbe", "gen_patches", 40, 8 },
|
||||
{ "RadArgs", "", 0, 64 },
|
||||
{ "RadArgs", "t", 0, 8 },
|
||||
{ "RadArgs", "n_t", 8, 4 },
|
||||
{ "RadArgs", "p", 16, 8 },
|
||||
{ "RadArgs", "n_p", 24, 4 },
|
||||
{ "RadArgs", "scratch", 32, 8 },
|
||||
{ "RadArgs", "scratch_bytes", 40, 8 },
|
||||
{ "RadArgs", "instance", 48, 8 },
|
||||
{ "RadArgs", "rank", 56, 4 },
|
||||
{ "RadArgs", "world_size", 60, 4 },
|
||||
{ "RadBatch", "", 0, 312 },
|
||||
{ "RadBatch", "phase", 0, 4 },
|
||||
{ "RadBatch", "step", 4, 4 },
|
||||
{ "RadBatch", "n_tok", 8, 8 },
|
||||
{ "RadBatch", "n_seq", 16, 8 },
|
||||
{ "RadBatch", "token_ids", 24, 8 },
|
||||
{ "RadBatch", "positions", 32, 8 },
|
||||
{ "RadBatch", "cu_seqlens", 40, 8 },
|
||||
{ "RadBatch", "seq_ids", 48, 8 },
|
||||
{ "RadBatch", "n_out", 56, 8 },
|
||||
{ "RadBatch", "out_ids", 64, 8 },
|
||||
{ "RadBatch", "q_lens", 72, 8 },
|
||||
{ "RadBatch", "ctx_lens", 80, 8 },
|
||||
{ "RadBatch", "max_q_len", 88, 4 },
|
||||
{ "RadBatch", "max_ctx_len", 92, 4 },
|
||||
{ "RadBatch", "n_kv_groups", 96, 4 },
|
||||
{ "RadBatch", "kv", 104, 8 },
|
||||
{ "RadBatch", "n_spec", 112, 4 },
|
||||
{ "RadBatch", "num_accepted", 120, 8 },
|
||||
{ "RadBatch", "spec_parent", 128, 8 },
|
||||
{ "RadBatch", "draft_pass", 136, 4 },
|
||||
{ "RadBatch", "n_checkpoints", 140, 4 },
|
||||
{ "RadBatch", "checkpoint_tok", 144, 8 },
|
||||
{ "RadBatch", "checkpoint_slot", 152, 8 },
|
||||
{ "RadBatch", "n_seq_decode", 160, 8 },
|
||||
{ "RadBatch", "n_tok_decode", 168, 8 },
|
||||
{ "RadBatch", "max_q_len_decode", 176, 4 },
|
||||
{ "RadBatch", "max_q_len_prefill", 180, 4 },
|
||||
{ "RadBatch", "n_draft_out", 184, 8 },
|
||||
{ "RadBatch", "draft_out_ids", 192, 8 },
|
||||
{ "RadBatch", "n_ahead", 200, 8 },
|
||||
{ "RadBatch", "rope_pos", 208, 8 },
|
||||
{ "RadBatch", "rope_mixed", 216, 4 },
|
||||
{ "RadBatch", "n_mm_rows", 224, 8 },
|
||||
{ "RadBatch", "mm_rows", 232, 8 },
|
||||
{ "RadBatch", "mm_embd", 240, 8 },
|
||||
{ "RadBatch", "enc", 248, 4 },
|
||||
{ "RadBatch", "enc_n_patch", 256, 8 },
|
||||
{ "RadBatch", "enc_pixels", 264, 8 },
|
||||
{ "RadBatch", "enc_coord", 272, 8 },
|
||||
{ "RadBatch", "enc_n_seg", 280, 8 },
|
||||
{ "RadBatch", "enc_cu", 288, 8 },
|
||||
{ "RadBatch", "enc_max_seg", 296, 4 },
|
||||
{ "RadBatch", "gen", 300, 4 },
|
||||
{ "RadBatch", "gen_b", 304, 8 },
|
||||
{ "RadBufDecl", "", 0, 80 },
|
||||
{ "RadBufDecl", "dtype", 0, 4 },
|
||||
{ "RadBufDecl", "rank", 4, 4 },
|
||||
{ "RadBufDecl", "shape", 8, 48 },
|
||||
{ "RadBufDecl", "kind", 56, 4 },
|
||||
{ "RadBufDecl", "domain", 60, 4 },
|
||||
{ "RadBufDecl", "derive", 64, 8 },
|
||||
{ "RadBufDecl", "kv", 72, 4 },
|
||||
{ "RadBuildCtx", "", 0, 104 },
|
||||
{ "RadBuildCtx", "rank", 0, 4 },
|
||||
{ "RadBuildCtx", "world_size", 4, 4 },
|
||||
{ "RadBuildCtx", "max_tok", 8, 8 },
|
||||
{ "RadBuildCtx", "max_seqs", 16, 8 },
|
||||
{ "RadBuildCtx", "max_ctx", 24, 8 },
|
||||
{ "RadBuildCtx", "max_spec", 32, 4 },
|
||||
{ "RadBuildCtx", "tp_wire_lossy", 36, 4 },
|
||||
{ "RadBuildCtx", "tp_wire_min_bytes", 40, 8 },
|
||||
{ "RadBuildCtx", "kv_dtype", 48, 4 },
|
||||
{ "RadBuildCtx", "is_draft", 52, 4 },
|
||||
{ "RadBuildCtx", "scope", 56, 8 },
|
||||
{ "RadBuildCtx", "shape_probe", 64, 4 },
|
||||
{ "RadBuildCtx", "max_enc_patches", 72, 8 },
|
||||
{ "RadBuildCtx", "max_out_rows", 80, 8 },
|
||||
{ "RadBuildCtx", "max_audio_frames", 88, 8 },
|
||||
{ "RadBuildCtx", "max_mixed_tok", 96, 8 },
|
||||
{ "RadAudioFormat", "", 0, 72 },
|
||||
{ "RadAudioFormat", "struct_size", 0, 4 },
|
||||
{ "RadAudioFormat", "audio_open", 8, 8 },
|
||||
{ "RadAudioFormat", "audio_close", 16, 8 },
|
||||
{ "RadAudioFormat", "transcribe_prompt", 24, 8 },
|
||||
{ "RadAudioFormat", "language_prompt", 32, 8 },
|
||||
{ "RadAudioFormat", "transcript_open", 40, 8 },
|
||||
{ "RadAudioFormat", "language_lead", 48, 8 },
|
||||
{ "RadAudioFormat", "languages", 56, 8 },
|
||||
{ "RadAudioFormat", "n_languages", 64, 4 },
|
||||
{ "RadChatFormat", "", 0, 200 },
|
||||
{ "RadChatFormat", "struct_size", 0, 4 },
|
||||
{ "RadChatFormat", "name", 8, 8 },
|
||||
{ "RadChatFormat", "reasoning_open", 16, 8 },
|
||||
{ "RadChatFormat", "reasoning_close", 24, 8 },
|
||||
{ "RadChatFormat", "reasoning_breaks", 32, 8 },
|
||||
{ "RadChatFormat", "n_reasoning_breaks", 40, 4 },
|
||||
{ "RadChatFormat", "reasoning_in_prompt", 44, 4 },
|
||||
{ "RadChatFormat", "section_open", 48, 8 },
|
||||
{ "RadChatFormat", "section_close", 56, 8 },
|
||||
{ "RadChatFormat", "call_separator", 64, 8 },
|
||||
{ "RadChatFormat", "call_open", 72, 8 },
|
||||
{ "RadChatFormat", "call_close", 80, 8 },
|
||||
{ "RadChatFormat", "name_prefix", 88, 8 },
|
||||
{ "RadChatFormat", "name_suffix", 96, 8 },
|
||||
{ "RadChatFormat", "call_end", 104, 8 },
|
||||
{ "RadChatFormat", "arg_prefix", 112, 8 },
|
||||
{ "RadChatFormat", "arg_name_suffix", 120, 8 },
|
||||
{ "RadChatFormat", "arg_value_prefix", 128, 8 },
|
||||
{ "RadChatFormat", "arg_value_suffix", 136, 8 },
|
||||
{ "RadChatFormat", "string_value", 144, 4 },
|
||||
{ "RadChatFormat", "other_value", 148, 4 },
|
||||
{ "RadChatFormat", "value_newlines", 152, 4 },
|
||||
{ "RadChatFormat", "triggers", 160, 8 },
|
||||
{ "RadChatFormat", "n_triggers", 168, 4 },
|
||||
{ "RadChatFormat", "args_form", 172, 4 },
|
||||
{ "RadChatFormat", "object_string_open", 176, 8 },
|
||||
{ "RadChatFormat", "object_string_close", 184, 8 },
|
||||
{ "RadChatFormat", "object_bare_keys", 192, 4 },
|
||||
{ "RadChatFormat", "reasoning_anywhere", 196, 4 },
|
||||
{ "RadConstraint", "", 0, 32 },
|
||||
{ "RadConstraint", "key", 0, 8 },
|
||||
{ "RadConstraint", "op", 8, 4 },
|
||||
{ "RadConstraint", "ival", 16, 8 },
|
||||
{ "RadConstraint", "sval", 24, 8 },
|
||||
{ "RadDeviceProps", "", 0, 208 },
|
||||
{ "RadDeviceProps", "name", 0, 128 },
|
||||
{ "RadDeviceProps", "arch", 128, 32 },
|
||||
{ "RadDeviceProps", "device_id", 160, 4 },
|
||||
{ "RadDeviceProps", "n_cu", 164, 4 },
|
||||
{ "RadDeviceProps", "warp_size", 168, 4 },
|
||||
{ "RadDeviceProps", "vram_bytes", 176, 8 },
|
||||
{ "RadDeviceProps", "vram_free", 184, 8 },
|
||||
{ "RadDeviceProps", "lds_bytes", 192, 8 },
|
||||
{ "RadDeviceProps", "supports_p2p", 200, 4 },
|
||||
{ "RadDeviceProps", "is_host_backend", 204, 4 },
|
||||
{ "RadDrafterDecl", "", 0, 56 },
|
||||
{ "RadDrafterDecl", "name", 0, 8 },
|
||||
{ "RadDrafterDecl", "kind", 8, 4 },
|
||||
{ "RadDrafterDecl", "depth", 12, 4 },
|
||||
{ "RadDrafterDecl", "proposal", 16, 4 },
|
||||
{ "RadDrafterDecl", "proposal_pitch", 24, 8 },
|
||||
{ "RadDrafterDecl", "mask_token", 32, 4 },
|
||||
{ "RadDrafterDecl", "window", 40, 8 },
|
||||
{ "RadDrafterDecl", "block", 48, 8 },
|
||||
{ "RadDtRow", "", 0, 24 },
|
||||
{ "RadDtRow", "dt", 0, 4 },
|
||||
{ "RadDtRow", "name", 8, 8 },
|
||||
{ "RadDtRow", "bits", 16, 4 },
|
||||
{ "RadEncPlane", "", 0, 64 },
|
||||
{ "RadEncPlane", "role", 0, 24 },
|
||||
{ "RadEncPlane", "dtype", 24, 4 },
|
||||
{ "RadEncPlane", "kind", 28, 4 },
|
||||
{ "RadEncPlane", "block", 32, 16 },
|
||||
{ "RadEncPlane", "extent", 48, 16 },
|
||||
{ "RadEncoderDecl", "", 0, 56 },
|
||||
{ "RadEncoderDecl", "name", 0, 8 },
|
||||
{ "RadEncoderDecl", "modalities", 8, 4 },
|
||||
{ "RadEncoderDecl", "patch_dim", 16, 8 },
|
||||
{ "RadEncoderDecl", "merge", 24, 8 },
|
||||
{ "RadEncoderDecl", "max_patches", 32, 8 },
|
||||
{ "RadEncoderDecl", "n_embd", 40, 8 },
|
||||
{ "RadEncoderDecl", "out", 48, 4 },
|
||||
{ "RadEncoding", "", 0, 568 },
|
||||
{ "RadEncoding", "scheme", 0, 24 },
|
||||
{ "RadEncoding", "transform", 24, 24 },
|
||||
{ "RadEncoding", "n_planes", 48, 4 },
|
||||
{ "RadEncoding", "reserved", 52, 4 },
|
||||
{ "RadEncoding", "plane", 56, 512 },
|
||||
{ "RadFileEntry", "", 0, 136 },
|
||||
{ "RadFileEntry", "name", 0, 8 },
|
||||
{ "RadFileEntry", "quantizer", 8, 8 },
|
||||
{ "RadFileEntry", "options", 16, 8 },
|
||||
{ "RadFileEntry", "enc", 24, 4 },
|
||||
{ "RadFileEntry", "rank", 28, 4 },
|
||||
{ "RadFileEntry", "shape", 32, 48 },
|
||||
{ "RadFileEntry", "layer", 80, 4 },
|
||||
{ "RadFileEntry", "expert", 84, 4 },
|
||||
{ "RadFileEntry", "slot", 88, 4 },
|
||||
{ "RadFileEntry", "n_planes", 92, 4 },
|
||||
{ "RadFileEntry", "plane_first", 96, 8 },
|
||||
{ "RadFileEntry", "offset", 104, 8 },
|
||||
{ "RadFileEntry", "bytes", 112, 8 },
|
||||
{ "RadFileEntry", "reserved", 120, 16 },
|
||||
{ "RadFileHeader", "", 0, 248 },
|
||||
{ "RadFileHeader", "magic", 0, 4 },
|
||||
{ "RadFileHeader", "version", 4, 4 },
|
||||
{ "RadFileHeader", "file_bytes", 8, 8 },
|
||||
{ "RadFileHeader", "arch_id", 16, 8 },
|
||||
{ "RadFileHeader", "model_name", 24, 8 },
|
||||
{ "RadFileHeader", "quant", 32, 8 },
|
||||
{ "RadFileHeader", "recipe", 40, 8 },
|
||||
{ "RadFileHeader", "created_by", 48, 8 },
|
||||
{ "RadFileHeader", "str_off", 56, 8 },
|
||||
{ "RadFileHeader", "str_bytes", 64, 8 },
|
||||
{ "RadFileHeader", "meta_off", 72, 8 },
|
||||
{ "RadFileHeader", "meta_count", 80, 8 },
|
||||
{ "RadFileHeader", "dir_off", 88, 8 },
|
||||
{ "RadFileHeader", "dir_count", 96, 8 },
|
||||
{ "RadFileHeader", "plane_off", 104, 8 },
|
||||
{ "RadFileHeader", "plane_count", 112, 8 },
|
||||
{ "RadFileHeader", "enc_off", 120, 8 },
|
||||
{ "RadFileHeader", "enc_count", 128, 8 },
|
||||
{ "RadFileHeader", "vocab_off", 136, 8 },
|
||||
{ "RadFileHeader", "vocab_bytes", 144, 8 },
|
||||
{ "RadFileHeader", "prof_off", 152, 8 },
|
||||
{ "RadFileHeader", "prof_count", 160, 8 },
|
||||
{ "RadFileHeader", "data_off", 168, 8 },
|
||||
{ "RadFileHeader", "data_bytes", 176, 8 },
|
||||
{ "RadFileHeader", "reserved", 184, 64 },
|
||||
{ "RadFileKV", "", 0, 24 },
|
||||
{ "RadFileKV", "key", 0, 8 },
|
||||
{ "RadFileKV", "type", 8, 4 },
|
||||
{ "RadFileKV", "pad", 12, 4 },
|
||||
{ "RadFileKV", "v", 16, 8 },
|
||||
{ "RadFilePlane", "", 0, 16 },
|
||||
{ "RadFilePlane", "offset", 0, 8 },
|
||||
{ "RadFilePlane", "bytes", 8, 8 },
|
||||
{ "RadFileProfile", "", 0, 16 },
|
||||
{ "RadFileProfile", "layer", 0, 4 },
|
||||
{ "RadFileProfile", "expert", 4, 4 },
|
||||
{ "RadFileProfile", "share", 8, 4 },
|
||||
{ "RadFileProfile", "reserved", 12, 4 },
|
||||
{ "RadFuseStep", "", 0, 624 },
|
||||
{ "RadFuseStep", "op", 0, 8 },
|
||||
{ "RadFuseStep", "p", 8, 576 },
|
||||
{ "RadFuseStep", "n_p", 584, 4 },
|
||||
{ "RadFuseStep", "from", 588, 32 },
|
||||
{ "RadFuseStep", "n_from", 620, 4 },
|
||||
{ "RadGenBatch", "", 0, 224 },
|
||||
{ "RadGenBatch", "rows", 0, 8 },
|
||||
{ "RadGenBatch", "src", 8, 8 },
|
||||
{ "RadGenBatch", "rope", 16, 8 },
|
||||
{ "RadGenBatch", "n_seg", 24, 8 },
|
||||
{ "RadGenBatch", "seg", 32, 8 },
|
||||
{ "RadGenBatch", "seg_h", 40, 8 },
|
||||
{ "RadGenBatch", "seg_bidi_h", 48, 8 },
|
||||
{ "RadGenBatch", "seg_cu", 56, 8 },
|
||||
{ "RadGenBatch", "seg_start", 64, 8 },
|
||||
{ "RadGenBatch", "slot_mapping", 72, 8 },
|
||||
{ "RadGenBatch", "n_px", 80, 8 },
|
||||
{ "RadGenBatch", "px", 88, 8 },
|
||||
{ "RadGenBatch", "px_h", 96, 8 },
|
||||
{ "RadGenBatch", "px_cu", 104, 8 },
|
||||
{ "RadGenBatch", "inpaint", 112, 4 },
|
||||
{ "RadGenBatch", "inp_mask", 120, 8 },
|
||||
{ "RadGenBatch", "n_lane", 128, 8 },
|
||||
{ "RadGenBatch", "lane_h", 136, 8 },
|
||||
{ "RadGenBatch", "sigma", 144, 8 },
|
||||
{ "RadGenBatch", "sigma_next", 152, 8 },
|
||||
{ "RadGenBatch", "cfg", 160, 8 },
|
||||
{ "RadGenBatch", "pair", 168, 8 },
|
||||
{ "RadGenBatch", "lane", 176, 8 },
|
||||
{ "RadGenBatch", "lane_dh", 184, 8 },
|
||||
{ "RadGenBatch", "flags", 192, 8 },
|
||||
{ "RadGenBatch", "seed", 200, 8 },
|
||||
{ "RadGenBatch", "dec_lane", 208, 4 },
|
||||
{ "RadGenBatch", "dec_height", 212, 4 },
|
||||
{ "RadGenBatch", "dec_width", 216, 4 },
|
||||
{ "RadGenBatch", "dec_preview", 220, 4 },
|
||||
{ "RadGeneratorDecl", "", 0, 248 },
|
||||
{ "RadGeneratorDecl", "name", 0, 8 },
|
||||
{ "RadGeneratorDecl", "layout", 8, 4 },
|
||||
{ "RadGeneratorDecl", "tmpl_text", 16, 8 },
|
||||
{ "RadGeneratorDecl", "tmpl_edit", 24, 8 },
|
||||
{ "RadGeneratorDecl", "tmpl_image", 32, 8 },
|
||||
{ "RadGeneratorDecl", "tmpl_image_sep", 40, 8 },
|
||||
{ "RadGeneratorDecl", "drop_prefix", 48, 8 },
|
||||
{ "RadGeneratorDecl", "tmpl_transparent", 56, 8 },
|
||||
{ "RadGeneratorDecl", "latent_channels", 64, 8 },
|
||||
{ "RadGeneratorDecl", "latent_scale", 72, 8 },
|
||||
{ "RadGeneratorDecl", "size_multiple", 80, 8 },
|
||||
{ "RadGeneratorDecl", "pixel_channels", 88, 8 },
|
||||
{ "RadGeneratorDecl", "slot_rows", 96, 8 },
|
||||
{ "RadGeneratorDecl", "max_tokens", 104, 8 },
|
||||
{ "RadGeneratorDecl", "max_refs", 112, 8 },
|
||||
{ "RadGeneratorDecl", "ref_area", 120, 8 },
|
||||
{ "RadGeneratorDecl", "default_width", 128, 8 },
|
||||
{ "RadGeneratorDecl", "default_height", 136, 8 },
|
||||
{ "RadGeneratorDecl", "default_steps", 144, 8 },
|
||||
{ "RadGeneratorDecl", "n_sigmas", 152, 4 },
|
||||
{ "RadGeneratorDecl", "sigmas", 160, 8 },
|
||||
{ "RadGeneratorDecl", "shift", 168, 8 },
|
||||
{ "RadGeneratorDecl", "dyn_shift", 176, 4 },
|
||||
{ "RadGeneratorDecl", "shift_exp", 180, 4 },
|
||||
{ "RadGeneratorDecl", "base_shift", 184, 8 },
|
||||
{ "RadGeneratorDecl", "max_shift", 192, 8 },
|
||||
{ "RadGeneratorDecl", "base_seq", 200, 8 },
|
||||
{ "RadGeneratorDecl", "max_seq", 208, 8 },
|
||||
{ "RadGeneratorDecl", "shift_terminal", 216, 8 },
|
||||
{ "RadGeneratorDecl", "default_cfg", 224, 8 },
|
||||
{ "RadGeneratorDecl", "max_lanes", 232, 8 },
|
||||
{ "RadGeneratorDecl", "image_out", 240, 4 },
|
||||
{ "RadKVGroupBatch", "", 0, 72 },
|
||||
{ "RadKVGroupBatch", "group", 0, 4 },
|
||||
{ "RadKVGroupBatch", "slot_mapping", 8, 8 },
|
||||
{ "RadKVGroupBatch", "block_table", 16, 8 },
|
||||
{ "RadKVGroupBatch", "block_table_pitch", 24, 8 },
|
||||
{ "RadKVGroupBatch", "seqused", 32, 8 },
|
||||
{ "RadKVGroupBatch", "state_index", 40, 8 },
|
||||
{ "RadKVGroupBatch", "state_index_pitch", 48, 8 },
|
||||
{ "RadKVGroupBatch", "block_size", 56, 8 },
|
||||
{ "RadKVGroupBatch", "max_blocks", 64, 8 },
|
||||
{ "RadKVGroupDecl", "", 0, 56 },
|
||||
{ "RadKVGroupDecl", "kind", 0, 4 },
|
||||
{ "RadKVGroupDecl", "dtype", 4, 4 },
|
||||
{ "RadKVGroupDecl", "window", 8, 8 },
|
||||
{ "RadKVGroupDecl", "n_head_kv", 16, 8 },
|
||||
{ "RadKVGroupDecl", "head_dim", 24, 8 },
|
||||
{ "RadKVGroupDecl", "state_dim", 32, 16 },
|
||||
{ "RadKVGroupDecl", "conv_width", 48, 8 },
|
||||
{ "RadKernelInfo", "", 0, 168 },
|
||||
{ "RadKernelInfo", "name", 0, 8 },
|
||||
{ "RadKernelInfo", "op", 8, 8 },
|
||||
{ "RadKernelInfo", "family", 16, 8 },
|
||||
{ "RadKernelInfo", "computes", 24, 8 },
|
||||
{ "RadKernelInfo", "shape", 32, 8 },
|
||||
{ "RadKernelInfo", "dtypes", 40, 8 },
|
||||
{ "RadKernelInfo", "domain", 48, 4 },
|
||||
{ "RadKernelInfo", "priority", 52, 4 },
|
||||
{ "RadKernelInfo", "constraints", 56, 8 },
|
||||
{ "RadKernelInfo", "n_constraints", 64, 4 },
|
||||
{ "RadKernelInfo", "tunables", 72, 8 },
|
||||
{ "RadKernelInfo", "n_tunables", 80, 4 },
|
||||
{ "RadKernelInfo", "tune_valid", 88, 8 },
|
||||
{ "RadKernelInfo", "init", 96, 8 },
|
||||
{ "RadKernelInfo", "fini", 104, 8 },
|
||||
{ "RadKernelInfo", "launch", 112, 8 },
|
||||
{ "RadKernelInfo", "scratch", 120, 8 },
|
||||
{ "RadKernelInfo", "layout", 128, 8 },
|
||||
{ "RadKernelInfo", "relayout", 136, 8 },
|
||||
{ "RadKernelInfo", "opd_shape", 144, 8 },
|
||||
{ "RadKernelInfo", "unrelayout", 152, 8 },
|
||||
{ "RadKernelInfo", "replaces", 160, 8 },
|
||||
{ "RadLayout", "", 0, 80 },
|
||||
{ "RadLayout", "tag", 0, 8 },
|
||||
{ "RadLayout", "dtype", 8, 4 },
|
||||
{ "RadLayout", "rank", 12, 4 },
|
||||
{ "RadLayout", "shape", 16, 48 },
|
||||
{ "RadLayout", "align", 64, 8 },
|
||||
{ "RadLayout", "bytes", 72, 8 },
|
||||
{ "RadModelMeta", "", 0, 144 },
|
||||
{ "RadModelMeta", "arch_id", 0, 8 },
|
||||
{ "RadModelMeta", "name", 8, 8 },
|
||||
{ "RadModelMeta", "quant", 16, 8 },
|
||||
{ "RadModelMeta", "n_layers", 24, 8 },
|
||||
{ "RadModelMeta", "n_embd", 32, 8 },
|
||||
{ "RadModelMeta", "n_head", 40, 8 },
|
||||
{ "RadModelMeta", "n_head_kv", 48, 8 },
|
||||
{ "RadModelMeta", "head_dim", 56, 8 },
|
||||
{ "RadModelMeta", "n_ff", 64, 8 },
|
||||
{ "RadModelMeta", "n_vocab", 72, 8 },
|
||||
{ "RadModelMeta", "n_ctx_train", 80, 8 },
|
||||
{ "RadModelMeta", "n_expert", 88, 8 },
|
||||
{ "RadModelMeta", "n_expert_used", 96, 8 },
|
||||
{ "RadModelMeta", "n_expert_shared", 104, 8 },
|
||||
{ "RadModelMeta", "rms_eps", 112, 4 },
|
||||
{ "RadModelMeta", "rope_theta", 116, 4 },
|
||||
{ "RadModelMeta", "rope_scale", 120, 4 },
|
||||
{ "RadModelMeta", "n_kv", 124, 4 },
|
||||
{ "RadModelMeta", "kv_key", 128, 8 },
|
||||
{ "RadModelMeta", "kv_val", 136, 8 },
|
||||
{ "RadNameMap", "", 0, 120 },
|
||||
{ "RadNameMap", "declared", 0, 8 },
|
||||
{ "RadNameMap", "mode", 8, 4 },
|
||||
{ "RadNameMap", "n_src", 12, 4 },
|
||||
{ "RadNameMap", "src", 16, 64 },
|
||||
{ "RadNameMap", "concat_dim", 80, 4 },
|
||||
{ "RadNameMap", "src_index", 84, 32 },
|
||||
{ "RadOpSchema", "", 0, 48 },
|
||||
{ "RadOpSchema", "op", 0, 8 },
|
||||
{ "RadOpSchema", "params", 8, 8 },
|
||||
{ "RadOpSchema", "n_params", 16, 4 },
|
||||
{ "RadOpSchema", "operands", 24, 8 },
|
||||
{ "RadOpSchema", "n_operands", 32, 4 },
|
||||
{ "RadOpSchema", "doc", 40, 8 },
|
||||
{ "RadOpdDesc", "", 0, 96 },
|
||||
{ "RadOpdDesc", "dtype", 0, 4 },
|
||||
{ "RadOpdDesc", "rank", 4, 4 },
|
||||
{ "RadOpdDesc", "shape", 8, 48 },
|
||||
{ "RadOpdDesc", "fill", 56, 4 },
|
||||
{ "RadOpdDesc", "fill_chunk", 64, 8 },
|
||||
{ "RadOpdDesc", "idx_max", 72, 8 },
|
||||
{ "RadOpdDesc", "idx_const", 80, 8 },
|
||||
{ "RadOpdDesc", "flags", 88, 4 },
|
||||
{ "RadOperand", "", 0, 48 },
|
||||
{ "RadOperand", "kind", 0, 1 },
|
||||
{ "RadOperand", "dtype", 4, 4 },
|
||||
{ "RadOperand", "handle", 8, 4 },
|
||||
{ "RadOperand", "raw", 16, 8 },
|
||||
{ "RadOperand", "offset", 24, 8 },
|
||||
{ "RadOperand", "rows", 32, 8 },
|
||||
{ "RadOperand", "cols", 40, 8 },
|
||||
{ "RadOperandSpec", "", 0, 16 },
|
||||
{ "RadOperandSpec", "name", 0, 8 },
|
||||
{ "RadOperandSpec", "role", 8, 4 },
|
||||
{ "RadOperandSpec", "optional", 12, 4 },
|
||||
{ "RadParam", "", 0, 48 },
|
||||
{ "RadParam", "key", 0, 8 },
|
||||
{ "RadParam", "kind", 8, 4 },
|
||||
{ "RadParam", "ival", 16, 8 },
|
||||
{ "RadParam", "ihi", 24, 8 },
|
||||
{ "RadParam", "sval", 32, 8 },
|
||||
{ "RadParam", "dval", 40, 8 },
|
||||
{ "RadParamSpec", "", 0, 24 },
|
||||
{ "RadParamSpec", "key", 0, 8 },
|
||||
{ "RadParamSpec", "type", 8, 4 },
|
||||
{ "RadParamSpec", "required", 12, 4 },
|
||||
{ "RadParamSpec", "role", 16, 4 },
|
||||
{ "RadPlanesEntry", "", 0, 80 },
|
||||
{ "RadPlanesEntry", "role", 0, 24 },
|
||||
{ "RadPlanesEntry", "dtype", 24, 4 },
|
||||
{ "RadPlanesEntry", "kind", 28, 4 },
|
||||
{ "RadPlanesEntry", "block", 32, 16 },
|
||||
{ "RadPlanesEntry", "rows", 48, 8 },
|
||||
{ "RadPlanesEntry", "cols", 56, 8 },
|
||||
{ "RadPlanesEntry", "row_bytes", 64, 8 },
|
||||
{ "RadPlanesEntry", "offset", 72, 8 },
|
||||
{ "RadPlanesHeader", "", 0, 40 },
|
||||
{ "RadPlanesHeader", "magic", 0, 4 },
|
||||
{ "RadPlanesHeader", "n_planes", 4, 4 },
|
||||
{ "RadPlanesHeader", "transform", 8, 24 },
|
||||
{ "RadPlanesHeader", "bytes", 32, 8 },
|
||||
{ "RadPluginInfo", "", 0, 40 },
|
||||
{ "RadPluginInfo", "kind", 0, 4 },
|
||||
{ "RadPluginInfo", "name", 8, 8 },
|
||||
{ "RadPluginInfo", "version", 16, 8 },
|
||||
{ "RadPluginInfo", "description", 24, 8 },
|
||||
{ "RadPluginInfo", "build_target", 32, 8 },
|
||||
{ "RadPrefetchNext", "", 0, 48 },
|
||||
{ "RadPrefetchNext", "layer", 0, 4 },
|
||||
{ "RadPrefetchNext", "router", 4, 4 },
|
||||
{ "RadPrefetchNext", "n_expert", 8, 8 },
|
||||
{ "RadPrefetchNext", "top_k", 16, 8 },
|
||||
{ "RadPrefetchNext", "n_parts", 24, 8 },
|
||||
{ "RadPrefetchNext", "parts", 32, 8 },
|
||||
{ "RadPrefetchNext", "count_at", 40, 8 },
|
||||
{ "RadQuantOption", "", 0, 32 },
|
||||
{ "RadQuantOption", "key", 0, 8 },
|
||||
{ "RadQuantOption", "type", 8, 4 },
|
||||
{ "RadQuantOption", "deflt", 16, 8 },
|
||||
{ "RadQuantOption", "doc", 24, 8 },
|
||||
{ "RadQuantWeight", "", 0, 96 },
|
||||
{ "RadQuantWeight", "name", 0, 8 },
|
||||
{ "RadQuantWeight", "rank", 8, 4 },
|
||||
{ "RadQuantWeight", "shape", 16, 48 },
|
||||
{ "RadQuantWeight", "rows", 64, 8 },
|
||||
{ "RadQuantWeight", "cols", 72, 8 },
|
||||
{ "RadQuantWeight", "layer", 80, 4 },
|
||||
{ "RadQuantWeight", "expert", 84, 4 },
|
||||
{ "RadQuantWeight", "importance", 88, 8 },
|
||||
{ "RadQuantizerInfo", "", 0, 64 },
|
||||
{ "RadQuantizerInfo", "name", 0, 8 },
|
||||
{ "RadQuantizerInfo", "doc", 8, 8 },
|
||||
{ "RadQuantizerInfo", "options", 16, 8 },
|
||||
{ "RadQuantizerInfo", "n_options", 24, 4 },
|
||||
{ "RadQuantizerInfo", "encoding", 32, 8 },
|
||||
{ "RadQuantizerInfo", "row_block", 40, 8 },
|
||||
{ "RadQuantizerInfo", "quantize", 48, 8 },
|
||||
{ "RadQuantizerInfo", "decode", 56, 8 },
|
||||
{ "RadRouting", "", 0, 56 },
|
||||
{ "RadRouting", "expert_ids", 0, 8 },
|
||||
{ "RadRouting", "expert_w", 8, 8 },
|
||||
{ "RadRouting", "expert_count", 16, 8 },
|
||||
{ "RadRouting", "sorted_tok", 24, 8 },
|
||||
{ "RadRouting", "expert_offset", 32, 8 },
|
||||
{ "RadRouting", "top_k", 40, 8 },
|
||||
{ "RadRouting", "n_expert", 48, 8 },
|
||||
{ "RadSampleParams", "", 0, 96 },
|
||||
{ "RadSampleParams", "seed", 0, 8 },
|
||||
{ "RadSampleParams", "pos", 8, 8 },
|
||||
{ "RadSampleParams", "temp", 16, 4 },
|
||||
{ "RadSampleParams", "top_p", 20, 4 },
|
||||
{ "RadSampleParams", "min_p", 24, 4 },
|
||||
{ "RadSampleParams", "typical_p", 28, 4 },
|
||||
{ "RadSampleParams", "rep_penalty", 32, 4 },
|
||||
{ "RadSampleParams", "freq_penalty", 36, 4 },
|
||||
{ "RadSampleParams", "pres_penalty", 40, 4 },
|
||||
{ "RadSampleParams", "xtc_probability", 44, 4 },
|
||||
{ "RadSampleParams", "xtc_threshold", 48, 4 },
|
||||
{ "RadSampleParams", "dry_multiplier", 52, 4 },
|
||||
{ "RadSampleParams", "dry_base", 56, 4 },
|
||||
{ "RadSampleParams", "top_k", 60, 4 },
|
||||
{ "RadSampleParams", "penalty_last_n", 64, 4 },
|
||||
{ "RadSampleParams", "dry_allowed_length", 68, 4 },
|
||||
{ "RadSampleParams", "dry_penalty_last_n", 72, 4 },
|
||||
{ "RadSampleParams", "hist_off", 76, 4 },
|
||||
{ "RadSampleParams", "hist_len", 80, 4 },
|
||||
{ "RadSampleParams", "mask_row", 84, 4 },
|
||||
{ "RadSampleParams", "flags", 88, 4 },
|
||||
{ "RadSampleParams", "dry_rep_limit", 92, 4 },
|
||||
{ "RadTensor", "", 0, 112 },
|
||||
{ "RadTensor", "data", 0, 8 },
|
||||
{ "RadTensor", "dtype", 8, 4 },
|
||||
{ "RadTensor", "rank", 12, 4 },
|
||||
{ "RadTensor", "shape", 16, 48 },
|
||||
{ "RadTensor", "stride", 64, 48 },
|
||||
{ "RadTunable", "", 0, 40 },
|
||||
{ "RadTunable", "key", 0, 8 },
|
||||
{ "RadTunable", "values", 8, 8 },
|
||||
{ "RadTunable", "n_values", 16, 4 },
|
||||
{ "RadTunable", "deflt", 24, 8 },
|
||||
{ "RadTunable", "doc", 32, 8 },
|
||||
{ "RadVocabHeader", "", 0, 128 },
|
||||
{ "RadVocabHeader", "kind", 0, 4 },
|
||||
{ "RadVocabHeader", "n_tokens", 4, 4 },
|
||||
{ "RadVocabHeader", "n_merges", 8, 4 },
|
||||
{ "RadVocabHeader", "n_steps", 12, 4 },
|
||||
{ "RadVocabHeader", "tok_text_off", 16, 8 },
|
||||
{ "RadVocabHeader", "tok_score_off", 24, 8 },
|
||||
{ "RadVocabHeader", "tok_type_off", 32, 8 },
|
||||
{ "RadVocabHeader", "merge_off", 40, 8 },
|
||||
{ "RadVocabHeader", "step_off", 48, 8 },
|
||||
{ "RadVocabHeader", "bos", 56, 4 },
|
||||
{ "RadVocabHeader", "eos", 60, 4 },
|
||||
{ "RadVocabHeader", "eot", 64, 4 },
|
||||
{ "RadVocabHeader", "pad_id", 68, 4 },
|
||||
{ "RadVocabHeader", "unk", 72, 4 },
|
||||
{ "RadVocabHeader", "sep", 76, 4 },
|
||||
{ "RadVocabHeader", "add_bos", 80, 4 },
|
||||
{ "RadVocabHeader", "add_eos", 84, 4 },
|
||||
{ "RadVocabHeader", "chat_template", 88, 8 },
|
||||
{ "RadVocabHeader", "flags", 96, 8 },
|
||||
{ "RadVocabHeader", "reserved", 104, 24 },
|
||||
{ "RadVocabStep", "", 0, 32 },
|
||||
{ "RadVocabStep", "kind", 0, 4 },
|
||||
{ "RadVocabStep", "flags", 4, 4 },
|
||||
{ "RadVocabStep", "arg0", 8, 8 },
|
||||
{ "RadVocabStep", "arg1", 16, 8 },
|
||||
{ "RadVocabStep", "iarg", 24, 8 },
|
||||
{ "RadWeightDecl", "", 0, 168 },
|
||||
{ "RadWeightDecl", "dtype", 0, 4 },
|
||||
{ "RadWeightDecl", "rank", 4, 4 },
|
||||
{ "RadWeightDecl", "shape", 8, 48 },
|
||||
{ "RadWeightDecl", "access", 56, 4 },
|
||||
{ "RadWeightDecl", "shard", 60, 4 },
|
||||
{ "RadWeightDecl", "group", 64, 12 },
|
||||
{ "RadWeightDecl", "optional", 76, 4 },
|
||||
{ "RadWeightDecl", "n_row_parts", 80, 4 },
|
||||
{ "RadWeightDecl", "row_parts", 88, 64 },
|
||||
{ "RadWeightDecl", "source", 152, 8 },
|
||||
{ "RadWeightDecl", "planes", 160, 8 },
|
||||
{ "RadWeightGroup", "", 0, 12 },
|
||||
{ "RadWeightGroup", "layer", 0, 4 },
|
||||
{ "RadWeightGroup", "expert", 4, 4 },
|
||||
{ "RadWeightGroup", "slot", 8, 4 },
|
||||
{ "RadYarn", "", 0, 16 },
|
||||
{ "RadYarn", "factor", 0, 4 },
|
||||
{ "RadYarn", "low", 4, 4 },
|
||||
{ "RadYarn", "high", 8, 4 },
|
||||
{ "RadYarn", "magnitude", 12, 4 },
|
||||
@@ -0,0 +1,220 @@
|
||||
/* abi_layout_test.cpp -- the ABI's struct layouts, pinned.
|
||||
*
|
||||
* Plugins are built apart from the engine, so a struct's layout is the contract: a field that moves
|
||||
* or changes size under one RAD_ABI_VERSION is read at the wrong offset by every plugin built
|
||||
* before it, and fields are appended without a version bump only because they are trailing and
|
||||
* zero-defaulted. The on-disk structs of rad_format.h (and the encoding records serialised into a
|
||||
* container) are the .rad format itself.
|
||||
*
|
||||
* Checked: a C translation unit (abi_c_test.c, strict C11) lays every struct out as C++ does; every
|
||||
* struct's listed fields account for its size, so the list in abi_layout_rows.h is complete; and
|
||||
* the layout agrees with the table below, taken at RAD_ABI_VERSION 17 and RAD_FORMAT_VER 2. Under
|
||||
* those versions a listed field may not move or change size, an ABI struct may only grow by fields
|
||||
* past its old end, and an on-disk struct may not change at all. The table is a snapshot of the
|
||||
* headers: nothing else states the layout. When it disagrees the test prints the live table.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
|
||||
#include "rad_abi.h"
|
||||
#include "rad_builder.h"
|
||||
#include "rad_device.h"
|
||||
#include "rad_encoding.h"
|
||||
#include "rad_format.h"
|
||||
#include "rad_philox.h"
|
||||
#include "rad_planes.h"
|
||||
#include "rad_plugin.h"
|
||||
#include "rad_quant.h"
|
||||
#include "rad_runtime.h"
|
||||
#include "rad_sample.h"
|
||||
#include "rad_types.h"
|
||||
#include "rad_yarn.h"
|
||||
|
||||
#include "abi_layout.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
struct Row {
|
||||
std::string type, field;
|
||||
size_t offset = 0, size = 0, align = 1;
|
||||
};
|
||||
|
||||
/* The C++ view, from the same row list as abi_c_test.c. */
|
||||
std::vector<Row> cpp_rows() {
|
||||
return {
|
||||
#define ABI_STRUCT(T) Row{ #T, "", 0, sizeof(T), alignof(T) },
|
||||
#define ABI_FIELD(T, f) Row{ #T, #f, offsetof(T, f), sizeof(((T*)0)->f), \
|
||||
alignof(decltype(((T*)0)->f)) },
|
||||
#include "abi_layout_rows.h"
|
||||
#undef ABI_STRUCT
|
||||
#undef ABI_FIELD
|
||||
};
|
||||
}
|
||||
|
||||
/* The layout at RAD_ABI_VERSION 17 / RAD_FORMAT_VER 2 (see the file header). */
|
||||
constexpr uint32_t kTableAbi = 17, kTableFormat = 2;
|
||||
const AbiRow kTable[] = {
|
||||
#include "abi_layout_table.h"
|
||||
};
|
||||
|
||||
/* The .rad container's records: they may not change at all under one RAD_FORMAT_VER. */
|
||||
const std::set<std::string> kOnDisk = { "RadEncPlane", "RadEncoding", "RadFileEntry",
|
||||
"RadFileHeader", "RadFileKV", "RadFilePlane",
|
||||
"RadFileProfile", "RadVocabHeader", "RadVocabStep" };
|
||||
|
||||
void print_table(const std::vector<Row>& rows) {
|
||||
fprintf(stderr, " the live table (abi_layout_table.h):\n");
|
||||
for (const Row& r : rows)
|
||||
fprintf(stderr, "{ \"%s\", \"%s\", %zu, %zu },\n", r.type.c_str(), r.field.c_str(),
|
||||
r.offset, r.size);
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* C and C++ lay every struct out alike: the ABI promises plain C, and a plugin written in C reads
|
||||
* the same bytes the engine writes. */
|
||||
TEST(c_and_cpp_lay_out_every_abi_struct_alike) {
|
||||
const std::vector<Row> cpp = cpp_rows();
|
||||
REQUIRE_EQ(cpp.size(), (size_t)abi_c_n_rows);
|
||||
int bad = 0;
|
||||
for (size_t i = 0; i < cpp.size(); ++i) {
|
||||
const AbiRow& c = abi_c_rows[i];
|
||||
if (cpp[i].type != c.type || cpp[i].field != c.field || cpp[i].offset != c.offset ||
|
||||
cpp[i].size != c.size) {
|
||||
fprintf(stderr, " %s.%s: C++ %zu+%zu, C %zu+%zu\n", cpp[i].type.c_str(),
|
||||
cpp[i].field.c_str(), cpp[i].offset, cpp[i].size, c.offset, c.size);
|
||||
++bad;
|
||||
}
|
||||
}
|
||||
CHECK_EQ(bad, 0);
|
||||
CHECK(cpp.size() > 400);
|
||||
}
|
||||
|
||||
/* Each struct's listed fields tile it: every field starts at the end of the one before, rounded up
|
||||
* to its own alignment, and the struct ends at the last field's end rounded up to the struct's. A
|
||||
* field missing from abi_layout_rows.h leaves a hole and fails here. */
|
||||
TEST(the_row_list_accounts_for_every_byte_of_every_struct) {
|
||||
std::map<std::string, std::vector<Row>> fields;
|
||||
std::map<std::string, Row> whole;
|
||||
for (const Row& r : cpp_rows()) {
|
||||
if (r.field.empty()) whole[r.type] = r;
|
||||
else fields[r.type].push_back(r);
|
||||
}
|
||||
int bad = 0;
|
||||
for (const auto& [type, w] : whole) {
|
||||
std::vector<Row> f = fields[type];
|
||||
std::sort(f.begin(), f.end(),
|
||||
[](const Row& a, const Row& b) { return a.offset < b.offset; });
|
||||
size_t end = 0;
|
||||
for (const Row& r : f) {
|
||||
const size_t want = (end + r.align - 1) / r.align * r.align;
|
||||
if (r.offset != want) {
|
||||
fprintf(stderr, " %s.%s at %zu; the fields before it end at %zu\n", type.c_str(),
|
||||
r.field.c_str(), r.offset, end);
|
||||
++bad;
|
||||
}
|
||||
end = r.offset + r.size;
|
||||
}
|
||||
if ((end + w.align - 1) / w.align * w.align != w.size) {
|
||||
fprintf(stderr, " %s is %zu bytes; its listed fields end at %zu\n", type.c_str(),
|
||||
w.size, end);
|
||||
++bad;
|
||||
}
|
||||
}
|
||||
CHECK_EQ(bad, 0);
|
||||
CHECK(whole.size() >= 45);
|
||||
}
|
||||
|
||||
/* The layout agrees with the table: under the table's versions no listed field moves or changes
|
||||
* size, an ABI struct grows only by fields past its old end, and an on-disk struct is unchanged. */
|
||||
TEST(the_abi_layout_matches_the_table_for_its_version) {
|
||||
const std::vector<Row> live = cpp_rows();
|
||||
if (RAD_ABI_VERSION != kTableAbi || RAD_FORMAT_VER != kTableFormat) {
|
||||
fprintf(stderr, " the table is for ABI %u / format %u and the headers are ABI %u / "
|
||||
"format %u: regenerate abi_layout_table.h from the printout and update "
|
||||
"kTableAbi / kTableFormat\n", kTableAbi, kTableFormat,
|
||||
(unsigned)RAD_ABI_VERSION, (unsigned)RAD_FORMAT_VER);
|
||||
print_table(live);
|
||||
CHECK(false);
|
||||
return;
|
||||
}
|
||||
std::map<std::pair<std::string, std::string>, const Row*> by;
|
||||
for (const Row& r : live) by[{ r.type, r.field }] = &r;
|
||||
std::map<std::string, size_t> old_size;
|
||||
std::set<std::pair<std::string, std::string>> listed;
|
||||
int bad = 0;
|
||||
for (const AbiRow& t : kTable) {
|
||||
listed.insert({ t.type, t.field });
|
||||
if (!*t.field) old_size[t.type] = t.size;
|
||||
const auto it = by.find({ t.type, t.field });
|
||||
if (it == by.end()) {
|
||||
fprintf(stderr, " %s.%s is gone\n", t.type, t.field);
|
||||
++bad;
|
||||
continue;
|
||||
}
|
||||
const Row& r = *it->second;
|
||||
const bool disk = kOnDisk.count(t.type) != 0;
|
||||
const bool ok = !*t.field ? (disk ? r.size == t.size : r.size >= t.size)
|
||||
: r.offset == t.offset && r.size == t.size;
|
||||
if (!ok) {
|
||||
fprintf(stderr, " %s%s%s: %zu+%zu, the table has %zu+%zu\n", t.type,
|
||||
*t.field ? "." : "", t.field, r.offset, r.size, t.offset, t.size);
|
||||
++bad;
|
||||
}
|
||||
}
|
||||
/* A field the table does not list is an addition: allowed past the struct's old end, on a
|
||||
* struct that is not on disk. */
|
||||
for (const Row& r : live) {
|
||||
if (r.field.empty() || listed.count({ r.type, r.field })) continue;
|
||||
const auto os = old_size.find(r.type);
|
||||
if (os == old_size.end()) continue; /* a struct the table predates */
|
||||
if (kOnDisk.count(r.type) || r.offset < os->second) {
|
||||
fprintf(stderr, " %s.%s is new at %zu, inside the struct's old %zu bytes\n",
|
||||
r.type.c_str(), r.field.c_str(), r.offset, os->second);
|
||||
++bad;
|
||||
}
|
||||
}
|
||||
if (bad) print_table(live);
|
||||
CHECK_EQ(bad, 0);
|
||||
}
|
||||
|
||||
/* rad_yarn.h's C form computes what its C++ form does, bit for bit, over a sweep of coefficients
|
||||
* and rotary indices, and both validate alike: one is what a C plugin's kernel runs, the other
|
||||
* what libref, libavx and libr4d run. */
|
||||
TEST(rad_yarn_is_the_same_function_in_c_and_cpp) {
|
||||
int bad = 0, n = 0;
|
||||
for (float factor : { 0.0f, 1.0f, 2.0f, 4.0f, 40.0f })
|
||||
for (float low : { 0.0f, 3.25f, 10.0f })
|
||||
for (float high : { 0.0f, 3.25f, 17.5f, 32.0f }) {
|
||||
RadYarn y{};
|
||||
y.factor = factor;
|
||||
y.low = low;
|
||||
y.high = high;
|
||||
y.magnitude = 1.07f;
|
||||
for (int i = 0; i < 64; ++i)
|
||||
for (float inv : { 1.0f, 0.37f, 1e-4f }) {
|
||||
++n;
|
||||
const float a = y.frequency(inv, i);
|
||||
const float b = abi_c_yarn_frequency(factor, low, high, 1.07f, inv, i);
|
||||
bad += std::memcmp(&a, &b, sizeof a) != 0;
|
||||
}
|
||||
}
|
||||
CHECK(n > 10000);
|
||||
CHECK_EQ(bad, 0);
|
||||
const float cases[][4] = { { 0, 0, 0, 1 }, { 2, 1, 5, 1.1f }, { 0.5f, 1, 5, 1 },
|
||||
{ 2, 5, 1, 1 }, { 2, 1, 5, 0 }, { NAN, 1, 5, 1 },
|
||||
{ 2, NAN, 5, 1 }, { INFINITY, 1, 5, 1 } };
|
||||
for (const auto& c : cases) {
|
||||
RadYarn y{};
|
||||
y.factor = c[0]; y.low = c[1]; y.high = c[2]; y.magnitude = c[3];
|
||||
CHECK_EQ((int)rad_yarn_valid(y), abi_c_yarn_valid(c[0], c[1], c[2], c[3]));
|
||||
}
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
@@ -0,0 +1,422 @@
|
||||
/* advance_test.cpp -- the card's bookkeeping between passes (core/sched/advance_impl.h), run on
|
||||
* host arrays, against the host's own acceptance rule and hand-computed rows.
|
||||
*
|
||||
* advance_impl.h is shared by the kernel and the host backend, so these rows are the arithmetic
|
||||
* the card runs. The slab below is carved the way BatchBuilder carves a build: one int32 array
|
||||
* per field, a row descriptor block, AdvGroup records and per-group tables.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
|
||||
#include "sample/accept.h"
|
||||
#include "sched/advance_impl.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
using namespace rad;
|
||||
|
||||
namespace {
|
||||
|
||||
static_assert(sizeof(AdvGroup) == 48, "AdvGroup's layout is part of the card's slab");
|
||||
|
||||
/* Word offsets of every array the advance reads or writes. Up to kSeq rows, kTok tokens and
|
||||
* kGroups KV groups, each group with a kPitch-entry block table per row. */
|
||||
struct Slab {
|
||||
static constexpr int kSeq = 8, kTok = 64, kPitch = 16, kGroups = 2;
|
||||
enum : int32_t {
|
||||
ROWS = 0, /* [4][kSeq] row descriptors */
|
||||
TOK = ROWS + 4 * kSeq,
|
||||
POS = TOK + kTok,
|
||||
CTX = POS + kTok,
|
||||
ACC = CTX + kSeq,
|
||||
OUT = ACC + kSeq,
|
||||
SID = OUT + kTok,
|
||||
CU = SID + kSeq,
|
||||
Q = CU + kSeq + 8,
|
||||
ROPE = Q + kSeq, /* [3][kTok] */
|
||||
GRP = ROPE + 3 * kTok, /* [kGroups] AdvGroup, 12 words each */
|
||||
SLOT = GRP + 12 * kGroups, /* [kGroups][kTok] */
|
||||
USED = SLOT + kGroups * kTok, /* [kGroups][kSeq] */
|
||||
BT = USED + kGroups * kSeq, /* [kGroups][kSeq][kPitch] */
|
||||
FIRST = BT + kGroups * kSeq * kPitch, /* [kGroups][kSeq] */
|
||||
END = FIRST + kGroups * kSeq
|
||||
};
|
||||
alignas(16) int32_t w[END] = {};
|
||||
StepSlot st[kSeq];
|
||||
int32_t src[3 * kTok] = {};
|
||||
int32_t eog[8] = {};
|
||||
AdvanceArgs a;
|
||||
|
||||
/* `n_groups` groups: group 0 paged with `block` tokens a block, group 1 (when present) a
|
||||
* state group. Every block table starts as block b at entry b, so slot == position. */
|
||||
Slab(const Slab&) = delete; /* `a` points into the object */
|
||||
explicit Slab(int mode, int n_groups = 1, int block = 16) {
|
||||
std::memset(st, 0x7f, sizeof st);
|
||||
a.mode = mode;
|
||||
a.n_groups = n_groups;
|
||||
a.slab = reinterpret_cast<char*>(w);
|
||||
a.row_off = ROWS * 4; a.row_pitch = kSeq;
|
||||
a.tok_off = TOK * 4; a.pos_off = POS * 4; a.ctx_off = CTX * 4; a.acc_off = ACC * 4;
|
||||
a.out_off = OUT * 4; a.sid_off = SID * 4; a.cu_off = CU * 4; a.q_off = Q * 4;
|
||||
a.grp_off = GRP * 4;
|
||||
a.st = st;
|
||||
a.src = src;
|
||||
a.eog = eog;
|
||||
for (int g = 0; g < n_groups; ++g) {
|
||||
AdvGroup G{};
|
||||
G.block_size = g == 0 ? block : 1;
|
||||
G.paged = g == 0 ? 1 : 0;
|
||||
G.pitch = g == 0 ? kPitch : 1;
|
||||
G.slot_off = (int64_t)(SLOT + g * kTok) * 4;
|
||||
G.used_off = (int64_t)(USED + g * kSeq) * 4;
|
||||
G.bt_off = (int64_t)(BT + g * kSeq * kPitch) * 4;
|
||||
G.first_off = (int64_t)(FIRST + g * kSeq) * 4;
|
||||
std::memcpy(reinterpret_cast<char*>(w) + GRP * 4 + g * (int)sizeof(AdvGroup), &G,
|
||||
sizeof G);
|
||||
for (int i = 0; i < kSeq; ++i)
|
||||
for (int b = 0; b < kPitch; ++b) bt(g, i)[b] = b;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t* bt(int g, int i) { return &w[BT + (g * kSeq + i) * kPitch]; }
|
||||
int32_t& first(int g, int i) { return w[FIRST + g * kSeq + i]; }
|
||||
int32_t& used(int g, int i) { return w[USED + g * kSeq + i]; }
|
||||
int32_t& slot(int g, int t) { return w[SLOT + g * kTok + t]; }
|
||||
|
||||
/* Row i: a device row or not, its tokens [k, k + n), its context, the StepSlot it names, and
|
||||
* the advance's row descriptor (first verified token row, first sampled row, mode number). */
|
||||
void row(int i, bool dev, int k, int n, int ctx, int card, int rtok, int rout, int aux) {
|
||||
w[ROWS + i] = dev ? 1 : 0;
|
||||
w[ROWS + kSeq + i] = rtok;
|
||||
w[ROWS + 2 * kSeq + i] = rout;
|
||||
w[ROWS + 3 * kSeq + i] = aux;
|
||||
w[CU + i] = k;
|
||||
w[CU + i + 1] = k + n;
|
||||
w[Q + i] = n;
|
||||
w[CTX + i] = ctx;
|
||||
w[SID + i] = card;
|
||||
if (i + 1 > a.n_seq) a.n_seq = i + 1;
|
||||
}
|
||||
void set_eog(std::initializer_list<int32_t> ids) {
|
||||
int n = 0;
|
||||
for (int32_t t : ids) eog[n++] = t;
|
||||
std::sort(eog, eog + n);
|
||||
a.n_eog = n;
|
||||
}
|
||||
void run() { for (int i = 0; i < a.n_seq; ++i) adv_row(a, i); }
|
||||
};
|
||||
|
||||
uint32_t lcg(uint32_t& s) { s = s * 1664525u + 1013904223u; return s >> 8; }
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* ================================================================== the end-of-generation cut */
|
||||
|
||||
/* The host's cut: the first end-of-generation token among the accepted drafts and the target's
|
||||
* own token is emitted and ends the run; a run without one is kept whole. */
|
||||
TEST(the_end_of_generation_cut_keeps_the_stop_token_and_drops_what_follows) {
|
||||
const int32_t out[3] = { 5, 9, 7 }; /* two accepted drafts, then the target's */
|
||||
auto in = [](std::initializer_list<int32_t> s) {
|
||||
return [s](int32_t t) { return std::find(s.begin(), s.end(), t) != s.end(); };
|
||||
};
|
||||
CHECK_EQ(accept_cut_at_eog(out, 2, in({})), 2);
|
||||
CHECK_EQ(accept_cut_at_eog(out, 2, in({ 5 })), 0); /* the first draft ends it */
|
||||
CHECK_EQ(accept_cut_at_eog(out, 2, in({ 9 })), 1);
|
||||
CHECK_EQ(accept_cut_at_eog(out, 2, in({ 7 })), 2); /* the target's own token */
|
||||
CHECK_EQ(accept_cut_at_eog(out, 2, in({ 9, 5 })), 0); /* the earliest wins */
|
||||
CHECK_EQ(accept_cut_at_eog(out, 0, in({ 9 })), 0); /* nothing accepted past out[0] */
|
||||
}
|
||||
|
||||
/* ================================================================== ADV_ACCEPT */
|
||||
|
||||
/* The card's acceptance is the host's: for any drafts, targets and end-of-generation set, a row's
|
||||
* StepSlot holds the drafts accept_greedy accepts, cut at the first end-of-generation token
|
||||
* (accept_cut_at_eog), and the token after them. The engine refuses a step where the two
|
||||
* disagree, so a drift between the copies stops serving; and the card's count positions every
|
||||
* later pass, so a wrong one writes K/V at the wrong positions. Rows that sampled nothing keep
|
||||
* their StepSlot. Seeded; a failure prints the case. */
|
||||
TEST(the_cards_acceptance_is_accept_greedy_and_the_end_of_generation_cut) {
|
||||
const uint32_t seed = 0x5eed2a2u;
|
||||
uint32_t rng = seed;
|
||||
int bad = 0, cut_cases = 0, partial = 0;
|
||||
for (int c = 0; c < 10000 && !bad; ++c) {
|
||||
Slab s(ADV_ACCEPT);
|
||||
/* Tokens from {1, 2, 3}, so drafts often agree; stop tokens a subset of {2, 3, 8}. */
|
||||
int n_eog = 0;
|
||||
int32_t eog_ids[3];
|
||||
for (int32_t t : { 2, 3, 8 }) if (lcg(rng) % 3 == 0) eog_ids[n_eog++] = t;
|
||||
for (int j = 0; j < n_eog; ++j) s.eog[j] = eog_ids[j];
|
||||
s.a.n_eog = n_eog;
|
||||
auto is_eog = [&](int32_t t) {
|
||||
return std::find(eog_ids, eog_ids + n_eog, t) != eog_ids + n_eog;
|
||||
};
|
||||
|
||||
const int n_rows = 1 + (int)(lcg(rng) % 4);
|
||||
int k = 0, out_row = 0;
|
||||
int32_t cards[Slab::kSeq];
|
||||
for (int i = 0; i < Slab::kSeq; ++i) cards[i] = i;
|
||||
for (int i = Slab::kSeq - 1; i > 0; --i) std::swap(cards[i], cards[lcg(rng) % (i + 1)]);
|
||||
struct Want { int card, rout, acc, tok, head; } want[4];
|
||||
for (int i = 0; i < n_rows; ++i) {
|
||||
const int kind = (int)(lcg(rng) % 4); /* 0: mid-prefill, 1: last chunk, else decode */
|
||||
const int n_spec = kind >= 2 ? (int)(lcg(rng) % 9) : 0;
|
||||
const int n_tok = kind >= 2 ? 1 + n_spec : 2 + (int)(lcg(rng) % 5);
|
||||
const int ctx = (int)(lcg(rng) % 1000);
|
||||
const int rtok = k + n_tok - 1 - n_spec;
|
||||
const int rout = kind == 0 ? -1 : out_row;
|
||||
s.row(i, kind >= 2, k, n_tok, ctx, cards[i], rtok, rout, n_spec);
|
||||
int32_t draft[8] = {}, target[9] = {};
|
||||
for (int j = 0; j < n_tok; ++j) s.w[Slab::TOK + k + j] = 50 + j;
|
||||
for (int j = 0; j < n_spec; ++j) {
|
||||
draft[j] = 1 + (int32_t)(lcg(rng) % 3);
|
||||
s.w[Slab::TOK + rtok + 1 + j] = draft[j];
|
||||
}
|
||||
for (int j = 0; j <= n_spec; ++j) {
|
||||
target[j] = (j < n_spec && lcg(rng) % 10 < 7) ? draft[j]
|
||||
: 1 + (int32_t)(lcg(rng) % 3);
|
||||
if (rout >= 0) s.src[rout + j] = target[j];
|
||||
}
|
||||
want[i] = { cards[i], rout, -1, 0, 0 };
|
||||
if (rout >= 0) {
|
||||
int32_t out[9] = {}, acc = -1;
|
||||
CHECK_OK(accept_greedy(draft, n_spec, target, out, &acc));
|
||||
const int32_t cut = accept_cut_at_eog(out, acc, is_eog);
|
||||
cut_cases += cut < acc;
|
||||
partial += cut > 0 && cut < n_spec;
|
||||
want[i].acc = cut;
|
||||
want[i].tok = out[cut];
|
||||
want[i].head = ctx + (rtok - k) + cut;
|
||||
out_row += 1 + n_spec;
|
||||
}
|
||||
k += n_tok;
|
||||
}
|
||||
s.run();
|
||||
for (int i = 0; i < n_rows && !bad; ++i) {
|
||||
const StepSlot& S = s.st[want[i].card];
|
||||
bool ok;
|
||||
if (want[i].rout < 0) {
|
||||
StepSlot untouched;
|
||||
std::memset(&untouched, 0x7f, sizeof untouched);
|
||||
ok = std::memcmp(&S, &untouched, sizeof S) == 0;
|
||||
} else {
|
||||
ok = S.acc == want[i].acc && S.tok[0] == want[i].tok && S.n_acc == want[i].acc + 1 &&
|
||||
S.head == want[i].head && S.ctx == want[i].head + 1;
|
||||
}
|
||||
if (!ok) {
|
||||
bad = 1;
|
||||
CHECK(ok);
|
||||
std::fprintf(stderr, " seed 0x%x, case %d, row %d: card acc %d tok %d head %d "
|
||||
"ctx %d n_acc %d; host acc %d tok %d head %d (sampled row %d)\n",
|
||||
seed, c, i, S.acc, S.tok[0], S.head, S.ctx, S.n_acc, want[i].acc,
|
||||
want[i].tok, want[i].head, want[i].rout);
|
||||
}
|
||||
}
|
||||
}
|
||||
CHECK_EQ(bad, 0);
|
||||
/* The draw reaches the interesting branches, not only full acceptance or none. */
|
||||
CHECK(cut_cases > 100);
|
||||
CHECK(partial > 100);
|
||||
}
|
||||
|
||||
/* ================================================================== ADV_TRUNK */
|
||||
|
||||
/* A verify step issued ahead takes its rows from the StepSlots: the bonus token and the head's
|
||||
* proposals as tokens, positions from the committed context, the rollback count, each group's
|
||||
* length and every slot through the row's own block table. Rows differ in offset, length,
|
||||
* context and StepSlot; a host row keeps what the host staged; a position past the table's pitch
|
||||
* or on an unassigned block gets no slot. A wrong row here writes K/V into another sequence's
|
||||
* blocks or reads the wrong token, with no error anywhere. */
|
||||
TEST(a_step_issued_ahead_takes_every_rows_tokens_positions_and_slots_from_its_step_slot) {
|
||||
Slab s(ADV_TRUNK, /*n_groups=*/2, /*block=*/4);
|
||||
/* Row 0: three positions (two drafts) for card 2, block b of its table at 100 + 3b. */
|
||||
s.row(0, true, 0, 3, /*ctx bound=*/45, /*card=*/2, 0, 0, 2);
|
||||
for (int b = 0; b < Slab::kPitch; ++b) s.bt(0, 0)[b] = 100 + 3 * b;
|
||||
s.st[2].ctx = 37; s.st[2].n_acc = 2;
|
||||
s.st[2].tok[0] = 501; s.st[2].tok[1] = 502; s.st[2].tok[2] = 503;
|
||||
/* Row 1: a host-staged prefill row, which no advance may touch. */
|
||||
s.row(1, false, 3, 2, 70, 4, 4, -1, 0);
|
||||
s.w[Slab::TOK + 3] = 900; s.w[Slab::TOK + 4] = 901;
|
||||
s.w[Slab::POS + 3] = 70; s.w[Slab::POS + 4] = 71;
|
||||
s.slot(0, 3) = 1234; s.slot(0, 4) = 1235;
|
||||
s.w[Slab::ACC + 1] = 1;
|
||||
s.used(0, 1) = 72;
|
||||
/* Row 2: one position for card 0, whose second block was never assigned. */
|
||||
s.row(2, true, 5, 1, 64, 0, 5, 3, 0);
|
||||
s.bt(0, 2)[1] = -1;
|
||||
s.st[0].ctx = 6; s.st[0].n_acc = 1; s.st[0].tok[0] = 777;
|
||||
/* Row 3: three positions for card 5 in a table rebased at 8; the last falls past the
|
||||
* pitch (position 72 is block (72 - 8) / 4 = 16). */
|
||||
s.row(3, true, 6, 3, 80, 5, 6, 4, 2);
|
||||
s.first(0, 3) = 8;
|
||||
s.st[5].ctx = 70; s.st[5].n_acc = 3;
|
||||
s.st[5].tok[0] = 601; s.st[5].tok[1] = 602; s.st[5].tok[2] = 603;
|
||||
s.run();
|
||||
|
||||
const int32_t tok[9] = { 501, 502, 503, 900, 901, 777, 601, 602, 603 };
|
||||
const int32_t pos[9] = { 37, 38, 39, 70, 71, 6, 70, 71, 72 };
|
||||
/* Paged slot = table[(p - first) / 4] * 4 + p % 4. */
|
||||
const int32_t slot[9] = { (100 + 3 * 9) * 4 + 1, (100 + 3 * 9) * 4 + 2, (100 + 3 * 9) * 4 + 3,
|
||||
1234, 1235, -1, 15 * 4 + 2, 15 * 4 + 3, -1 };
|
||||
for (int t = 0; t < 9; ++t) {
|
||||
CHECK_EQ(s.w[Slab::TOK + t], tok[t]);
|
||||
CHECK_EQ(s.w[Slab::POS + t], pos[t]);
|
||||
CHECK_EQ(s.slot(0, t), slot[t]);
|
||||
}
|
||||
const int32_t ctx[4] = { 37, 70, 6, 70 }, acc[4] = { 2, 1, 1, 3 };
|
||||
const int32_t used0[4] = { 40, 72, 7, 65 }, used1[4] = { 40, 0, 7, 73 };
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
CHECK_EQ(s.w[Slab::CTX + i], ctx[i]);
|
||||
CHECK_EQ(s.w[Slab::ACC + i], acc[i]);
|
||||
CHECK_EQ(s.used(0, i), used0[i]); /* from the table's first position */
|
||||
CHECK_EQ(s.used(1, i), used1[i]); /* a state group counts from 0 and has no slots */
|
||||
}
|
||||
for (int t = 0; t < 9; ++t) CHECK_EQ(s.slot(1, t), 0);
|
||||
}
|
||||
|
||||
/* A row the card moves keeps the host's offset between its position and its rotary position on
|
||||
* all three planes (a text row after an image rotates at its index plus a shift); a row whose
|
||||
* position does not move keeps the host's three components, which differ for a media token. A
|
||||
* wrong shift misplaces every M-RoPE text row after a picture during speculation. */
|
||||
TEST(a_moved_row_keeps_its_rotary_shift_and_an_unmoved_row_keeps_its_components) {
|
||||
Slab s(ADV_TRUNK);
|
||||
s.a.rope_off = Slab::ROPE * 4;
|
||||
s.a.rope_pitch = 3;
|
||||
int32_t* r = &s.w[Slab::ROPE];
|
||||
/* Row 0 (one position) moves from the bound 120 to 100; its rotary index was 120 + 7. */
|
||||
s.row(0, true, 0, 1, 120, 0, 0, 0, 0);
|
||||
s.w[Slab::POS + 0] = 120;
|
||||
r[0] = 127; r[3 + 0] = 127; r[6 + 0] = 127;
|
||||
s.st[0].ctx = 100; s.st[0].n_acc = 1; s.st[0].tok[0] = 11;
|
||||
/* Row 1 (two positions) is already where the card puts it: a media row's three components
|
||||
* stay as the host staged them. */
|
||||
s.row(1, true, 1, 2, 50, 1, 1, 1, 1);
|
||||
s.w[Slab::POS + 1] = 50; s.w[Slab::POS + 2] = 51;
|
||||
r[1] = 10; r[3 + 1] = 20; r[6 + 1] = 30;
|
||||
r[2] = 31; r[3 + 2] = 21; r[6 + 2] = 11;
|
||||
s.st[1].ctx = 50; s.st[1].n_acc = 1; s.st[1].tok[0] = 12; s.st[1].tok[1] = 13;
|
||||
s.run();
|
||||
CHECK_EQ(s.w[Slab::POS + 0], 100);
|
||||
for (int p = 0; p < 3; ++p) CHECK_EQ(r[3 * p + 0], 107);
|
||||
CHECK_EQ(r[1], 10); CHECK_EQ(r[3 + 1], 20); CHECK_EQ(r[6 + 1], 30);
|
||||
CHECK_EQ(r[2], 31); CHECK_EQ(r[3 + 2], 21); CHECK_EQ(r[6 + 2], 11);
|
||||
}
|
||||
|
||||
/* ================================================================== the draft passes */
|
||||
|
||||
/* Round r reads row i's proposal at i * src_pitch: a head with a proposal buffer lays rows out at
|
||||
* its own pitch. Reading at i instead gives sequence i the proposal of sequence i / pitch, and
|
||||
* acceptance collapses with no error. Both the round's token and the final take follow it. */
|
||||
TEST(draft_rounds_read_each_rows_proposal_at_the_buffers_pitch) {
|
||||
for (int mode : { (int)ADV_ROUND, (int)ADV_TAKE }) {
|
||||
Slab s(mode);
|
||||
s.a.round = 3;
|
||||
s.a.src_pitch = 3;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
s.row(i, true, i, 1, 0, /*card=*/2 - i, i, i, 0);
|
||||
s.st[2 - i].head = 100 * (i + 1);
|
||||
for (int c = 0; c < 3; ++c) s.src[i * 3 + c] = 1000 * (i + 1) + c;
|
||||
}
|
||||
s.run();
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
const StepSlot& S = s.st[2 - i];
|
||||
if (mode == ADV_ROUND) {
|
||||
CHECK_EQ(S.tok[2], 1000 * (i + 1));
|
||||
CHECK_EQ(s.w[Slab::TOK + i], 1000 * (i + 1));
|
||||
CHECK_EQ(s.w[Slab::POS + i], 100 * (i + 1) + 2); /* head + round - 1 */
|
||||
CHECK_EQ(s.w[Slab::CTX + i], 100 * (i + 1) + 2);
|
||||
} else {
|
||||
CHECK_EQ(S.tok[3], 1000 * (i + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* A history pass with `aux` host-staged positions before the verified ones: those keep the host's
|
||||
* tokens, the verified positions up to the last committed one take the sampled tokens, and rows
|
||||
* past it repeat it, so no rejected draft's hidden state reaches the head's cache. */
|
||||
TEST(a_history_pass_keeps_the_hosts_rows_and_repeats_the_last_committed_one) {
|
||||
Slab s(ADV_HIST);
|
||||
s.row(0, true, 0, 5, 0, 1, 0, 6, /*aux=*/2);
|
||||
s.w[Slab::TOK + 0] = 41; s.w[Slab::TOK + 1] = 42;
|
||||
s.w[Slab::OUT + 0] = 20;
|
||||
s.st[1].head = 103; s.st[1].acc = 1;
|
||||
s.src[6] = 7001; s.src[7] = 7002; s.src[8] = 7003;
|
||||
s.run();
|
||||
/* base = head - acc - aux = 100; rows reach index aux + acc = 3. */
|
||||
const int32_t pos[5] = { 100, 101, 102, 103, 103 }, tok[5] = { 41, 42, 7001, 7002, 7002 };
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
CHECK_EQ(s.w[Slab::POS + j], pos[j]);
|
||||
CHECK_EQ(s.w[Slab::TOK + j], tok[j]);
|
||||
CHECK_EQ(s.w[Slab::OUT + j], 20 + (j < 3 ? j : 3));
|
||||
CHECK_EQ(s.slot(0, j), pos[j]);
|
||||
}
|
||||
CHECK_EQ(s.w[Slab::CTX], 100);
|
||||
CHECK_EQ(s.used(0, 0), 105);
|
||||
}
|
||||
|
||||
/* What the card writes into a draft pass, for both head shapes. A verify at positions 101..105
|
||||
* accepted two drafts: committed position 103, trunk token 7003; slot p is position p. A head
|
||||
* with its own cache gets the verified run, tail repeated, context to its end; a cacheless head
|
||||
* gets the committed position and a context ending there, every round. */
|
||||
TEST(the_card_stages_a_cacheless_head_at_the_committed_position) {
|
||||
auto slab = [](Slab& s, int n_rows, int round, bool shared, int shift) {
|
||||
s.a.round = round;
|
||||
s.a.shared_kv = shared ? 1 : 0;
|
||||
s.a.rot_shift = shift;
|
||||
s.row(0, true, 0, n_rows, 0, 0, 0, 0, 0);
|
||||
s.w[Slab::OUT] = 40; /* the host staged the run's first trunk row */
|
||||
s.src[0] = 7001; s.src[1] = 7002; s.src[2] = 7003; s.src[3] = 7004; s.src[4] = 7005;
|
||||
s.st[0].head = 103; s.st[0].acc = 2; s.st[0].ctx = 104; s.st[0].n_acc = 3;
|
||||
s.st[0].tok[0] = 7003;
|
||||
};
|
||||
/* The history pass. */
|
||||
{
|
||||
Slab o(ADV_HIST);
|
||||
slab(o, 5, 0, false, 0);
|
||||
o.run();
|
||||
const int32_t pos[5] = { 101, 102, 103, 103, 103 }, tok[5] = { 7001, 7002, 7003, 7003, 7003 };
|
||||
for (int j = 0; j < 5; ++j) {
|
||||
CHECK_EQ(o.w[Slab::POS + j], pos[j]);
|
||||
CHECK_EQ(o.w[Slab::TOK + j], tok[j]);
|
||||
CHECK_EQ(o.w[Slab::OUT + j], 40 + (j < 2 ? j : 2));
|
||||
CHECK_EQ(o.slot(0, j), pos[j]);
|
||||
}
|
||||
CHECK_EQ(o.used(0, 0), 106); /* the verify step's whole run */
|
||||
CHECK_EQ(o.w[Slab::CTX], 101);
|
||||
}
|
||||
for (int shift = 0; shift < 2; ++shift) {
|
||||
Slab s(ADV_HIST);
|
||||
slab(s, 1, 0, true, shift);
|
||||
s.run();
|
||||
CHECK_EQ(s.w[Slab::POS], 103 + shift);
|
||||
CHECK_EQ(s.w[Slab::TOK], 7003);
|
||||
CHECK_EQ(s.w[Slab::OUT], 42);
|
||||
CHECK_EQ(s.used(0, 0), 104); /* the committed positions and no more */
|
||||
CHECK_EQ(s.w[Slab::CTX], 103);
|
||||
}
|
||||
/* Round 3: the old head two positions on, the cacheless one where it was. */
|
||||
{
|
||||
Slab o(ADV_ROUND);
|
||||
slab(o, 1, 3, false, 0);
|
||||
o.src[0] = 9001;
|
||||
o.run();
|
||||
CHECK_EQ(o.w[Slab::POS], 105);
|
||||
CHECK_EQ(o.used(0, 0), 106);
|
||||
CHECK_EQ(o.w[Slab::TOK], 9001);
|
||||
CHECK_EQ(o.st[0].tok[2], 9001);
|
||||
}
|
||||
for (int shift = 0; shift < 2; ++shift) {
|
||||
Slab s(ADV_ROUND);
|
||||
slab(s, 1, 3, true, shift);
|
||||
s.src[0] = 9001;
|
||||
s.run();
|
||||
CHECK_EQ(s.w[Slab::POS], 103 + shift);
|
||||
CHECK_EQ(s.used(0, 0), 104);
|
||||
CHECK_EQ(s.w[Slab::CTX], 103);
|
||||
CHECK_EQ(s.w[Slab::TOK], 9001);
|
||||
CHECK_EQ(s.st[0].tok[2], 9001);
|
||||
}
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
+3383
-706
File diff suppressed because it is too large.
Load diff
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
# avx_check_general.sh CHECK LIBREF SUBSET
|
||||
#
|
||||
# rad-avx-check as a general host-library checker, run on tests/avx_subset_plugin.cpp (part of
|
||||
# libref, named "subset"):
|
||||
# 1. it passes although the library lacks three of libref's ops, lists them, counts the f16
|
||||
# rmsnorm cases its constraint excludes and the hand-built cases for ops it does not serve, and
|
||||
# runs one pass at the library's own level with no file-backed gather;
|
||||
# 2. a row that declines a geometry libref serves still fails.
|
||||
set -u
|
||||
CHECK=$1; REF=$2; SUBSET=$3
|
||||
export RAD_SUBSET_OF="$REF" OMP_NUM_THREADS=${OMP_NUM_THREADS:-4}
|
||||
fail() { printf 'FAIL: %s\n' "$*"; printf '%s\n' "$out" | tail -30; exit 1; }
|
||||
has() { printf '%s\n' "$out" | grep -q -- "$1" || fail "missing: $1"; }
|
||||
lacks() { printf '%s\n' "$out" | grep -q -- "$1" && fail "unexpected: $1"; return 0; }
|
||||
|
||||
out=$("$CHECK" --ref "$REF" --avx "$SUBSET" 2>&1); rc=$?
|
||||
[ $rc -eq 0 ] || fail "exit $rc for a library that lacks ops"
|
||||
has "checked as a host library"
|
||||
has "3 of libref's ops have no host row here"
|
||||
gaps=$(printf '%s\n' "$out" | grep -A1 "not checked:" | tail -1)
|
||||
for op in softmax sample_merge_topk dflash_select; do
|
||||
printf '%s\n' "$gaps" | grep -qw "$op" || fail "$op is not listed as a gap"
|
||||
done
|
||||
has "== subset =="
|
||||
has "admitted by no row's constraints"
|
||||
has "for ops subset does not serve"
|
||||
has "^PASS\$"
|
||||
lacks "== level"
|
||||
lacks "embed_lookup_q from a file"
|
||||
lacks "COVER "
|
||||
|
||||
out=$(RAD_SUBSET_DECLINE=gemm_nt "$CHECK" --ref "$REF" --avx "$SUBSET" --op gemm_nt 2>&1); rc=$?
|
||||
[ $rc -ne 0 ] || fail "exit 0 although gemm_nt declines every launch"
|
||||
has "DECLINED"
|
||||
has "^FAIL\$"
|
||||
echo "avx_check_general: ok"
|
||||
@@ -0,0 +1,88 @@
|
||||
/* avx_subset_plugin.cpp -- a host kernel library made of part of libref, for avx_check_general.
|
||||
*
|
||||
* rad-avx-check holds libavx to its own contract and checks any other host library as one: the
|
||||
* ops it lacks are listed rather than failed, each case runs on the row whose constraints admit it,
|
||||
* and the ISA sweep, the threaded rerun and the file-backed gather are left out. This plugin is
|
||||
* such a library. It loads libref (the path in RAD_SUBSET_OF) and re-exports its schemas and its
|
||||
* rows, minus three ops, with rmsnorm limited to f32 and bf16 by a constraint. With
|
||||
* RAD_SUBSET_DECLINE=<op> that op's row returns RAD_E_UNSUPPORTED for every launch, which the
|
||||
* checker must fail in any library. */
|
||||
#include "rad_abi.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
|
||||
const char* const kDropped[] = { "softmax", "sample_merge_topk", "dflash_select" };
|
||||
const RadConstraint kRmsnormDtypes[] = { { "dtype", RAD_C_IN, 0, "f32 bf16" } };
|
||||
|
||||
struct Subset {
|
||||
int (*schema_count)() = nullptr;
|
||||
const RadOpSchema* (*schema_at)(int) = nullptr;
|
||||
std::vector<RadKernelInfo> rows;
|
||||
};
|
||||
|
||||
int declined(const RadArgs*, RadStream) { return RAD_E_UNSUPPORTED; }
|
||||
|
||||
const Subset& subset() {
|
||||
static const Subset s = [] {
|
||||
Subset r;
|
||||
const char* path = std::getenv("RAD_SUBSET_OF");
|
||||
void* h = path ? dlopen(path, RTLD_NOW | RTLD_LOCAL) : nullptr;
|
||||
if (!h) {
|
||||
std::fprintf(stderr, "avx_subset_plugin: set RAD_SUBSET_OF to libref.so\n");
|
||||
return r;
|
||||
}
|
||||
auto count = (int (*)())dlsym(h, "rad_kernel_count");
|
||||
auto at = (const RadKernelInfo* (*)(int))dlsym(h, "rad_kernel_at");
|
||||
r.schema_count = (int (*)())dlsym(h, "rad_kernel_schema_count");
|
||||
r.schema_at = (const RadOpSchema* (*)(int))dlsym(h, "rad_kernel_schema_at");
|
||||
if (!count || !at || !r.schema_count || !r.schema_at) return r;
|
||||
const char* decline = std::getenv("RAD_SUBSET_DECLINE");
|
||||
for (int i = 0, n = count(); i < n; ++i) {
|
||||
RadKernelInfo k = *at(i);
|
||||
bool drop = false;
|
||||
for (const char* d : kDropped) drop = drop || !std::strcmp(k.op, d);
|
||||
if (drop) continue;
|
||||
if (!std::strcmp(k.op, "rmsnorm")) {
|
||||
k.constraints = kRmsnormDtypes;
|
||||
k.n_constraints = 1;
|
||||
}
|
||||
if (decline && !std::strcmp(k.op, decline)) k.launch = declined;
|
||||
r.rows.push_back(k);
|
||||
}
|
||||
return r;
|
||||
}();
|
||||
return s;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
||||
uint32_t rad_plugin_abi_version(void) { return RAD_ABI_VERSION; }
|
||||
|
||||
const RadPluginInfo* rad_plugin_info(void) {
|
||||
static const RadPluginInfo info = { RAD_PLUGIN_KERNEL, "subset", "0.1.0",
|
||||
"part of libref, for avx_check_general", "host" };
|
||||
return &info;
|
||||
}
|
||||
|
||||
int rad_kernel_schema_count(void) {
|
||||
return subset().schema_count ? subset().schema_count() : 0;
|
||||
}
|
||||
const RadOpSchema* rad_kernel_schema_at(int i) {
|
||||
return subset().schema_at ? subset().schema_at(i) : nullptr;
|
||||
}
|
||||
int rad_kernel_count(void) { return (int)subset().rows.size(); }
|
||||
const RadKernelInfo* rad_kernel_at(int i) {
|
||||
const std::vector<RadKernelInfo>& r = subset().rows;
|
||||
return i >= 0 && i < (int)r.size() ? &r[(size_t)i] : nullptr;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
+801
-300
File diff suppressed because it is too large.
Load diff
+349
-310
File diff suppressed because it is too large.
Load diff
@@ -1,20 +1,19 @@
|
||||
/* chatparse_gemma4_test.cpp -- Gemma 4's reply format: a reasoning channel, and calls written as a
|
||||
* name and ONE object in a dialect of JSON.
|
||||
* name and one object in a JSON dialect.
|
||||
*
|
||||
* Gemma 4's template is one llama.cpp reads with a hand-written handler, so the template analysis
|
||||
* finds no format in it and the plugins declare one (arch/common/rad_gemma4_chat.h):
|
||||
* llama.cpp reads Gemma 4's template with a hand-written handler, so template analysis finds no
|
||||
* format and the plugins declare one (arch/common/rad_gemma4_chat.h):
|
||||
*
|
||||
* <|channel>thought\n ... <channel|> reasoning
|
||||
* <|tool_call>call:NAME{key:<|"|>text<|"|>,n:3}<tool_call|> a call, repeated for more
|
||||
*
|
||||
* Every case reads a reply under a request rendered through the model's REAL template
|
||||
* (tests/data/chat/gemma4), and where the reply is within the format the answer is held, byte for
|
||||
* byte, to llama.cpp's own Gemma 4 parser -- the PEG grammar and value mapper its handler builds
|
||||
* (tests/legacy, the `old` side). Every reply is also streamed cut every way (chatdiff.h
|
||||
* check_stream): each delta a prefix of the finished value, the deltas adding up to it, the bytes
|
||||
* held under the format's bound, and a closed call's arguments JSON.
|
||||
* Each case reads a reply under a request rendered through the real template
|
||||
* (tests/data/chat/gemma4). Where the reply is within the format, the result must match llama.cpp's
|
||||
* Gemma 4 parser byte for byte (tests/legacy, the `old` side). Every reply is also streamed at
|
||||
* every cut (chatdiff.h check_stream): each delta a prefix of the final value, the deltas summing
|
||||
* to it, held bytes within the format's bound, and a closed call's arguments valid JSON.
|
||||
*
|
||||
* The object family itself -- JSON behind a name tag or a function tag -- is chatparse_test's.
|
||||
* The object family in general (JSON behind a name or function tag) is chatparse_test's.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
|
||||
@@ -55,8 +54,7 @@ static std::string fixture() {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/* The vocabulary's spellings: generation_config.json ends a turn on <eos>, <turn|> and
|
||||
* <|tool_response>. */
|
||||
/* Turn terminators, per generation_config.json: <eos>, <turn|> and <|tool_response>. */
|
||||
static const Model& gemma() {
|
||||
static const Model m = { "gemma4", "gemma4", "<bos>", "<eos>",
|
||||
{ "<eos>", "<turn|>", "<|tool_response>" },
|
||||
@@ -88,7 +86,7 @@ static std::string quote(const std::string& s) {
|
||||
return json(s).dump(-1, ' ', false, json::error_handler_t::replace);
|
||||
}
|
||||
|
||||
/* One call as the model writes it. `args` is the object's inside. */
|
||||
/* One call as the model writes it; `args` is the object's body. */
|
||||
static std::string G(const std::string& name, const std::string& args) {
|
||||
return "<|tool_call>call:" + name + "{" + args + "}<tool_call|>";
|
||||
}
|
||||
@@ -103,8 +101,8 @@ static std::vector<size_t> every(size_t n, size_t step) {
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Every cut of the reply against its one-shot parse: one piece, byte by byte, token-sized pieces,
|
||||
* and every two-way split. */
|
||||
/* Every cut of the reply against its one-shot parse: whole, byte by byte, token-sized pieces, and
|
||||
* every two-way split. */
|
||||
static std::string stream_all(const ReplyParser& p, const std::string& text) {
|
||||
const ReplyMessage expect = reply_parse(p, text);
|
||||
std::string err = check_stream(p, text, {}, expect);
|
||||
@@ -154,10 +152,9 @@ static std::shared_ptr<const ReplyParser> parser(const std::string& gp, bool too
|
||||
return p;
|
||||
}
|
||||
|
||||
/* The three generation prompts a reply follows: a turn with thinking off (the template closes an
|
||||
* empty channel), a turn with thinking on (the model opens its own), and the continuation after a
|
||||
* tool response with thinking on (the template has opened the channel). With thinking off a
|
||||
* continuation has no generation prompt at all. */
|
||||
/* The three generation prompts: thinking off (the template closes an empty channel), thinking on
|
||||
* (the model opens its own), and the continuation after a tool response with thinking on (the
|
||||
* template has opened the channel). With thinking off a continuation has no generation prompt. */
|
||||
static const std::string kOff = "<|turn>model\n<|channel>thought\n<channel|>";
|
||||
static const std::string kOn = "<|turn>model\n";
|
||||
static const std::string kAfter = "<|channel>thought\n";
|
||||
@@ -177,17 +174,17 @@ TEST(the_declaration_is_a_format_the_parser_runs) {
|
||||
"anywhere; calls \"<|tool_call>\"\"call:\"NAME\"\" {OBJECT, strings "
|
||||
"\"<|\\\"|>\"..\"<|\\\"|>\", bare keys} \"\"\"<tool_call|>\"; grammar on "
|
||||
"\"<|tool_call>\""));
|
||||
/* What the decoder must render as text: every delimiter, the string's included -- without it
|
||||
* a string argument reaches the parser with its quotes gone. */
|
||||
/* The decoder must render every delimiter as text, including the string delimiter, or string
|
||||
* arguments lose their quotes. */
|
||||
const std::vector<std::string> m = chat_format_markers(f);
|
||||
for (const char* want : { "<|channel>thought", "<channel|>", "<|tool_call>", "<tool_call|>",
|
||||
"call:", "<|\"|>" })
|
||||
CHECK(std::find(m.begin(), m.end(), std::string(want)) != m.end());
|
||||
}
|
||||
|
||||
/* A plugin compiled against the header before the object family reads its new fields as zero:
|
||||
* the tagged family, no dialect, reasoning at the start only -- and Gemma's declaration read that
|
||||
* way is refused by name rather than run wrongly. */
|
||||
/* A plugin built against the header before the object family reads the new fields as zero (the
|
||||
* tagged family, no dialect, reasoning at the start only); Gemma's declaration read that way is
|
||||
* refused by name. */
|
||||
TEST(an_older_struct_reads_the_object_fields_as_zero) {
|
||||
RadChatFormat c = *rad::arch::gemma4_chat_format();
|
||||
c.struct_size = (uint32_t)offsetof(RadChatFormat, args_form);
|
||||
@@ -228,7 +225,7 @@ TEST(an_object_format_the_parser_cannot_read_is_refused_by_name) {
|
||||
CHECK(refused([](RadChatFormat& c) { c.reasoning_open = ""; }, "reasoning_anywhere"));
|
||||
CHECK(refused([](RadChatFormat& c) { c.call_open = "<|channel>thought"; c.reasoning_breaks = nullptr;
|
||||
c.n_reasoning_breaks = 0; }, "content"));
|
||||
/* The tagged family is untouched: a dialect field there is refused, not ignored. */
|
||||
/* In the tagged family a dialect field is refused, not ignored. */
|
||||
CHECK(refused([](RadChatFormat& c) {
|
||||
c.args_form = RAD_CHAT_ARGS_TAGGED;
|
||||
c.name_suffix = ">"; c.call_end = "</f>"; c.arg_prefix = "<a="; c.arg_name_suffix = ">";
|
||||
@@ -238,9 +235,9 @@ TEST(an_object_format_the_parser_cannot_read_is_refused_by_name) {
|
||||
/* ================================================================== the template's own replies
|
||||
*
|
||||
* An assistant message rendered through the template is what the model is trained to write. With
|
||||
* thinking on the reply is exactly what the template writes after the generation prompt; with it
|
||||
* off the template renders a past turn without the empty channel its generation prompt holds, so
|
||||
* those replies are read by the hand-written cases below instead. */
|
||||
* thinking on, the reply is what the template writes after the generation prompt; with it off,
|
||||
* a past turn omits the empty channel the generation prompt holds, so the hand-written cases below
|
||||
* cover those. */
|
||||
TEST(rendered_replies_read_back_as_the_template_wrote_them) {
|
||||
Bench* b = bench(thinking(true));
|
||||
REQUIRE(b != nullptr);
|
||||
@@ -252,7 +249,7 @@ TEST(rendered_replies_read_back_as_the_template_wrote_them) {
|
||||
const ReplyMessage m = b->new_parse(reply, &strict);
|
||||
const legacy::Answer o = b->old_parse(reply);
|
||||
|
||||
/* The calls come back as the message had them, arguments as JSON values. */
|
||||
/* The calls come back as in the message, arguments as JSON values. */
|
||||
const size_t ncalls = msg.contains("tool_calls") ? msg["tool_calls"].size() : 0;
|
||||
REQUIRE_EQ(m.calls.size(), ncalls);
|
||||
for (size_t i = 0; i < ncalls; ++i) {
|
||||
@@ -267,9 +264,9 @@ TEST(rendered_replies_read_back_as_the_template_wrote_them) {
|
||||
CHECK_EQ(m.reasoning, r.empty() ? r : r + "\n");
|
||||
CHECK_EQ(m.content, msg["content"].get<std::string>());
|
||||
|
||||
/* llama.cpp's parser reads the same calls and reasoning, byte for byte. Where the template
|
||||
* wrote content AFTER the calls -- its order for a past turn, not the model's -- the old
|
||||
* parser drops that content and the new one keeps it, leniently. */
|
||||
/* llama.cpp's parser reads the same calls and reasoning byte for byte. Where the template
|
||||
* writes content after the calls (its past-turn order, not the model's), the old parser
|
||||
* drops it and the new one keeps it. */
|
||||
CHECK_EQ(o.calls.size(), m.calls.size());
|
||||
for (size_t i = 0; i < std::min(o.calls.size(), m.calls.size()); ++i) {
|
||||
CHECK_EQ(o.calls[i].name, m.calls[i].name);
|
||||
@@ -285,8 +282,8 @@ TEST(rendered_replies_read_back_as_the_template_wrote_them) {
|
||||
CHECK(read > 10);
|
||||
}
|
||||
|
||||
/* Every prefix of a rendered reply -- a reply the decoder stopped anywhere -- streams to its own
|
||||
* one-shot parse, and a call the reply ended inside reads back as its text. */
|
||||
/* Every prefix of a rendered reply (the decoder stopping anywhere) streams to its own one-shot
|
||||
* parse, and a call cut off mid-way reads back as its text. */
|
||||
TEST(every_truncation_of_a_rendered_reply_keeps_the_contract) {
|
||||
Bench* b = bench(thinking(true));
|
||||
REQUIRE(b != nullptr);
|
||||
@@ -313,9 +310,8 @@ TEST(every_truncation_of_a_rendered_reply_keeps_the_contract) {
|
||||
|
||||
/* ================================================================== the decided shapes
|
||||
*
|
||||
* Replies written the way the model writes them, and the ways it leaves its format. Each reads as
|
||||
* stated, streams under the contract, and -- where `oracle` says so -- agrees with llama.cpp's
|
||||
* parser byte for byte. */
|
||||
* Replies as the model writes them, including ways it leaves its format. Each reads as stated,
|
||||
* streams under the contract, and where `oracle` is set matches llama.cpp's parser byte for byte. */
|
||||
|
||||
struct Call { std::string name, args; bool closed = true; };
|
||||
struct Shape {
|
||||
@@ -358,16 +354,15 @@ static std::vector<Shape> shapes() {
|
||||
",path:" + S("/x")), "", "",
|
||||
{ { "write", "{\"content\":\"{a:1,} [<|tool_call>call:x()<tool_call|>] <channel|> <|\\\" .\","
|
||||
"\"path\":\"/x\"}" } }, true, true },
|
||||
/* Text ending in the start of the delimiter reads as written. (No grammar of this shape
|
||||
* can write it -- llama.cpp's cannot either.) */
|
||||
/* Text ending in the start of the delimiter reads as written (no grammar of this shape,
|
||||
* llama.cpp's included, can produce it). */
|
||||
{ "a string ending in the start of its own delimiter", kOff,
|
||||
G("write", "content:" + S("a <|\"") + ",path:" + S("/x")), "", "",
|
||||
{ { "write", "{\"content\":\"a <|\\\"\",\"path\":\"/x\"}" } }, true, true },
|
||||
/* llama.cpp's key rule takes everything up to the colon, delimiters included, and
|
||||
* hands the client a key `<|"|>path<|"|>`. */
|
||||
/* llama.cpp's key rule keeps the delimiters, yielding the key `<|"|>path<|"|>`. */
|
||||
{ "a key written as a string", kOff, G("read", S("path") + ":" + S("/a")), "", "",
|
||||
{ { "read", "{\"path\":\"/a\"}" } }, true, false },
|
||||
/* And keeps the blank after a number, `"limit":3 }`, which is no JSON. */
|
||||
/* It also keeps the blank after a number, `"limit":3 }`, which is not JSON. */
|
||||
{ "whitespace inside the object", kOff, G("read", " path: " + S("/a") + ",\n limit: 3 "),
|
||||
"", "", { { "read", "{\"path\":\"/a\",\"limit\":3}" } }, true, false },
|
||||
|
||||
@@ -400,9 +395,9 @@ static std::vector<Shape> shapes() {
|
||||
/* leaving the object */
|
||||
{ "a JSON string", kOff, G("bash", "command:\"ls -la\""), "", "",
|
||||
{ { "bash", "{\"command\":\"ls -la\"}" } }, false, false },
|
||||
/* Gemma's plain-quoted values are its own strings with, at most, the quotes escaped
|
||||
* (measured: `code: "const s = \"a\nb\";"` for the JS `const s = "a\nb";`): an
|
||||
* escaped quote is a quote, every other backslash is text. */
|
||||
/* Gemma's plain-quoted values escape at most the quotes (the model writes
|
||||
* `code: "const s = \"a\nb\";"` for the JS `const s = "a\nb";`): an escaped quote is a
|
||||
* quote, every other backslash is text. */
|
||||
{ "a plain-quoted value with its quotes escaped", kOff,
|
||||
G("bash", "command:\"a\\\"b\\\\c\\u00e9\\n\\q\""), "", "",
|
||||
{ { "bash", "{\"command\":\"a\\\"b\\\\\\\\c\\\\u00e9\\\\n\\\\q\"}" } }, false,
|
||||
@@ -411,16 +406,16 @@ static std::vector<Shape> shapes() {
|
||||
G("write", "content:\"const s = \"a\\nb\"; f(\"x\", {y: 1});\",path:" + S("/x")), "", "",
|
||||
{ { "write", "{\"content\":\"const s = \\\"a\\\\nb\\\"; f(\\\"x\\\", {y: 1});\",\"path\":\"/x\"}" } },
|
||||
false, false },
|
||||
/* Measured: asked for nested arguments, the model writes Python's quotes. */
|
||||
/* For nested arguments the model writes Python-style quotes. */
|
||||
{ "single-quoted values, as served", kOff,
|
||||
G("configure", "label: 'prod \"eu\"', extra: {note: 'x: {y}', tags: ['a,b', 'c}']}, mode: 'it\\'s'"),
|
||||
"", "", { { "configure", "{\"label\":\"prod \\\"eu\\\"\",\"extra\":{\"note\":\"x: {y}\",\"tags\":[\"a,b\",\"c}\"]},"
|
||||
"\"mode\":\"it's\"}" } }, false, false },
|
||||
{ "a plain quote closed by the dialect's delimiter", kOff, G("bash", "command:\"ls" + Q), "",
|
||||
"", { { "bash", "{\"command\":\"ls\"}" } }, false, false },
|
||||
/* The model leaves a string unclosed and writes the object's `}` and the call's close
|
||||
* (measured: the close delimiter at p=0.86, `}` at p=0.08). The close ends the string and
|
||||
* the call; the closers before it are the object's. */
|
||||
/* The model may leave a string unclosed before the object's `}` and the call's close
|
||||
* (observed: close delimiter at p=0.86, `}` at p=0.08). The close ends the string and the
|
||||
* call; the closers before it are the object's. */
|
||||
{ "a string the model left open, as served", kOff,
|
||||
"<|tool_call>call:execute{code:" + Q + "const s = \"line1\\nline2\"; console.log(...);}"
|
||||
"<tool_call|><tool_call|><|channel>thought\n<channel|><channel|>"
|
||||
@@ -436,7 +431,7 @@ static std::vector<Shape> shapes() {
|
||||
"<|tool_call>call:configure{extra:{a:[" + Q + "x]}\n}<tool_call|>" + G("bash", "command:" + S("ls")),
|
||||
"", "", { { "configure", "{\"extra\":{\"a\":[\"x\"]}}" }, { "bash", "{\"command\":\"ls\"}" } },
|
||||
false, false },
|
||||
/* Thinking on, measured: the close spelled as a plain quote, and text after the call. */
|
||||
/* Observed with thinking on: the close spelled as a plain quote, and text after the call. */
|
||||
{ "a string closed by a stray quote, text after the call", kOn,
|
||||
"<|tool_call>call:bash{command:" + Q + "f(\"a\");\n\"}<tool_call|>end", "end", "",
|
||||
{ { "bash", "{\"command\":\"f(\\\"a\\\");\\n\"}" } }, false, false },
|
||||
@@ -464,7 +459,7 @@ static std::vector<Shape> shapes() {
|
||||
{ "an object the call's close cuts off", kOff,
|
||||
"<|tool_call>call:configure{extra:{a:[1,{b:" + S("c") + "<tool_call|>" + ls, "", "",
|
||||
{ { "configure", "{\"extra\":{\"a\":[1,{\"b\":\"c\"}]}}" }, { "bash", LS } }, false, false },
|
||||
/* llama.cpp's grammar has no arm for it and reads no call at all. */
|
||||
/* llama.cpp's grammar has no arm for it and reads no call. */
|
||||
{ "a call to a function that is not a tool", kOff, G("frobnicate", "x:1"), "", "",
|
||||
{ { "frobnicate", "{\"x\":1}" } }, false, false },
|
||||
{ "a call written without its wrapper", kOff, "call:bash{command:" + S("ls") + "}", "", "",
|
||||
@@ -498,8 +493,8 @@ TEST(what_gemma_writes_reads_as_decided) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Where the reply is within the format, llama.cpp's own Gemma 4 parser -- run on the generation
|
||||
* prompt and the reply, as its handler runs it -- reads exactly what this one reads. */
|
||||
/* Where the reply is within the format, llama.cpp's Gemma 4 parser (run on generation prompt and
|
||||
* reply, as its handler does) reads exactly what this one reads. */
|
||||
TEST(the_shapes_in_the_format_read_as_llama_cpp_reads_them) {
|
||||
int compared = 0;
|
||||
for (const Shape& s : shapes()) {
|
||||
@@ -545,8 +540,8 @@ TEST(thinking_off_starts_the_reply_after_the_closed_channel) {
|
||||
CHECK(!parser("")->reasoning().starts_open);
|
||||
}
|
||||
|
||||
/* reasoning_format "none": the channel stays in the content as the model wrote it, and with it
|
||||
* the call grammar's break -- a call still ends the text before it. */
|
||||
/* reasoning_format "none": the channel stays in the content as written, and a call still ends
|
||||
* the text before it. */
|
||||
TEST(reasoning_format_none_keeps_the_channel_in_the_content) {
|
||||
std::shared_ptr<const ReplyParser> p = parser(kOn, true, /*reasoning=*/false);
|
||||
const std::string reply = "<|channel>thought\nhm\n<channel|>Yes." +
|
||||
@@ -558,8 +553,8 @@ TEST(reasoning_format_none_keeps_the_channel_in_the_content) {
|
||||
streams(*p, reply, "reasoning none");
|
||||
}
|
||||
|
||||
/* A request that sent no tools reads call syntax as the text it is -- but the thought channel is
|
||||
* still the model's reasoning, wherever it opens. */
|
||||
/* A request without tools reads call syntax as text, but the thought channel is still reasoning
|
||||
* wherever it opens. */
|
||||
TEST(without_tools_a_call_is_text_and_a_late_channel_is_still_reasoning) {
|
||||
std::shared_ptr<const ReplyParser> p = parser(kOff, /*tools=*/false);
|
||||
const std::string reply = "Use <|tool_call>call:bash{} to run it.<|channel>thought\nx\n<channel|>";
|
||||
@@ -580,9 +575,9 @@ TEST(parallel_tool_calls_false_still_reads_a_second_call) {
|
||||
|
||||
/* ================================================================== a conversation
|
||||
*
|
||||
* The turn after a call: the assistant message carries the call, a `role: tool` message its
|
||||
* result, and the template writes both into the model's own turn -- the call in the model's
|
||||
* spelling, the result as a response block -- and leaves the turn open for the model to go on. */
|
||||
* The turn after a call: the assistant message carries the call and a `role: tool` message its
|
||||
* result. The template writes both into the model's turn (the call in the model's spelling, the
|
||||
* result as a response block) and leaves the turn open. */
|
||||
static json conversation(bool two_calls) {
|
||||
json calls = json::array();
|
||||
calls.push_back({ { "id", "c1" }, { "type", "function" },
|
||||
@@ -616,8 +611,8 @@ TEST(a_tool_result_renders_into_the_open_turn_and_the_reply_goes_on) {
|
||||
if (p.prompt.find(want) == std::string::npos)
|
||||
::radtest::fail(__FILE__, __LINE__, "the turn is not rendered as " + quote(want) +
|
||||
"\n prompt: " + quote(p.prompt));
|
||||
/* The model goes on in the same turn: thinking off with nothing written for it,
|
||||
* thinking on inside a channel the template opened. */
|
||||
/* The model continues the same turn: with thinking off nothing is written for it;
|
||||
* with thinking on, inside a channel the template opened. */
|
||||
CHECK_EQ(p.generation_prompt, std::string(on ? kAfter : ""));
|
||||
CHECK(p.prompt.size() >= want.size() &&
|
||||
p.prompt.compare(p.prompt.size() - p.generation_prompt.size() - 0,
|
||||
@@ -667,8 +662,8 @@ TEST(fuzzed_replies_keep_the_contract) {
|
||||
CHECK(n > 0);
|
||||
}
|
||||
|
||||
/* A long reply holds a bounded number of bytes, whatever it holds: a file written into a string
|
||||
* streams as it arrives. */
|
||||
/* A long reply holds a bounded number of bytes: a file written into a string streams as it
|
||||
* arrives. */
|
||||
TEST(a_long_string_streams_and_holds_a_bounded_number_of_bytes) {
|
||||
std::string file;
|
||||
while (file.size() < 200000) file += " x = compute(a, b) # <tag> & \"quoted\" <| ]] \\n\n";
|
||||
@@ -714,7 +709,7 @@ static std::string grammar_for(const ChatGrammarRequest& gq) {
|
||||
}
|
||||
|
||||
/* The lazy call grammar admits every call the template writes and every strict call above, as
|
||||
* llama.cpp's own Gemma 4 grammar does; it refuses what leaves the dialect. */
|
||||
* llama.cpp's Gemma 4 grammar does, and refuses what leaves the dialect. */
|
||||
TEST(the_call_grammar_admits_what_the_model_writes_and_refuses_the_rest) {
|
||||
Bench* b = bench(thinking(true));
|
||||
REQUIRE(b != nullptr);
|
||||
@@ -769,9 +764,8 @@ TEST(the_call_grammar_admits_what_the_model_writes_and_refuses_the_rest) {
|
||||
CHECK_EQ(admits(g.text, "", bad), 0);
|
||||
}
|
||||
|
||||
/* tool_choice "required" makes the grammar the whole reply: from the generation prompt, an
|
||||
* optional thought, then the calls and nothing after them; a named function admits that one, and
|
||||
* parallel_tool_calls false one call. */
|
||||
/* tool_choice "required" constrains the whole reply: an optional thought, then calls and nothing
|
||||
* after. A named function admits only that one; parallel_tool_calls false admits one call. */
|
||||
TEST(a_required_call_is_the_whole_reply) {
|
||||
for (const std::string& gp : { kOff, kOn }) {
|
||||
ChatGrammarRequest gq;
|
||||
@@ -810,9 +804,9 @@ TEST(a_response_format_is_the_whole_reply) {
|
||||
|
||||
/* ================================================================== the server's view
|
||||
*
|
||||
* The chat bridge serves the model from the plugin's declaration: tool requests are no longer
|
||||
* refused, the grammar comes from the format, and the decoder renders the dialect's string
|
||||
* delimiter -- a control token like the format's tags -- so the parser sees it. */
|
||||
* The chat bridge serves the model from the plugin's declaration: tool requests are accepted, the
|
||||
* grammar comes from the format, and the decoder renders the dialect's string delimiter (a control
|
||||
* token like the format's tags) so the parser sees it. */
|
||||
static std::shared_ptr<Vocab> gemma_vocab() {
|
||||
VocabBuild vb;
|
||||
vb.tokens = { "<pad>", "<eos>", "<bos>", "a", "<|tool_call>", "<tool_call|>", "<|tool_response>",
|
||||
@@ -820,7 +814,7 @@ static std::shared_ptr<Vocab> gemma_vocab() {
|
||||
"thought", "call:" };
|
||||
vb.types.assign(vb.tokens.size(), RAD_TT_CONTROL);
|
||||
vb.types[3] = vb.types[13] = vb.types[14] = RAD_TT_NORMAL;
|
||||
/* The letters the markers' text is spelled with, so a marker tokenises whole. */
|
||||
/* The letters the markers are spelled with, so a marker tokenises whole. */
|
||||
for (const char* c : { "t", "h", "o", "u", "g", "c", "l", ":" }) {
|
||||
vb.tokens.push_back(c);
|
||||
vb.types.push_back(RAD_TT_NORMAL);
|
||||
|
||||
+228
-207
@@ -1,27 +1,24 @@
|
||||
/* chatparse_test.cpp -- the streaming reply parser, against the legacy parser in tests/legacy/.
|
||||
*
|
||||
* core/text/chatparse.h reads a reply once, as it streams, from a format description. The legacy
|
||||
* path re-parses the whole reply on every chunk with the PEG parser llama.cpp's auto-parser
|
||||
* generates from the chat template, then trims and lifts calls in a second pass. It is kept in
|
||||
* tests/legacy/ as the ORACLE, and every case here runs both on the same request rendered through
|
||||
* the real template of each model this engine serves (tests/data/chat).
|
||||
* path re-parses the whole reply on every chunk with the PEG parser llama.cpp's auto-parser builds
|
||||
* from the chat template, then trims and lifts calls in a second pass. It is the oracle: every
|
||||
* case runs both on the same request rendered through each served model's real template
|
||||
* (tests/data/chat).
|
||||
*
|
||||
* THE RULE THE COMPARISON ENFORCES (chatdiff::judge). Where both parsers read a reply within the
|
||||
* format's grammar, their answers are IDENTICAL -- content, reasoning, every call's name and
|
||||
* arguments byte for byte. Where the legacy grammar rejects the reply, its answer is the whole
|
||||
* reply as content with calls lifted out by hand, decided only once the reply is complete; a
|
||||
* streaming parser cannot take back what it already sent, and reads such a reply by local
|
||||
* recovery instead (strict() says so). The one other difference: the legacy path also lifts a
|
||||
* call written without the format's call opener out of content (`bare_lift`); the streaming
|
||||
* parser leaves it as the content the grammar says it is.
|
||||
* Comparison rule (chatdiff::judge): where both read a reply within the format's grammar, the
|
||||
* answers are identical byte for byte (content, reasoning, every call's name and arguments).
|
||||
* Where the legacy grammar rejects the reply, it returns the whole reply as content with calls
|
||||
* lifted by hand once complete; a streaming parser cannot retract what it sent, so it recovers
|
||||
* locally instead (strict() reports this). The legacy path also lifts a call written without the
|
||||
* format's opener out of content (`bare_lift`); the streaming parser leaves it as content.
|
||||
*
|
||||
* THE STREAMING CONTRACT, checked on every reply cut every way: one piece, every two-way split,
|
||||
* byte by byte and in token-sized pieces. Every delta is a prefix of the finished value, the
|
||||
* deltas add up to it, it equals the one-shot parse, and the bytes held back never exceed the
|
||||
* format's bound.
|
||||
* Streaming contract, checked at every cut (whole, every two-way split, byte by byte, token-sized):
|
||||
* each delta is a prefix of the final value, the deltas sum to it, it equals the one-shot parse,
|
||||
* and held bytes never exceed the format's bound.
|
||||
*
|
||||
* And the cost: a long reply streamed a byte at a time costs a constant factor of parsing it
|
||||
* once, and twice the reply costs twice the time.
|
||||
* Cost: streaming a long reply byte by byte is a constant factor of parsing it once, and cost is
|
||||
* linear in reply length.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
|
||||
@@ -64,8 +61,8 @@ static std::string fixture(const std::string& dir) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/* One bench per (model, request), built once. A fixture that does not load is a failure, not a
|
||||
* skip: the templates are in the repository. */
|
||||
/* One bench per (model, request), built once. A fixture that does not load fails rather than
|
||||
* skips, since the templates are in the repository. */
|
||||
static Bench* bench(const Model& m, const ChatRequest& rq, const json& tools = agent_tools()) {
|
||||
static std::map<std::string, std::unique_ptr<Bench>> cache;
|
||||
const std::string key = m.name + "|" + describe(rq) + "|" + rq.schema + "|" + tools.dump();
|
||||
@@ -80,14 +77,24 @@ static Bench* bench(const Model& m, const ChatRequest& rq, const json& tools = a
|
||||
return (cache[key] = std::move(b)).get();
|
||||
}
|
||||
|
||||
/* The parser for format `f` under `ro`, as the server builds it: the format compiled, then
|
||||
* bound to the request. Null after a failed check when either step refuses. */
|
||||
static std::shared_ptr<const ReplyParser> parser_of(const ChatFormat& f, const ReplyOptions& ro) {
|
||||
std::string why;
|
||||
std::shared_ptr<const ReplyFormat> rf;
|
||||
std::shared_ptr<const ReplyParser> rp;
|
||||
CHECK_OK(ReplyFormat::compile(f, &rf, &why));
|
||||
if (rf) CHECK_OK(ReplyParser::create(rf, ro, &rp, &why));
|
||||
return rp;
|
||||
}
|
||||
|
||||
/* A reply quoted for a failure message. Mutated replies need not be UTF-8. */
|
||||
static std::string quote(const std::string& s) {
|
||||
return json(s).dump(-1, ' ', false, json::error_handler_t::replace);
|
||||
}
|
||||
|
||||
/* The requests every corpus is read under: what an agent sends, and each switch that changes
|
||||
* what a reply means. */
|
||||
/* The requests every corpus is read under: an agent's request, and each switch that changes what
|
||||
* a reply means. */
|
||||
static std::vector<ChatRequest> requests() {
|
||||
std::vector<ChatRequest> v;
|
||||
v.push_back(ChatRequest{});
|
||||
@@ -120,8 +127,8 @@ static std::vector<size_t> tokenish(const std::string& s, uint32_t seed) {
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Every way of cutting the reply that matters, against its one-shot parse. Two-way splits are
|
||||
* exhaustive for replies up to `split_cap` bytes. */
|
||||
/* Every relevant cut of the reply, against its one-shot parse. Two-way splits are exhaustive for
|
||||
* replies up to `split_cap` bytes. */
|
||||
static std::string stream_all(const ReplyParser& p, const std::string& text, size_t split_cap = 4096) {
|
||||
const ReplyMessage expect = reply_parse(p, text);
|
||||
std::string err = check_stream(p, text, {}, expect);
|
||||
@@ -134,8 +141,8 @@ static std::string stream_all(const ReplyParser& p, const std::string& text, siz
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Read `text` under bench `b`: the differential verdict must be allowed, and every cut of it
|
||||
* must stream to the same answer. Returns the verdict for the caller's own expectations. */
|
||||
/* Read `text` under bench `b`: the differential verdict must be allowed and every cut must stream
|
||||
* to the same answer. Returns the verdict for further checks. */
|
||||
static Verdict run(Bench* b, const std::string& text, const char* what, size_t split_cap = 4096) {
|
||||
Verdict v;
|
||||
if (!b) return v;
|
||||
@@ -155,17 +162,13 @@ static Verdict run(Bench* b, const std::string& text, const char* what, size_t s
|
||||
|
||||
/* ================================================================== corpus 1: rendered replies
|
||||
*
|
||||
* An assistant message rendered through the model's own template is exactly the text the model
|
||||
* is trained to write. Each is read back by both parsers, which must agree and read it within the
|
||||
* grammar, and the calls must come back as the message had them. */
|
||||
* An assistant message rendered through the model's template is the text the model is trained to
|
||||
* write. Both parsers must agree, read it within the grammar, and return the message's calls. */
|
||||
|
||||
/* What the template wrote for an argument, read back: a string argument is its text and any
|
||||
* other one is JSON -- a boolean or null included, which Jinja renders the Python way (`True`,
|
||||
* `None`) and the parser reads back as JSON's. One exception, the template's rendering rather than
|
||||
* the parser's reading: MiniCPM's template prints a value with a bare `{{ param_value }}`, and a
|
||||
* list or an object comes out of this Jinja engine without its brackets. Those are compared by
|
||||
* what the reply says, which the differential check already covers, rather than by what the
|
||||
* message held. */
|
||||
/* An argument as rendered and read back: a string is its text, anything else JSON, including
|
||||
* booleans and null, which Jinja renders Python-style (`True`, `None`). Exception: MiniCPM's
|
||||
* template prints values with a bare `{{ param_value }}`, so lists and objects lose their brackets;
|
||||
* those are covered by the differential check rather than compared with the message. */
|
||||
static bool round_trips(const json& want, const json& got, bool containers) {
|
||||
if (!got.is_object() || want.size() != got.size()) return false;
|
||||
for (auto it = want.begin(); it != want.end(); ++it) {
|
||||
@@ -176,10 +179,9 @@ static bool round_trips(const json& want, const json& got, bool containers) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* A rendered reply the format's own grammar does not admit, and why. The grammar admits one call
|
||||
* when the request asked for no parallel calls; and MiniCPM's grammar ends a value at the first
|
||||
* `</param>`, so a CDATA-wrapped value that contains its own closing tag is split there -- by the
|
||||
* old path's grammar and by this parser alike. */
|
||||
/* A rendered reply the format's grammar does not admit, and why: without parallel calls the
|
||||
* grammar admits one call, and MiniCPM's grammar ends a value at the first `</param>`, so a CDATA
|
||||
* value containing that tag is split there by both parsers. */
|
||||
static bool outside_grammar(const Model& m, const ChatRequest& rq, const json& msg) {
|
||||
const size_t ncalls = msg.contains("tool_calls") ? msg["tool_calls"].size() : 0;
|
||||
if (!rq.parallel && ncalls > 1) return true;
|
||||
@@ -197,7 +199,7 @@ TEST(rendered_replies_read_back_identically_under_every_request) {
|
||||
const json& msg = corpus[i];
|
||||
if (!rq.tools && msg.contains("tool_calls")) continue;
|
||||
const std::string reply = b->render_reply(msg);
|
||||
if (reply.empty()) continue; /* the template does not continue its own prompt */
|
||||
if (reply.empty()) continue; /* the template does not continue its prompt */
|
||||
const std::string what = "rendered reply " + std::to_string(i);
|
||||
const Verdict v = run(b, reply, what.c_str());
|
||||
if (outside_grammar(m, rq, msg)) continue;
|
||||
@@ -224,8 +226,8 @@ TEST(rendered_replies_read_back_identically_under_every_request) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Every rendered reply, cut off after every byte: a truncated reply is read exactly as the legacy
|
||||
* path reads it -- a call in progress stays a call with the arguments that arrived. */
|
||||
/* Every rendered reply truncated after every byte reads as the legacy path reads it: a call in
|
||||
* progress stays a call with the arguments that arrived. */
|
||||
TEST(every_truncation_of_a_rendered_reply_reads_as_the_old_path_did) {
|
||||
const std::vector<json> corpus = rendered_corpus();
|
||||
for (const Model& m : models()) {
|
||||
@@ -251,8 +253,8 @@ TEST(every_truncation_of_a_rendered_reply_reads_as_the_old_path_did) {
|
||||
|
||||
/* ================================================================== corpus 2: adversarial replies
|
||||
*
|
||||
* Hand-written in each format's spelling: the shapes models actually write, and the ones a
|
||||
* streaming parser is easiest to get wrong. */
|
||||
* Hand-written in each format's spelling: shapes models write, and those a streaming parser most
|
||||
* easily gets wrong. */
|
||||
|
||||
TEST(adversarial_replies_agree_with_the_old_path_or_differ_as_documented) {
|
||||
for (const Model& m : models()) {
|
||||
@@ -264,7 +266,7 @@ TEST(adversarial_replies_agree_with_the_old_path_or_differ_as_documented) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The adversarial shapes whose reading is a decision, stated. */
|
||||
/* Adversarial shapes whose reading is a design decision, with the decided result. */
|
||||
static ReplyMessage read_adv(const Model& m, const std::string& name) {
|
||||
Bench* b = bench(m, ChatRequest{});
|
||||
for (const Adversarial& a : adversarial(m))
|
||||
@@ -283,9 +285,8 @@ TEST(the_decided_shapes_read_as_decided) {
|
||||
CHECK_EQ(r.calls.size(), (size_t)1);
|
||||
if (!r.calls.empty()) CHECK(!r.calls[0].closed);
|
||||
|
||||
/* Qwen's reasoning ends where a call starts; MiniCPM's template analysis names no call
|
||||
* opener to end it at, so its unclosed block keeps the call as reasoning, as the legacy
|
||||
* path reads it. */
|
||||
/* Qwen's reasoning ends where a call starts; MiniCPM's analysis names no call opener to
|
||||
* end it at, so an unclosed block keeps the call as reasoning, as the legacy path does. */
|
||||
r = read_adv(m, "unclosed think before a call");
|
||||
CHECK_EQ(r.calls.size(), q ? (size_t)1 : (size_t)0);
|
||||
|
||||
@@ -295,8 +296,8 @@ TEST(the_decided_shapes_read_as_decided) {
|
||||
if (!r.calls.empty())
|
||||
CHECK_EQ(r.calls[0].arguments, std::string("{\"command\":\"sleep\",\"timeout\":\"30 seconds\"}"));
|
||||
|
||||
/* A typed argument always reads as JSON: Python's literals as JSON's, inside a container
|
||||
* too, an empty value as null, and text that spells no JSON value as a string of it.
|
||||
/* A typed argument always reads as JSON: Python literals become JSON's (inside containers
|
||||
* too), an empty value becomes null, and text that is no JSON value becomes a string.
|
||||
* Qwen's format reads non-string arguments as JSON; MiniCPM's reads every one as text. */
|
||||
if (q) {
|
||||
r = read_adv(m, "Python literals");
|
||||
@@ -322,8 +323,8 @@ TEST(the_decided_shapes_read_as_decided) {
|
||||
r = read_adv(m, "a number that is not one");
|
||||
if (!r.calls.empty())
|
||||
CHECK_EQ(r.calls[0].arguments, std::string("{\"path\":\"/a\",\"limit\":\"01\"}"));
|
||||
/* A raw line break or tab inside a string is the escape JSON spells it as: a client's
|
||||
* JSON parser refuses the raw character. */
|
||||
/* A raw line break or tab inside a string is escaped, since JSON parsers refuse the
|
||||
* raw character. */
|
||||
r = read_adv(m, "JSON strings holding a raw line break and tab");
|
||||
CHECK_EQ(r.calls.size(), (size_t)1);
|
||||
if (!r.calls.empty()) {
|
||||
@@ -334,8 +335,8 @@ TEST(the_decided_shapes_read_as_decided) {
|
||||
CHECK(a["extra"]["b"] == json("\tx"));
|
||||
}
|
||||
}
|
||||
/* A container is JSON once normalised, or the string of its text: a trailing comma,
|
||||
* a bare word or a missing bracket is no JSON, and the arguments must stay JSON. */
|
||||
/* A container is normalised JSON, or else its text as a string (trailing comma, bare
|
||||
* word, missing bracket), so the arguments stay JSON. */
|
||||
r = read_adv(m, "Python containers that are no JSON");
|
||||
CHECK_EQ(r.calls.size(), (size_t)1);
|
||||
if (!r.calls.empty())
|
||||
@@ -347,8 +348,8 @@ TEST(the_decided_shapes_read_as_decided) {
|
||||
r = read_adv(m, "an escaped quote in a double-quoted string");
|
||||
if (!r.calls.empty())
|
||||
CHECK_EQ(r.calls[0].arguments, std::string("{\"tags\":[\"it's\", \"x\"]}"));
|
||||
/* The grammar's JSON admits a number past a double's range and an unpaired surrogate
|
||||
* escape, which a client's JSON parser refuses: such a value is its text. */
|
||||
/* The grammar admits a number beyond double range and an unpaired surrogate escape,
|
||||
* which clients' JSON parsers refuse, so such a value becomes its text. */
|
||||
r = read_adv(m, "JSON a client cannot read");
|
||||
if (!r.calls.empty()) {
|
||||
const json a = json::parse(r.calls[0].arguments, nullptr, false);
|
||||
@@ -416,10 +417,10 @@ TEST(the_decided_shapes_read_as_decided) {
|
||||
}
|
||||
}
|
||||
|
||||
/* AN ARGUMENT NAME THAT REPEATS ITS OWN TAG'S OPENING -- `<parameter=parameter=command>`, which
|
||||
* models write and the grammar's undeclared arm admits -- is the argument it names, read
|
||||
* leniently: as the undeclared `parameter=command` the call reaches the tool without its command.
|
||||
* A name the repetition does not make a declared one stays as written. */
|
||||
/* An argument name repeating its tag's opening, `<parameter=parameter=command>` (models write it
|
||||
* and the undeclared arm admits it), is read leniently as the argument it names; otherwise the
|
||||
* tool would get `parameter=command` and no command. A name that does not resolve to a declared
|
||||
* one stays as written. */
|
||||
TEST(an_argument_name_repeating_its_tag_is_the_argument_it_names) {
|
||||
for (const Model& m : models()) {
|
||||
Bench* b = bench(m, ChatRequest{});
|
||||
@@ -444,9 +445,9 @@ TEST(an_argument_name_repeating_its_tag_is_the_argument_it_names) {
|
||||
}
|
||||
}
|
||||
|
||||
/* A CALL THE REPLY ENDED INSIDE reads back, as content, as the text it was written as: the content
|
||||
* before it, then the call's own bytes -- never the reasoning, never a call that closed before it.
|
||||
* What a buffered response answers with when that call cannot be reported as a call. */
|
||||
/* A call the reply ended inside reads back as content in its written form: the content before it,
|
||||
* then the call's bytes, never the reasoning or an earlier closed call. A buffered response uses
|
||||
* this when the call cannot be reported as a call. */
|
||||
TEST(a_call_the_reply_ended_inside_reads_back_as_its_text) {
|
||||
auto trimmed = [](std::string s) {
|
||||
while (!s.empty() && (s.back() == '\n' || s.back() == ' ')) s.pop_back();
|
||||
@@ -493,14 +494,13 @@ TEST(a_call_the_reply_ended_inside_reads_back_as_its_text) {
|
||||
|
||||
/* ================================================================== calls without the wrapper
|
||||
*
|
||||
* Qwen's grammar opens a call at `<tool_call>\n`, and the lazy grammar engages only there -- so a
|
||||
* call the model writes WITHOUT that exact opener is unconstrained, and it is exactly the call that
|
||||
* reaches the parser malformed. Agent transcripts contain calls of these shapes: a bare
|
||||
* Qwen's lazy grammar engages only at `<tool_call>\n`, so a call written without that exact
|
||||
* opener is unconstrained and the likeliest to arrive malformed. Agent transcripts contain a bare
|
||||
* `<function=NAME>` ... `</function>`, or `<tool_call>` run straight into `<function=`. The legacy
|
||||
* path lifts them out of the content in a second pass; the parser reads them as calls in its one
|
||||
* pass, once what follows the name tag shows it is a call, and says the reply left its grammar.
|
||||
* path lifts these in a second pass; the parser reads them as calls in one pass once what follows
|
||||
* the name tag shows a call, and reports that the reply left its grammar.
|
||||
*
|
||||
* Each shape is read whole and cut every way, and compared with the legacy path's answer. */
|
||||
* Each shape is read whole and at every cut, and compared with the legacy path. */
|
||||
|
||||
static std::string qbare(const std::string& name,
|
||||
const std::vector<std::pair<std::string, std::string>>& args) {
|
||||
@@ -514,7 +514,7 @@ struct Shape {
|
||||
size_t calls;
|
||||
bool strict; /* the reply stays within the grammar: nothing was read as a loose call */
|
||||
/* The opener is inside the reasoning block the generation prompt opened. With thinking off
|
||||
* the prompt has closed that block already, the text is content, and the call is a call. */
|
||||
* the prompt already closed it, so the text is content and the call is a call. */
|
||||
bool in_reasoning = false;
|
||||
};
|
||||
|
||||
@@ -530,13 +530,13 @@ static std::vector<Shape> bare_shapes() {
|
||||
{ "two bare calls", T + ls + "\n" + rd, 2, false },
|
||||
{ "two bare calls with a sentence between", T + ls + "\nNow the file.\n" + rd, 2, false },
|
||||
{ "a bare call with no arguments", T + "<function=which gcc cc>\n</function>", 1, false },
|
||||
/* The first argument's name is what makes the opener a call, and it is held while it is
|
||||
* read: a tag name, not a delimiter, however long. */
|
||||
/* The first argument's name confirms the call, so it is held while read: a tag name of
|
||||
* any length, not a delimiter. */
|
||||
{ "a bare call whose first argument name is long",
|
||||
T + "<function=bash>\n<parameter=" + std::string(200, 'x') + ">\nls\n</parameter>\n</function>",
|
||||
1, false },
|
||||
/* Unconstrained, the model need not write the newlines the template puts around each
|
||||
* tag; a loose call's tags are read with that whitespace optional. */
|
||||
/* Unconstrained, the model may omit the newlines the template puts around each tag, so
|
||||
* that whitespace is optional in a loose call. */
|
||||
{ "a bare call written without newlines",
|
||||
T + "<function=bash><parameter=command>ls -la</parameter></function>", 1, false },
|
||||
{ "the wrapper without its newline",
|
||||
@@ -554,7 +554,7 @@ static std::vector<Shape> bare_shapes() {
|
||||
{ "the wrapper and opener in prose", T + "Write `<tool_call><function=f>` first.", 0, true },
|
||||
{ "a bare opener whose tag never closes", T + "See <function=bash and more.", 0, true },
|
||||
{ "a bare opener at the very end", T + "Next: <function=ba", 0, true },
|
||||
/* An argument name that runs into a tag is no argument: the opener was text. */
|
||||
/* An argument name that runs into a tag is not an argument; the opener was text. */
|
||||
{ "a bare opener whose argument name runs into a tag",
|
||||
T + "<function=bash>\n<parameter=com\nls\n</parameter>\n</function>", 0, true },
|
||||
{ "a bare opener whose long argument name runs into a tag",
|
||||
@@ -590,7 +590,7 @@ TEST(a_qwen_call_without_its_wrapper_is_a_call_as_the_old_path_read_it) {
|
||||
CHECK(c.closed);
|
||||
CHECK(server::json_complete(c.arguments));
|
||||
}
|
||||
/* Nothing of a call read loosely is ever left in the content. */
|
||||
/* No part of a loosely read call is left in the content. */
|
||||
if (s.calls > 0 && !s.strict) {
|
||||
CHECK(r.content.find("<function=") == std::string::npos);
|
||||
CHECK(r.content.find("<parameter=") == std::string::npos);
|
||||
@@ -601,8 +601,8 @@ TEST(a_qwen_call_without_its_wrapper_is_a_call_as_the_old_path_read_it) {
|
||||
}
|
||||
}
|
||||
|
||||
/* WHERE THE LEGACY PATH ANSWERS DIFFERENTLY, and why. Each is asserted as the parser reads it,
|
||||
* beside what the legacy path returns, so a change to either is seen. */
|
||||
/* Where the legacy path answers differently, and why. Both answers are asserted so a change to
|
||||
* either is noticed. */
|
||||
TEST(a_bare_call_differs_from_the_old_path_only_where_the_old_path_was_wrong) {
|
||||
for (const Model& m : models()) {
|
||||
if (!is_qwen(m)) continue;
|
||||
@@ -610,11 +610,10 @@ TEST(a_bare_call_differs_from_the_old_path_only_where_the_old_path_was_wrong) {
|
||||
if (!b) continue;
|
||||
const std::string T = "Thinking it over.\n</think>\n\n";
|
||||
|
||||
/* The legacy lifter knows no schema, so a typed argument comes back as a string; and it
|
||||
* trims every value, which eats the indentation of an edit's first line -- the defect
|
||||
* vendor/patches/0005 fixes on the grammar path. The parser types the value from the
|
||||
* schema and strips only the newline the format puts around it, as it does inside the
|
||||
* wrapper. */
|
||||
/* The legacy lifter has no schema, so typed arguments come back as strings, and it trims
|
||||
* every value, losing an edit's first-line indentation (vendor/patches/0005 fixes this on
|
||||
* the grammar path). The parser types values from the schema and strips only the
|
||||
* format's delimiting newline, as inside the wrapper. */
|
||||
{
|
||||
const std::string text =
|
||||
T + qbare("read", { { "path", "/work/a.py" }, { "limit", "40" } }) + "\n" +
|
||||
@@ -629,7 +628,7 @@ TEST(a_bare_call_differs_from_the_old_path_only_where_the_old_path_was_wrong) {
|
||||
std::string("{\"path\":\"/work/b.py\",\"content\":\"return a + b\"}"));
|
||||
CHECK_EQ(r.calls[1].arguments,
|
||||
std::string("{\"path\":\"/work/b.py\",\"content\":\" return a + b\"}"));
|
||||
/* And read inside the wrapper, the same call gives the same arguments. */
|
||||
/* Inside the wrapper the same call gives the same arguments. */
|
||||
const ReplyMessage w = b->new_parse(
|
||||
T + "<tool_call>\n" + qbare("read", { { "path", "/work/a.py" }, { "limit", "40" } }) +
|
||||
"\n</tool_call>");
|
||||
@@ -637,8 +636,8 @@ TEST(a_bare_call_differs_from_the_old_path_only_where_the_old_path_was_wrong) {
|
||||
CHECK_EQ(w.calls[0].arguments, r.calls[0].arguments);
|
||||
}
|
||||
|
||||
/* The legacy lifter runs only when nothing else parses as a call, so a bare call beside a
|
||||
* wrapped one stays in the content as XML. */
|
||||
/* The legacy lifter runs only when nothing else parses as a call, so it leaves a bare
|
||||
* call beside a wrapped one in the content as XML. */
|
||||
{
|
||||
const std::string text = T + qbare("bash", { { "command", "ls" } }) +
|
||||
"\n<tool_call>\n" + qbare("read", { { "path", "/a" } }) +
|
||||
@@ -654,9 +653,9 @@ TEST(a_bare_call_differs_from_the_old_path_only_where_the_old_path_was_wrong) {
|
||||
CHECK(r.content.empty());
|
||||
}
|
||||
|
||||
/* The legacy lifter drops a whole call when a LATER argument name runs into a tag. By then
|
||||
* the call has streamed, so it ends at that argument, with the arguments before it, and
|
||||
* the rest is content. */
|
||||
/* The legacy lifter drops a whole call when a later argument name runs into a tag. The
|
||||
* call has already streamed by then, so it ends at that argument and the rest is
|
||||
* content. */
|
||||
{
|
||||
const std::string text = T + "<function=bash>\n<parameter=command>\nls\n</parameter>\n"
|
||||
"<parameter=x<y>\n1\n</parameter>\n</function>";
|
||||
@@ -671,9 +670,9 @@ TEST(a_bare_call_differs_from_the_old_path_only_where_the_old_path_was_wrong) {
|
||||
CHECK(b->old_parse(text).calls.empty());
|
||||
}
|
||||
|
||||
/* The legacy lifter leaves a bare call cut off mid-argument as content, since it reads
|
||||
* only what it can read end to end; a stream has already announced the call by then, so
|
||||
* it is a call whose arguments did not finish -- as a wrapped call cut off there is. */
|
||||
/* The legacy lifter leaves a bare call cut off mid-argument as content. A stream has
|
||||
* already announced the call, so it is a call with unfinished arguments, as a wrapped
|
||||
* call cut off there is. */
|
||||
{
|
||||
const std::string text = T + "<function=bash>\n<parameter=command>\nls -";
|
||||
const Verdict v = run(b, text, "truncated bare call");
|
||||
@@ -687,9 +686,9 @@ TEST(a_bare_call_differs_from_the_old_path_only_where_the_old_path_was_wrong) {
|
||||
}
|
||||
}
|
||||
|
||||
/* MiniCPM's calls are not wrapped: its opener is `<function name="` alone, which its grammar
|
||||
* already opens a call with. None of the above applies: its content automaton has its one opener,
|
||||
* a call is strict, and Qwen's spellings in its content are content. */
|
||||
/* MiniCPM's calls are unwrapped: its opener is `<function name="`, which its grammar already
|
||||
* opens a call with. So none of the above applies: a call is strict and Qwen's spellings in its
|
||||
* content are content. */
|
||||
TEST(minicpm_reads_with_no_loose_opener) {
|
||||
const Model& m = models()[2];
|
||||
REQUIRE(!is_qwen(m));
|
||||
@@ -709,7 +708,7 @@ TEST(minicpm_reads_with_no_loose_opener) {
|
||||
CHECK(v.strict);
|
||||
CHECK_EQ(b->new_parse(text).calls.size(), n);
|
||||
}
|
||||
/* A Qwen-spelled call in a MiniCPM reply is that model's content, left in place. */
|
||||
/* A Qwen-spelled call in a MiniCPM reply is content, left in place. */
|
||||
const std::string q = T + "<tool_call>\n" + qbare("bash", { { "command", "ls" } }) + "\n</tool_call>";
|
||||
bool strict = false;
|
||||
const ReplyMessage r = b->new_parse(q, &strict);
|
||||
@@ -720,11 +719,10 @@ TEST(minicpm_reads_with_no_loose_opener) {
|
||||
|
||||
/* ================================================================== corpus 3: fuzz
|
||||
*
|
||||
* Random replies assembled from each format's own fragments -- which is what reaches the deep
|
||||
* states -- and random byte mutations of every corpus reply. Both parsers read each one; the
|
||||
* verdict must be allowed and every cut must stream to the same answer. Mutations may break
|
||||
* UTF-8, which no reply ever does once the decoder has sanitised it: the comparison runs on the
|
||||
* sanitised text, and the raw bytes are fed too, for the invariants alone. */
|
||||
* Random replies assembled from each format's fragments (to reach deep states) and random byte
|
||||
* mutations of every corpus reply. The verdict must be allowed and every cut must stream to the
|
||||
* same answer. Mutations may break UTF-8, which the decoder always sanitises, so the comparison
|
||||
* runs on sanitised text and the raw bytes are fed only to check invariants. */
|
||||
|
||||
TEST(fuzzed_replies_never_break_the_contract) {
|
||||
std::mt19937 rng(20260924);
|
||||
@@ -745,7 +743,7 @@ TEST(fuzzed_replies_never_break_the_contract) {
|
||||
} else {
|
||||
text = mutate(rng, seeds[rng() % seeds.size()], frag);
|
||||
}
|
||||
/* The raw bytes, for the invariants: no crash, and the stream agrees with itself. */
|
||||
/* Raw bytes: no crash, and the stream agrees with itself. */
|
||||
const std::string raw = stream_all(b->parser(), text, 0);
|
||||
if (!raw.empty())
|
||||
::radtest::fail(__FILE__, __LINE__, m.name + " raw fuzz: " + raw + "\n reply: " +
|
||||
@@ -770,8 +768,7 @@ TEST(fuzzed_replies_never_break_the_contract) {
|
||||
|
||||
/* ================================================================== response formats
|
||||
*
|
||||
* With a response format the reply is one JSON document, optionally fenced, and the document is
|
||||
* the content. */
|
||||
* With a response format the reply is one JSON document, optionally fenced, and is the content. */
|
||||
TEST(response_format_replies_read_as_the_old_path_read_them) {
|
||||
const std::string schema = R"({"type":"object","properties":{"answer":{"type":"string"},)"
|
||||
R"("n":{"type":"integer"}},"required":["answer"]})";
|
||||
@@ -802,8 +799,8 @@ TEST(response_format_replies_read_as_the_old_path_read_them) {
|
||||
|
||||
/* ================================================================== the grammar
|
||||
*
|
||||
* For a template-analysed format the grammar generated from the description is the vendored
|
||||
* generator's grammar, byte for byte, and accepts and rejects the same call text. */
|
||||
* For a template-analysed format the grammar generated from the description equals the vendored
|
||||
* generator's byte for byte and accepts and rejects the same call text. */
|
||||
|
||||
static std::vector<json> tool_sets() {
|
||||
std::vector<json> v;
|
||||
@@ -819,8 +816,8 @@ static std::vector<json> tool_sets() {
|
||||
return v;
|
||||
}
|
||||
|
||||
/* The rules one grammar has and the other does not, marked - for the vendored and + for the
|
||||
* generated. Both list their rules sorted by name, one to a line. */
|
||||
/* Rules in only one grammar, marked - for vendored and + for generated. Both list rules sorted by
|
||||
* name, one per line. */
|
||||
static std::string line_diff(const std::string& a, const std::string& b) {
|
||||
auto lines = [](const std::string& s) {
|
||||
std::vector<std::string> v;
|
||||
@@ -872,8 +869,8 @@ TEST(the_generated_grammar_is_the_vendored_grammar) {
|
||||
CHECK(compared > 0);
|
||||
}
|
||||
|
||||
/* The call section of every rendered reply is admitted by both grammars, and a mutated one is
|
||||
* admitted by both or by neither. */
|
||||
/* Both grammars admit every rendered reply's call section, and a mutated one by both or
|
||||
* neither. */
|
||||
TEST(the_generated_grammar_accepts_what_the_vendored_one_accepts) {
|
||||
log_set_level(Log::Error);
|
||||
std::mt19937 rng(7);
|
||||
@@ -888,7 +885,7 @@ TEST(the_generated_grammar_accepts_what_the_vendored_one_accepts) {
|
||||
CHECK_OK(chat_format_grammar(b->format(), gq, &g, &why));
|
||||
const std::string opener = b->format().call_open;
|
||||
const std::vector<std::string> frag = fragments(m);
|
||||
/* A vocabulary of the printable bytes: the grammar walks text, and no mask is asked for. */
|
||||
/* A vocabulary of printable bytes: the grammar walks text and no mask is requested. */
|
||||
static const SimpleVocab vocab = [] {
|
||||
SimpleVocab v;
|
||||
for (int c = 32; c < 127; ++c) v.add(std::string(1, (char)c));
|
||||
@@ -918,10 +915,9 @@ TEST(the_generated_grammar_accepts_what_the_vendored_one_accepts) {
|
||||
log_set_level(Log::Warn);
|
||||
}
|
||||
|
||||
/* A REQUIRED CALL IS THE WHOLE REPLY: from the generation prompt the sampler feeds it, the
|
||||
* reasoning block and then the calls, with no prose before them and nothing after them -- so a
|
||||
* complete grammar admits only the end of the turn and the reply stops at the last call. A named
|
||||
* function admits that function alone, and `parallel_tool_calls: false` one call. */
|
||||
/* A required call constrains the whole reply: after the generation prompt, the reasoning block and
|
||||
* then the calls, with no prose before or after, so the reply ends at the last call. A named
|
||||
* function admits only that function; `parallel_tool_calls: false` admits one call. */
|
||||
TEST(a_required_call_grammar_is_the_whole_reply) {
|
||||
log_set_level(Log::Error);
|
||||
static const SimpleVocab vocab = [] {
|
||||
@@ -950,7 +946,7 @@ TEST(a_required_call_grammar_is_the_whole_reply) {
|
||||
return g.text;
|
||||
};
|
||||
/* 1 complete, 0 admitted but unfinished or refused. The sampler feeds the generation
|
||||
* prompt first (SamplingParams::grammar_prefix), so the reply is read after it. */
|
||||
* prompt first (SamplingParams::grammar_prefix). */
|
||||
auto admits = [&](const std::string& gbnf, const std::string& reply) {
|
||||
std::unique_ptr<GbnfGrammar> gr;
|
||||
std::string err;
|
||||
@@ -1022,13 +1018,13 @@ TEST(the_derived_formats_are_the_ones_in_service) {
|
||||
CHECK(f.triggers.empty());
|
||||
CHECK(f.reasoning_breaks.empty());
|
||||
}
|
||||
/* The decoder is told the same markers the vendored analysis named. */
|
||||
/* The decoder gets the same markers the vendored analysis named. */
|
||||
Bench* b = bench(m, ChatRequest{});
|
||||
if (b) CHECK(chat_format_markers(f) == b->prompt().preserved_tokens);
|
||||
}
|
||||
}
|
||||
|
||||
/* The ChatML fallback -- a model with no template -- has neither reasoning nor calls. */
|
||||
/* The ChatML fallback (a model with no template) has neither reasoning nor calls. */
|
||||
TEST(no_template_is_a_format_with_no_reasoning_and_no_calls) {
|
||||
ChatFormat f;
|
||||
std::string refused, why;
|
||||
@@ -1042,7 +1038,7 @@ TEST(no_template_is_a_format_with_no_reasoning_and_no_calls) {
|
||||
CHECK_OK(ReplyParser::create(rf, ro, &rp, &why));
|
||||
const ReplyMessage r = reply_parse(*rp, " <think>x</think> <tool_call>\n");
|
||||
CHECK_EQ(r.content, std::string(" <think>x</think> <tool_call>"));
|
||||
/* And a request with tools is refused, naming why. */
|
||||
/* A request with tools is refused with the reason. */
|
||||
const json tools = agent_tools();
|
||||
ro.tools = &tools;
|
||||
CHECK(ReplyParser::create(rf, ro, &rp, &why) == RAD_E_UNSUPPORTED);
|
||||
@@ -1080,10 +1076,10 @@ static RadChatFormat qwen_abi() {
|
||||
return c;
|
||||
}
|
||||
|
||||
/* WHERE THE REPLY STARTS AGAINST ITS REASONING BLOCK, read from the generation prompt as the stream
|
||||
* reads it: opened by the prompt, opened and closed again (thinking off), or not opened at all --
|
||||
* and the markers trimmed of the whitespace that is optional to match. The engine counts and closes
|
||||
* the block by these, so a reply this calls open has to be one the stream reads as reasoning. */
|
||||
/* Where the reply starts relative to its reasoning block, read from the generation prompt as the
|
||||
* stream reads it: opened, opened and closed (thinking off), or not opened, with markers trimmed of
|
||||
* optional whitespace. The engine counts and closes the block by these, so a reply reported open
|
||||
* must be one the stream reads as reasoning. */
|
||||
TEST(the_parser_says_whether_a_reply_starts_inside_its_reasoning_block) {
|
||||
RadChatFormat c = qwen_abi();
|
||||
ChatFormat f;
|
||||
@@ -1109,15 +1105,14 @@ TEST(the_parser_says_whether_a_reply_starts_inside_its_reasoning_block) {
|
||||
|
||||
ChatFormat none;
|
||||
CHECK_OK(chat_format_from_template("", "", "", &none, &why, &why));
|
||||
CHECK_OK(ReplyFormat::compile(none, &rf, &why));
|
||||
std::shared_ptr<const ReplyParser> rp;
|
||||
CHECK_OK(ReplyParser::create(rf, ReplyOptions{}, &rp, &why));
|
||||
const std::shared_ptr<const ReplyParser> rp = parser_of(none, ReplyOptions{});
|
||||
REQUIRE(rp);
|
||||
CHECK(rp->reasoning().close.empty());
|
||||
CHECK(!rp->reasoning().starts_open);
|
||||
}
|
||||
|
||||
/* A plugin that declares its model's format gets exactly what the template analysis derives for
|
||||
* the same model: the same parser behaviour and the same grammar. */
|
||||
/* A plugin-declared format behaves exactly as the template-derived one: same parser, same
|
||||
* grammar. */
|
||||
TEST(a_declared_format_reads_and_constrains_like_the_derived_one) {
|
||||
const Model& m = models()[0];
|
||||
RadChatFormat c = qwen_abi();
|
||||
@@ -1132,14 +1127,12 @@ TEST(a_declared_format_reads_and_constrains_like_the_derived_one) {
|
||||
CHECK(chat_format_describe(derived) == chat_format_describe(declared));
|
||||
CHECK(chat_format_markers(derived) == chat_format_markers(declared));
|
||||
|
||||
std::shared_ptr<const ReplyFormat> rf;
|
||||
CHECK_OK(ReplyFormat::compile(declared, &rf, &why));
|
||||
ReplyOptions ro;
|
||||
ro.generation_prompt = b->prompt().generation_prompt;
|
||||
ro.tools = &agent_tools();
|
||||
ro.terminators = m.terminators;
|
||||
std::shared_ptr<const ReplyParser> rp;
|
||||
CHECK_OK(ReplyParser::create(rf, ro, &rp, &why));
|
||||
const std::shared_ptr<const ReplyParser> rp = parser_of(declared, ro);
|
||||
REQUIRE(rp);
|
||||
for (const json& msg : rendered_corpus()) {
|
||||
const std::string reply = b->render_reply(msg);
|
||||
CHECK(same(reply_parse(*rp, reply), b->new_parse(reply)));
|
||||
@@ -1152,10 +1145,9 @@ TEST(a_declared_format_reads_and_constrains_like_the_derived_one) {
|
||||
CHECK_EQ(g.text, b->prompt().grammar);
|
||||
}
|
||||
|
||||
/* oh-my-pi's `task` tool in its batch form: `"model?": "never"`, which Arktype exports as
|
||||
* `{"not": {}}`. A schema no value satisfies needs no arm, and the declared format and the derived
|
||||
* one agree about that as they agree about everything else. Before, both refused the tool and the
|
||||
* request with it. */
|
||||
/* oh-my-pi's `task` tool in batch form: `"model?": "never"`, which Arktype exports as
|
||||
* `{"not": {}}`. A schema no value satisfies gets no arm, and the declared and derived formats
|
||||
* agree on it. */
|
||||
TEST(an_argument_no_value_satisfies_has_no_arm_in_either_grammar) {
|
||||
const json tools = json::parse(R"([{"type":"function","function":{"name":"task",
|
||||
"description":"Spawn subagents.","parameters":{"type":"object","properties":{
|
||||
@@ -1182,8 +1174,8 @@ TEST(an_argument_no_value_satisfies_has_no_arm_in_either_grammar) {
|
||||
CHECK_OK(chat_format_grammar(declared, gq, &g, &why));
|
||||
CHECK_EQ(g.text, b->prompt().grammar);
|
||||
|
||||
/* And the parser reads such an argument as the grammar does, by the undeclared arm: text,
|
||||
* though its value spells JSON. */
|
||||
/* The parser reads such an argument via the undeclared arm, as the grammar does: as text,
|
||||
* even when it spells JSON. */
|
||||
const std::string reply = "Thinking it over.\n</think>\n\n" +
|
||||
C(models()[0], "task", { { "context", "c" }, { "tasks", "[]" }, { "model", "123" } });
|
||||
const Verdict v = run(b, reply, "an argument no value satisfies");
|
||||
@@ -1193,10 +1185,10 @@ TEST(an_argument_no_value_satisfies_has_no_arm_in_either_grammar) {
|
||||
CHECK_EQ(r.calls[0].arguments, std::string("{\"context\":\"c\",\"tasks\":[],\"model\":\"123\"}"));
|
||||
}
|
||||
|
||||
/* OH-MY-PI 18.6.0's TOOLS AS AN UNMODIFIED CLIENT SENDS THEM (tests/data/chat), descriptions aside.
|
||||
* Its `task` tool spells the optional `model` as the `not` of a union of all six JSON types rather
|
||||
* than `{"not": {}}`, which is `never` all the same; the declared format must give it no arm and
|
||||
* agree with the derived format about the whole tool set, as it does about every other. */
|
||||
/* oh-my-pi 18.6.0's tools as the client sends them (tests/data/chat), without descriptions. Its
|
||||
* `task` tool spells the optional `model` as `not` of a union of all six JSON types, which is also
|
||||
* `never`; the declared format gives it no arm and agrees with the derived format on the whole
|
||||
* tool set. */
|
||||
TEST(oh_my_pis_tools_build_the_same_grammar_in_either_format) {
|
||||
std::ifstream f(std::string(RAD_CHAT_FIXTURES) + "/oh-my-pi-18.6.0-tools.json");
|
||||
std::ostringstream ss;
|
||||
@@ -1224,9 +1216,9 @@ TEST(oh_my_pis_tools_build_the_same_grammar_in_either_format) {
|
||||
CHECK_EQ(g.text, b->prompt().grammar);
|
||||
}
|
||||
|
||||
/* THE STRUCT GROWS AT ITS END. A plugin built against a header with fewer fields reports a smaller
|
||||
* struct_size, and the fields past it read as zero; one built against a larger header has its
|
||||
* extra fields ignored. Nothing is read past what the plugin said it has. */
|
||||
/* The struct grows at its end. A plugin built against an older header reports a smaller
|
||||
* struct_size and the missing fields read as zero; extra fields from a newer header are ignored.
|
||||
* Nothing is read past the reported size. */
|
||||
TEST(the_declaration_reads_only_what_the_plugin_compiled) {
|
||||
RadChatFormat c = qwen_abi();
|
||||
ChatFormat f;
|
||||
@@ -1251,7 +1243,7 @@ TEST(the_declaration_reads_only_what_the_plugin_compiled) {
|
||||
CHECK(chat_format_from_abi(nullptr, &f, &why) == RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* What the parser cannot read is refused by name, never guessed at. */
|
||||
/* What the parser cannot read is refused by name, never guessed. */
|
||||
TEST(a_format_the_parser_cannot_read_is_refused_by_name) {
|
||||
auto refused = [](void (*edit)(RadChatFormat&), const char* word) {
|
||||
RadChatFormat c = qwen_abi();
|
||||
@@ -1276,8 +1268,8 @@ TEST(a_format_the_parser_cannot_read_is_refused_by_name) {
|
||||
CHECK(refused([](RadChatFormat& c) { c.string_value = RAD_CHAT_VALUE_JSON; }, "string_value"));
|
||||
}
|
||||
|
||||
/* A tool whose own name contains the delimiter that ends a name cannot be read unambiguously in
|
||||
* this format: the request is refused at admission, naming the tool. */
|
||||
/* A tool whose name contains the name-ending delimiter is ambiguous in this format; the request
|
||||
* is refused at admission, naming the tool. */
|
||||
TEST(a_tool_name_holding_the_format_delimiter_is_refused_at_admission) {
|
||||
Bench* b = bench(models()[0], ChatRequest{});
|
||||
if (!b) return;
|
||||
@@ -1299,25 +1291,18 @@ TEST(a_tool_name_holding_the_format_delimiter_is_refused_at_admission) {
|
||||
|
||||
/* ================================================================== the wire
|
||||
*
|
||||
* What a streaming client assembles from the SSE chunks -- content, reasoning, each call's id,
|
||||
* name and arguments -- is the buffered answer, for every reply, cut a byte at a time. Every
|
||||
* chunk is the bytes nlohmann writes for the value it carries: the delta chunks are written
|
||||
* directly rather than through a tree, and are held to it here. */
|
||||
* What a streaming client assembles from the SSE chunks (content, reasoning, each call's id, name
|
||||
* and arguments) equals the buffered answer, for every reply cut a byte at a time. Delta chunks
|
||||
* are written directly rather than through a JSON tree, and must match nlohmann's bytes. */
|
||||
TEST(what_a_streaming_client_assembles_is_the_buffered_answer) {
|
||||
for (const Model& m : models()) {
|
||||
Bench* b = bench(m, ChatRequest{});
|
||||
if (!b) continue;
|
||||
std::shared_ptr<const ReplyParser> rp;
|
||||
{
|
||||
std::shared_ptr<const ReplyFormat> rf;
|
||||
std::string why;
|
||||
CHECK_OK(ReplyFormat::compile(b->format(), &rf, &why));
|
||||
ReplyOptions ro;
|
||||
ro.generation_prompt = b->prompt().generation_prompt;
|
||||
ro.tools = &agent_tools();
|
||||
ro.terminators = m.terminators;
|
||||
CHECK_OK(ReplyParser::create(rf, ro, &rp, &why));
|
||||
}
|
||||
ReplyOptions ro;
|
||||
ro.generation_prompt = b->prompt().generation_prompt;
|
||||
ro.tools = &agent_tools();
|
||||
ro.terminators = m.terminators;
|
||||
const std::shared_ptr<const ReplyParser> rp = parser_of(b->format(), ro);
|
||||
server::ReplyParserBridge bridge(rp);
|
||||
std::vector<std::string> replies;
|
||||
for (const json& msg : rendered_corpus()) replies.push_back(b->render_reply(msg));
|
||||
@@ -1371,7 +1356,7 @@ TEST(what_a_streaming_client_assembles_is_the_buffered_answer) {
|
||||
CHECK_EQ(args[k], want.calls[k].arguments);
|
||||
CHECK_EQ(p.tool_calls[k].id, ids[k]);
|
||||
}
|
||||
/* A call is reported as one only when it closed and its arguments parse. */
|
||||
/* A call is reported only when it closed and its arguments parse. */
|
||||
bool complete = !want.calls.empty() && want.calls.back().closed;
|
||||
for (const ReplyCall& c : want.calls) complete = complete && server::json_complete(c.arguments);
|
||||
CHECK_EQ(finish, std::string(complete ? "tool_calls" : "stop"));
|
||||
@@ -1381,10 +1366,10 @@ TEST(what_a_streaming_client_assembles_is_the_buffered_answer) {
|
||||
|
||||
/* ================================================================== the chat bridge
|
||||
*
|
||||
* What the server is handed for a request is all derived from ONE format: the grammar and its
|
||||
* trigger words, the tokens the decoder must render, and the parser. A plugin's declaration of
|
||||
* the same format yields the same request; a declaration the parser cannot run stops the chat
|
||||
* endpoint at startup; a template whose calls it cannot describe has its tool requests refused. */
|
||||
* Everything the server gets for a request derives from one format: the grammar and its triggers,
|
||||
* the tokens the decoder renders, and the parser. A plugin's declaration of the same format yields
|
||||
* the same request; an unrunnable declaration stops the chat endpoint at startup; a template whose
|
||||
* calls cannot be described has its tool requests refused. */
|
||||
|
||||
static std::shared_ptr<Vocab> vocab_with(const std::string& tmpl) {
|
||||
VocabBuild vb;
|
||||
@@ -1435,7 +1420,7 @@ TEST(the_chat_bridge_derives_the_whole_request_from_one_format) {
|
||||
REQUIRE(pm.tool_calls.size() == 1);
|
||||
CHECK_EQ(pm.tool_calls[0].arguments, std::string("{\"path\":\"/a\",\"limit\":3}"));
|
||||
|
||||
/* The same format, declared by a plugin: the same request. */
|
||||
/* The same format declared by a plugin yields the same request. */
|
||||
RadChatFormat c = qwen_abi();
|
||||
server::ChatTemplateBridge declared;
|
||||
CHECK_OK(declared.init(*v, &c, "radtest"));
|
||||
@@ -1444,12 +1429,12 @@ TEST(the_chat_bridge_derives_the_whole_request_from_one_format) {
|
||||
CHECK(d.grammar_triggers.size() == 1 && d.grammar_triggers[0].value == "<tool_call>\n");
|
||||
CHECK(d.preserved_tokens == r.preserved_tokens);
|
||||
|
||||
/* A declaration the parser cannot run is refused at startup, naming the field. */
|
||||
/* An unrunnable declaration is refused at startup, naming the field. */
|
||||
c.call_separator = ", ";
|
||||
server::ChatTemplateBridge broken;
|
||||
CHECK(broken.init(*v, &c, "radtest") < 0);
|
||||
|
||||
/* A tool this format cannot read unambiguously is refused at admission, naming it. */
|
||||
/* An ambiguous tool is refused at admission, by name. */
|
||||
std::string why;
|
||||
const server::ChatRender bad = bridge_render(
|
||||
derived, json::parse(R"([{"type":"function","function":{"name":"a>b"}}])"), &why);
|
||||
@@ -1457,9 +1442,8 @@ TEST(the_chat_bridge_derives_the_whole_request_from_one_format) {
|
||||
CHECK(why.find("a>b") != std::string::npos);
|
||||
}
|
||||
|
||||
/* A template that writes each call as a JSON object is a format this parser does not describe:
|
||||
* the model still chats with its reasoning split, and a request with tools is refused with the
|
||||
* reason instead of being read by some other parser. */
|
||||
/* A template writing each call as a JSON object is not a describable format: the model still
|
||||
* chats with reasoning split, and a request with tools is refused with the reason. */
|
||||
TEST(a_template_whose_calls_cannot_be_described_refuses_tools_and_still_chats) {
|
||||
const std::string tmpl =
|
||||
"{%- if tools -%}<|im_start|>system\n# Tools\n{%- for t in tools %}\n{{ t | tojson }}"
|
||||
@@ -1476,7 +1460,7 @@ TEST(a_template_whose_calls_cannot_be_described_refuses_tools_and_still_chats) {
|
||||
REQUIRE(v != nullptr);
|
||||
server::ChatTemplateBridge br;
|
||||
CHECK_OK(br.init(*v));
|
||||
if (!br.supports_tools()) return; /* the probe saw no tool support at all: nothing to refuse */
|
||||
if (!br.supports_tools()) return; /* no tool support probed, nothing to refuse */
|
||||
CHECK(!br.tool_refusal().empty());
|
||||
const server::ChatRender r = bridge_render(br, json::array());
|
||||
REQUIRE(r.parser != nullptr);
|
||||
@@ -1485,7 +1469,7 @@ TEST(a_template_whose_calls_cannot_be_described_refuses_tools_and_still_chats) {
|
||||
rd->finish(nullptr);
|
||||
CHECK(rd->message().tool_calls.empty());
|
||||
CHECK(rd->message().content.find("Hello.") == 0);
|
||||
/* A render with tools is refused too, should one get past the admission check. */
|
||||
/* A render with tools is refused too, should one pass admission. */
|
||||
std::string why;
|
||||
const server::ChatRender t = bridge_render(br, agent_tools(), &why);
|
||||
CHECK(t.prompt.empty());
|
||||
@@ -1494,11 +1478,10 @@ TEST(a_template_whose_calls_cannot_be_described_refuses_tools_and_still_chats) {
|
||||
|
||||
/* ================================================================== the object family
|
||||
*
|
||||
* A call written as its name and ONE object holding the arguments (ChatArgs::Object): JSON behind
|
||||
* a name tag with neither an end nor a wrapper -- Mistral's `[TOOL_CALLS]NAME[ARGS]{...}` -- and
|
||||
* behind a function tag that has its own close. The dialect fields (Gemma 4's strings and bare
|
||||
* keys) are held in chatparse_gemma4_test, against the model's own template and llama.cpp's
|
||||
* parser for it. */
|
||||
* A call written as its name and one object of arguments (ChatArgs::Object): JSON after a name tag
|
||||
* with no end or wrapper (Mistral's `[TOOL_CALLS]NAME[ARGS]{...}`), or after a function tag with
|
||||
* its own close. The dialect fields (Gemma 4's strings and bare keys) are tested in
|
||||
* chatparse_gemma4_test. */
|
||||
|
||||
static std::shared_ptr<const ReplyParser> object_format(bool tagged_end, ChatFormat* out = nullptr) {
|
||||
static const char* const kT1[] = { "[TOOL_CALLS]" };
|
||||
@@ -1564,12 +1547,12 @@ TEST(json_arguments_behind_a_name_tag_read_as_one_object) {
|
||||
CHECK_EQ(m.calls[1].arguments, std::string("{\"path\":\"/a\",\"limit\":[1,{\"x\":null}]}"));
|
||||
const std::string err = stream_all(*p, reply);
|
||||
if (!err.empty()) ::radtest::fail(__FILE__, __LINE__, err);
|
||||
/* A bare key is outside JSON: read, and said so. */
|
||||
/* A bare key is outside JSON: read, and reported non-strict. */
|
||||
const ReplyMessage b = reply_parse(*p, "[TOOL_CALLS]read[ARGS]{path: \"/a\"}", &strict);
|
||||
CHECK(!strict);
|
||||
REQUIRE(b.calls.size() == 1);
|
||||
CHECK_EQ(b.calls[0].arguments, std::string("{\"path\":\"/a\"}"));
|
||||
/* No object after the tag: a call with none, and what stood there is content. */
|
||||
/* No object after the tag: a call without arguments, and the rest is content. */
|
||||
const ReplyMessage n = reply_parse(*p, "[TOOL_CALLS]ping[ARGS] and then", &strict);
|
||||
CHECK(!strict);
|
||||
REQUIRE(n.calls.size() == 1);
|
||||
@@ -1591,7 +1574,7 @@ TEST(json_arguments_behind_a_function_tag_end_at_its_close) {
|
||||
CHECK_EQ(m.calls[1].arguments, std::string("{\"path\":\"/a\"}"));
|
||||
const std::string err = stream_all(*p, reply);
|
||||
if (!err.empty()) ::radtest::fail(__FILE__, __LINE__, err);
|
||||
/* The function's close where the object was still open closes it. */
|
||||
/* The function's close also closes a still-open object. */
|
||||
const ReplyMessage c = reply_parse(
|
||||
*p, "<tool_call>\n<function=read>{\"path\": \"/a\"</function>\n</tool_call>", &strict);
|
||||
CHECK(!strict);
|
||||
@@ -1599,7 +1582,7 @@ TEST(json_arguments_behind_a_function_tag_end_at_its_close) {
|
||||
CHECK(c.calls[0].closed);
|
||||
CHECK_EQ(c.calls[0].arguments, std::string("{\"path\":\"/a\"}"));
|
||||
|
||||
/* The grammar: a JSON object between the tags, and the tags as written. */
|
||||
/* The grammar: the tags as written with a JSON object between. */
|
||||
ChatGrammarRequest gq;
|
||||
gq.tools = &agent_tools();
|
||||
ChatGrammar g;
|
||||
@@ -1614,29 +1597,27 @@ TEST(json_arguments_behind_a_function_tag_end_at_its_close) {
|
||||
log_set_level(Log::Warn);
|
||||
}
|
||||
|
||||
/* reasoning_anywhere: a block that opens after the answer is reasoning there too, and a close
|
||||
* with no block open is not part of the answer. Without it, both are content. */
|
||||
/* reasoning_anywhere: a block opening after the answer is still reasoning, and a close with no
|
||||
* block open is dropped. Without it, both are content. */
|
||||
TEST(a_reasoning_block_may_open_again_later_when_the_format_says_so) {
|
||||
for (bool anywhere : { false, true }) {
|
||||
RadChatFormat c = qwen_abi();
|
||||
c.reasoning_anywhere = anywhere ? 1 : 0;
|
||||
ChatFormat f;
|
||||
std::string why;
|
||||
std::shared_ptr<const ReplyFormat> rf;
|
||||
std::shared_ptr<const ReplyParser> p;
|
||||
CHECK_OK(chat_format_from_abi(&c, &f, &why));
|
||||
CHECK_OK(ReplyFormat::compile(f, &rf, &why));
|
||||
ReplyOptions ro;
|
||||
ro.generation_prompt = "<|im_start|>assistant\n<think>\n";
|
||||
ro.tools = &agent_tools();
|
||||
CHECK_OK(ReplyParser::create(rf, ro, &p, &why));
|
||||
const std::shared_ptr<const ReplyParser> p = parser_of(f, ro);
|
||||
REQUIRE(p);
|
||||
const std::string reply = "Plan.\n</think>\n\nAnswer.<think>\nmore\n</think>\n\nTail.</think>";
|
||||
bool strict = false;
|
||||
const ReplyMessage m = reply_parse(*p, reply, &strict);
|
||||
if (anywhere) {
|
||||
CHECK_EQ(m.reasoning, std::string("Plan.\nmore\n"));
|
||||
CHECK_EQ(m.content, std::string("Answer.Tail."));
|
||||
CHECK(!strict); /* the last </think> closed nothing */
|
||||
CHECK(!strict); /* the last </think> closes nothing */
|
||||
} else {
|
||||
CHECK_EQ(m.reasoning, std::string("Plan.\n"));
|
||||
CHECK_EQ(m.content, std::string("Answer.<think>\nmore\n</think>\n\nTail.</think>"));
|
||||
@@ -1675,9 +1656,51 @@ TEST(an_object_format_the_parser_cannot_read_is_refused) {
|
||||
|
||||
/* ================================================================== cost
|
||||
*
|
||||
* The legacy path re-parses the whole reply on every chunk, so a reply of n bytes costs O(n^2). The
|
||||
* budgets below are loose enough for a loaded machine and tight enough that a quadratic path
|
||||
* cannot pass them: a 200 KB reply streamed byte by byte re-parsed from the top would read 20 GB. */
|
||||
* The legacy path re-parses the whole reply per chunk, O(n^2). The parser's own count of what it
|
||||
* reads twice checks the claim deterministically; the `perf_` cases time it, with budgets that
|
||||
* tolerate a loaded machine but no quadratic path (re-parsing a 200 KB reply per byte would read
|
||||
* 20 GB). The timed cases belong in a serial run, apart from the unit tests. */
|
||||
|
||||
/* Each step of the parser consumes a byte or queues bytes to be read again
|
||||
* (ReplyStream::reread), so what it reads twice bounds its work per byte. Plain prose and a
|
||||
* well-formed call are read once. A near miss of the call syntax is held and read again, a fixed
|
||||
* amount each time, whatever the chunking: a path that re-read what it holds on every chunk, or
|
||||
* everything since its last decision, would grow with the chunk count or the reply's square. */
|
||||
TEST(the_parser_reads_a_byte_twice_only_where_a_near_miss_is_read_again) {
|
||||
for (const Model& m : models()) {
|
||||
Bench* b = bench(m, ChatRequest{});
|
||||
if (!b) continue;
|
||||
auto reread = [&](const std::string& text, size_t piece) {
|
||||
std::unique_ptr<ReplyStream> s = b->parser().open();
|
||||
for (size_t at = 0; at < text.size(); at += piece)
|
||||
s->feed(std::string_view(text).substr(at, piece), nullptr);
|
||||
s->finish(nullptr);
|
||||
return s->reread();
|
||||
};
|
||||
const std::string plain = long_reply(m, 200 * 1024);
|
||||
for (const size_t piece : { plain.size(), (size_t)4, (size_t)1 })
|
||||
CHECK_EQ(reread(plain, piece), (size_t)0);
|
||||
|
||||
/* Openers that turn out to be text, then an argument that turns out not to be JSON. */
|
||||
const std::string unit =
|
||||
(is_qwen(m) ? std::string("See <function=read and <function= more <tool_call> text, "
|
||||
"<function=x>\nnot a call. ")
|
||||
: std::string("Use <function name=\"x\" oops and <function name= and "
|
||||
"<param name=\"a\">v</param> here. ")) +
|
||||
C(m, "configure", { { "verbose", "yes please" }, { "extra", "{'a': [1, 2}" } }) + "\n";
|
||||
size_t at64 = 0;
|
||||
for (const size_t copies : { (size_t)64, (size_t)256 }) {
|
||||
std::string text = "Thinking it over.\n</think>\n\n";
|
||||
for (size_t k = 0; k < copies; ++k) text += unit;
|
||||
const size_t whole = reread(text, text.size());
|
||||
CHECK_EQ(reread(text, 4), whole);
|
||||
CHECK_EQ(reread(text, 1), whole);
|
||||
CHECK(whole >= copies && whole < text.size());
|
||||
if (copies == 64) at64 = whole;
|
||||
else CHECK(whole <= 4 * at64 + 64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static double seconds_to(const std::function<void()>& f, int reps = 3) {
|
||||
double best = 1e30;
|
||||
@@ -1705,7 +1728,7 @@ static double stream_bytes(const ReplyParser& p, const std::string& text, size_t
|
||||
}, per_call ? 1 : reps);
|
||||
}
|
||||
|
||||
TEST(a_long_reply_streamed_byte_by_byte_costs_a_constant_factor_of_parsing_it_once) {
|
||||
TEST(perf_a_long_reply_streamed_byte_by_byte_costs_a_constant_factor_of_parsing_it_once) {
|
||||
for (const Model& m : models()) {
|
||||
Bench* b = bench(m, ChatRequest{});
|
||||
if (!b) continue;
|
||||
@@ -1719,19 +1742,17 @@ TEST(a_long_reply_streamed_byte_by_byte_costs_a_constant_factor_of_parsing_it_on
|
||||
"(%.1f ns/byte), 4-byte pieces %.3f ms\n",
|
||||
m.name.c_str(), text.size(), t_once * 1e3, text.size() / t_once / 1e6,
|
||||
t_bytes * 1e3, t_bytes / text.size() * 1e9, t_tokens * 1e3);
|
||||
/* A constant factor: the per-call cost of feeding one byte against a memchr skip. */
|
||||
/* A constant factor: per-call cost of feeding one byte versus a memchr skip. */
|
||||
CHECK(t_bytes < 200.0 * std::max(t_once, 50e-6));
|
||||
/* And an absolute ceiling per byte, far below one re-parse of the reply per byte. */
|
||||
/* An absolute per-byte ceiling, far below one re-parse per byte. */
|
||||
CHECK(t_bytes / text.size() < 1e-6);
|
||||
}
|
||||
}
|
||||
|
||||
/* FOUR TIMES THE REPLY COSTS FOUR TIMES THE TIME, and a quadratic path sixteen: the bound of 8 sits
|
||||
* a factor of two from each. The two sizes are timed in turns, best of five each, so a burst of load
|
||||
* from whatever else the machine runs lands on both: timed one size after the other, best of three,
|
||||
* a 2x step read x3.9 beside three other test binaries and a server, against the 4 a quadratic
|
||||
* path gives. */
|
||||
TEST(four_times_the_reply_costs_four_times_the_time) {
|
||||
/* Four times the reply costs four times the time, and a quadratic path sixteen; the bound of 8 is
|
||||
* a factor of two from each. The sizes are timed alternately, best of five, so bursts of machine
|
||||
* load affect both equally. */
|
||||
TEST(perf_four_times_the_reply_costs_four_times_the_time) {
|
||||
for (const Model& m : models()) {
|
||||
Bench* b = bench(m, ChatRequest{});
|
||||
if (!b) continue;
|
||||
@@ -1748,7 +1769,7 @@ TEST(four_times_the_reply_costs_four_times_the_time) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(a_chunk_costs_microseconds_at_the_99th_percentile) {
|
||||
TEST(perf_a_chunk_costs_microseconds_at_the_99th_percentile) {
|
||||
for (const Model& m : models()) {
|
||||
Bench* b = bench(m, ChatRequest{});
|
||||
if (!b) continue;
|
||||
@@ -1763,7 +1784,7 @@ TEST(a_chunk_costs_microseconds_at_the_99th_percentile) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The held bytes of a long plain-text reply stay a constant: no buffer grows with the reply. */
|
||||
/* Held bytes stay constant over a long plain-text reply: no buffer grows with it. */
|
||||
TEST(a_long_reply_holds_a_constant_number_of_bytes) {
|
||||
for (const Model& m : models()) {
|
||||
Bench* b = bench(m, ChatRequest{});
|
||||
|
||||
+1034
-209
File diff suppressed because it is too large.
Load diff
+411
-191
@@ -1,25 +1,25 @@
|
||||
/* config_test.cpp -- the command line.
|
||||
*
|
||||
* WHAT THIS IS HOLDING DOWN. Every pool in this engine is budgeted explicitly (spec §6), and a
|
||||
* budget flag is the one kind of input where a typo and a decision look identical downstream:
|
||||
* nothing after this function can tell "the operator asked for 0.82" from "the operator asked for
|
||||
* 0.87 and it did not parse". The parser's whole job is to make that distinction at the door --
|
||||
* to refuse by name rather than to fall through to a default -- and a refusal that stops
|
||||
* refusing is silent everywhere else.
|
||||
* Every pool is budgeted explicitly (spec §6), and downstream a mistyped budget flag looks like a
|
||||
* decision: nothing after the parser can tell a requested value from one that failed to parse and
|
||||
* fell back to a default. So the parser refuses by name, and these tests keep it refusing.
|
||||
*
|
||||
* Three groups of property here, and they fail differently:
|
||||
*
|
||||
* TAKEN the value reaches the field an operator thinks it reaches
|
||||
* REFUSED a value outside the legal set stops the server rather than being rounded into it
|
||||
* RESOLVED what is left unsaid comes from the environment or from a stated default
|
||||
* Taken the value reaches the field an operator expects
|
||||
* Refused a value outside the legal set stops the server instead of being rounded into it
|
||||
* Resolved what is left unsaid comes from the environment or a stated default
|
||||
*
|
||||
* No device, no model, no container: argc/argv in, a Config out.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
|
||||
#include "rad_core.h"
|
||||
#include "diag/diag.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
@@ -30,37 +30,21 @@ using namespace rad;
|
||||
|
||||
namespace {
|
||||
|
||||
/* config_parse takes `char**`, so the argument strings have to be writable. Held by the caller
|
||||
* for the life of the call, which is what argv is. */
|
||||
struct Args {
|
||||
std::vector<std::string> store;
|
||||
std::vector<char*> argv;
|
||||
|
||||
explicit Args(std::initializer_list<const char*> v) {
|
||||
store.emplace_back("radiance"); /* argv[0], which the parser skips */
|
||||
for (const char* s : v) store.emplace_back(s);
|
||||
for (std::string& s : store) argv.push_back(s.data());
|
||||
}
|
||||
int argc() const { return (int)argv.size(); }
|
||||
};
|
||||
|
||||
/* Parse, with a model so that the required-argument check is not what every case trips over. */
|
||||
/* Parse with a --model prepended, so the required-argument check does not trip every case. */
|
||||
int parse(std::initializer_list<const char*> v, Config* c) {
|
||||
std::vector<std::string> store{ "radiance", "--model", "/m/x.rad" };
|
||||
for (const char* s : v) store.emplace_back(s);
|
||||
std::vector<char*> argv;
|
||||
for (std::string& s : store) argv.push_back(s.data());
|
||||
return config_parse((int)argv.size(), argv.data(), c);
|
||||
std::vector<std::string> args{ "--model", "/m/x.rad" };
|
||||
args.insert(args.end(), v.begin(), v.end());
|
||||
Argv a(std::move(args));
|
||||
return config_parse(a.argc(), a.argv.data(), c);
|
||||
}
|
||||
|
||||
/* The same into a Config of its own, for a case whose answer depends on flags not carrying over
|
||||
* from an earlier parse. */
|
||||
/* Parse into a fresh Config, for cases that must not inherit flags from an earlier parse. */
|
||||
int parse_fresh(std::initializer_list<const char*> v) {
|
||||
Config c;
|
||||
return parse(v, &c);
|
||||
}
|
||||
|
||||
/* The level `-v` moves and every other test in this binary reads. */
|
||||
/* Restores the log level, which `-v` changes and every test in this binary reads. */
|
||||
struct LogGuard {
|
||||
Log saved = log_level();
|
||||
~LogGuard() { log_set_level(saved); }
|
||||
@@ -71,20 +55,19 @@ struct LogGuard {
|
||||
/* ================================================================== the shape of the call */
|
||||
|
||||
TEST(help_is_reported_separately_from_an_error) {
|
||||
/* 1 rather than a negative: the caller prints usage and exits ZERO. Folding it into the error
|
||||
* path would make `--help` a failed run in anything scripting the binary. */
|
||||
/* 1, not an error: the caller prints usage and exits 0, so `--help` is not a failed run. */
|
||||
Config c;
|
||||
Args a{ "--help" };
|
||||
Argv a({ "--help" });
|
||||
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), 1);
|
||||
Args b{ "-h" };
|
||||
Argv b({ "-h" });
|
||||
CHECK_EQ(config_parse(b.argc(), b.argv.data(), &c), 1);
|
||||
/* And it wins from anywhere on the line, including ahead of an otherwise fatal argument. */
|
||||
Args d{ "--tp", "0", "--help" };
|
||||
/* It wins from anywhere on the line, even after an otherwise fatal argument. */
|
||||
Argv d({ "--tp", "0", "--help" });
|
||||
CHECK_EQ(config_parse(d.argc(), d.argv.data(), &c), 1);
|
||||
}
|
||||
|
||||
/* AN UNKNOWN FLAG IS AN ERROR NAMING IT, NOT A WARNING. A typo in a budget flag is the difference
|
||||
* between the plan you asked for and one the planner invented. */
|
||||
/* An unknown flag is an error naming it, not a warning: a typo in a budget flag would otherwise
|
||||
* yield a plan the operator did not ask for. */
|
||||
TEST(an_unknown_option_is_refused) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--not-a-flag" }, &c), RAD_E_INVAL);
|
||||
@@ -93,14 +76,11 @@ TEST(an_unknown_option_is_refused) {
|
||||
CHECK_EQ(parse({ "positional" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* A RETIRED FLAG IS REFUSED, NOT ACCEPTED AND IGNORED. Each of these names a decision the engine
|
||||
* does not take from the operator: the KV cache is elastic on every run and derives its own
|
||||
* buffer, the activation arena is computed from the buffer plan and charged by name, and a
|
||||
* finished conversation is copied to host memory and on to disk as soon as it can be rather than
|
||||
* after an idle time. A command line carrying one expects behaviour the engine does not have, and
|
||||
* starting it anyway gives an operator a server that is not the one they asked for and no way to
|
||||
* tell. Refusing names the flag and stops; accepting and warning puts the
|
||||
* answer in a log nobody reads. */
|
||||
/* A retired flag is refused, not accepted and ignored. Each names a decision the engine does not
|
||||
* take from the operator: the KV cache is elastic and derives its own buffer, the activation arena
|
||||
* comes from the buffer plan, and a finished conversation is copied to host memory as soon as
|
||||
* possible rather than after an idle time. Starting anyway would serve something other than what
|
||||
* the command line expects; a warning would go unread. */
|
||||
TEST(a_retired_flag_is_refused) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--kv-flex-mib", "512" }, &c), RAD_E_INVAL);
|
||||
@@ -110,20 +90,18 @@ TEST(a_retired_flag_is_refused) {
|
||||
CHECK_EQ(parse({ "--kv-host-cache-mib", "4096" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* A FLAG WHOSE ARGUMENT IS OFF THE END OF THE LINE. Reading past argv is the failure this
|
||||
* prevents, and the one shape that reaches it is the flag written last. */
|
||||
/* A flag written last with no argument is refused rather than reading past argv. */
|
||||
TEST(a_flag_missing_its_argument_is_refused_rather_than_read_past) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--tp" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--port" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype" }, &c), RAD_E_INVAL);
|
||||
Args a{ "--model" };
|
||||
Argv a({ "--model" });
|
||||
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* THE KL MODE TAKES ONE DIRECTION AND WHAT THAT DIRECTION READS. Recording into a directory and
|
||||
* scoring against one in the same run would leave the engine to guess which the operator meant,
|
||||
* and guessing wrong makes a quantised model the yardstick. */
|
||||
/* KL mode records or scores, never both, and requires that direction's inputs. Guessing between
|
||||
* them could make a quantised model the reference. */
|
||||
TEST(the_kl_mode_records_or_scores_and_says_which_input_it_lacks) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--kld-record", "/r", "--kld-corpus", "/c.jsonl" }, &c), RAD_OK);
|
||||
@@ -151,7 +129,7 @@ TEST(the_kl_mode_records_or_scores_and_says_which_input_it_lacks) {
|
||||
|
||||
TEST(the_model_is_required_and_nothing_else_is) {
|
||||
Config c;
|
||||
Args none{};
|
||||
Argv none({});
|
||||
CHECK_EQ(config_parse(none.argc(), none.argv.data(), &c), RAD_E_INVAL);
|
||||
|
||||
Config ok;
|
||||
@@ -162,8 +140,8 @@ TEST(the_model_is_required_and_nothing_else_is) {
|
||||
/* ================================================================== taken */
|
||||
|
||||
TEST(the_pool_size_flags_are_gone_and_say_what_replaced_them) {
|
||||
/* The card's split is the resolver's (core/mem/vram_budget.h); a launch line that sizes a
|
||||
* pool is refused by name, not served with a split other than the one it asked for. */
|
||||
/* The card's split belongs to the resolver (core/mem/vram_budget.h); a launch line that sizes
|
||||
* a pool is refused by name rather than served with a different split. */
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--vram-weights-mib", "20480" }, &c), RAD_E_INVAL);
|
||||
Config k;
|
||||
@@ -171,8 +149,8 @@ TEST(the_pool_size_flags_are_gone_and_say_what_replaced_them) {
|
||||
}
|
||||
|
||||
TEST(the_prefix_cache_disk_flags_are_gone_and_the_host_size_was_renamed) {
|
||||
/* The prefix cache keeps nothing on a drive. A launch line still naming the disk tier, or the
|
||||
* host tier's old name, is refused rather than served without what it asked for. */
|
||||
/* The prefix cache has no disk tier. A launch line naming the disk tier, or the host tier's
|
||||
* old flag name, is refused. */
|
||||
for (const char* f : { "--prefix-cache-host-mib", "--prefix-cache-disk-mib", "--prefix-cache-dir" }) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ f, "4096" }, &c), RAD_E_INVAL);
|
||||
@@ -215,8 +193,7 @@ TEST(the_sizes_and_counts_reach_the_fields_they_name) {
|
||||
CHECK_EQ(c.tp_wire_min_kb, 64ll);
|
||||
CHECK_EQ(c.port, 8100);
|
||||
|
||||
/* A CONTEXT BOUND THAT DOES NOT FIT IN AN int. --max-model-len is the flag most likely to
|
||||
* carry a number past two billion, and atoi would wrap it. */
|
||||
/* --max-model-len may exceed INT_MAX and must not wrap. */
|
||||
Config big;
|
||||
CHECK_EQ(parse({ "--max-model-len", "4294967296" }, &big), RAD_OK);
|
||||
CHECK_EQ(big.max_ctx, 4294967296ll);
|
||||
@@ -242,7 +219,7 @@ TEST(the_paths_and_names_reach_their_fields) {
|
||||
CHECK_EQ(c.override_chat_template, std::string("/t.jinja"));
|
||||
}
|
||||
|
||||
/* The reasoning budget is a count or nothing: unset is -1, which no request default can mean. */
|
||||
/* The reasoning budget is a count or unset (-1); a negative value cannot be given. */
|
||||
TEST(thinking_token_budget_takes_a_count_and_defaults_to_none) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({}, &c), RAD_OK);
|
||||
@@ -263,7 +240,7 @@ TEST(the_boolean_flags_are_off_until_they_are_given) {
|
||||
Config d;
|
||||
CHECK_EQ(parse({}, &d), RAD_OK);
|
||||
CHECK(!d.deterministic);
|
||||
CHECK(d.prefix_cache); /* on by default; the flag only turns it off */
|
||||
CHECK(d.prefix_cache); /* on by default; the flag turns it off */
|
||||
CHECK(!d.debug_graph);
|
||||
CHECK(!d.debug_selection);
|
||||
CHECK(!d.debug_placement);
|
||||
@@ -282,8 +259,8 @@ TEST(the_boolean_flags_are_off_until_they_are_given) {
|
||||
CHECK(c.live_view);
|
||||
}
|
||||
|
||||
/* THE GRAPH DUMP IMPLIES THE SELECTION TABLE, because a graph without the kernel that resolved
|
||||
* each node is a picture of a program nobody can tell is the one that will run. */
|
||||
/* The graph dump implies the selection table: without the kernel chosen for each node, the graph
|
||||
* does not show what will run. */
|
||||
TEST(debug_graph_turns_the_selection_table_on_too) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--debug-graph" }, &c), RAD_OK);
|
||||
@@ -292,7 +269,7 @@ TEST(debug_graph_turns_the_selection_table_on_too) {
|
||||
|
||||
Config s;
|
||||
CHECK_EQ(parse({ "--debug-selection" }, &s), RAD_OK);
|
||||
CHECK(!s.debug_graph); /* and not the other way round */
|
||||
CHECK(!s.debug_graph); /* not the reverse */
|
||||
CHECK(s.debug_selection);
|
||||
}
|
||||
|
||||
@@ -312,19 +289,267 @@ TEST(tp_below_one_is_refused) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--tp", "0" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--tp", "-1" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--tp", "notanumber" }, &c), RAD_E_INVAL); /* atoi gives 0 */
|
||||
CHECK_EQ(parse({ "--tp", "notanumber" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--tp", "1" }, &c), RAD_OK);
|
||||
}
|
||||
|
||||
/* A span is a whole number of intervals, one or more; 1 is the default and plans as before. */
|
||||
TEST(a_prefill_span_below_one_interval_is_refused) {
|
||||
Config c;
|
||||
CHECK_EQ(c.prefill_span, 1);
|
||||
CHECK_EQ(parse({ "--prefill-span", "0" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--prefill-span", "-2" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--prefill-span", "2x" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--prefill-span", "4" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.prefill_span, 4);
|
||||
}
|
||||
|
||||
/* A budget flag takes a whole number; a typo is refused rather than read as 0 or its prefix. */
|
||||
TEST(a_numeric_flag_refuses_what_is_not_a_number) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--max-num-seqs", "8x" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--max-num-batched-tokens", "4k" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--host-pool-mib", "-1" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--checkpoint-interval", "" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--port", "70000" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--num-speculative-tokens", "three" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--num-speculative-tokens", "-1" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--num-speculative-tokens", "auto" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.n_spec, -1);
|
||||
CHECK_EQ(parse({ "--num-speculative-tokens", "3" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.n_spec, 3);
|
||||
}
|
||||
|
||||
/* --prefill-interleave is a step count, off by default and at most 64. */
|
||||
TEST(prefill_interleave_takes_a_step_count_up_to_64) {
|
||||
Config d;
|
||||
REQUIRE_EQ(parse({}, &d), RAD_OK);
|
||||
CHECK_EQ(d.prefill_interleave, 0);
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--prefill-interleave", "4" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.prefill_interleave, 4);
|
||||
CHECK_EQ(parse({ "--prefill-interleave", "65" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--prefill-interleave", "-1" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* ================================================================== the table, the parser and the help agree
|
||||
*
|
||||
* One table (g_flags) drives the help text and the startup report, and a separate chain of ifs
|
||||
* parses. A flag in the table the parser does not take, a number read without the strict parser,
|
||||
* or a default the help states by hand that the code does not have, each passes every sampled
|
||||
* test. These walk the whole table. */
|
||||
namespace {
|
||||
|
||||
/* Each option and its argument's metavariable as the help prints them ("" for a switch). */
|
||||
std::vector<std::pair<std::string, std::string>> usage_options() {
|
||||
const std::string text = stderr_of([] { config_usage("radiance"); });
|
||||
std::vector<std::pair<std::string, std::string>> out;
|
||||
size_t at = 0;
|
||||
while (at < text.size()) {
|
||||
size_t nl = text.find('\n', at);
|
||||
if (nl == std::string::npos) nl = text.size();
|
||||
const std::string line = text.substr(at, nl - at);
|
||||
at = nl + 1;
|
||||
if (line.rfind(" -", 0) != 0) continue;
|
||||
std::istringstream in(line);
|
||||
std::string name, arg;
|
||||
in >> name >> arg;
|
||||
/* The help starts after the padded column; a metavariable is upper case. */
|
||||
const bool is_arg = !arg.empty() && line.find(name + " " + arg) == 2 &&
|
||||
std::all_of(arg.begin(), arg.end(), [](char ch) {
|
||||
return (ch >= 'A' && ch <= 'Z') || ch == '_';
|
||||
});
|
||||
out.emplace_back(name, is_arg ? arg : "");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* A legal value for every option that takes one, with any option it cannot be given without. */
|
||||
const std::map<std::string, std::vector<std::string>>& legal_values() {
|
||||
static const std::map<std::string, std::vector<std::string>> v = {
|
||||
{ "--model", { "/m/y.rad" } }, { "--download-dir", { "/d" } },
|
||||
{ "--radiance-home", { "/h1:/h2" } }, { "--kernels", { "libref" } },
|
||||
{ "--tp", { "2" } }, { "--tp-wire", { "wht6" } }, { "--tp-wire-min-kb", { "64" } },
|
||||
{ "--p2p", { "off" } }, { "--max-num-batched-tokens", { "512" } },
|
||||
{ "--busy-prefill-chunk", { "256" } }, { "--prefill-interleave", { "2" } },
|
||||
{ "--max-num-seqs", { "4" } },
|
||||
{ "--max-model-len", { "4096" } }, { "--rope-scaling", { "yarn:4" } },
|
||||
{ "--gpu-headroom-mib", { "128" } }, { "--kv-cache-dtype", { "fp8" } },
|
||||
{ "--host-pool-mib", { "1024" } }, { "--embedding-placement", { "vram" } },
|
||||
{ "--vision-tower-placement", { "ram" } }, { "--ngram-placement", { "disk" } },
|
||||
{ "--prefix-cache-mib", { "256" } }, { "--prefix-cache-ttl", { "60" } },
|
||||
{ "--placement", { "all_vram" } }, { "--checkpoint-interval", { "256" } },
|
||||
{ "--prefill-span", { "2" } },
|
||||
{ "--checkpoint-slots", { "4" } }, { "--checkpoint-policy", { "tip-only" } },
|
||||
{ "--num-speculative-tokens", { "2" } }, { "--draft-window", { "fixed" } },
|
||||
{ "--host", { "127.0.0.1" } }, { "--port", { "8001" } }, { "--api-key", { "k" } },
|
||||
{ "--served-model-name", { "m" } }, { "--mm-max-patches", { "1024" } },
|
||||
{ "--generation-config", { "/g.json" } }, { "--override-chat-template", { "/t.jinja" } },
|
||||
{ "--temp", { "0.7" } }, { "--top-k", { "40" } }, { "--top-p", { "0.9" } },
|
||||
{ "--min-p", { "0.05" } }, { "--reasoning-effort", { "low" } },
|
||||
{ "--reasoning-effort-map", { "high=xhigh" } }, { "--thinking-token-budget", { "128" } },
|
||||
{ "--typical-p", { "0.9" } }, { "--presence-penalty", { "0.5" } },
|
||||
{ "--frequency-penalty", { "0.5" } }, { "--repetition-penalty", { "1.1" } },
|
||||
{ "--repeat-last-n", { "64" } }, { "--dry-multiplier", { "0.8" } },
|
||||
{ "--dry-base", { "1.75" } }, { "--dry-allowed-length", { "2" } },
|
||||
{ "--dry-penalty-last-n", { "-1" } }, { "--dry-sequence-breakers", { "[\"\\n\"]" } },
|
||||
{ "--xtc-probability", { "0.5" } }, { "--xtc-threshold", { "0.1" } },
|
||||
{ "--default-max-tokens", { "256" } }, { "--max-tokens-cap", { "1024" } },
|
||||
{ "--max-n", { "4" } }, { "--max-queued-requests", { "4096" } },
|
||||
{ "--max-stop-strings", { "8" } }, { "--max-stop-bytes", { "256" } },
|
||||
{ "--chat-template-kwargs", { "{\"enable_thinking\": false}" } },
|
||||
{ "--reasoning-format", { "none" } }, { "--http-threads", { "4" } },
|
||||
{ "--read-timeout", { "10" } }, { "--write-timeout", { "10" } },
|
||||
{ "--keep-alive-timeout", { "2" } }, { "--max-body-mib", { "64" } },
|
||||
{ "--retry-after", { "2" } }, { "--image-min-pixels", { "1024" } },
|
||||
{ "--image-max-pixels", { "4096" } }, { "--video-min-pixels", { "1024" } },
|
||||
{ "--video-max-pixels", { "4096" } }, { "--video-fps", { "2" } },
|
||||
{ "--video-min-frames", { "2" } }, { "--video-max-frames", { "8" } },
|
||||
{ "--video-max-frame-tokens", { "70" } }, { "--image-tokens", { "280" } },
|
||||
{ "--max-source-pixels", { "1000000" } },
|
||||
{ "--kld-record", { "/r", "--kld-corpus", "/c.jsonl" } }, { "--kld-ref", { "/r" } },
|
||||
{ "--kld-corpus", { "/c.jsonl", "--kld-record", "/r" } },
|
||||
{ "--kld-out", { "/o.json", "--kld-ref", "/r" } },
|
||||
};
|
||||
return v;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* Every option the table lists parses with a legal value (a switch with none) and is reported as
|
||||
* given on the command line. --draft-model is listed to be refused by name, and --help is not a
|
||||
* setting. */
|
||||
TEST(every_listed_option_parses_and_is_reported_as_given) {
|
||||
LogGuard lg;
|
||||
const auto opts = usage_options();
|
||||
CHECK(opts.size() > 90);
|
||||
const std::vector<std::string> names = diag::config_option_names();
|
||||
int checked = 0;
|
||||
for (const auto& [name, arg] : opts) {
|
||||
if (name == "--help" || name == "--draft-model") continue;
|
||||
CHECK(std::find(names.begin(), names.end(), name) != names.end());
|
||||
std::vector<std::string> args{ "--model", "/m/x.rad", name };
|
||||
if (!arg.empty()) {
|
||||
auto it = legal_values().find(name);
|
||||
if (it == legal_values().end()) {
|
||||
std::fprintf(stderr, " no legal value listed for %s %s\n", name.c_str(), arg.c_str());
|
||||
CHECK(false);
|
||||
continue;
|
||||
}
|
||||
args.insert(args.end(), it->second.begin(), it->second.end());
|
||||
}
|
||||
Config c;
|
||||
Argv a(args);
|
||||
int st = RAD_OK;
|
||||
const std::string log = stderr_of([&] { st = config_parse(a.argc(), a.argv.data(), &c); });
|
||||
if (st != RAD_OK) std::fprintf(stderr, " %s refused: %s", name.c_str(), log.c_str());
|
||||
CHECK_EQ(st, (int)RAD_OK);
|
||||
auto g = c.given.find(name);
|
||||
CHECK(g != c.given.end() && g->second == "command line");
|
||||
++checked;
|
||||
}
|
||||
CHECK(checked > 90);
|
||||
}
|
||||
|
||||
/* A whole-number option refuses what is not one, and a number option a word: "8x" read as 8, ""
|
||||
* as 0 or "12k" as 12 would each be served as a decision. Seconds are whole numbers too. */
|
||||
TEST(every_numeric_option_refuses_what_is_not_its_kind) {
|
||||
const std::vector<std::string> seconds = { "--prefix-cache-ttl", "--read-timeout",
|
||||
"--write-timeout", "--keep-alive-timeout",
|
||||
"--retry-after" };
|
||||
int n_int = 0, n_num = 0;
|
||||
for (const auto& [name, arg] : usage_options()) {
|
||||
const bool whole = arg == "N" ||
|
||||
std::find(seconds.begin(), seconds.end(), name) != seconds.end();
|
||||
if (!whole && arg != "F") continue;
|
||||
(whole ? n_int : n_num)++;
|
||||
for (const char* bad : whole ? std::vector<const char*>{ "8x", "", "12k", "1.5", "high" }
|
||||
: std::vector<const char*>{ "high", "", "0.5x" }) {
|
||||
Config c;
|
||||
int st = RAD_OK;
|
||||
const std::string log = stderr_of([&] { st = parse({ name.c_str(), bad }, &c); });
|
||||
if (st != RAD_E_INVAL)
|
||||
std::fprintf(stderr, " %s %s was not refused\n", name.c_str(), bad);
|
||||
CHECK_EQ(st, (int)RAD_E_INVAL);
|
||||
CHECK(has(log, name));
|
||||
}
|
||||
}
|
||||
std::fprintf(stderr, " %d whole-number and %d number option(s)\n", n_int, n_num);
|
||||
CHECK(n_int >= 35);
|
||||
CHECK(n_num >= 12);
|
||||
}
|
||||
|
||||
/* A default the help states as a number is the default a parse with no flags reports. */
|
||||
TEST(every_default_the_help_states_is_the_one_reported) {
|
||||
const std::string text = stderr_of([] { config_usage("radiance"); });
|
||||
Config c;
|
||||
REQUIRE_EQ(parse({}, &c), RAD_OK);
|
||||
const std::vector<diag::ConfigRow> rows = diag::config_rows(c);
|
||||
/* The help of one option: its line and the indented lines after it. */
|
||||
std::string block, flag;
|
||||
int compared = 0;
|
||||
auto settle = [&] {
|
||||
std::smatch m;
|
||||
static const std::regex def(R"(\(default (-?[0-9][0-9.]*)\))");
|
||||
if (flag.empty() || !std::regex_search(block, m, def)) return;
|
||||
const std::string want = m[1];
|
||||
const diag::ConfigRow* row = nullptr;
|
||||
for (const diag::ConfigRow& r : rows) if (r.flag == flag) row = &r;
|
||||
REQUIRE(row != nullptr);
|
||||
const bool ok = row->value == want || row->value.rfind(want + " ", 0) == 0;
|
||||
if (!ok) std::fprintf(stderr, " %s: help says %s, the report %s\n", flag.c_str(),
|
||||
want.c_str(), row->value.c_str());
|
||||
CHECK(ok);
|
||||
++compared;
|
||||
};
|
||||
size_t at = 0;
|
||||
while (at < text.size()) {
|
||||
size_t nl = text.find('\n', at);
|
||||
if (nl == std::string::npos) nl = text.size();
|
||||
const std::string line = text.substr(at, nl - at);
|
||||
at = nl + 1;
|
||||
if (line.rfind(" -", 0) == 0) {
|
||||
settle();
|
||||
std::istringstream in(line);
|
||||
in >> flag;
|
||||
block = line;
|
||||
} else if (line.rfind(" ", 0) == 0) {
|
||||
block += " " + line;
|
||||
} else {
|
||||
settle();
|
||||
flag.clear();
|
||||
block.clear();
|
||||
}
|
||||
}
|
||||
settle();
|
||||
CHECK(compared >= 8);
|
||||
}
|
||||
|
||||
/* --placement names one of the planner's four strategies, refused at the command line rather than
|
||||
* at startup once the model is open. */
|
||||
TEST(the_placement_is_one_of_the_planners_four) {
|
||||
for (const char* ok : { "all_vram", "layer_offload", "expert_tiered", "auto" }) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--placement", ok }, &c), RAD_OK);
|
||||
CHECK_EQ(c.placement, std::string(ok));
|
||||
}
|
||||
for (const char* bad : { "all-vram", "AUTO", "", "tiered" }) {
|
||||
Config c;
|
||||
int st = RAD_OK;
|
||||
const std::string log = stderr_of([&] { st = parse({ "--placement", bad }, &c); });
|
||||
CHECK_EQ(st, (int)RAD_E_INVAL);
|
||||
CHECK(has(log, "--placement"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(the_wire_mode_is_one_of_two_names) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--tp-wire", "exact" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.tp_wire_exact, 1);
|
||||
CHECK_EQ(parse({ "--tp-wire", "wht6" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.tp_wire_exact, 0);
|
||||
/* A LOSSY WIRE IS A DEPLOYMENT CHOICE AND NOTHING DOWNSTREAM CAN DETECT IT: the sum a rank
|
||||
* receives is not the sum it would have received. So a name this build does not know has to
|
||||
* stop the server rather than fall through to whichever mode happens to be the default. */
|
||||
/* A lossy wire is undetectable downstream (a rank just receives a different sum), so an
|
||||
* unknown name stops the server instead of falling through to the default mode. */
|
||||
CHECK_EQ(parse({ "--tp-wire", "wht8" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--tp-wire", "" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--tp-wire", "EXACT" }, &c), RAD_E_INVAL);
|
||||
@@ -339,8 +564,8 @@ TEST(the_p2p_mode_is_one_of_three_names) {
|
||||
CHECK_EQ(c.p2p, RAD_P2P_OFF);
|
||||
CHECK_EQ(parse({ "--p2p", "auto" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.p2p, RAD_P2P_AUTO);
|
||||
/* A name this build does not know stops the server: `on` exists so a deployment measured on
|
||||
* P2P cannot quietly serve on host memory, and a typo falling through to auto would do that. */
|
||||
/* An unknown name stops the server: `on` guarantees a deployment measured on P2P never
|
||||
* silently serves through host memory, which a typo falling through to auto could do. */
|
||||
CHECK_EQ(parse({ "--p2p", "yes" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--p2p", "" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--p2p", "OFF" }, &c), RAD_E_INVAL);
|
||||
@@ -352,8 +577,8 @@ TEST(the_kv_cache_dtype_is_one_of_two_names) {
|
||||
CHECK_EQ(c.kv_cache_dtype, std::string("bf16"));
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "fp8" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.kv_cache_dtype, std::string("fp8"));
|
||||
/* Two values and not three: an "auto" resolving to bf16 would be a second name for the
|
||||
* default, and a flag whose values are not all distinct cannot be read back out of a log. */
|
||||
/* Two values only: an "auto" resolving to bf16 would be a second name for the default, and
|
||||
* each value should be unambiguous in a log. */
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "auto" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "fp16" }, &c), RAD_E_INVAL);
|
||||
|
||||
@@ -362,17 +587,16 @@ TEST(the_kv_cache_dtype_is_one_of_two_names) {
|
||||
CHECK_EQ(d.kv_cache_dtype, std::string("bf16"));
|
||||
}
|
||||
|
||||
/* THE TWO TABLE PLACEMENTS: the embedding takes ram (the default) or vram, the n-gram table auto
|
||||
* (the default), vram, ram or disk, and nothing else. A parse records whether the embedding's was
|
||||
* named and leaves the resolved values to Engine::plan: where each table may go is the engine's to
|
||||
* refuse, with the model in hand -- not the parser's. */
|
||||
/* The embedding takes ram (default) or vram; the n-gram table takes auto (default), vram, ram or
|
||||
* disk. The parser records whether the embedding placement was named and leaves resolution to
|
||||
* Engine::plan, which can refuse a placement with the model in hand. */
|
||||
TEST(the_embedding_is_ram_or_vram_and_the_ngram_table_takes_four) {
|
||||
Config d;
|
||||
CHECK_EQ(parse({}, &d), RAD_OK);
|
||||
CHECK(d.embedding_placement == TablePlacement::Ram);
|
||||
CHECK(!d.embedding_placement_given);
|
||||
CHECK(d.ngram_placement == TablePlacement::Auto);
|
||||
CHECK_EQ(d.embedding_host_mib, 0ll); /* the resolver's */
|
||||
CHECK_EQ(d.embedding_host_mib, 0ll); /* set by the resolver */
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--embedding-placement", "ram", "--ngram-placement", "disk" }, &c), RAD_OK);
|
||||
CHECK(c.embedding_placement == TablePlacement::Ram);
|
||||
@@ -395,9 +619,9 @@ TEST(the_embedding_is_ram_or_vram_and_the_ngram_table_takes_four) {
|
||||
CHECK_EQ(parse({ "--ngram-placement" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* --draft-window takes its two names and nothing else; the default is kDraftWindowDefault, and the
|
||||
* help text states it from there. Whether the window CAN adapt -- a serial drafter, a depth above
|
||||
* zero -- is the scheduler's to say with the program in hand, not the parser's. */
|
||||
/* --draft-window takes exactly two names; the default is kDraftWindowDefault, which the help text
|
||||
* also states. Whether the window can adapt (a serial drafter, depth above zero) is decided by the
|
||||
* scheduler with the program in hand, not the parser. */
|
||||
TEST(the_draft_window_is_fixed_or_adaptive) {
|
||||
Config d;
|
||||
CHECK_EQ(parse({}, &d), RAD_OK);
|
||||
@@ -417,8 +641,8 @@ TEST(the_draft_window_is_fixed_or_adaptive) {
|
||||
CHECK_EQ(std::string(draft_window_name(DraftWindow::Fixed)), std::string("fixed"));
|
||||
}
|
||||
|
||||
/* A POLICY NAME THIS BUILD DOES NOT KNOW WOULD FALL THROUGH TO THE DEFAULT, and a measurement
|
||||
* comparing the default against itself is the failure that costs the most to notice. */
|
||||
/* An unknown policy name is refused; falling through to the default would make a comparison
|
||||
* silently measure the default against itself. */
|
||||
TEST(the_checkpoint_policy_is_one_of_the_three_that_exist) {
|
||||
Config c;
|
||||
for (const char* p : { "geometric-backoff", "tip-only", "keep-all" }) {
|
||||
@@ -433,9 +657,8 @@ TEST(the_checkpoint_policy_is_one_of_the_three_that_exist) {
|
||||
CHECK_EQ(d.checkpoint_policy, std::string("geometric-backoff"));
|
||||
}
|
||||
|
||||
/* THE SAME RANGES THE REQUEST PARSER ENFORCES, refused here rather than at the first request: a
|
||||
* default outside them is a 400 on every request that omits the field, which is a server that
|
||||
* starts, reports healthy and answers nothing. */
|
||||
/* The request parser's ranges, enforced at startup: a default outside them would 400 every
|
||||
* request omitting the field, from a server that reports healthy. */
|
||||
TEST(the_sampler_defaults_are_range_checked_at_startup) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--temp", "0.7", "--top-k", "20", "--top-p", "0.95",
|
||||
@@ -445,7 +668,7 @@ TEST(the_sampler_defaults_are_range_checked_at_startup) {
|
||||
CHECK_NEAR(c.sample_top_p, 0.95f, 1e-6);
|
||||
CHECK_NEAR(c.sample_min_p, 0.05f, 1e-6);
|
||||
|
||||
/* The legal endpoints. Temperature 0 is greedy and top_k 0 is off: both are real settings. */
|
||||
/* The legal endpoints. Temperature 0 is greedy and top_k 0 is off. */
|
||||
CHECK_EQ(parse({ "--temp", "0" }, &c), RAD_OK);
|
||||
CHECK_EQ(parse({ "--temp", "2" }, &c), RAD_OK);
|
||||
CHECK_EQ(parse({ "--top-k", "0" }, &c), RAD_OK);
|
||||
@@ -454,21 +677,20 @@ TEST(the_sampler_defaults_are_range_checked_at_startup) {
|
||||
CHECK_EQ(parse({ "--min-p", "1" }, &c), RAD_OK);
|
||||
|
||||
CHECK_EQ(parse({ "--temp", "2.1" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--top-p", "0" }, &c), RAD_E_INVAL); /* a nucleus of nothing */
|
||||
CHECK_EQ(parse({ "--top-p", "0" }, &c), RAD_E_INVAL); /* empty nucleus */
|
||||
CHECK_EQ(parse({ "--top-p", "1.5" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--min-p", "1.5" }, &c), RAD_E_INVAL);
|
||||
|
||||
/* A negative value is refused rather than read as "unset", which is what a negative field
|
||||
* means below the parser -- the container's default would be served in its place. */
|
||||
/* A negative value is refused: below the parser a negative field means unset, and the
|
||||
* container's default would be served instead. */
|
||||
CHECK_EQ(parse({ "--temp", "-0.5" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--top-k", "-5" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--top-p", "-0.5" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--min-p", "-0.5" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--temp", "nan" }, &c), RAD_E_INVAL);
|
||||
|
||||
/* UNSET IS NEGATIVE AND NOT ZERO, which is what lets the container's own generation config be
|
||||
* resolved underneath: zero is a real temperature and a real top_k, so a default of zero
|
||||
* would be indistinguishable from an operator asking for greedy. */
|
||||
/* Unset is negative, not zero, so the container's generation config can be resolved
|
||||
* underneath: zero is a real temperature and top_k, indistinguishable from asking for greedy. */
|
||||
Config d;
|
||||
CHECK_EQ(parse({}, &d), RAD_OK);
|
||||
CHECK(d.sample_temp < 0.0f);
|
||||
@@ -477,7 +699,7 @@ TEST(the_sampler_defaults_are_range_checked_at_startup) {
|
||||
CHECK(d.sample_min_p < 0.0f);
|
||||
}
|
||||
|
||||
/* A NUMBER IS THE WHOLE ARGUMENT. atof read "high" as 0, which for --temp is greedy decoding. */
|
||||
/* A number must be the whole argument; atof would read "high" as 0, which for --temp is greedy. */
|
||||
TEST(a_sampler_default_that_is_not_a_number_is_refused) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--temp", "high" }, &c), RAD_E_INVAL);
|
||||
@@ -490,9 +712,8 @@ TEST(a_sampler_default_that_is_not_a_number_is_refused) {
|
||||
|
||||
/* ================================================================== request defaults and bounds
|
||||
*
|
||||
* NONE OF THEM MOVES ANYTHING UNTIL IT IS GIVEN. Each field's unset value is the one the server
|
||||
* used before the flag existed (or a marker the engine reads as "leave it"), so a command line
|
||||
* that names none of them serves exactly what it served before. */
|
||||
* None of these changes anything until given: each unset value is the server's built-in behaviour
|
||||
* or a marker the engine reads as "leave it". */
|
||||
TEST(the_request_defaults_and_bounds_are_unset_until_given) {
|
||||
Config d;
|
||||
CHECK_EQ(parse({}, &d), RAD_OK);
|
||||
@@ -552,24 +773,24 @@ TEST(the_request_defaults_reach_their_fields) {
|
||||
CHECK_EQ(c.max_stop_bytes, 256ll);
|
||||
CHECK_EQ(c.reasoning_format, std::string("none"));
|
||||
|
||||
/* `auto` is 0, which the server resolves per request to what the context leaves. */
|
||||
/* `auto` is 0, resolved per request to what the context leaves. */
|
||||
Config a;
|
||||
CHECK_EQ(parse({ "--default-max-tokens", "auto" }, &a), RAD_OK);
|
||||
CHECK_EQ(a.default_max_tokens, 0ll);
|
||||
|
||||
/* An empty breaker list is a stated value -- DRY with no breakers -- and stays one. */
|
||||
/* An empty breaker list is a stated value (DRY with no breakers), not unset. */
|
||||
Config e;
|
||||
CHECK_EQ(parse({ "--dry-sequence-breakers", "[]" }, &e), RAD_OK);
|
||||
CHECK(e.sample_dry_seq_breakers && e.sample_dry_seq_breakers->empty());
|
||||
|
||||
/* A negative penalty is a value a request can send, so the flag can state it. */
|
||||
/* A request may send a negative penalty, so the flag accepts one. */
|
||||
Config n;
|
||||
CHECK_EQ(parse({ "--presence-penalty", "-2" }, &n), RAD_OK);
|
||||
CHECK_NEAR(*n.sample_pres_penalty, -2.0f, 1e-6);
|
||||
}
|
||||
|
||||
/* THE RANGES A REQUEST IS HELD TO, at startup: a default outside them would be a 400 on every
|
||||
* request that leaves the field to it. */
|
||||
/* Request ranges, enforced at startup: a default outside them would 400 every request that
|
||||
* omits the field. */
|
||||
TEST(the_request_defaults_are_range_checked_like_a_request) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--typical-p", "0" }, &c), RAD_E_INVAL);
|
||||
@@ -583,14 +804,19 @@ TEST(the_request_defaults_are_range_checked_like_a_request) {
|
||||
CHECK_EQ(parse({ "--xtc-probability", "1.5" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--xtc-threshold", "-0.1" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--dry-allowed-length", "3.5" }, &c), RAD_E_INVAL);
|
||||
/* With DRY on, a request whose allowed length is below 1 is refused at admission, so a
|
||||
* default below 1 is refused here rather than refusing every such request. */
|
||||
CHECK_EQ(parse({ "--dry-allowed-length", "0" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--dry-allowed-length", "-1" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--dry-allowed-length", "1" }, &c), RAD_OK);
|
||||
CHECK_EQ(parse({ "--dry-sequence-breakers", R"("\n")" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--dry-sequence-breakers", "[1]" }, &c), RAD_E_INVAL);
|
||||
/* The sampler takes at most 16 (sample/host_ref.h); every DRY request would be refused. */
|
||||
/* The sampler takes at most 16 (sample/host_ref.h); more would refuse every DRY request. */
|
||||
CHECK_EQ(parse({ "--dry-sequence-breakers",
|
||||
R"(["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q"])" },
|
||||
&c), RAD_E_INVAL);
|
||||
|
||||
CHECK_EQ(parse({ "--default-max-tokens", "0" }, &c), RAD_E_INVAL); /* auto is the word */
|
||||
CHECK_EQ(parse({ "--default-max-tokens", "0" }, &c), RAD_E_INVAL); /* spell it `auto` */
|
||||
CHECK_EQ(parse({ "--default-max-tokens", "-1" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--default-max-tokens", "AUTO" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--default-max-tokens", "4294967296" }, &c), RAD_E_INVAL);
|
||||
@@ -603,8 +829,8 @@ TEST(the_request_defaults_are_range_checked_like_a_request) {
|
||||
CHECK_EQ(parse({ "--reasoning-format", "" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* BOUNDS THAT CONTRADICT EACH OTHER. A default above the cap is a default no request is served
|
||||
* at; an `n` above the queue is a request that is 429 however long its caller waits. */
|
||||
/* Contradictory bounds are refused: a default above the cap is never served, and an `n` above the
|
||||
* queue size gets 429 however long its caller waits. */
|
||||
TEST(request_bounds_that_contradict_each_other_are_refused) {
|
||||
CHECK_EQ(parse_fresh({ "--default-max-tokens", "4096", "--max-tokens-cap", "1024" }), RAD_E_INVAL);
|
||||
CHECK_EQ(parse_fresh({ "--default-max-tokens", "1024", "--max-tokens-cap", "1024" }), RAD_OK);
|
||||
@@ -612,10 +838,10 @@ TEST(request_bounds_that_contradict_each_other_are_refused) {
|
||||
|
||||
CHECK_EQ(parse_fresh({ "--max-n", "65", "--max-queued-requests", "64" }), RAD_E_INVAL);
|
||||
CHECK_EQ(parse_fresh({ "--max-n", "64", "--max-queued-requests", "64" }), RAD_OK);
|
||||
/* The queue's default is 8 x --max-num-seqs, and the check reads it. */
|
||||
/* The queue's default is 8 x --max-num-seqs, and the check uses it. */
|
||||
CHECK_EQ(parse_fresh({ "--max-num-seqs", "2", "--max-n", "17" }), RAD_E_INVAL);
|
||||
CHECK_EQ(parse_fresh({ "--max-num-seqs", "2", "--max-n", "16" }), RAD_OK);
|
||||
/* And a stated queue smaller than the default n (8, or --max-num-seqs). */
|
||||
/* A stated queue smaller than the default n (8, or --max-num-seqs). */
|
||||
CHECK_EQ(parse_fresh({ "--max-queued-requests", "4" }), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
@@ -629,17 +855,17 @@ TEST(the_template_variables_merge_key_by_key_and_later_wins) {
|
||||
CHECK_EQ(c.chat_template_kwargs["n"], std::string("3"));
|
||||
|
||||
/* @FILE reads the object from a file. */
|
||||
char path[] = "/tmp/rad_kwargs_XXXXXX";
|
||||
const int fd = mkstemp(path);
|
||||
REQUIRE(fd >= 0);
|
||||
const std::string path = radtest::tmp_path("kwargs.json");
|
||||
FILE* fp = std::fopen(path.c_str(), "w");
|
||||
REQUIRE(fp != nullptr);
|
||||
const std::string body = R"({"date_string": "01 Jan 2026"})";
|
||||
CHECK_EQ((size_t)write(fd, body.data(), body.size()), body.size());
|
||||
close(fd);
|
||||
CHECK_EQ(std::fwrite(body.data(), 1, body.size(), fp), body.size());
|
||||
std::fclose(fp);
|
||||
Config f;
|
||||
const std::string at = std::string("@") + path;
|
||||
const std::string at = "@" + path;
|
||||
CHECK_EQ(parse({ "--chat-template-kwargs", at.c_str() }, &f), RAD_OK);
|
||||
CHECK_EQ(f.chat_template_kwargs["date_string"], std::string("\"01 Jan 2026\""));
|
||||
unlink(path);
|
||||
unlink(path.c_str());
|
||||
CHECK_EQ(parse({ "--chat-template-kwargs", at.c_str() }, &f), RAD_E_INVAL); /* gone */
|
||||
}
|
||||
|
||||
@@ -648,12 +874,12 @@ TEST(a_template_variable_the_server_owns_or_cannot_read_is_refused) {
|
||||
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", "{nope" }), RAD_E_INVAL);
|
||||
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", R"("enable_thinking")" }), RAD_E_INVAL);
|
||||
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", R"({"enable_thinking": "no"})" }), RAD_E_INVAL);
|
||||
/* The renderer writes these over the context; one here would replace every conversation. */
|
||||
/* The renderer sets these; one here would replace every conversation. */
|
||||
for (const char* k : { "messages", "tools", "bos_token", "eos_token", "add_generation_prompt" }) {
|
||||
const std::string j = std::string("{\"") + k + "\": 1}";
|
||||
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", j.c_str() }), RAD_E_INVAL);
|
||||
}
|
||||
/* Two defaults for thinking, in two flags, with no order between them. */
|
||||
/* Two flags setting the thinking default, with no precedence between them. */
|
||||
CHECK_EQ(parse_fresh({ "--reasoning-effort", "low",
|
||||
"--chat-template-kwargs", R"({"reasoning_effort": "high"})" }), RAD_E_INVAL);
|
||||
CHECK_EQ(parse_fresh({ "--chat-template-kwargs", R"({"enable_thinking": true})",
|
||||
@@ -675,7 +901,7 @@ TEST(the_transport_flags_reach_their_fields_and_hold_their_floors) {
|
||||
CHECK_EQ(c.retry_after_s, 5);
|
||||
CHECK(!c.cors);
|
||||
|
||||
/* The transport keeps four workers whatever it is told, so fewer is refused, not ignored. */
|
||||
/* The transport keeps at least four workers, so fewer is refused, not ignored. */
|
||||
CHECK_EQ(parse({ "--http-threads", "2" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--read-timeout", "0" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--write-timeout", "-1" }, &c), RAD_E_INVAL);
|
||||
@@ -714,9 +940,8 @@ TEST(the_media_flags_reach_their_fields_and_refuse_an_empty_band) {
|
||||
CHECK_EQ(parse({ "--max-source-pixels", "0" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
/* REFUSED, NOT QUIETLY IGNORED. Accepting it and then serving the container's own drafter -- or
|
||||
* none -- hands the caller a server that is not the one they asked for, with nothing in the
|
||||
* output to say so. A caller coming from vLLM will reach for this flag. */
|
||||
/* --draft-model (familiar from vLLM) is refused by name; accepting it and serving the container's
|
||||
* own drafter, or none, would silently differ from what was asked. */
|
||||
TEST(draft_model_is_refused_by_name_rather_than_ignored) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--draft-model", "/d.rad" }, &c), RAD_E_INVAL);
|
||||
@@ -726,8 +951,8 @@ TEST(draft_model_is_refused_by_name_rather_than_ignored) {
|
||||
/* ================================================================== resolved */
|
||||
|
||||
TEST(auto_speculation_is_negative_one_and_not_zero) {
|
||||
/* The depth is a property of the DRAFTER, which the architecture plugin states once the
|
||||
* container is open -- so "auto" has to survive as a distinct value here. Zero is off. */
|
||||
/* The depth is the drafter's, stated by the architecture plugin once the container is open,
|
||||
* so "auto" survives as a distinct value here. Zero is off. */
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--num-speculative-tokens", "auto" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.n_spec, -1);
|
||||
@@ -735,7 +960,7 @@ TEST(auto_speculation_is_negative_one_and_not_zero) {
|
||||
CHECK_EQ(c.n_spec, 0);
|
||||
CHECK_EQ(parse({ "--num-speculative-tokens", "3" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.n_spec, 3);
|
||||
/* Only the word says auto: a negative depth would read as it downstream. */
|
||||
/* Only the word means auto; a negative depth would be read as auto downstream. */
|
||||
CHECK_EQ(parse({ "--num-speculative-tokens", "-3" }, &c), RAD_E_INVAL);
|
||||
CHECK_EQ(parse({ "--num-speculative-tokens", "-1" }, &c), RAD_E_INVAL);
|
||||
|
||||
@@ -744,8 +969,7 @@ TEST(auto_speculation_is_negative_one_and_not_zero) {
|
||||
CHECK_EQ(d.n_spec, -1); /* auto is also the default */
|
||||
}
|
||||
|
||||
/* IT TAKES THE SHORT NAME TOO: "-mib" is the unit, and this is the flag an operator reaches for.
|
||||
* Both spellings parse to the same field, so a line written either way means one thing. */
|
||||
/* --gpu-headroom is an alias for --gpu-headroom-mib; both set the same field. */
|
||||
TEST(gpu_headroom_parses_under_both_spellings) {
|
||||
Config a, b, d;
|
||||
CHECK_EQ(parse({ "--gpu-headroom-mib", "256" }, &a), RAD_OK);
|
||||
@@ -756,15 +980,15 @@ TEST(gpu_headroom_parses_under_both_spellings) {
|
||||
CHECK_EQ(d.gpu_headroom_mib, 96ll);
|
||||
}
|
||||
|
||||
TEST(the_kernel_hierarchy_is_comma_separated_and_ordered) {
|
||||
TEST(the_kernel_hierarchy_is_separated_by_commas_or_colons_and_ordered) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--kernels", "libr4d.so,libref.so" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.kernel_hierarchy.size(), 2u);
|
||||
CHECK_EQ(c.kernel_hierarchy[0], std::string("libr4d.so")); /* first wins, so order is data */
|
||||
CHECK_EQ(c.kernel_hierarchy[0], std::string("libr4d.so")); /* first wins, so order matters */
|
||||
CHECK_EQ(c.kernel_hierarchy[1], std::string("libref.so"));
|
||||
|
||||
/* Empty segments are dropped rather than kept as empty names: a trailing comma is a typing
|
||||
* artefact, and a plugin path of "" matches nothing and would warn on every start. */
|
||||
/* Empty segments are dropped: a trailing comma is a typo, and a plugin path of "" matches
|
||||
* nothing and would warn on every start. */
|
||||
Config t;
|
||||
CHECK_EQ(parse({ "--kernels", ",a,,b," }, &t), RAD_OK);
|
||||
CHECK_EQ(t.kernel_hierarchy.size(), 2u);
|
||||
@@ -774,20 +998,28 @@ TEST(the_kernel_hierarchy_is_comma_separated_and_ordered) {
|
||||
Config one;
|
||||
CHECK_EQ(parse({ "--kernels", "solo" }, &one), RAD_OK);
|
||||
CHECK_EQ(one.kernel_hierarchy.size(), 1u);
|
||||
|
||||
/* A colon separates as a comma does: rad-kbench, rad-tune and rad-convert document
|
||||
* `--kernels A:B`, and the engine must load the same list from the same spelling. */
|
||||
Config col;
|
||||
CHECK_EQ(parse({ "--kernels", "mykernels:libr4d,libref" }, &col), RAD_OK);
|
||||
REQUIRE_EQ(col.kernel_hierarchy.size(), 3u);
|
||||
CHECK_EQ(col.kernel_hierarchy[0], std::string("mykernels"));
|
||||
CHECK_EQ(col.kernel_hierarchy[1], std::string("libr4d"));
|
||||
CHECK_EQ(col.kernel_hierarchy[2], std::string("libref"));
|
||||
}
|
||||
|
||||
/* AND THERE IS NO BUILT-IN DEFAULT HIERARCHY, deliberately: naming one card's kernel library in
|
||||
* the core would, on every other machine, rank the library that IS installed behind the reference
|
||||
* implementation. An empty hierarchy is not "no order" -- the loader supplies one. */
|
||||
/* There is deliberately no built-in default hierarchy: naming one card's kernel library in the
|
||||
* core would rank the installed library behind the reference elsewhere. The loader orders an empty
|
||||
* hierarchy. */
|
||||
TEST(an_unnamed_hierarchy_stays_empty_for_the_loader_to_order) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({}, &c), RAD_OK);
|
||||
CHECK_EQ(c.kernel_hierarchy.size(), 0u);
|
||||
}
|
||||
|
||||
/* THE ENGINE HONOURS THE SAME VARIABLE THE TOOLS DO. Otherwise an operator who validated a
|
||||
* third-party plugin with rad-kbench or rad-tune has no way to serve with it short of editing
|
||||
* every launcher's command line. */
|
||||
/* The engine honours the same environment variables as the tools, so a plugin validated with
|
||||
* rad-kbench or rad-tune serves without editing every launcher's command line. */
|
||||
TEST(the_environment_supplies_what_the_line_left_unsaid) {
|
||||
const char* old_home = getenv("RADIANCE_HOME");
|
||||
const char* old_kern = getenv("RADIANCE_KERNELS");
|
||||
@@ -803,33 +1035,45 @@ TEST(the_environment_supplies_what_the_line_left_unsaid) {
|
||||
CHECK_EQ(c.kernel_hierarchy.size(), 2u);
|
||||
CHECK_EQ(c.kernel_hierarchy[0], std::string("env_a"));
|
||||
|
||||
/* The command line wins over the environment, in both cases. */
|
||||
/* The command line wins over the environment. */
|
||||
Config f;
|
||||
CHECK_EQ(parse({ "--radiance-home", "/flag/home", "--kernels", "flag_only" }, &f), RAD_OK);
|
||||
CHECK_EQ(f.radiance_home, std::string("/flag/home"));
|
||||
CHECK_EQ(f.kernel_hierarchy.size(), 1u);
|
||||
CHECK_EQ(f.kernel_hierarchy[0], std::string("flag_only"));
|
||||
|
||||
/* An empty variable says nothing rather than saying "the empty hierarchy". */
|
||||
/* An empty variable is treated as unset, not as an empty hierarchy. */
|
||||
setenv("RADIANCE_KERNELS", "", 1);
|
||||
Config e;
|
||||
CHECK_EQ(parse({}, &e), RAD_OK);
|
||||
CHECK_EQ(e.kernel_hierarchy.size(), 0u);
|
||||
|
||||
/* $RADIANCE_KERNELS splits by the same rule as --kernels. */
|
||||
setenv("RADIANCE_KERNELS", "env_a:env_b", 1);
|
||||
Config k;
|
||||
CHECK_EQ(parse({}, &k), RAD_OK);
|
||||
CHECK(k.kernel_hierarchy == (std::vector<std::string>{ "env_a", "env_b" }));
|
||||
|
||||
unsetenv("RADIANCE_HOME");
|
||||
Config h;
|
||||
CHECK_EQ(parse({}, &h), RAD_OK);
|
||||
CHECK(!h.radiance_home.empty()); /* the compiled-in default, whatever it is */
|
||||
CHECK(!h.radiance_home.empty()); /* the compiled-in default */
|
||||
|
||||
/* A home set but empty is unset too: as the tools read it, and an empty home would load no
|
||||
* plugin. The source names the default, not the environment. */
|
||||
setenv("RADIANCE_HOME", "", 1);
|
||||
Config eh;
|
||||
CHECK_EQ(parse({}, &eh), RAD_OK);
|
||||
CHECK_EQ(eh.radiance_home, h.radiance_home);
|
||||
CHECK(!eh.given.count("--radiance-home"));
|
||||
|
||||
if (old_home) setenv("RADIANCE_HOME", save_home.c_str(), 1); else unsetenv("RADIANCE_HOME");
|
||||
if (old_kern) setenv("RADIANCE_KERNELS", save_kern.c_str(), 1); else unsetenv("RADIANCE_KERNELS");
|
||||
}
|
||||
|
||||
/* LATER WINS, for every flag that takes a value. Scripts build these lines by appending, and a
|
||||
* parser that kept the first occurrence would make an override a no-op. */
|
||||
TEST(the_download_dir_is_taken_and_left_empty_until_given) {
|
||||
/* Empty means "the XDG cache", which hf_model.cpp resolves only when --model is a repo id:
|
||||
* a server started on a local file never reads HOME for it. */
|
||||
/* Empty means the XDG cache, which hf_model.cpp resolves only when --model is a repo id, so a
|
||||
* server started on a local file never reads HOME for it. */
|
||||
Config c;
|
||||
CHECK_EQ(parse({}, &c), 0);
|
||||
CHECK(c.download_dir.empty());
|
||||
@@ -838,64 +1082,40 @@ TEST(the_download_dir_is_taken_and_left_empty_until_given) {
|
||||
CHECK_EQ(d.download_dir, std::string("/big/models"));
|
||||
}
|
||||
|
||||
/* The last occurrence wins for every flag with a value: scripts append overrides. */
|
||||
TEST(a_repeated_flag_takes_the_last_one) {
|
||||
Config c;
|
||||
CHECK_EQ(parse({ "--port", "1", "--port", "8100" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.port, 8100);
|
||||
CHECK_EQ(parse({ "--kv-cache-dtype", "bf16", "--kv-cache-dtype", "fp8" }, &c), RAD_OK);
|
||||
CHECK_EQ(c.kv_cache_dtype, std::string("fp8"));
|
||||
/* And a bad value refuses even when a good one preceded it. */
|
||||
/* A bad value is refused even after a good one. */
|
||||
CHECK_EQ(parse({ "--tp-wire", "exact", "--tp-wire", "nope" }, &c), RAD_E_INVAL);
|
||||
}
|
||||
|
||||
TEST(usage_names_every_flag_it_documents) {
|
||||
/* config_usage writes to stderr; the property worth holding is that it mentions the flags an
|
||||
* operator is most likely to be looking for, so a flag added without a help line is caught. */
|
||||
FILE* f = tmpfile();
|
||||
CHECK(f != nullptr);
|
||||
if (!f) return;
|
||||
const int saved = dup(2);
|
||||
CHECK(saved >= 0);
|
||||
fflush(stderr);
|
||||
dup2(fileno(f), 2);
|
||||
config_usage("radiance");
|
||||
fflush(stderr);
|
||||
dup2(saved, 2);
|
||||
close(saved);
|
||||
|
||||
std::string text;
|
||||
rewind(f);
|
||||
char buf[4096];
|
||||
size_t n;
|
||||
while ((n = fread(buf, 1, sizeof buf, f)) > 0) text.append(buf, n);
|
||||
fclose(f);
|
||||
|
||||
CHECK(text.find("--model") != std::string::npos);
|
||||
CHECK(text.find("--host-pool-mib") != std::string::npos);
|
||||
CHECK(text.find("--kv-cache-dtype") != std::string::npos);
|
||||
CHECK(text.find("--num-speculative-tokens") != std::string::npos);
|
||||
CHECK(text.find("--draft-window") != std::string::npos);
|
||||
CHECK(text.find(std::string("Default ") + draft_window_name(kDraftWindowDefault)) !=
|
||||
std::string::npos);
|
||||
CHECK(text.find("--checkpoint-policy") != std::string::npos);
|
||||
CHECK(text.find("--prefix-cache-mib") != std::string::npos);
|
||||
CHECK(text.find("--prefix-cache-ttl") != std::string::npos);
|
||||
CHECK(text.find("--tp-wire") != std::string::npos);
|
||||
CHECK(text.find("--embedding-placement") != std::string::npos);
|
||||
CHECK(text.find("--ngram-placement") != std::string::npos);
|
||||
CHECK(text.find("--kld-record") != std::string::npos);
|
||||
CHECK(text.find("--kld-ref") != std::string::npos);
|
||||
for (const char* f : { "--default-max-tokens", "--max-tokens-cap", "--presence-penalty",
|
||||
"--dry-sequence-breakers", "--chat-template-kwargs",
|
||||
"--reasoning-format", "--max-n", "--max-queued-requests",
|
||||
"--max-stop-strings", "--http-threads", "--max-body-mib", "--no-cors",
|
||||
"--image-max-pixels", "--video-fps", "--max-source-pixels",
|
||||
"--download-dir" })
|
||||
CHECK(text.find(f) != std::string::npos);
|
||||
/* config_usage writes to stderr; it must mention the flags an operator most likely looks
|
||||
* for, so a flag added without a help line is caught. */
|
||||
const std::string text = stderr_of([] { config_usage("radiance"); });
|
||||
for (const char* f : { "--model", "--host-pool-mib", "--kv-cache-dtype",
|
||||
"--num-speculative-tokens", "--draft-window", "--checkpoint-policy",
|
||||
"--prefix-cache-mib", "--prefix-cache-ttl", "--tp-wire",
|
||||
"--embedding-placement", "--ngram-placement", "--kld-record",
|
||||
"--kld-ref", "--default-max-tokens", "--max-tokens-cap",
|
||||
"--presence-penalty", "--dry-sequence-breakers",
|
||||
"--chat-template-kwargs", "--reasoning-format", "--max-n",
|
||||
"--max-queued-requests", "--max-stop-strings", "--http-threads",
|
||||
"--max-body-mib", "--no-cors", "--image-max-pixels", "--video-fps",
|
||||
"--max-source-pixels", "--download-dir" })
|
||||
CHECK(has(text, f));
|
||||
CHECK(has(text, std::string("Default ") + draft_window_name(kDraftWindowDefault)));
|
||||
/* top_k 0 is the sampler's candidate width, not the whole vocabulary or "off". */
|
||||
CHECK(has(text, "0 is the 1024 most"));
|
||||
CHECK(!has(text, "top_k (0 = off)"));
|
||||
CHECK(text.size() > 1000);
|
||||
}
|
||||
|
||||
/* --rope-scaling is checked at the command line: a typo is a refusal, not a model served with its
|
||||
/* --rope-scaling is validated at the command line: a typo is refused rather than serving the
|
||||
* trained rotary at a length it cannot reach. */
|
||||
TEST(rope_scaling_takes_yarn_with_a_factor_above_one_or_none) {
|
||||
for (const char* ok : { "yarn:4", "yarn:2.5", "yarn:4:262144", "none" }) {
|
||||
|
||||
@@ -0,0 +1,511 @@
|
||||
/* convert_test.cpp -- rad-convert end to end on a tiny synthetic checkpoint (tests/tiny_model.h).
|
||||
*
|
||||
* The binary runs as a child on the host backend; the containers it writes are read back with
|
||||
* core's reader and decoder. The checkpoint is a two-layer LLaMA served by llama_dense_fp8, whose
|
||||
* recipe makes every linear block fp8 and keeps the norms, the embedding and the head as the
|
||||
* checkpoint holds them, so one conversion writes a quantised and a copied weight of every kind.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
#include "tiny_model.h"
|
||||
|
||||
#include "format/encoding.h"
|
||||
#include "format/radfile.h"
|
||||
#include "gen_config.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
using namespace rad;
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<std::string> convert_env(const std::vector<std::string>& more = {}) {
|
||||
std::vector<std::string> e = { "ROCR_VISIBLE_DEVICES=99", "OMP_WAIT_POLICY=passive",
|
||||
"OMP_NUM_THREADS=2",
|
||||
std::string("RADIANCE_HOME=") + RAD_E2E_HOME };
|
||||
e.insert(e.end(), more.begin(), more.end());
|
||||
return e;
|
||||
}
|
||||
|
||||
/* rad-convert `ckpt` with `args`: its exit status, and its output in `log`. */
|
||||
int convert(const std::string& ckpt, const std::vector<std::string>& args, std::string* log,
|
||||
const std::vector<std::string>& env = {}) {
|
||||
std::vector<std::string> a = { RAD_E2E_CONVERT, ckpt };
|
||||
a.insert(a.end(), args.begin(), args.end());
|
||||
std::string out;
|
||||
const int st = tiny::run(a, convert_env(env), &out);
|
||||
if (log) *log = out;
|
||||
return st;
|
||||
}
|
||||
|
||||
bool exists(const std::string& p) {
|
||||
struct stat st {};
|
||||
return stat(p.c_str(), &st) == 0;
|
||||
}
|
||||
|
||||
bool copy_file(const std::string& from, const std::string& to) {
|
||||
std::error_code ec;
|
||||
std::filesystem::copy_file(from, to, std::filesystem::copy_options::overwrite_existing, ec);
|
||||
return !ec;
|
||||
}
|
||||
|
||||
/* The checkpoint, its recipe and one conversion of it, shared by every case. */
|
||||
struct World {
|
||||
tiny::TempDir dir{ "convert" };
|
||||
std::string ckpt, recipe, base;
|
||||
std::map<std::string, tiny::Tensor> src; /* the checkpoint's tensors by name */
|
||||
std::string log;
|
||||
bool ok = false;
|
||||
|
||||
World() {
|
||||
if (!dir.ok()) return;
|
||||
ckpt = dir / "llama";
|
||||
recipe = dir / "fp8.recipe";
|
||||
base = dir / "base.rad";
|
||||
if (mkdir(ckpt.c_str(), 0755) != 0 || !tiny::write_llama(ckpt, {}) ||
|
||||
!tiny::write_text(recipe, tiny::kLlamaFp8Recipe))
|
||||
return;
|
||||
for (tiny::Tensor& t : tiny::read_safetensors(ckpt + "/model.safetensors"))
|
||||
src[t.name] = std::move(t);
|
||||
ok = !src.empty() && convert(ckpt, { "-o", base, "--recipe", recipe }, &log) == 0;
|
||||
if (!ok) fprintf(stderr, " the base conversion failed:\n%s\n", log.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
World& world() {
|
||||
static World w;
|
||||
return w;
|
||||
}
|
||||
|
||||
/* A weight's planes, decoded to f32 [rows, cols] by the core's decoder. */
|
||||
std::vector<float> decode(const RadFile& f, const RadFileEntry& e) {
|
||||
const int64_t cols = e.shape[e.rank - 1];
|
||||
int64_t rows = 1;
|
||||
for (uint32_t k = 0; k + 1 < e.rank; ++k) rows *= e.shape[k];
|
||||
const void* planes[RAD_ENC_MAX_PLANES] = {};
|
||||
for (uint32_t k = 0; k < e.n_planes; ++k) planes[k] = f.data(f.plane(e, (int)k));
|
||||
EncodedView v;
|
||||
enc_view(f.encoding(e), rows, cols, planes, &v);
|
||||
std::vector<float> out((size_t)(rows * cols));
|
||||
if (enc_decode_rows(v, 0, rows, out.data()) != RAD_OK) out.clear();
|
||||
return out;
|
||||
}
|
||||
|
||||
/* The bytes of an entry's planes, concatenated. */
|
||||
std::string entry_bytes(const RadFile& f, const RadFileEntry& e) {
|
||||
std::string s;
|
||||
for (uint32_t k = 0; k < e.n_planes; ++k) {
|
||||
const RadFilePlane& p = f.plane(e, (int)k);
|
||||
s.append((const char*)f.data(p), (size_t)p.bytes);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Every weight whose planes differ between two containers. */
|
||||
std::vector<std::string> differing_weights(const RadFile& a, const RadFile& b) {
|
||||
std::vector<std::string> out;
|
||||
for (int64_t i = 0; i < a.entry_count(); ++i) {
|
||||
const RadFileEntry& e = a.entry(i);
|
||||
const RadFileEntry* o = b.find(a.str(e.name));
|
||||
if (!o || entry_bytes(a, e) != entry_bytes(b, *o)) out.push_back(a.str(e.name));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* ================================================================== what a conversion writes */
|
||||
|
||||
/* A recipe weight is block fp8 over the rows its name map joins, in the map's order: attn_qkv is
|
||||
* q, then k, then v, and ffn_gate_up is gate then up. Each element decodes to its source within
|
||||
* E4M3's half step (2^-4 relative) plus one subnormal step of its block's scale (amax / 448 /
|
||||
* 2^9). A part out of order, or a block's scale applied to another block's rows, is off by the
|
||||
* source's own magnitude. */
|
||||
TEST(a_recipe_weight_decodes_to_its_source_rows_in_name_map_order) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
RadFile f;
|
||||
REQUIRE_EQ(f.open(w.base.c_str()), RAD_OK);
|
||||
const struct { const char* weight; std::vector<const char*> parts; } kJoins[] = {
|
||||
{ "blk.0.attn_qkv.weight", { "model.layers.0.self_attn.q_proj.weight",
|
||||
"model.layers.0.self_attn.k_proj.weight",
|
||||
"model.layers.0.self_attn.v_proj.weight" } },
|
||||
{ "blk.1.ffn_gate_up.weight", { "model.layers.1.mlp.gate_proj.weight",
|
||||
"model.layers.1.mlp.up_proj.weight" } },
|
||||
{ "blk.1.ffn_down.weight", { "model.layers.1.mlp.down_proj.weight" } },
|
||||
{ "blk.0.attn_output.weight", { "model.layers.0.self_attn.o_proj.weight" } },
|
||||
};
|
||||
for (const auto& j : kJoins) {
|
||||
const RadFileEntry* e = f.find(j.weight);
|
||||
REQUIRE(e != nullptr);
|
||||
CHECK_EQ(enc_name(f.encoding(*e)), std::string("fp8_e4m3*bf16[128x128]"));
|
||||
CHECK_EQ(std::string(f.str(e->quantizer)), std::string("rtn"));
|
||||
const std::vector<float> got = decode(f, *e);
|
||||
REQUIRE(!got.empty());
|
||||
const int64_t rows = e->shape[0], cols = e->shape[1];
|
||||
std::vector<float> want;
|
||||
for (const char* part : j.parts) {
|
||||
const tiny::Tensor& t = w.src.at(part);
|
||||
REQUIRE_EQ(t.shape[1], cols);
|
||||
for (int64_t i = 0; i < t.shape[0] * cols; ++i) {
|
||||
uint16_t h;
|
||||
std::memcpy(&h, t.bytes.data() + 2 * i, 2);
|
||||
want.push_back(rad_bf16_to_f32(h));
|
||||
}
|
||||
}
|
||||
REQUIRE_EQ((int64_t)want.size(), rows * cols);
|
||||
int64_t bad = 0;
|
||||
for (int64_t r0 = 0; r0 < rows; r0 += 128)
|
||||
for (int64_t c0 = 0; c0 < cols; c0 += 128) {
|
||||
float amax = 0;
|
||||
for (int64_t r = r0; r < std::min(rows, r0 + 128); ++r)
|
||||
for (int64_t c = c0; c < std::min(cols, c0 + 128); ++c)
|
||||
amax = std::max(amax, std::fabs(want[(size_t)(r * cols + c)]));
|
||||
for (int64_t r = r0; r < std::min(rows, r0 + 128); ++r)
|
||||
for (int64_t c = c0; c < std::min(cols, c0 + 128); ++c) {
|
||||
const size_t i = (size_t)(r * cols + c);
|
||||
const float tol = 0.0625f * std::fabs(want[i]) + amax / 448.0f / 512.0f;
|
||||
if (!(std::fabs(got[i] - want[i]) <= tol)) ++bad;
|
||||
}
|
||||
}
|
||||
if (bad)
|
||||
fprintf(stderr, " %s: %lld elements outside the bound\n", j.weight, (long long)bad);
|
||||
CHECK_EQ(bad, (int64_t)0);
|
||||
}
|
||||
}
|
||||
|
||||
/* A weight no rule matches keeps the checkpoint's encoding, byte for byte. */
|
||||
TEST(a_weight_no_rule_matches_is_the_checkpoints_bytes) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
RadFile f;
|
||||
REQUIRE_EQ(f.open(w.base.c_str()), RAD_OK);
|
||||
const std::pair<const char*, const char*> kCopies[] = {
|
||||
{ "token_embd.weight", "model.embed_tokens.weight" },
|
||||
{ "output.weight", "lm_head.weight" },
|
||||
{ "output_norm.weight", "model.norm.weight" },
|
||||
{ "blk.1.attn_norm.weight", "model.layers.1.input_layernorm.weight" },
|
||||
{ "blk.0.ffn_norm.weight", "model.layers.0.post_attention_layernorm.weight" },
|
||||
};
|
||||
for (const auto& [name, from] : kCopies) {
|
||||
const RadFileEntry* e = f.find(name);
|
||||
REQUIRE(e != nullptr);
|
||||
CHECK_EQ(enc_name(f.encoding(*e)), std::string("bf16"));
|
||||
CHECK_EQ(std::string(f.str(e->quantizer)), std::string(""));
|
||||
const tiny::Tensor& t = w.src.at(from);
|
||||
CHECK(entry_bytes(f, *e) == std::string(t.bytes.begin(), t.bytes.end()));
|
||||
}
|
||||
}
|
||||
|
||||
/* The header names the architecture and the recipe, the metadata carries config.json's
|
||||
* dimensions under RadModelMeta's names, and the provenance names the checkpoint without the
|
||||
* absolute path of the machine that converted it. */
|
||||
TEST(the_header_and_metadata_describe_the_checkpoint) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
RadFile f;
|
||||
REQUIRE_EQ(f.open(w.base.c_str()), RAD_OK);
|
||||
const RadFileHeader& h = f.header();
|
||||
CHECK_EQ(std::string(f.str(h.arch_id)), std::string("llama"));
|
||||
CHECK_EQ(std::string(f.str(h.quant)), std::string(""));
|
||||
const std::string recipe = f.str(h.recipe);
|
||||
for (const char* rule : { "blk.*.attn_qkv.weight", "blk.*.attn_output.weight",
|
||||
"blk.*.ffn_gate_up.weight", "blk.*.ffn_down.weight" })
|
||||
CHECK(has(recipe, rule));
|
||||
const std::string by = f.str(h.created_by);
|
||||
CHECK(has(by, "rad-convert"));
|
||||
CHECK(!has(by, w.dir.path));
|
||||
const tiny::Llama s{};
|
||||
const std::pair<const char*, int64_t> kDims[] = {
|
||||
{ "n_layers", s.layers }, { "n_embd", s.hidden }, { "n_head", s.heads },
|
||||
{ "n_head_kv", s.kv_heads }, { "head_dim", s.head_dim }, { "n_ff", s.ffn },
|
||||
{ "n_vocab", s.vocab }, { "n_ctx_train", s.ctx } };
|
||||
for (const auto& [key, want] : kDims) {
|
||||
int64_t v = -1;
|
||||
CHECK(f.get_i(key, &v));
|
||||
CHECK_EQ(v, want);
|
||||
}
|
||||
CHECK_EQ(f.entry_count(), (int64_t)15);
|
||||
CHECK(f.vocab());
|
||||
}
|
||||
|
||||
/* Weights are quantised in parallel pieces; the bytes must not depend on how many threads. */
|
||||
TEST(a_conversion_is_the_same_bytes_at_any_thread_count) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_t");
|
||||
for (const char* n : { "1", "7" }) {
|
||||
const std::string out = d / (std::string("t") + n + ".rad");
|
||||
REQUIRE_EQ(convert(w.ckpt, { "-o", out, "--recipe", w.recipe }, nullptr,
|
||||
{ std::string("OMP_NUM_THREADS=") + n }), 0);
|
||||
CHECK(tiny::read_text(out) == tiny::read_text(w.base));
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================== --reuse and --changed */
|
||||
|
||||
/* --reuse copies every weight converted the same way, which for an unchanged checkpoint is all
|
||||
* of them: the result is the same file. */
|
||||
TEST(reuse_of_an_unchanged_checkpoint_writes_the_same_file) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_r");
|
||||
std::string log;
|
||||
REQUIRE_EQ(convert(w.ckpt, { "-o", d / "r.rad", "--recipe", w.recipe, "--reuse", w.base },
|
||||
&log), 0);
|
||||
CHECK(has(log, "--reuse: 15 weight(s)"));
|
||||
CHECK(tiny::read_text(d / "r.rad") == tiny::read_text(w.base));
|
||||
}
|
||||
|
||||
/* --reuse matches on how a weight was converted, not on its source bytes, so a changed tensor is
|
||||
* copied stale unless --changed names it; named, exactly the weights that read it are converted
|
||||
* again. */
|
||||
TEST(changed_reconverts_exactly_the_weights_that_read_a_changed_tensor) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_c");
|
||||
const std::string ck = d / "llama";
|
||||
REQUIRE(mkdir(ck.c_str(), 0755) == 0);
|
||||
for (const char* f : { "config.json", "tokenizer.json" })
|
||||
REQUIRE(copy_file(w.ckpt + "/" + f, ck + "/" + f));
|
||||
std::vector<tiny::Tensor> ts = tiny::read_safetensors(w.ckpt + "/model.safetensors");
|
||||
for (tiny::Tensor& t : ts)
|
||||
if (t.name == "model.layers.0.mlp.down_proj.weight")
|
||||
for (size_t i = 0; i < t.bytes.size(); i += 2) t.bytes[i + 1] ^= 0x80; /* negate */
|
||||
REQUIRE(tiny::write_safetensors(ck + "/model.safetensors", ts));
|
||||
REQUIRE(tiny::write_text(d / "changed",
|
||||
"# the fine-tuned tensor\nmodel.layers.0.mlp.down_proj.weight\n"));
|
||||
|
||||
RadFile base;
|
||||
REQUIRE_EQ(base.open(w.base.c_str()), RAD_OK);
|
||||
{
|
||||
REQUIRE_EQ(convert(ck, { "-o", d / "stale.rad", "--recipe", w.recipe, "--reuse", w.base },
|
||||
nullptr), 0);
|
||||
RadFile f;
|
||||
REQUIRE_EQ(f.open((d / "stale.rad").c_str()), RAD_OK);
|
||||
CHECK(differing_weights(base, f).empty());
|
||||
}
|
||||
std::string log;
|
||||
REQUIRE_EQ(convert(ck, { "-o", d / "fresh.rad", "--recipe", w.recipe, "--reuse", w.base,
|
||||
"--changed", d / "changed" }, &log), 0);
|
||||
RadFile f;
|
||||
REQUIRE_EQ(f.open((d / "fresh.rad").c_str()), RAD_OK);
|
||||
const std::vector<std::string> diff = differing_weights(base, f);
|
||||
CHECK_EQ(diff.size(), (size_t)1);
|
||||
CHECK(!diff.empty() && diff[0] == "blk.0.ffn_down.weight");
|
||||
/* And it is the negated weight, not merely different bytes. */
|
||||
const RadFileEntry* a = base.find("blk.0.ffn_down.weight");
|
||||
const RadFileEntry* b = f.find("blk.0.ffn_down.weight");
|
||||
REQUIRE(a && b);
|
||||
const std::vector<float> va = decode(base, *a), vb = decode(f, *b);
|
||||
REQUIRE(!va.empty() && va.size() == vb.size());
|
||||
int64_t neg = 0;
|
||||
for (size_t i = 0; i < va.size(); ++i) neg += va[i] == -vb[i];
|
||||
CHECK_EQ(neg, (int64_t)va.size());
|
||||
}
|
||||
|
||||
/* --changed is a list for --reuse: without it, or naming a tensor no weight reads (a typo would
|
||||
* otherwise copy the stale weight it meant), the run stops before writing anything. */
|
||||
TEST(changed_is_refused_without_reuse_or_for_a_tensor_nothing_reads) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_cr");
|
||||
REQUIRE(tiny::write_text(d / "unread", "model.layers.0.mlp.nope.weight\n"));
|
||||
REQUIRE(tiny::write_text(d / "real", "model.layers.0.mlp.down_proj.weight\n"));
|
||||
const std::vector<std::vector<std::string>> kRuns = {
|
||||
{ "-o", d / "a.rad", "--recipe", w.recipe, "--changed", d / "real" },
|
||||
{ "-o", d / "b.rad", "--recipe", w.recipe, "--reuse", w.base, "--changed", d / "unread" },
|
||||
};
|
||||
for (const auto& args : kRuns) {
|
||||
std::string log;
|
||||
CHECK(convert(w.ckpt, args, &log) != 0);
|
||||
CHECK(!exists(args[1]));
|
||||
CHECK(!exists(args[1] + ".blob.tmp"));
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================== --in-place */
|
||||
|
||||
/* Extending a container with nothing new keeps every weight at its offset, and the .pre-append
|
||||
* file (the old header and length) restores the original byte for byte. */
|
||||
TEST(in_place_keeps_every_weight_where_it_was_and_can_be_undone) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_ip");
|
||||
const std::string ip = d / "ip.rad";
|
||||
REQUIRE(copy_file(w.base, ip));
|
||||
std::string log;
|
||||
REQUIRE_EQ(convert(w.ckpt, { "--recipe", w.recipe, "--reuse", ip, "--in-place" }, &log), 0);
|
||||
CHECK(has(log, "15 weight(s)"));
|
||||
RadFile a, b;
|
||||
REQUIRE_EQ(a.open(w.base.c_str()), RAD_OK);
|
||||
REQUIRE_EQ(b.open(ip.c_str()), RAD_OK);
|
||||
REQUIRE_EQ(a.entry_count(), b.entry_count());
|
||||
for (int64_t i = 0; i < a.entry_count(); ++i) {
|
||||
const RadFileEntry* e = b.find(a.str(a.entry(i).name));
|
||||
REQUIRE(e != nullptr);
|
||||
CHECK_EQ(e->offset, a.entry(i).offset);
|
||||
}
|
||||
b.close();
|
||||
|
||||
const std::string bak = tiny::read_text(ip + ".pre-append");
|
||||
REQUIRE_EQ(bak.size(), sizeof(RadFileHeader) + sizeof(int64_t));
|
||||
int64_t len = 0;
|
||||
std::memcpy(&len, bak.data() + sizeof(RadFileHeader), sizeof len);
|
||||
std::string file = tiny::read_text(ip);
|
||||
REQUIRE(len > 0 && (size_t)len <= file.size());
|
||||
file.replace(0, sizeof(RadFileHeader), bak.data(), sizeof(RadFileHeader));
|
||||
file.resize((size_t)len);
|
||||
CHECK(file == tiny::read_text(w.base));
|
||||
}
|
||||
|
||||
/* In place, a weight cannot be replaced: a rule that would write one differently is refused and
|
||||
* the file is left as it was. Without --in-place, -o may not name the --reuse container, whose
|
||||
* weights the run reads while it truncates the output. */
|
||||
TEST(in_place_refuses_to_change_a_weight_and_reuse_never_truncates_its_source) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_ipr");
|
||||
const std::string ip = d / "ip.rad";
|
||||
REQUIRE(copy_file(w.base, ip));
|
||||
REQUIRE(tiny::write_text(d / "search.recipe",
|
||||
std::string("blk.0.attn_qkv.weight rtn codes=fp8_e4m3 block=128x128 "
|
||||
"scale=bf16 rule=search\n") + tiny::kLlamaFp8Recipe));
|
||||
std::string log;
|
||||
CHECK(convert(w.ckpt, { "--recipe", d / "search.recipe", "--reuse", ip, "--in-place" },
|
||||
&log) != 0);
|
||||
CHECK(has(log, "cannot be replaced in place"));
|
||||
CHECK(tiny::read_text(ip) == tiny::read_text(w.base));
|
||||
CHECK_EQ(convert(w.ckpt, { "-o", ip, "--recipe", w.recipe, "--reuse", ip }, &log), 2);
|
||||
CHECK(tiny::read_text(ip) == tiny::read_text(w.base));
|
||||
}
|
||||
|
||||
/* ================================================================== refusals and options */
|
||||
|
||||
/* --plan-only declares and plans every weight, and writes nothing. */
|
||||
TEST(plan_only_writes_nothing) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_p");
|
||||
std::string log;
|
||||
CHECK_EQ(convert(w.ckpt, { "-o", d / "p.rad", "--recipe", w.recipe, "--plan-only" }, &log), 0);
|
||||
CHECK(has(log, "nothing was written"));
|
||||
CHECK(!exists(d / "p.rad"));
|
||||
}
|
||||
|
||||
/* A recipe or flag that cannot be honoured stops the run with status 2 before any file exists:
|
||||
* an unknown quantiser, option, or non-integer value, a recipe that cannot be read, an unset
|
||||
* $VARIABLE, a --set without `=`, and a KV dtype that is not bf16 or fp8. */
|
||||
TEST(a_recipe_or_flag_that_cannot_be_honoured_is_refused_before_writing) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_x");
|
||||
const char* kRule = "blk.*.attn_qkv.weight ";
|
||||
const std::pair<const char*, std::string> kRecipes[] = {
|
||||
{ "quantiser", std::string(kRule) + "nope codes=fp8_e4m3" },
|
||||
{ "option", std::string(kRule) + "rtn codez=fp8_e4m3 block=128x128 scale=bf16" },
|
||||
{ "integer", std::string(kRule) + "rtn codes=i4 group=abc scale=f16" },
|
||||
{ "variable", std::string(kRule) + "rtn codes=$RAD_CONVERT_TEST_UNSET block=128x128" },
|
||||
};
|
||||
int k = 0;
|
||||
for (const auto& [what, text] : kRecipes) {
|
||||
const std::string r = d / (std::string(what) + ".recipe");
|
||||
const std::string out = d / ("x" + std::to_string(k++));
|
||||
REQUIRE(tiny::write_text(r, text + "\n"));
|
||||
std::string log;
|
||||
const int st = convert(w.ckpt, { "-o", out, "--recipe", r }, &log,
|
||||
{ "RAD_CONVERT_TEST_UNSET" });
|
||||
if (st != 2) fprintf(stderr, " %s: status %d\n%s\n", what, st, log.c_str());
|
||||
CHECK_EQ(st, 2);
|
||||
CHECK(!exists(out));
|
||||
}
|
||||
const std::vector<std::vector<std::string>> kFlags = {
|
||||
{ "--recipe", d / "absent.recipe" },
|
||||
{ "--recipe", w.recipe, "--set", "foo" },
|
||||
{ "--recipe", w.recipe, "--kv-cache-dtype", "auto" },
|
||||
};
|
||||
for (const auto& args : kFlags) {
|
||||
std::vector<std::string> a = { "-o", d / "f.rad" };
|
||||
a.insert(a.end(), args.begin(), args.end());
|
||||
CHECK_EQ(convert(w.ckpt, a, nullptr), 2);
|
||||
CHECK(!exists(d / "f.rad"));
|
||||
}
|
||||
}
|
||||
|
||||
/* A rule that matches nothing is almost always a typo, so it is named; the run goes on. */
|
||||
TEST(a_rule_that_matches_no_weight_is_warned_about) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_w");
|
||||
REQUIRE(tiny::write_text(d / "r", std::string("blk.*.attn_qvk.weight rtn codes=fp8_e4m3 "
|
||||
"block=128x128 scale=bf16\n") +
|
||||
tiny::kLlamaFp8Recipe));
|
||||
std::string log;
|
||||
CHECK_EQ(convert(w.ckpt, { "-o", d / "w.rad", "--recipe", d / "r" }, &log), 0);
|
||||
CHECK(has(log, "'blk.*.attn_qvk.weight rtn' matches no weight"));
|
||||
}
|
||||
|
||||
/* --set writes a key into the container, where declare and the engine both read it; setting the
|
||||
* quantization_config makes it the header's descriptor, which selects the plugin. */
|
||||
TEST(set_writes_a_metadata_key_and_can_state_the_quantisation) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_s");
|
||||
REQUIRE_EQ(convert(w.ckpt, { "-o", d / "s.rad", "--recipe", w.recipe, "--set", "foo.bar=7",
|
||||
"--set", "quantization_config.quant_method=fp8",
|
||||
"--set", "quantization_config.fmt=e4m3" }, nullptr), 0);
|
||||
RadFile f;
|
||||
REQUIRE_EQ(f.open((d / "s.rad").c_str()), RAD_OK);
|
||||
const char* v = f.get_s("foo.bar");
|
||||
int64_t i = -1;
|
||||
CHECK((v && std::string(v) == "7") || (f.get_i("foo.bar", &i) && i == 7));
|
||||
CHECK_EQ(std::string(f.str(f.header().quant)), std::string("fp8_e4m3"));
|
||||
}
|
||||
|
||||
/* generation_config.json beside the checkpoint travels as `generation.*` keys, which is where
|
||||
* the engine reads a container's sampling defaults. */
|
||||
TEST(generation_config_travels_as_generation_keys) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_g");
|
||||
const std::string ck = d / "llama";
|
||||
REQUIRE(mkdir(ck.c_str(), 0755) == 0);
|
||||
for (const char* f : { "config.json", "tokenizer.json", "model.safetensors" })
|
||||
REQUIRE(copy_file(w.ckpt + "/" + f, ck + "/" + f));
|
||||
REQUIRE(tiny::write_text(
|
||||
ck + "/generation_config.json",
|
||||
R"({"temperature": 0.6, "top_k": 20, "top_p": 0.95, "do_sample": true})"));
|
||||
REQUIRE_EQ(convert(ck, { "-o", d / "g.rad", "--recipe", w.recipe }, nullptr), 0);
|
||||
RadFile f;
|
||||
REQUIRE_EQ(f.open((d / "g.rad").c_str()), RAD_OK);
|
||||
std::vector<std::string> keep;
|
||||
GenSampling g;
|
||||
CHECK(gen_sampling_from_kv(
|
||||
[&](const char* k) -> const char* {
|
||||
const std::string key = std::string("generation.") + k;
|
||||
if (const char* s = f.get_s(key.c_str())) return s;
|
||||
int64_t i;
|
||||
double x;
|
||||
if (f.get_i(key.c_str(), &i)) keep.push_back(std::to_string(i));
|
||||
else if (f.get_f(key.c_str(), &x)) keep.push_back(std::to_string(x));
|
||||
else return nullptr;
|
||||
return keep.back().c_str();
|
||||
},
|
||||
&g));
|
||||
CHECK_NEAR(g.temp, 0.6, 1e-6);
|
||||
CHECK_EQ(g.top_k, 20);
|
||||
CHECK_NEAR(g.top_p, 0.95, 1e-6);
|
||||
}
|
||||
|
||||
/* Declare runs at the KV dtype the engine will use; fp8 resolves on the host kernels too. */
|
||||
TEST(an_fp8_kv_cache_declares) {
|
||||
World& w = world();
|
||||
REQUIRE(w.ok);
|
||||
tiny::TempDir d("convert_k");
|
||||
CHECK_EQ(convert(w.ckpt, { "-o", d / "k.rad", "--recipe", w.recipe, "--kv-cache-dtype", "fp8" },
|
||||
nullptr), 0);
|
||||
CHECK(exists(d / "k.rad"));
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
@@ -0,0 +1,342 @@
|
||||
/* tests/dashboard_test.cpp -- what the dashboard and its JSON routes show.
|
||||
*
|
||||
* The page at `/` polls /stats and /sessions and reads dozens of their fields by name; a field
|
||||
* renamed on either side blanks a panel with no error anywhere. So the routes are checked for the
|
||||
* values a populated engine gives them, and the page's own script is read for every field it
|
||||
* takes from them, each of which a route must emit. The KV figures behind both come from
|
||||
* SchedulerBridge's aggregation over the scheduler's groups, checked here on a hybrid model's
|
||||
* groups, where summing or picking the wrong group goes wrong silently.
|
||||
*/
|
||||
#include "server_fakes.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace {
|
||||
|
||||
/* A scheduler with a live request table, stored sessions and idle-tier counters. */
|
||||
struct StatsScheduler : FakeScheduler {
|
||||
int requests(std::vector<RequestStat>* out) const override {
|
||||
RequestStat r;
|
||||
r.id = 41;
|
||||
r.state = "decode";
|
||||
r.prompt_tokens = 900;
|
||||
r.computed_tokens = 900;
|
||||
r.cached_tokens = 512;
|
||||
r.output_tokens = 33;
|
||||
r.max_tokens = 4096;
|
||||
r.ctx_tokens = 933;
|
||||
r.kv_blocks = 120;
|
||||
r.kv_tokens = 960;
|
||||
r.n_draft = 3;
|
||||
r.slot = 2;
|
||||
r.age_s = 4.5;
|
||||
r.ttft_s = 0.25;
|
||||
r.decode_tps = 61.0;
|
||||
out->assign(1, r);
|
||||
return 1;
|
||||
}
|
||||
int sessions(std::vector<SessionStat>* out, SessionOccupancy* occ) const override {
|
||||
SessionStat s;
|
||||
s.id = 7;
|
||||
s.model = "m";
|
||||
s.label = "conv-7";
|
||||
s.n_tokens = 5000;
|
||||
s.bytes = 1 << 20;
|
||||
s.idle_s = 12.0;
|
||||
s.age_s = 300.0;
|
||||
s.on_device = 40;
|
||||
s.on_host = 10;
|
||||
s.snapshots = 2;
|
||||
s.snap_bytes = 4096;
|
||||
s.resume_tokens = 4096;
|
||||
s.moving = true;
|
||||
out->assign(1, s);
|
||||
occ->host_bytes = 8 << 20;
|
||||
occ->host_cap_bytes = 64 << 20;
|
||||
return 1;
|
||||
}
|
||||
TierCounters tier_counters() const override {
|
||||
TierCounters c;
|
||||
c.to_host = 3; c.dropped = 2; c.promoted = 1; c.host_drops = 4; c.failures = 0;
|
||||
c.host_bytes = 8 << 20; c.ck_bytes = 2048; c.ck_slots = 16;
|
||||
c.restores = 5; c.restore_ns = 2000000; c.flushes = 6; c.flush_ns = 3000000;
|
||||
c.host_on = true;
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
/* Every value a snapshot carries, set, so every optional field is emitted. */
|
||||
void populated(LiveSnapshot& s) {
|
||||
CardStat c;
|
||||
c.index = 0;
|
||||
c.name = "R9700";
|
||||
c.util = 0.5;
|
||||
c.vram_used = 10LL << 30;
|
||||
c.vram_total = 32LL << 30;
|
||||
c.power_w = 200;
|
||||
c.temp_c = 60;
|
||||
s.cards = { c };
|
||||
s.experts.n_layers = 2;
|
||||
s.experts.n_experts = 3;
|
||||
s.experts.tier = { 0, 1, 2, 0, 0, 1 };
|
||||
for (int t = 0; t < kLiveTiers; ++t) { s.experts.units[t] = t + 1; s.experts.bytes[t] = (t + 1) << 20; }
|
||||
s.experts.n_units = 6;
|
||||
s.experts.total_bytes = 6 << 20;
|
||||
s.experts.movable = 4;
|
||||
s.experts.layer_units = { 3, 3 };
|
||||
s.experts.layer_resident = { 2, 3 };
|
||||
s.experts.promotions = 9; s.experts.demotions = 8; s.experts.readmits = 2;
|
||||
s.experts.distinct_promoted = 7; s.experts.dispatches = 20; s.experts.refused = 3;
|
||||
s.experts.no_candidate = 1; s.experts.routed = 100; s.experts.routed_resident = 80;
|
||||
s.experts.flex_bytes = 1 << 20; s.experts.flex_capacity = 2 << 20;
|
||||
s.experts.heat_enabled = true;
|
||||
s.link.present = true;
|
||||
s.link.world = 2;
|
||||
s.link.ar_calls = 50; s.link.ar_bytes = 5000; s.link.h2d_bytes = 900; s.link.d2h_bytes = 800;
|
||||
s.link.ssd_reads = 4; s.link.ssd_bytes = 400; s.link.stream_bytes = 700;
|
||||
s.link.prefetched = 2; s.link.prefetch_bytes = 300; s.link.staged_bytes = 200;
|
||||
s.passes.present = true;
|
||||
s.passes.played = 10; s.passes.recorded = 2;
|
||||
}
|
||||
|
||||
struct Dash {
|
||||
StatsScheduler sched;
|
||||
FakeTokenizer tok;
|
||||
std::unique_ptr<Server> srv;
|
||||
explicit Dash(bool with_graph) {
|
||||
Deps d;
|
||||
d.sched = &sched;
|
||||
d.tok = &tok;
|
||||
d.live = populated;
|
||||
ServerOptions o;
|
||||
o.model_id = "dash";
|
||||
o.max_seqs = 4;
|
||||
if (with_graph) o.graph_json = [] { return std::string(R"({"order":[]})"); };
|
||||
sched.m.running = 1;
|
||||
sched.m.waiting = 2;
|
||||
sched.m.kv_tokens_used = 1000;
|
||||
sched.m.kv_tokens_total = 4000;
|
||||
sched.m.kv_tokens_cached = 300;
|
||||
sched.m.kv_tokens_max = 6000;
|
||||
sched.m.prefix_ckpt_lru = 3;
|
||||
sched.m.hit_cut_no_snapshot = 2;
|
||||
sched.m.hit_cut_tokens = 9000;
|
||||
sched.m.draft_depth_seen = 2;
|
||||
sched.m.draft_pos_reached[0] = 10; sched.m.draft_pos_accepted[0] = 8;
|
||||
sched.m.draft_pos_reached[1] = 8; sched.m.draft_pos_accepted[1] = 2;
|
||||
srv.reset(new Server(d, o));
|
||||
}
|
||||
json get(const char* path) {
|
||||
HttpResponse r = srv->router().call("GET", path);
|
||||
CHECK_EQ(r.status, 200);
|
||||
return json::parse(r.body, nullptr, false);
|
||||
}
|
||||
};
|
||||
|
||||
/* The identifiers `var.<name>` that `text` reads, and the string arguments of `calls("<name>")`. */
|
||||
std::set<std::string> fields(const std::string& text, const std::string& var) {
|
||||
std::set<std::string> out;
|
||||
const std::string pat = var + ".";
|
||||
for (size_t at = text.find(pat); at != std::string::npos; at = text.find(pat, at + 1)) {
|
||||
if (at > 0) {
|
||||
const char b = text[at - 1];
|
||||
if (std::isalnum((unsigned char)b) || b == '_' || b == '.' || b == '$') continue;
|
||||
}
|
||||
size_t e = at + pat.size();
|
||||
while (e < text.size() && (std::isalnum((unsigned char)text[e]) || text[e] == '_')) ++e;
|
||||
if (e > at + pat.size()) out.insert(text.substr(at + pat.size(), e - at - pat.size()));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::set<std::string> called(const std::string& text, const std::string& fn) {
|
||||
std::set<std::string> out;
|
||||
const std::string pat = fn + "(\"";
|
||||
for (size_t at = text.find(pat); at != std::string::npos; at = text.find(pat, at + 1)) {
|
||||
if (at > 0 && (std::isalnum((unsigned char)text[at - 1]) || text[at - 1] == '_')) continue;
|
||||
const size_t b = at + pat.size(), e = text.find('"', b);
|
||||
out.insert(text.substr(b, e - b));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* The page's script from `from` up to the line that closes the function starting there. */
|
||||
std::string function_body(const std::string& page, const std::string& from) {
|
||||
const size_t at = page.find(from);
|
||||
if (at == std::string::npos) return std::string();
|
||||
const size_t end = page.find("\n}\n", at);
|
||||
return page.substr(at, end == std::string::npos ? std::string::npos : end - at);
|
||||
}
|
||||
|
||||
void each_field_is_emitted(const std::set<std::string>& names, const json& o, const char* what) {
|
||||
for (const std::string& n : names) {
|
||||
const bool there = o.is_object() && o.contains(n);
|
||||
CHECK(there);
|
||||
if (!there) fprintf(stderr, " the page reads %s.%s, which the route does not emit\n", what, n.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* ================================================================== the routes */
|
||||
|
||||
/* /stats carries the scheduler's figures, the live request table, the draft positions with their
|
||||
* reach, and the engine's snapshot (cards, experts by named tier, link, passes); /graph is the
|
||||
* provider's JSON, or a 501 naming the missing provider. */
|
||||
TEST(stats_carries_the_engine_the_requests_and_the_snapshot) {
|
||||
Dash d(false);
|
||||
const json s = d.get("/stats");
|
||||
CHECK_EQ(s.value("model", ""), std::string("dash"));
|
||||
CHECK_EQ(s.value("queue_cap", (int64_t)0), (int64_t)32);
|
||||
CHECK_EQ(s.value("in_flight", (int64_t)-1), (int64_t)0);
|
||||
CHECK_EQ(s.value("running", (int64_t)0), (int64_t)1);
|
||||
CHECK_EQ(s.value("kv_tokens_cached", (int64_t)0), (int64_t)300);
|
||||
CHECK_EQ(s.value("kv_tokens_max", (int64_t)0), (int64_t)6000);
|
||||
REQUIRE(s["draft_positions"].size() == 2);
|
||||
CHECK_NEAR(s["draft_positions"][1]["rate"].get<double>(), 0.25, 1e-12);
|
||||
CHECK_EQ(s["draft_positions"][1]["reached"].get<int64_t>(), (int64_t)8);
|
||||
REQUIRE(s["requests"].size() == 1);
|
||||
const json& r = s["requests"][0];
|
||||
CHECK_EQ(r.value("state", ""), std::string("decode"));
|
||||
CHECK_EQ(r.value("kv_tokens", (int64_t)0), (int64_t)960);
|
||||
CHECK_NEAR(r.value("ttft_s", -1.0), 0.25, 1e-12);
|
||||
REQUIRE(s["cards"].size() == 1);
|
||||
CHECK_EQ(s["cards"][0].value("name", ""), std::string("R9700"));
|
||||
REQUIRE(s["experts"]["tiers"].size() == (size_t)kTierCount);
|
||||
for (int t = 0; t < kTierCount; ++t) {
|
||||
CHECK_EQ(s["experts"]["tiers"][t].value("name", ""), std::string(tier_name((Tier)t)));
|
||||
CHECK_EQ(s["experts"]["tiers"][t].value("units", (int64_t)0), (int64_t)(t + 1));
|
||||
}
|
||||
CHECK_EQ(s["link"].value("stream_bytes", (int64_t)0), (int64_t)700);
|
||||
CHECK_EQ(s["passes"].value("played", (int64_t)0), (int64_t)10);
|
||||
CHECK_EQ(s["ckpt_evictions"].value("store_full", (int64_t)0), (int64_t)3);
|
||||
CHECK_EQ(s["hit_cuts"].value("no_snapshot", (int64_t)0), (int64_t)2);
|
||||
CHECK_EQ(s.value("hit_cut_tokens", (int64_t)0), (int64_t)9000);
|
||||
|
||||
CHECK_EQ(d.srv->router().call("GET", "/graph").status, 501);
|
||||
Dash g(true);
|
||||
CHECK_EQ(g.get("/graph").value("order", json()).size(), (size_t)0);
|
||||
}
|
||||
|
||||
/* /sessions lists each stored conversation with where its blocks are, the pool as the card holds
|
||||
* it (each block once), the tiers' counters and the snapshot store. */
|
||||
TEST(sessions_lists_each_conversation_and_what_the_tiers_did) {
|
||||
Dash d(false);
|
||||
const json s = d.get("/sessions");
|
||||
REQUIRE(s["sessions"].size() == 1);
|
||||
const json& e = s["sessions"][0];
|
||||
CHECK_EQ(e.value("label", ""), std::string("conv-7"));
|
||||
CHECK_EQ(e.value("on_device", (int64_t)0), (int64_t)40);
|
||||
CHECK_EQ(e.value("resume_tokens", (int64_t)0), (int64_t)4096);
|
||||
CHECK_EQ(s["blocks_sum_overlapping"].value("host", (int64_t)0), (int64_t)10);
|
||||
CHECK_EQ(s["pool"].value("tokens_used", (int64_t)0), (int64_t)1000);
|
||||
CHECK_EQ(s["pool"].value("unshared_tokens", (int64_t)0), (int64_t)300);
|
||||
CHECK_EQ(s["moved"].value("to_host", (int64_t)0), (int64_t)3);
|
||||
CHECK_EQ(s["snapshot_store"].value("bytes_each", (int64_t)0), (int64_t)2048);
|
||||
CHECK_NEAR(s["stall"].value("restore_ms", 0.0), 2.0, 1e-9);
|
||||
CHECK_EQ(s["occupancy"].value("host_cap_bytes", (int64_t)0), (int64_t)(64 << 20));
|
||||
CHECK(s.value("enabled", false));
|
||||
CHECK_EQ(s["linear"]["evictions"].value("store_full", (int64_t)0), (int64_t)3);
|
||||
CHECK_EQ(s["linear"]["hit_cuts"].value("no_snapshot", (int64_t)0), (int64_t)2);
|
||||
CHECK_EQ(s["linear"].value("hit_cut_tokens", (int64_t)0), (int64_t)9000);
|
||||
}
|
||||
|
||||
/* ================================================================== the page's field contract */
|
||||
|
||||
/* Every field the page's script reads from /stats (in its update and the request table) and from
|
||||
* /sessions (its loader and the session rows) is one the routes emit for a populated engine. A
|
||||
* rename on either side otherwise blanks a panel and reports nothing. */
|
||||
TEST(every_field_the_page_reads_is_one_the_routes_emit) {
|
||||
Dash d(false);
|
||||
HttpResponse page = d.srv->router().call("GET", "/");
|
||||
REQUIRE(page.status == 200 && has(page.body, "function update(s, dt)"));
|
||||
const std::string& p = page.body;
|
||||
const json stats = d.get("/stats");
|
||||
const json sessions = d.get("/sessions");
|
||||
|
||||
const std::string update = function_body(p, "function update(s, dt)");
|
||||
const std::string batch = function_body(p, "function renderBatch(list, s)");
|
||||
REQUIRE(!update.empty() && !batch.empty());
|
||||
std::set<std::string> top = fields(update, "s");
|
||||
for (const std::string& n : fields(batch, "s")) top.insert(n);
|
||||
CHECK(top.size() > 15);
|
||||
each_field_is_emitted(top, stats, "stats");
|
||||
each_field_is_emitted(fields(update, "ex"), stats["experts"], "experts");
|
||||
each_field_is_emitted(fields(update, "t"), stats["experts"]["tiers"][0], "experts.tiers[]");
|
||||
std::set<std::string> link = fields(update, "lk");
|
||||
for (const char* fn : { "d", "pre", "dP" })
|
||||
for (const std::string& n : called(update, fn)) link.insert(n);
|
||||
each_field_is_emitted(link, stats["link"], "link");
|
||||
each_field_is_emitted(fields(update, "c"), stats["cards"][0], "cards[]");
|
||||
each_field_is_emitted(fields(update, "p"), stats["draft_positions"][0], "draft_positions[]");
|
||||
|
||||
/* The request table: renderBatch through renderRequests. */
|
||||
const size_t rb = p.find("function renderBatch("), up = p.find("function update(s, dt)");
|
||||
REQUIRE(rb != std::string::npos && up > rb);
|
||||
each_field_is_emitted(fields(p.substr(rb, up - rb), "r"), stats["requests"][0], "requests[]");
|
||||
|
||||
/* The sessions view: its loader, and the rows from reuseOf through sessRow. */
|
||||
const std::string load = function_body(p, "async function loadSessions()");
|
||||
REQUIRE(!load.empty());
|
||||
each_field_is_emitted(fields(load, "s"), sessions, "sessions");
|
||||
each_field_is_emitted(fields(load, "mv"), sessions["snapshot_store"], "snapshot_store");
|
||||
each_field_is_emitted(fields(load, "ln"), sessions["linear"], "linear");
|
||||
each_field_is_emitted(fields(load, "pool"), sessions["pool"], "pool");
|
||||
each_field_is_emitted(fields(load, "occ"), sessions["occupancy"], "occupancy");
|
||||
const size_t ro = p.find("const reuseOf"), lo = p.find("async function loadSessions()");
|
||||
REQUIRE(ro != std::string::npos && lo > ro);
|
||||
std::set<std::string> rows = fields(p.substr(ro, lo - ro), "r");
|
||||
for (const std::string& n : fields(load, "r")) rows.insert(n);
|
||||
each_field_is_emitted(rows, sessions["sessions"][0], "sessions[]");
|
||||
}
|
||||
|
||||
/* ================================================================== the bridge's KV figures */
|
||||
|
||||
/* SchedulerBridge's aggregation over a hybrid model's groups: two paged groups share one token
|
||||
* axis, so the token figures are the fuller one's, not their sum; a linear state has no token
|
||||
* axis and adds only bytes; a windowed group's carve bounds lookback, not fit, so it neither
|
||||
* binds the token figures (a drafter's window sits full for the server's life) nor bounds
|
||||
* kv_tokens_max. Utilisation is the maximum over every group, bytes their sum, the cache's
|
||||
* unshared share is clamped to what is used, and the draft depth to the table's size. */
|
||||
TEST(the_bridge_reads_the_binding_paged_group_and_sums_only_bytes) {
|
||||
rad::SchedMetrics m;
|
||||
m.n_kv_groups = 4;
|
||||
auto group = [&](int i, int64_t bt, int64_t total, int64_t free_, bool window, int64_t bytes) {
|
||||
m.kv[i].block_tokens = bt;
|
||||
m.kv[i].blocks_total = total;
|
||||
m.kv[i].blocks_free = free_;
|
||||
m.kv[i].utilisation = total ? (float)(1.0 - (double)free_ / (double)total) : 0.0f;
|
||||
m.kv[i].window = window;
|
||||
m.kv[i].bytes_total = bytes;
|
||||
m.kv[i].bytes_used = bytes / 2;
|
||||
m.kv[i].bytes_carved = bytes * 2;
|
||||
};
|
||||
group(0, 16, 100, 40, false, 1000); /* attention, 60% */
|
||||
group(1, 16, 100, 10, false, 200); /* a second paged group on the same axis, 90% */
|
||||
group(2, 0, 8, 0, false, 500); /* linear state, full, no token axis */
|
||||
group(3, 16, 4, 0, true, 64); /* a drafter's window, always full */
|
||||
m.prefix_held_tokens = 5000;
|
||||
m.draft_depth_seen = 70;
|
||||
for (int j = 0; j < 64; ++j) { m.draft_pos_reached[j] = 100 - j; m.draft_pos_accepted[j] = j; }
|
||||
|
||||
const server::SchedMetrics o = bridge_metrics(m);
|
||||
CHECK_NEAR(o.kv_util, 1.0, 1e-6);
|
||||
CHECK_EQ(o.kv_tokens_total, (int64_t)(100 * 16));
|
||||
CHECK_EQ(o.kv_tokens_used, (int64_t)(90 * 16));
|
||||
CHECK_EQ(o.kv_tokens_max, (int64_t)(100 * 16));
|
||||
CHECK_EQ(o.kv_bytes_total, (int64_t)(1000 + 200 + 500 + 64));
|
||||
CHECK_EQ(o.kv_bytes_used, (int64_t)(500 + 100 + 250 + 32));
|
||||
CHECK_EQ(o.kv_bytes_carved, (int64_t)(2000 + 400 + 1000 + 128));
|
||||
CHECK_EQ(o.kv_tokens_cached, o.kv_tokens_used);
|
||||
CHECK_EQ(o.draft_depth_seen, server::SchedMetrics::MAX_DRAFT_POS);
|
||||
CHECK_EQ(o.draft_pos_reached[63], (int64_t)37);
|
||||
|
||||
/* The fuller group binds wherever it sits in the list. */
|
||||
group(0, 16, 200, 10, false, 1000);
|
||||
const server::SchedMetrics p = bridge_metrics(m);
|
||||
CHECK_EQ(p.kv_tokens_total, (int64_t)(200 * 16));
|
||||
CHECK_EQ(p.kv_tokens_used, (int64_t)(190 * 16));
|
||||
CHECK_EQ(p.kv_tokens_max, (int64_t)(100 * 16));
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
@@ -0,0 +1,6 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<turn|>
|
||||
<|turn>user
|
||||
Describe<|image|>briefly.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,6 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<turn|>
|
||||
<|turn>user
|
||||
Hi.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,6 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<turn|>
|
||||
<|turn>user
|
||||
Hi.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,10 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<turn|>
|
||||
<|turn>user
|
||||
First question.<turn|>
|
||||
<|turn>model
|
||||
First answer.<turn|>
|
||||
<|turn>user
|
||||
Second question.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,10 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<turn|>
|
||||
<|turn>user
|
||||
First question.<turn|>
|
||||
<|turn>model
|
||||
First answer.<turn|>
|
||||
<|turn>user
|
||||
Second question.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,10 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<turn|>
|
||||
<|turn>user
|
||||
First question.<turn|>
|
||||
<|turn>model
|
||||
First answer.<turn|>
|
||||
<|turn>user
|
||||
Second question.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,7 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<turn|>
|
||||
<|turn>user
|
||||
Hi.<turn|>
|
||||
<|turn>model
|
||||
Hello.<turn|>
|
||||
@@ -0,0 +1,11 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<|tool>declaration:read{description:<|"|>Read a file.<|"|>,parameters:{properties:{limit:{type:<|"|>INTEGER<|"|>},path:{description:<|"|>Absolute path<|"|>,type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:edit{description:<|"|>Apply edits — exact text, «quoted» & <tagged>, 日本語.<|"|>,parameters:{properties:{dry_run:{type:<|"|>BOOLEAN<|"|>},edits:{items:{properties:{newText:{type:<|"|>STRING<|"|>},oldText:{type:<|"|>STRING<|"|>}},required:[<|"|>oldText<|"|>,<|"|>newText<|"|>],type:<|"|>OBJECT<|"|>},type:<|"|>ARRAY<|"|>},mode:{enum:[<|"|>fast<|"|>,<|"|>safe<|"|>],type:<|"|>STRING<|"|>},path:{type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>,<|"|>edits<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:ping{description:<|"|>Takes no arguments.<|"|>,parameters:{type:<|"|>OBJECT<|"|>}}<tool|><turn|>
|
||||
<|turn>user
|
||||
Edit both files, then ping.<turn|>
|
||||
<|turn>model
|
||||
<|tool_call>call:edit{dry_run:false,edits:[{newText:<|"|> return a < b & c # it's
|
||||
<|"|>,oldText:<|"|> return a
|
||||
<|"|>},{newText:<|"|>\"<|"|>,oldText:<|"|>x y<|"|>}],mode:<|"|>safe<|"|>,path:<|"|>/work/a.py<|"|>}<tool_call|><|tool_call>call:read{limit:3,path:<|"|>/work/über.py<|"|>}<tool_call|><|tool_call>call:ping{}<tool_call|><|tool_response>response:edit{value:<|"|>{"ok": true}<|"|>}<tool_response|><|tool_response>response:read{value:<|"|>x = 1
|
||||
<|"|>}<tool_response|><|tool_response>response:ping{value:<|"|>pong<|"|>}<tool_response|>Doing all three.<turn|>
|
||||
<|channel>thought
|
||||
@@ -0,0 +1,6 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
You are terse.<turn|>
|
||||
<|turn>user
|
||||
What is 2+2?<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,5 @@
|
||||
<bos><|turn>user
|
||||
Hi.<turn|>
|
||||
<|turn>model
|
||||
<|channel>thought
|
||||
<channel|>
|
||||
@@ -0,0 +1,11 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<|tool>declaration:read{description:<|"|>Read a file.<|"|>,parameters:{properties:{limit:{type:<|"|>INTEGER<|"|>},path:{description:<|"|>Absolute path<|"|>,type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:edit{description:<|"|>Apply edits — exact text, «quoted» & <tagged>, 日本語.<|"|>,parameters:{properties:{dry_run:{type:<|"|>BOOLEAN<|"|>},edits:{items:{properties:{newText:{type:<|"|>STRING<|"|>},oldText:{type:<|"|>STRING<|"|>}},required:[<|"|>oldText<|"|>,<|"|>newText<|"|>],type:<|"|>OBJECT<|"|>},type:<|"|>ARRAY<|"|>},mode:{enum:[<|"|>fast<|"|>,<|"|>safe<|"|>],type:<|"|>STRING<|"|>},path:{type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>,<|"|>edits<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:ping{description:<|"|>Takes no arguments.<|"|>,parameters:{type:<|"|>OBJECT<|"|>}}<tool|><turn|>
|
||||
<|turn>user
|
||||
Fix /work/a.py.<turn|>
|
||||
<|turn>model
|
||||
<|tool_call>call:read{limit:40,path:<|"|>/work/a.py<|"|>}<tool_call|><|tool_response>response:read{value:<|"|>print(1)
|
||||
<|"|>}<tool_response|>It prints 1.<turn|>
|
||||
<|turn>user
|
||||
Now make it print 2.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,10 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<|tool>declaration:read{description:<|"|>Read a file.<|"|>,parameters:{properties:{limit:{type:<|"|>INTEGER<|"|>},path:{description:<|"|>Absolute path<|"|>,type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:edit{description:<|"|>Apply edits — exact text, «quoted» & <tagged>, 日本語.<|"|>,parameters:{properties:{dry_run:{type:<|"|>BOOLEAN<|"|>},edits:{items:{properties:{newText:{type:<|"|>STRING<|"|>},oldText:{type:<|"|>STRING<|"|>}},required:[<|"|>oldText<|"|>,<|"|>newText<|"|>],type:<|"|>OBJECT<|"|>},type:<|"|>ARRAY<|"|>},mode:{enum:[<|"|>fast<|"|>,<|"|>safe<|"|>],type:<|"|>STRING<|"|>},path:{type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>,<|"|>edits<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:ping{description:<|"|>Takes no arguments.<|"|>,parameters:{type:<|"|>OBJECT<|"|>}}<tool|><turn|>
|
||||
<|turn>user
|
||||
Fix /work/a.py.<turn|>
|
||||
<|turn>model
|
||||
<|channel>thought
|
||||
Read it first.
|
||||
<channel|><|tool_call>call:read{limit:40,path:<|"|>/work/a.py<|"|>}<tool_call|><|tool_response>response:read{value:<|"|>print(1)
|
||||
<|"|>}<tool_response|><|channel>thought
|
||||
@@ -0,0 +1,13 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<|tool>declaration:read{description:<|"|>Read a file.<|"|>,parameters:{properties:{limit:{type:<|"|>INTEGER<|"|>},path:{description:<|"|>Absolute path<|"|>,type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:edit{description:<|"|>Apply edits — exact text, «quoted» & <tagged>, 日本語.<|"|>,parameters:{properties:{dry_run:{type:<|"|>BOOLEAN<|"|>},edits:{items:{properties:{newText:{type:<|"|>STRING<|"|>},oldText:{type:<|"|>STRING<|"|>}},required:[<|"|>oldText<|"|>,<|"|>newText<|"|>],type:<|"|>OBJECT<|"|>},type:<|"|>ARRAY<|"|>},mode:{enum:[<|"|>fast<|"|>,<|"|>safe<|"|>],type:<|"|>STRING<|"|>},path:{type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>,<|"|>edits<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:ping{description:<|"|>Takes no arguments.<|"|>,parameters:{type:<|"|>OBJECT<|"|>}}<tool|><turn|>
|
||||
<|turn>user
|
||||
Fix /work/a.py.<turn|>
|
||||
<|turn>model
|
||||
<|channel>thought
|
||||
Read it first.
|
||||
<channel|><|tool_call>call:read{path:<|"|>/work/a.py<|"|>}<tool_call|><|tool_response>response:read{value:<|"|>print(1)
|
||||
<|"|>}<tool_response|><turn|>
|
||||
<|turn>user
|
||||
Go on.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,6 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<|tool>declaration:read{description:<|"|>Read a file.<|"|>,parameters:{properties:{limit:{type:<|"|>INTEGER<|"|>},path:{description:<|"|>Absolute path<|"|>,type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:edit{description:<|"|>Apply edits — exact text, «quoted» & <tagged>, 日本語.<|"|>,parameters:{properties:{dry_run:{type:<|"|>BOOLEAN<|"|>},edits:{items:{properties:{newText:{type:<|"|>STRING<|"|>},oldText:{type:<|"|>STRING<|"|>}},required:[<|"|>oldText<|"|>,<|"|>newText<|"|>],type:<|"|>OBJECT<|"|>},type:<|"|>ARRAY<|"|>},mode:{enum:[<|"|>fast<|"|>,<|"|>safe<|"|>],type:<|"|>STRING<|"|>},path:{type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>,<|"|>edits<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:ping{description:<|"|>Takes no arguments.<|"|>,parameters:{type:<|"|>OBJECT<|"|>}}<tool|><turn|>
|
||||
<|turn>user
|
||||
Read /work/a.py.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,6 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
You are a coding agent.<|tool>declaration:read{description:<|"|>Read a file.<|"|>,parameters:{properties:{limit:{type:<|"|>INTEGER<|"|>},path:{description:<|"|>Absolute path<|"|>,type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:edit{description:<|"|>Apply edits — exact text, «quoted» & <tagged>, 日本語.<|"|>,parameters:{properties:{dry_run:{type:<|"|>BOOLEAN<|"|>},edits:{items:{properties:{newText:{type:<|"|>STRING<|"|>},oldText:{type:<|"|>STRING<|"|>}},required:[<|"|>oldText<|"|>,<|"|>newText<|"|>],type:<|"|>OBJECT<|"|>},type:<|"|>ARRAY<|"|>},mode:{enum:[<|"|>fast<|"|>,<|"|>safe<|"|>],type:<|"|>STRING<|"|>},path:{type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>,<|"|>edits<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:ping{description:<|"|>Takes no arguments.<|"|>,parameters:{type:<|"|>OBJECT<|"|>}}<tool|><turn|>
|
||||
<|turn>user
|
||||
Read /work/a.py.<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,6 @@
|
||||
<bos><|turn>system
|
||||
<|think|>
|
||||
<|tool>declaration:read{description:<|"|>Read a file.<|"|>,parameters:{properties:{limit:{type:<|"|>INTEGER<|"|>},path:{description:<|"|>Absolute path<|"|>,type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:edit{description:<|"|>Apply edits — exact text, «quoted» & <tagged>, 日本語.<|"|>,parameters:{properties:{dry_run:{type:<|"|>BOOLEAN<|"|>},edits:{items:{properties:{newText:{type:<|"|>STRING<|"|>},oldText:{type:<|"|>STRING<|"|>}},required:[<|"|>oldText<|"|>,<|"|>newText<|"|>],type:<|"|>OBJECT<|"|>},type:<|"|>ARRAY<|"|>},mode:{enum:[<|"|>fast<|"|>,<|"|>safe<|"|>],type:<|"|>STRING<|"|>},path:{type:<|"|>STRING<|"|>}},required:[<|"|>path<|"|>,<|"|>edits<|"|>],type:<|"|>OBJECT<|"|>}}<tool|><|tool>declaration:ping{description:<|"|>Takes no arguments.<|"|>,parameters:{type:<|"|>OBJECT<|"|>}}<tool|><turn|>
|
||||
<|turn>user
|
||||
Übersetze: 日本語 🙂 "quoted" \ back<turn|>
|
||||
<|turn>model
|
||||
@@ -0,0 +1,124 @@
|
||||
{
|
||||
"about": "Requests rendered through each shipped template by Python jinja2 (tests/mkchatgolden.py) and by ChatTemplate::apply (tests/chat_test.cpp). Messages are OpenAI-shaped, as the server receives them: tool-call arguments are JSON strings and a media part is the server's media_marker part. Each model's renders are in <model>/golden/<case>.txt, or <case>.err holding the message of a template that refused the request.",
|
||||
"models": {
|
||||
"qwen3.8": { "bos": "", "eos": "<|im_end|>", "media": "<|vision_start|><|image_pad|><|vision_end|>" },
|
||||
"qwen3.6": { "bos": "", "eos": "<|im_end|>", "media": "<|vision_start|><|image_pad|><|vision_end|>" },
|
||||
"minicpm5": { "bos": "<s>", "eos": "</s>", "media": "" },
|
||||
"gemma4": { "bos": "<bos>", "eos": "<eos>", "media": "<|image|>" }
|
||||
},
|
||||
"tools": [
|
||||
{ "type": "function", "function": { "name": "read", "description": "Read a file.",
|
||||
"parameters": { "type": "object", "properties": {
|
||||
"path": { "type": "string", "description": "Absolute path" },
|
||||
"limit": { "type": "integer" } }, "required": ["path"] } } },
|
||||
{ "type": "function", "function": { "name": "edit",
|
||||
"description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.",
|
||||
"parameters": { "type": "object", "properties": {
|
||||
"path": { "type": "string" },
|
||||
"edits": { "type": "array", "items": { "type": "object", "properties": {
|
||||
"oldText": { "type": "string" }, "newText": { "type": "string" } },
|
||||
"required": ["oldText", "newText"] } },
|
||||
"dry_run": { "type": "boolean" },
|
||||
"mode": { "type": "string", "enum": ["fast", "safe"] } },
|
||||
"required": ["path", "edits"] } } },
|
||||
{ "type": "function", "function": { "name": "ping", "description": "Takes no arguments.",
|
||||
"parameters": { "type": "object", "properties": {} } } }
|
||||
],
|
||||
"cases": [
|
||||
{ "name": "system_and_user",
|
||||
"messages": [
|
||||
{ "role": "system", "content": "You are terse." },
|
||||
{ "role": "user", "content": "What is 2+2?" } ] },
|
||||
{ "name": "thinking_off",
|
||||
"enable_thinking": false,
|
||||
"messages": [ { "role": "user", "content": "Hi." } ] },
|
||||
{ "name": "tools_and_user",
|
||||
"tools": true,
|
||||
"messages": [ { "role": "user", "content": "Read /work/a.py." } ] },
|
||||
{ "name": "tools_system_and_user",
|
||||
"tools": true,
|
||||
"messages": [
|
||||
{ "role": "system", "content": "You are a coding agent." },
|
||||
{ "role": "user", "content": "Read /work/a.py." } ] },
|
||||
{ "name": "history_with_reasoning",
|
||||
"messages": [
|
||||
{ "role": "user", "content": "First question." },
|
||||
{ "role": "assistant", "reasoning_content": "Thinking about the first.", "content": "First answer." },
|
||||
{ "role": "user", "content": "Second question." } ] },
|
||||
{ "name": "history_with_reasoning_preserved",
|
||||
"kwargs": { "preserve_thinking": true },
|
||||
"messages": [
|
||||
{ "role": "user", "content": "First question." },
|
||||
{ "role": "assistant", "reasoning_content": "Thinking about the first.", "content": "First answer." },
|
||||
{ "role": "user", "content": "Second question." } ] },
|
||||
{ "name": "history_with_reasoning_dropped",
|
||||
"kwargs": { "preserve_thinking": false },
|
||||
"messages": [
|
||||
{ "role": "user", "content": "First question." },
|
||||
{ "role": "assistant", "reasoning_content": "Thinking about the first.", "content": "First answer." },
|
||||
{ "role": "user", "content": "Second question." } ] },
|
||||
{ "name": "tool_call_then_result",
|
||||
"tools": true,
|
||||
"messages": [
|
||||
{ "role": "user", "content": "Fix /work/a.py." },
|
||||
{ "role": "assistant", "reasoning_content": "Read it first.", "content": null,
|
||||
"tool_calls": [ { "id": "call_1", "type": "function",
|
||||
"function": { "name": "read", "arguments": "{\"path\": \"/work/a.py\", \"limit\": 40}" } } ] },
|
||||
{ "role": "tool", "tool_call_id": "call_1", "content": "print(1)\n" } ] },
|
||||
{ "name": "tool_call_answered_then_user",
|
||||
"tools": true,
|
||||
"messages": [
|
||||
{ "role": "user", "content": "Fix /work/a.py." },
|
||||
{ "role": "assistant", "reasoning_content": "Read it first.", "content": null,
|
||||
"tool_calls": [ { "id": "call_1", "type": "function",
|
||||
"function": { "name": "read", "arguments": "{\"path\": \"/work/a.py\", \"limit\": 40}" } } ] },
|
||||
{ "role": "tool", "tool_call_id": "call_1", "content": "print(1)\n" },
|
||||
{ "role": "assistant", "content": "It prints 1." },
|
||||
{ "role": "user", "content": "Now make it print 2." } ] },
|
||||
{ "name": "tool_calls_preserving_reasoning",
|
||||
"tools": true,
|
||||
"kwargs": { "preserve_thinking": true },
|
||||
"messages": [
|
||||
{ "role": "user", "content": "Fix /work/a.py." },
|
||||
{ "role": "assistant", "reasoning_content": "Read it first.", "content": "",
|
||||
"tool_calls": [ { "id": "call_1", "type": "function",
|
||||
"function": { "name": "read", "arguments": "{\"path\": \"/work/a.py\"}" } } ] },
|
||||
{ "role": "tool", "tool_call_id": "call_1", "content": "print(1)\n" },
|
||||
{ "role": "user", "content": "Go on." } ] },
|
||||
{ "name": "parallel_calls_with_typed_arguments",
|
||||
"tools": true,
|
||||
"messages": [
|
||||
{ "role": "user", "content": "Edit both files, then ping." },
|
||||
{ "role": "assistant", "content": "Doing all three.",
|
||||
"tool_calls": [
|
||||
{ "id": "call_a", "type": "function", "function": { "name": "edit",
|
||||
"arguments": "{\"path\": \"/work/a.py\", \"edits\": [{\"oldText\": \" return a\\n\", \"newText\": \" return a < b & c # it's\\n\"}, {\"oldText\": \"x\\ty\", \"newText\": \"\\\\\\\"\"}], \"dry_run\": false, \"mode\": \"safe\"}" } },
|
||||
{ "id": "call_b", "type": "function", "function": { "name": "read",
|
||||
"arguments": "{\"path\": \"/work/über.py\", \"limit\": 3}" } },
|
||||
{ "id": "call_c", "type": "function", "function": { "name": "ping", "arguments": "{}" } } ] },
|
||||
{ "role": "tool", "tool_call_id": "call_a", "content": "{\"ok\": true}" },
|
||||
{ "role": "tool", "tool_call_id": "call_b", "content": "x = 1\n" },
|
||||
{ "role": "tool", "tool_call_id": "call_c", "content": "pong" } ] },
|
||||
{ "name": "no_generation_prompt",
|
||||
"add_generation_prompt": false,
|
||||
"messages": [
|
||||
{ "role": "user", "content": "Hi." },
|
||||
{ "role": "assistant", "content": "Hello." } ] },
|
||||
{ "name": "unicode_text",
|
||||
"tools": true,
|
||||
"messages": [ { "role": "user", "content": "Übersetze: 日本語 🙂 \"quoted\" \\ back" } ] },
|
||||
{ "name": "effort_low",
|
||||
"kwargs": { "reasoning_effort": "low" },
|
||||
"messages": [ { "role": "user", "content": "Hi." } ] },
|
||||
{ "name": "effort_the_template_refuses",
|
||||
"kwargs": { "reasoning_effort": "high" },
|
||||
"messages": [ { "role": "user", "content": "Hi." } ] },
|
||||
{ "name": "a_picture_between_text",
|
||||
"models": ["qwen3.8", "qwen3.6", "gemma4"],
|
||||
"messages": [
|
||||
{ "role": "user", "content": [
|
||||
{ "type": "text", "text": "Describe" },
|
||||
{ "type": "media_marker", "text": "<__media__>" },
|
||||
{ "type": "text", "text": "briefly." } ] } ] }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<s><|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,4 @@
|
||||
<s><|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,12 @@
|
||||
<s><|im_start|>user
|
||||
First question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Thinking about the first.
|
||||
</think>
|
||||
|
||||
First answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Second question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,12 @@
|
||||
<s><|im_start|>user
|
||||
First question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Thinking about the first.
|
||||
</think>
|
||||
|
||||
First answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Second question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,12 @@
|
||||
<s><|im_start|>user
|
||||
First question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Thinking about the first.
|
||||
</think>
|
||||
|
||||
First answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Second question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,8 @@
|
||||
<s><|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
Hello.<|im_end|>
|
||||
@@ -0,0 +1,39 @@
|
||||
<s><|im_start|>system
|
||||
# Tools
|
||||
|
||||
You are provided with function signatures within <tools></tools> XML tags:
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
Tool usage guidelines:
|
||||
- You may call zero or more functions. If no function calls are needed, just answer normally and do not include any <function ... </function>.
|
||||
- When calling a function, return an XML object within <function ... </function> using:
|
||||
<function name="function-name"><param name="param-name">param-value</param></function>
|
||||
- param-value may be multi-line. If it contains <, & or newline characters, wrap it in a CDATA block: <param name="param-name"><![CDATA[...multi-line value...]]></param><|im_end|>
|
||||
<|im_start|>user
|
||||
Edit both files, then ping.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
Doing all three.
|
||||
<function name="edit"><param name="path">/work/a.py</param><param name="edits">[{'oldText': ' return a\n', 'newText': " return a < b & c # it's\n"}, {'oldText': 'x\ty', 'newText': '\\"'}]</param><param name="dry_run">False</param><param name="mode">safe</param></function>
|
||||
<function name="read"><param name="path">/work/über.py</param><param name="limit">3</param></function>
|
||||
<function name="ping"></function><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
{"ok": true}
|
||||
</tool_response>
|
||||
<tool_response>
|
||||
x = 1
|
||||
|
||||
</tool_response>
|
||||
<tool_response>
|
||||
pong
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,6 @@
|
||||
<s><|im_start|>system
|
||||
You are terse.<|im_end|>
|
||||
<|im_start|>user
|
||||
What is 2+2?<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,7 @@
|
||||
<s><|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<s><|im_start|>system
|
||||
# Tools
|
||||
|
||||
You are provided with function signatures within <tools></tools> XML tags:
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
Tool usage guidelines:
|
||||
- You may call zero or more functions. If no function calls are needed, just answer normally and do not include any <function ... </function>.
|
||||
- When calling a function, return an XML object within <function ... </function> using:
|
||||
<function name="function-name"><param name="param-name">param-value</param></function>
|
||||
- param-value may be multi-line. If it contains <, & or newline characters, wrap it in a CDATA block: <param name="param-name"><![CDATA[...multi-line value...]]></param><|im_end|>
|
||||
<|im_start|>user
|
||||
Fix /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Read it first.
|
||||
</think>
|
||||
|
||||
<function name="read"><param name="path">/work/a.py</param><param name="limit">40</param></function><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
print(1)
|
||||
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
It prints 1.<|im_end|>
|
||||
<|im_start|>user
|
||||
Now make it print 2.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,30 @@
|
||||
<s><|im_start|>system
|
||||
# Tools
|
||||
|
||||
You are provided with function signatures within <tools></tools> XML tags:
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
Tool usage guidelines:
|
||||
- You may call zero or more functions. If no function calls are needed, just answer normally and do not include any <function ... </function>.
|
||||
- When calling a function, return an XML object within <function ... </function> using:
|
||||
<function name="function-name"><param name="param-name">param-value</param></function>
|
||||
- param-value may be multi-line. If it contains <, & or newline characters, wrap it in a CDATA block: <param name="param-name"><![CDATA[...multi-line value...]]></param><|im_end|>
|
||||
<|im_start|>user
|
||||
Fix /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Read it first.
|
||||
</think>
|
||||
|
||||
<function name="read"><param name="path">/work/a.py</param><param name="limit">40</param></function><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
print(1)
|
||||
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,32 @@
|
||||
<s><|im_start|>system
|
||||
# Tools
|
||||
|
||||
You are provided with function signatures within <tools></tools> XML tags:
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
Tool usage guidelines:
|
||||
- You may call zero or more functions. If no function calls are needed, just answer normally and do not include any <function ... </function>.
|
||||
- When calling a function, return an XML object within <function ... </function> using:
|
||||
<function name="function-name"><param name="param-name">param-value</param></function>
|
||||
- param-value may be multi-line. If it contains <, & or newline characters, wrap it in a CDATA block: <param name="param-name"><![CDATA[...multi-line value...]]></param><|im_end|>
|
||||
<|im_start|>user
|
||||
Fix /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Read it first.
|
||||
</think>
|
||||
|
||||
<function name="read"><param name="path">/work/a.py</param></function><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
print(1)
|
||||
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>user
|
||||
Go on.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,19 @@
|
||||
<s><|im_start|>system
|
||||
# Tools
|
||||
|
||||
You are provided with function signatures within <tools></tools> XML tags:
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
Tool usage guidelines:
|
||||
- You may call zero or more functions. If no function calls are needed, just answer normally and do not include any <function ... </function>.
|
||||
- When calling a function, return an XML object within <function ... </function> using:
|
||||
<function name="function-name"><param name="param-name">param-value</param></function>
|
||||
- param-value may be multi-line. If it contains <, & or newline characters, wrap it in a CDATA block: <param name="param-name"><![CDATA[...multi-line value...]]></param><|im_end|>
|
||||
<|im_start|>user
|
||||
Read /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,21 @@
|
||||
<s><|im_start|>system
|
||||
You are a coding agent.
|
||||
|
||||
# Tools
|
||||
|
||||
You are provided with function signatures within <tools></tools> XML tags:
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
Tool usage guidelines:
|
||||
- You may call zero or more functions. If no function calls are needed, just answer normally and do not include any <function ... </function>.
|
||||
- When calling a function, return an XML object within <function ... </function> using:
|
||||
<function name="function-name"><param name="param-name">param-value</param></function>
|
||||
- param-value may be multi-line. If it contains <, & or newline characters, wrap it in a CDATA block: <param name="param-name"><![CDATA[...multi-line value...]]></param><|im_end|>
|
||||
<|im_start|>user
|
||||
Read /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,19 @@
|
||||
<s><|im_start|>system
|
||||
# Tools
|
||||
|
||||
You are provided with function signatures within <tools></tools> XML tags:
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
Tool usage guidelines:
|
||||
- You may call zero or more functions. If no function calls are needed, just answer normally and do not include any <function ... </function>.
|
||||
- When calling a function, return an XML object within <function ... </function> using:
|
||||
<function name="function-name"><param name="param-name">param-value</param></function>
|
||||
- param-value may be multi-line. If it contains <, & or newline characters, wrap it in a CDATA block: <param name="param-name"><![CDATA[...multi-line value...]]></param><|im_end|>
|
||||
<|im_start|>user
|
||||
Übersetze: 日本語 🙂 "quoted" \ back<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,4 @@
|
||||
<|im_start|>user
|
||||
Describe<|vision_start|><|image_pad|><|vision_end|>briefly.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,4 @@
|
||||
<|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,4 @@
|
||||
<|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,8 @@
|
||||
<|im_start|>user
|
||||
First question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
First answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Second question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,8 @@
|
||||
<|im_start|>user
|
||||
First question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
First answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Second question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,12 @@
|
||||
<|im_start|>user
|
||||
First question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Thinking about the first.
|
||||
</think>
|
||||
|
||||
First answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Second question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,8 @@
|
||||
<|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
Hello.<|im_end|>
|
||||
@@ -0,0 +1,84 @@
|
||||
<|im_start|>system
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Edit both files, then ping.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
Doing all three.
|
||||
|
||||
<tool_call>
|
||||
<function=edit>
|
||||
<parameter=path>
|
||||
/work/a.py
|
||||
</parameter>
|
||||
<parameter=edits>
|
||||
[{"oldText": " return a\n", "newText": " return a < b & c # it's\n"}, {"oldText": "x\ty", "newText": "\\\""}]
|
||||
</parameter>
|
||||
<parameter=dry_run>
|
||||
false
|
||||
</parameter>
|
||||
<parameter=mode>
|
||||
safe
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
<tool_call>
|
||||
<function=read>
|
||||
<parameter=path>
|
||||
/work/über.py
|
||||
</parameter>
|
||||
<parameter=limit>
|
||||
3
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
<tool_call>
|
||||
<function=ping>
|
||||
</function>
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
{"ok": true}
|
||||
</tool_response>
|
||||
<tool_response>
|
||||
x = 1
|
||||
</tool_response>
|
||||
<tool_response>
|
||||
pong
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,6 @@
|
||||
<|im_start|>system
|
||||
You are terse.<|im_end|>
|
||||
<|im_start|>user
|
||||
What is 2+2?<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,7 @@
|
||||
<|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<|im_start|>system
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Fix /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<tool_call>
|
||||
<function=read>
|
||||
<parameter=path>
|
||||
/work/a.py
|
||||
</parameter>
|
||||
<parameter=limit>
|
||||
40
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
print(1)
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
It prints 1.<|im_end|>
|
||||
<|im_start|>user
|
||||
Now make it print 2.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,56 @@
|
||||
<|im_start|>system
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Fix /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Read it first.
|
||||
</think>
|
||||
|
||||
<tool_call>
|
||||
<function=read>
|
||||
<parameter=path>
|
||||
/work/a.py
|
||||
</parameter>
|
||||
<parameter=limit>
|
||||
40
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
print(1)
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,55 @@
|
||||
<|im_start|>system
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Fix /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Read it first.
|
||||
</think>
|
||||
|
||||
<tool_call>
|
||||
<function=read>
|
||||
<parameter=path>
|
||||
/work/a.py
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
print(1)
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>user
|
||||
Go on.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,37 @@
|
||||
<|im_start|>system
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Read /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,39 @@
|
||||
<|im_start|>system
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT>
|
||||
|
||||
You are a coding agent.<|im_end|>
|
||||
<|im_start|>user
|
||||
Read /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,37 @@
|
||||
<|im_start|>system
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Übersetze: 日本語 🙂 "quoted" \ back<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,6 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Describe<|vision_start|><|image_pad|><|vision_end|>briefly.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,6 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.<|im_end|>
|
||||
<|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1 @@
|
||||
Unexpected reasoning effort high. Supported types are xhigh (default), medium, and low.
|
||||
@@ -0,0 +1,14 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
First question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Thinking about the first.
|
||||
</think>
|
||||
|
||||
First answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Second question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,10 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
First question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
First answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Second question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,14 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
First question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Thinking about the first.
|
||||
</think>
|
||||
|
||||
First answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Second question.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,10 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.<|im_end|>
|
||||
<|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
Hello.<|im_end|>
|
||||
@@ -0,0 +1,86 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.
|
||||
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Edit both files, then ping.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
Doing all three.
|
||||
|
||||
<tool_call>
|
||||
<function=edit>
|
||||
<parameter=path>
|
||||
/work/a.py
|
||||
</parameter>
|
||||
<parameter=edits>
|
||||
[{"oldText": " return a\n", "newText": " return a < b & c # it's\n"}, {"oldText": "x\ty", "newText": "\\\""}]
|
||||
</parameter>
|
||||
<parameter=dry_run>
|
||||
false
|
||||
</parameter>
|
||||
<parameter=mode>
|
||||
safe
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
<tool_call>
|
||||
<function=read>
|
||||
<parameter=path>
|
||||
/work/über.py
|
||||
</parameter>
|
||||
<parameter=limit>
|
||||
3
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
<tool_call>
|
||||
<function=ping>
|
||||
</function>
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
{"ok": true}
|
||||
</tool_response>
|
||||
<tool_response>
|
||||
x = 1
|
||||
</tool_response>
|
||||
<tool_response>
|
||||
pong
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,8 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.
|
||||
|
||||
You are terse.<|im_end|>
|
||||
<|im_start|>user
|
||||
What is 2+2?<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,7 @@
|
||||
<|im_start|>user
|
||||
Hi.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.
|
||||
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Fix /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Read it first.
|
||||
</think>
|
||||
|
||||
<tool_call>
|
||||
<function=read>
|
||||
<parameter=path>
|
||||
/work/a.py
|
||||
</parameter>
|
||||
<parameter=limit>
|
||||
40
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
print(1)
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
|
||||
</think>
|
||||
|
||||
It prints 1.<|im_end|>
|
||||
<|im_start|>user
|
||||
Now make it print 2.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,58 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.
|
||||
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Fix /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Read it first.
|
||||
</think>
|
||||
|
||||
<tool_call>
|
||||
<function=read>
|
||||
<parameter=path>
|
||||
/work/a.py
|
||||
</parameter>
|
||||
<parameter=limit>
|
||||
40
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
print(1)
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,57 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.
|
||||
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Fix /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
Read it first.
|
||||
</think>
|
||||
|
||||
<tool_call>
|
||||
<function=read>
|
||||
<parameter=path>
|
||||
/work/a.py
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call><|im_end|>
|
||||
<|im_start|>user
|
||||
<tool_response>
|
||||
print(1)
|
||||
</tool_response><|im_end|>
|
||||
<|im_start|>user
|
||||
Go on.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,39 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.
|
||||
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Read /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,41 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.
|
||||
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT>
|
||||
|
||||
You are a coding agent.<|im_end|>
|
||||
<|im_start|>user
|
||||
Read /work/a.py.<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -0,0 +1,39 @@
|
||||
<|im_start|>system
|
||||
Reasoning effort is set to xhigh. Please think carefully through the task, validate key assumptions, consider plausible alternatives, and prioritize correctness, consistency, and clarity in the final answer.
|
||||
|
||||
# Tools
|
||||
|
||||
You have access to the following functions:
|
||||
|
||||
<tools>
|
||||
{"type": "function", "function": {"name": "read", "description": "Read a file.", "parameters": {"type": "object", "properties": {"path": {"type": "string", "description": "Absolute path"}, "limit": {"type": "integer"}}, "required": ["path"]}}}
|
||||
{"type": "function", "function": {"name": "edit", "description": "Apply edits — exact text, «quoted» & <tagged>, 日本語.", "parameters": {"type": "object", "properties": {"path": {"type": "string"}, "edits": {"type": "array", "items": {"type": "object", "properties": {"oldText": {"type": "string"}, "newText": {"type": "string"}}, "required": ["oldText", "newText"]}}, "dry_run": {"type": "boolean"}, "mode": {"type": "string", "enum": ["fast", "safe"]}}, "required": ["path", "edits"]}}}
|
||||
{"type": "function", "function": {"name": "ping", "description": "Takes no arguments.", "parameters": {"type": "object", "properties": {}}}}
|
||||
</tools>
|
||||
|
||||
If you choose to call a function ONLY reply in the following format with NO suffix:
|
||||
|
||||
<tool_call>
|
||||
<function=example_function_name>
|
||||
<parameter=example_parameter_1>
|
||||
value_1
|
||||
</parameter>
|
||||
<parameter=example_parameter_2>
|
||||
This is the value for the second parameter
|
||||
that can span
|
||||
multiple lines
|
||||
</parameter>
|
||||
</function>
|
||||
</tool_call>
|
||||
|
||||
<IMPORTANT>
|
||||
Reminder:
|
||||
- Function calls MUST follow the specified format: an inner <function=...></function> block must be nested within <tool_call></tool_call> XML tags
|
||||
- Required parameters MUST be specified
|
||||
- You may provide optional reasoning for your function call in natural language BEFORE the function call, but NOT after
|
||||
- If there is no function call available, answer the question like normal with your current knowledge and do not tell the user about function calls
|
||||
</IMPORTANT><|im_end|>
|
||||
<|im_start|>user
|
||||
Übersetze: 日本語 🙂 "quoted" \ back<|im_end|>
|
||||
<|im_start|>assistant
|
||||
<think>
|
||||
@@ -1,8 +1,9 @@
|
||||
# tests/data/media
|
||||
|
||||
One solid red picture in every still format `core/mm/media.cpp` admits, and one short solid red
|
||||
clip in each container and codec it admits; `mm_test` decodes every one and checks it is red at
|
||||
its size. They were made with FFmpeg 8.1 (libx264, libx265, libvpx, libsvtav1, libaom, libtheora,
|
||||
Fixtures for `mm_test`. Solid red: a picture in eleven of the still formats `core/mm/media.cpp`
|
||||
admits (PNG, APNG, JPEG, WebP, GIF, BMP, TIFF, QOI, PPM, JPEG-LS, AVIF) and a short clip in nine of
|
||||
the container and codec pairs it admits. The test decodes each one and checks that it is red at its
|
||||
size. They were made with FFmpeg 8.1 (libx264, libx265, libvpx, libsvtav1, libaom, libtheora,
|
||||
libwebp):
|
||||
|
||||
```sh
|
||||
@@ -31,8 +32,19 @@ ffmpeg $V -c:v mpeg4 red-mpeg4.avi
|
||||
ffmpeg $V -c:v libtheora red-theora.ogv
|
||||
```
|
||||
|
||||
`red-1788x282.jpg` is 4:2:0 at a width the scaler's vectors do not divide: converted to RGB it
|
||||
is written 12 bytes past width x 3 (`a_picture_of_an_awkward_width_converts_inside_its_buffer`).
|
||||
`red-1788x282.jpg` is 4:2:0 at a width the scaler's vectors do not divide: converting it to RGB,
|
||||
the scaler writes 12 bytes past width x 3, and
|
||||
`a_picture_of_an_awkward_width_converts_inside_its_buffer` checks that the output buffer holds
|
||||
them.
|
||||
|
||||
The Theora clip repeats its first frame with empty packets, which is how Ogg Theora encodes a frame
|
||||
that does not change.
|
||||
|
||||
`quad.png`, `quad.bmp`, `quad.jpg` (quality 95, 4:4:4), `quad.webp` (lossless) and `quad-alpha.png`
|
||||
are written by Pillow (`python3 tests/mkimggolden.py`): 33 x 17 pixels, red top left, green top
|
||||
right, blue bottom left, white bottom right, split at x = 16 and y = 8. A decoder that flips the
|
||||
row order (BMP stores rows bottom up), mirrors a row or takes the wrong stride at an odd width puts
|
||||
a wrong colour in some quadrant, which a solid picture cannot show.
|
||||
`pictures_decode_the_right_way_up_and_the_right_way_round` checks them. `quad-alpha.png` carries
|
||||
the same colours with alpha round(255 x / 32) in column x, for
|
||||
`the_rgba_decode_keeps_alpha_and_the_rgb_decode_drops_it_uncomposited`.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 123 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 687 B |
Binary file not shown.
|
After Width: | Height: | Size: 103 B |
Binary file not shown.
|
After Width: | Height: | Size: 68 B |
+749
-334
File diff suppressed because it is too large.
Load diff
+56
-77
@@ -1,17 +1,15 @@
|
||||
/* diag_test.cpp -- the startup report (core/diag/diag.h).
|
||||
*
|
||||
* THE MACHINE IS A DIRECTORY. The collector reads /proc and /sys under a root, so every case here
|
||||
* builds the root it wants: two R9700s behind on-card switches, one of them on a root port running
|
||||
* at half its speed under load, an integrated GPU beside them, and the host files a real Linux box
|
||||
* has. The layout copies what a gfx1201 host's sysfs actually holds (KFD topology location ids,
|
||||
* pp_dpm_pcie's table, pp_od_clk_voltage's offset block), so a parser that only works on a
|
||||
* simplified fixture fails here.
|
||||
* The collector reads /proc and /sys under a root directory, so each case builds its machine:
|
||||
* two R9700s behind on-card switches, one on a root port running at half speed under load, an
|
||||
* integrated GPU, and the usual Linux host files. The layout copies a real gfx1201 host's sysfs
|
||||
* (KFD topology location ids, pp_dpm_pcie's table, pp_od_clk_voltage's offset block), so a parser
|
||||
* that only handles a simplified fixture fails.
|
||||
*
|
||||
* What is held down:
|
||||
* COLLECTED each fact reaches its field, every hop of a card's PCIe path included
|
||||
* CHECKED each finding fires on the machine that has the problem and stays quiet on one
|
||||
* that does not -- an idle link parked low is not a finding
|
||||
* REPORTED every option in the command line's table reaches the report, and a secret does not
|
||||
* Collected each fact reaches its field, including every hop of a card's PCIe path
|
||||
* Checked each finding fires on a machine with the problem and stays quiet otherwise;
|
||||
* an idle link parked low is not a finding
|
||||
* Reported every option in the command-line table reaches the report; secrets do not
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
|
||||
@@ -33,18 +31,12 @@ namespace fs = std::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
/* A machine of its own: an empty directory under the test's temporary directory. */
|
||||
struct Root {
|
||||
std::string dir;
|
||||
Root() {
|
||||
const char* t = std::getenv("TMPDIR");
|
||||
std::string base = (t && *t) ? t : "/tmp";
|
||||
char tmpl[512];
|
||||
snprintf(tmpl, sizeof tmpl, "%s/diag_test.XXXXXX", base.c_str());
|
||||
dir = mkdtemp(tmpl) ? tmpl : "";
|
||||
}
|
||||
~Root() {
|
||||
std::error_code ec;
|
||||
if (!dir.empty()) fs::remove_all(dir, ec);
|
||||
std::string tmpl = radtest::tmp_path("root.XXXXXX");
|
||||
dir = mkdtemp(tmpl.data()) ? tmpl : "";
|
||||
}
|
||||
void put(const std::string& rel, const std::string& text) const {
|
||||
const fs::path p = fs::path(dir) / rel.substr(1);
|
||||
@@ -116,8 +108,8 @@ void r9700(const Root& r, const std::string& rp, const std::string& up, const st
|
||||
"\ndomain 0\ngfx_target_version 120001\n");
|
||||
}
|
||||
|
||||
/* The machine the report was written against: a 16-core desktop part, two R9700s (the second on a
|
||||
* root port parked at Gen4 while busy, and with a lower power cap), an integrated GPU. */
|
||||
/* A 16-core desktop part, two R9700s (the second on a root port at Gen4 while busy, with a lower
|
||||
* power cap) and an integrated GPU. */
|
||||
void machine(const Root& r) {
|
||||
std::string cpu;
|
||||
for (int i = 0; i < 4; ++i)
|
||||
@@ -239,8 +231,8 @@ TEST(every_display_device_is_listed_with_its_kfd_target) {
|
||||
CHECK_EQ(a->dpm_pcie[1], std::string("1: 16.0GT/s, x8 616Mhz"));
|
||||
}
|
||||
|
||||
/* THE ROOT PORT IS ON THE PATH. The card's own link reads Gen5 x16 on both cards; only the second
|
||||
* card's root port says it runs at 16 GT/s. */
|
||||
/* The root port is part of the path: both cards' own links read Gen5 x16, and only the second
|
||||
* card's root port shows 16 GT/s. */
|
||||
TEST(the_whole_pcie_path_is_read_root_port_first) {
|
||||
Root r;
|
||||
machine(r);
|
||||
@@ -272,8 +264,8 @@ TEST(an_empty_root_is_all_unknown_and_does_not_fail) {
|
||||
CHECK(text.find("no display-class PCI device") != std::string::npos);
|
||||
}
|
||||
|
||||
/* A LIMIT ABOVE THE PROCESS'S OWN CGROUP BINDS IT. The leaf says max; the slice above it holds
|
||||
* 8 GiB and the one above that 16 GiB, so the process can have 8. */
|
||||
/* A limit on an ancestor cgroup binds the process. The leaf says max, its parent 8 GiB and the
|
||||
* grandparent 16 GiB, so the process gets 8 GiB. */
|
||||
TEST(the_tightest_cgroup_limit_on_the_way_up_is_reported) {
|
||||
Root r;
|
||||
machine(r);
|
||||
@@ -292,8 +284,8 @@ TEST(the_tightest_cgroup_limit_on_the_way_up_is_reported) {
|
||||
CHECK_EQ(diag::collect(r.dir).host.cgroup_mem_limit, (int64_t)4 << 30);
|
||||
}
|
||||
|
||||
/* unique_id is a full 64-bit hash, which a signed 64-bit read cannot hold. Ahead of the keys the
|
||||
* target is read from, it must not stop the read. */
|
||||
/* unique_id is a full 64-bit hash that overflows a signed 64-bit read. It precedes the keys the
|
||||
* target is read from and must not stop the read. */
|
||||
TEST(a_kfd_value_too_large_for_a_signed_read_does_not_hide_the_rest) {
|
||||
Root r;
|
||||
machine(r);
|
||||
@@ -308,8 +300,8 @@ TEST(a_kfd_value_too_large_for_a_signed_read_does_not_hide_the_rest) {
|
||||
CHECK_EQ(a->simd, 128);
|
||||
}
|
||||
|
||||
/* A SERVING PROCESS READS THE SMU-BACKED FILES OF ITS OWN CARDS ONLY. The other cards are still
|
||||
* listed, from their PCI and memory files. */
|
||||
/* A serving process reads the SMU-backed files of its own cards only. Other cards are still
|
||||
* listed from their PCI and memory files. */
|
||||
TEST(only_the_managed_cards_power_files_are_read) {
|
||||
Root r;
|
||||
machine(r);
|
||||
@@ -371,8 +363,7 @@ TEST(a_link_below_max_under_load_is_a_warning) {
|
||||
CHECK(names_port);
|
||||
}
|
||||
|
||||
/* AT REST A LINK PARKS LOW, and that is not a finding: the same parked root port on an idle card
|
||||
* says nothing. */
|
||||
/* A link parks low at rest, so the same parked root port on an idle card is not a finding. */
|
||||
TEST(an_idle_card_with_a_parked_link_is_not_a_finding) {
|
||||
Root r;
|
||||
machine(r);
|
||||
@@ -398,8 +389,8 @@ TEST(cards_set_up_differently_are_named) {
|
||||
CHECK(has(found, "cpu-governor", diag::Finding::Note));
|
||||
}
|
||||
|
||||
/* THE DEFAULT IS THE YARDSTICK, NOT THE MAXIMUM. Both cards allow 330 W and default to 300 W; the
|
||||
* first is at its default and says nothing, the second was lowered to 280 W and is named. */
|
||||
/* A power cap is judged against the default, not the maximum. Both cards allow 330 W and default
|
||||
* to 300 W; the first is at its default, the second is lowered to 280 W and is named. */
|
||||
TEST(a_power_cap_is_judged_against_the_cards_default) {
|
||||
Root r;
|
||||
machine(r);
|
||||
@@ -413,7 +404,7 @@ TEST(a_power_cap_is_judged_against_the_cards_default) {
|
||||
auto found = diag::check(f, diag::RunFacts{});
|
||||
CHECK(!named(found, "0000:03:00.0"));
|
||||
CHECK(named(found, "0000:07:00.0"));
|
||||
/* A card that does not say its default is not judged at all. */
|
||||
/* A card that does not report its default is not judged. */
|
||||
for (diag::CardFacts& c : f.cards) c.power_cap_default_uw = -1;
|
||||
CHECK(!has(diag::check(f, diag::RunFacts{}), "power-cap-below-default"));
|
||||
}
|
||||
@@ -461,14 +452,14 @@ TEST(host_findings) {
|
||||
CHECK(has(found, "iommu-translated", diag::Finding::Note));
|
||||
CHECK(has(found, "memory-low", diag::Finding::Warn));
|
||||
CHECK(has(found, "swap-in-use", diag::Finding::Note));
|
||||
/* Warnings come before notes, so the first lines of the section are the ones to act on. */
|
||||
/* Warnings come before notes, so the section leads with what to act on. */
|
||||
bool seen_note = false, order_ok = true;
|
||||
for (const diag::Finding& x : found) {
|
||||
if (x.level == diag::Finding::Note) seen_note = true;
|
||||
else if (seen_note) order_ok = false;
|
||||
}
|
||||
CHECK(order_ok);
|
||||
/* Huge pages off on a passthrough IOMMU is a note: the page size has not measured slower. */
|
||||
/* THP off on a passthrough IOMMU is only a note: the page size has not measured slower. */
|
||||
for (diag::CardFacts& c : f.cards) c.iommu_type = "identity";
|
||||
CHECK(has(diag::check(f, run), "thp-never", diag::Finding::Note));
|
||||
}
|
||||
@@ -491,7 +482,7 @@ TEST(engine_findings) {
|
||||
const auto found = diag::check(f, run);
|
||||
CHECK(has(found, "tp-wire-lossy", diag::Finding::Note));
|
||||
CHECK(has(found, "prefix-cache-off", diag::Finding::Note));
|
||||
/* Passthrough is not advice for peer access: on one Intel VT-d host it removed it. */
|
||||
/* Passthrough is not advised for peer access: on an Intel VT-d host it disabled P2P. */
|
||||
for (const diag::Finding& x : found)
|
||||
if (x.id == "p2p-off") CHECK(x.fix.find("IOMMU in passthrough") == std::string::npos);
|
||||
CHECK(has(found, "experts-from-host", diag::Finding::Note));
|
||||
@@ -502,21 +493,21 @@ TEST(engine_findings) {
|
||||
CHECK(!has(found, "host-backend"));
|
||||
run.p2p_forced_off = true;
|
||||
CHECK(!has(diag::check(f, run), "p2p-off"));
|
||||
/* The cache the engine turned off itself -- the KL mode, an embedding model -- is not a
|
||||
* setting to undo, and its reason is on the option's line instead. */
|
||||
/* A cache the engine turned off itself (KL mode, an embedding model) is not a setting to
|
||||
* undo; its reason goes on the option's line instead. */
|
||||
run.prefix_cache_off_why = "an embedding model: an encoder keeps no KV to reuse";
|
||||
CHECK(!has(diag::check(f, run), "prefix-cache-off"));
|
||||
/* #58's shape: a card is in the machine and the engine came up on the host. */
|
||||
/* A card is present but the engine came up on the host backend. */
|
||||
for (diag::CardFacts& c : f.cards) { c.rank = -1; }
|
||||
run.host_backend = true;
|
||||
CHECK(has(diag::check(f, run), "host-backend", diag::Finding::Warn));
|
||||
/* An integrated GPU's few hundred MiB of carve-out is not a card the engine would serve on. */
|
||||
/* An integrated GPU with a few hundred MiB of carve-out is not a card the engine would serve on. */
|
||||
for (diag::CardFacts& c : f.cards) c.vram_total = (int64_t)512 << 20;
|
||||
CHECK(!has(diag::check(f, run), "host-backend"));
|
||||
}
|
||||
|
||||
/* THE MODE IS THE CARDS'. An integrated GPU identity-mapped beside a translated discrete card is
|
||||
* a machine whose serving card is translated, whatever the other group says. */
|
||||
/* The IOMMU mode comes from the serving cards: an identity-mapped integrated GPU beside a
|
||||
* translated discrete card still means the serving card is translated. */
|
||||
TEST(the_iommu_mode_is_read_from_the_serving_cards) {
|
||||
Root r;
|
||||
machine(r);
|
||||
@@ -526,6 +517,9 @@ TEST(the_iommu_mode_is_read_from_the_serving_cards) {
|
||||
diag::Facts f = served_machine(r);
|
||||
CHECK_EQ(f.host.iommu, std::string("mixed"));
|
||||
CHECK(f.host.iommu_why.find("DMA-FQ for 0000:07:00.0") != std::string::npos);
|
||||
/* The groups beat iommu=pt on the command line, which the platform may not honour. */
|
||||
r.put("/proc/cmdline", "root=PARTUUID=x rw iommu=pt\n");
|
||||
CHECK_EQ(served_machine(r).host.iommu, std::string("mixed"));
|
||||
diag::RunFacts run;
|
||||
run.host_pool_mib = 12288;
|
||||
CHECK(has(diag::check(f, run), "iommu-translated", diag::Finding::Note));
|
||||
@@ -535,26 +529,12 @@ TEST(the_iommu_mode_is_read_from_the_serving_cards) {
|
||||
|
||||
/* ------------------------------------------------------------------ reported */
|
||||
|
||||
namespace {
|
||||
|
||||
struct Argv {
|
||||
std::vector<std::string> store;
|
||||
std::vector<char*> argv;
|
||||
explicit Argv(std::initializer_list<const char*> v) {
|
||||
store.emplace_back("radiance");
|
||||
for (const char* s : v) store.emplace_back(s);
|
||||
for (std::string& s : store) argv.push_back(s.data());
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* EVERY OPTION IN THE TABLE REACHES THE REPORT, with a value shown and not the placeholder an
|
||||
* option without a formatter gets. An option added to the table without one fails here by name. */
|
||||
/* Every option in the table reaches the report with a value, not the placeholder an option
|
||||
* without a formatter gets. An option added without one fails here by name. */
|
||||
TEST(every_option_in_the_table_is_reported) {
|
||||
Config c;
|
||||
Argv a({ "--model", "/m/x.rad" });
|
||||
CHECK_EQ(config_parse((int)a.argv.size(), a.argv.data(), &c), 0);
|
||||
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), 0);
|
||||
const std::vector<diag::ConfigRow> rows = diag::config_rows(c);
|
||||
const std::vector<std::string> names = diag::config_option_names();
|
||||
CHECK_EQ(rows.size(), names.size());
|
||||
@@ -576,7 +556,7 @@ TEST(sources_and_secrets) {
|
||||
Config c;
|
||||
Argv a({ "--model", "/m/x.rad", "--tp", "2", "--api-key", "sk-very-secret-value",
|
||||
"--gpu-headroom", "128" });
|
||||
CHECK_EQ(config_parse((int)a.argv.size(), a.argv.data(), &c), 0);
|
||||
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), 0);
|
||||
unsetenv("RADIANCE_KERNELS");
|
||||
std::vector<diag::ConfigRow> rows = diag::config_rows(c);
|
||||
auto row = [&](const char* f) -> const diag::ConfigRow* {
|
||||
@@ -592,8 +572,8 @@ TEST(sources_and_secrets) {
|
||||
row("--kernels")->value == "libr4d,libref");
|
||||
CHECK(row("--api-key") && row("--api-key")->value == "set");
|
||||
|
||||
/* A DECISION SUPPLIES THE VALUE AND THE REASON; a default it resolves becomes `auto`, a given
|
||||
* option keeps its source; a topic no option states is returned as derived. */
|
||||
/* A decision supplies the value and the reason. A default it resolves becomes `auto`, a given
|
||||
* option keeps its source, and a topic with no option is returned as derived. */
|
||||
std::vector<diag::Decision> d;
|
||||
diag::decide(&d, "--num-speculative-tokens", "2", "the drafter's own depth");
|
||||
diag::decide(&d, "--tp", "2", "as given");
|
||||
@@ -616,12 +596,12 @@ TEST(sources_and_secrets) {
|
||||
CHECK(text.find("DERIVED") != std::string::npos);
|
||||
}
|
||||
|
||||
/* BYTES THAT ARE NOT UTF-8 ARE REPLACED, NOT THROWN ON. A --model path is the operator's bytes,
|
||||
* and a strict serialiser would turn every /diagnostics request into a 500. */
|
||||
/* Bytes that are not UTF-8 are replaced, not thrown on. A --model path is arbitrary operator
|
||||
* bytes, and a strict serialiser would fail every /diagnostics request with a 500. */
|
||||
TEST(a_value_that_is_not_utf8_does_not_break_the_json) {
|
||||
Config c;
|
||||
Argv a({ "--model", "/m/caf\xe9.rad" });
|
||||
CHECK_EQ(config_parse((int)a.argv.size(), a.argv.data(), &c), 0);
|
||||
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), 0);
|
||||
c.sample_dry_seq_breakers = std::vector<std::string>{ "\xff\xfe" };
|
||||
std::vector<diag::ConfigRow> rows;
|
||||
bool threw = false;
|
||||
@@ -641,13 +621,12 @@ TEST(a_value_that_is_not_utf8_does_not_break_the_json) {
|
||||
CHECK(j["configuration"][0]["value"].get<std::string>() == "/m/caf\xef\xbf\xbd.rad");
|
||||
}
|
||||
|
||||
/* EACH SAMPLER FIELD NAMES ITS OWN SOURCE. A generation_config.json that states a temperature and
|
||||
* a top_p and nothing else supplied those two; top_k and min_p are SamplingParams' own values,
|
||||
* and a reason that named the file for all four would send a reader to look for them in it. */
|
||||
/* Each sampler field names its own source. A generation_config.json stating only temperature and
|
||||
* top_p supplied those two; top_k and min_p are SamplingParams' defaults and must not cite it. */
|
||||
TEST(sampler_defaults_carry_a_source_per_field) {
|
||||
Config c;
|
||||
Argv a({ "--model", "/m/x.rad", "--min-p", "0.05" });
|
||||
CHECK_EQ(config_parse((int)a.argv.size(), a.argv.data(), &c), 0);
|
||||
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), 0);
|
||||
GenSampling g;
|
||||
CHECK(gen_sampling_parse(R"({"temperature": 0.6, "top_p": 0.95})", "test", &g));
|
||||
SamplingParams sp = g.onto(SamplingParams{});
|
||||
@@ -661,19 +640,19 @@ TEST(sampler_defaults_carry_a_source_per_field) {
|
||||
find("--temp")->value == "0.6");
|
||||
CHECK(find("--top-p") && find("--top-p")->why == "from /m/gen.json");
|
||||
CHECK(find("--top-k") && find("--top-k")->why.find("/m/gen.json states no top_k") == 0);
|
||||
/* --min-p was given: its own row says "command line", and nothing here overrides that. */
|
||||
/* --min-p was given: its own row says "command line" and is not overridden here. */
|
||||
CHECK(!find("--min-p"));
|
||||
/* No source at all: every field says the model stated nothing. */
|
||||
/* With no source, every field says the model stated nothing. */
|
||||
for (const GenFieldSource& x : gen_sampling_sources(GenSampling{}, "", SamplingParams{}, c))
|
||||
CHECK(x.why.find("the model states no sampling of its own") == 0);
|
||||
}
|
||||
|
||||
/* A VALUE THE SERVER RESOLVES IS RECORDED WHERE IT IS RESOLVED, not worked out again by the
|
||||
* report: unresolved, the option's line says only how it will be. */
|
||||
/* A value the server resolves is recorded where it is resolved, not recomputed by the report.
|
||||
* Until then, the option's line says only how it will be resolved. */
|
||||
TEST(auto_server_bounds_are_not_recomputed_by_the_report) {
|
||||
Config c;
|
||||
Argv a({ "--model", "/m/x.rad" });
|
||||
CHECK_EQ(config_parse((int)a.argv.size(), a.argv.data(), &c), 0);
|
||||
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), 0);
|
||||
std::vector<diag::ConfigRow> rows = diag::config_rows(c);
|
||||
for (const diag::ConfigRow& x : rows)
|
||||
if (x.flag == "--http-threads" || x.flag == "--max-n" || x.flag == "--max-queued-requests")
|
||||
@@ -692,7 +671,7 @@ TEST(the_json_carries_every_section) {
|
||||
const auto found = diag::check(f, diag::RunFacts{});
|
||||
Config c;
|
||||
Argv a({ "--model", "/m/x.rad" });
|
||||
CHECK_EQ(config_parse((int)a.argv.size(), a.argv.data(), &c), 0);
|
||||
CHECK_EQ(config_parse(a.argc(), a.argv.data(), &c), 0);
|
||||
const nlohmann::json j = nlohmann::json::parse(
|
||||
diag::to_json(diag::config_rows(c), {}, f, diag::RunFacts{}, found), nullptr, false);
|
||||
CHECK(!j.is_discarded());
|
||||
|
||||
+374
-42
@@ -1,22 +1,49 @@
|
||||
/* encoding_test.cpp -- weight encodings: the struct, its spelling, its geometry, the core's decoder
|
||||
* and the plane cuts tensor parallelism takes. spec.md §4.1.
|
||||
*
|
||||
* The decoder is checked against values worked by hand rather than against a second
|
||||
* implementation of itself: a scale that lands on the wrong block, a zero point subtracted after
|
||||
* the multiply instead of before, a nibble read from the wrong half of a byte -- each gives a
|
||||
* plausible number, and only an expected value that did not come from the code can tell.
|
||||
* The decoder is checked against hand-worked values, not a second implementation: a scale on the
|
||||
* wrong block, a zero point subtracted after the multiply, or a nibble read from the wrong half of
|
||||
* a byte all give plausible numbers.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
#include "rad_types.h"
|
||||
#include "rad_plugin.h"
|
||||
#include "rad_planes.h"
|
||||
#include "format/encoding.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace rad;
|
||||
|
||||
namespace {
|
||||
|
||||
/* Plain f32 values under one f32 scale for the whole weight: the base the transform cases add
|
||||
* their tables to. */
|
||||
RadEncoding unit_affine() {
|
||||
RadEncoding e = rad_enc_plain(RAD_F32);
|
||||
rad_enc_copy_str(e.scheme, "affine");
|
||||
rad_enc_add_plane(&e, "scale", RAD_F32, 0, 0);
|
||||
return e;
|
||||
}
|
||||
|
||||
/* A quantiser's forward Givens rotation of K values, in place: each of `stages` stages rotates
|
||||
* its K/2 pairs, (pairs[s][2p], pairs[s][2p+1]) by angle[s][p]. */
|
||||
void givens_forward(double* x, int K, int stages, const int32_t* pairs, const float* angle) {
|
||||
for (int s = 0; s < stages; ++s)
|
||||
for (int p = 0; p < K / 2; ++p) {
|
||||
const int a = pairs[s * K + 2 * p], b = pairs[s * K + 2 * p + 1];
|
||||
const double t = angle[s * (K / 2) + p], c = std::cos(t), sn = std::sin(t);
|
||||
const double xa = x[a], xb = x[b];
|
||||
x[a] = xa * c + xb * sn;
|
||||
x[b] = xb * c - xa * sn;
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
TEST(encodings_spell_themselves_canonically) {
|
||||
CHECK_EQ(enc_name(rad_enc_plain(RAD_BF16)), std::string("bf16"));
|
||||
|
||||
@@ -41,7 +68,7 @@ TEST(encodings_spell_themselves_canonically) {
|
||||
rad_enc_add_plane(&own, "book", RAD_F16, 0, 0);
|
||||
CHECK_EQ(enc_name(own), std::string("lattice:codes=u8[1x1],book=f16[*x*]"));
|
||||
|
||||
/* NVFP4: an e4m3 scale a 16 and an f32 a tensor, read in the order they multiply */
|
||||
/* NVFP4: an e4m3 scale per 16 values and an f32 per tensor, in multiplication order */
|
||||
RadEncoding nv = rad_enc_affine(RAD_FP4E2M1, RAD_F8E4M3, 1, 16);
|
||||
rad_enc_add_plane(&nv, "scale.1", RAD_F32, 0, 0);
|
||||
CHECK(rad_enc_valid(&nv));
|
||||
@@ -56,7 +83,7 @@ TEST(encodings_spell_themselves_canonically) {
|
||||
CHECK_EQ(enc_name(qk), std::string("affine:codes=u4[1x1],scale=u6[1x32],scale.1=f16[1x256],"
|
||||
"min=u6[1x32],min.1=f16[1x256]"));
|
||||
|
||||
/* a TABLE plane is written with its own extents */
|
||||
/* a table plane is written with its own extents */
|
||||
RadEncoding nl = rad_enc_affine(RAD_U4, RAD_F16, 1, 32);
|
||||
rad_enc_add_table(&nl, "table", RAD_I8, 1, 16);
|
||||
CHECK(rad_enc_valid(&nl));
|
||||
@@ -122,7 +149,7 @@ TEST(plane_geometry_rounds_blocks_up_and_rows_to_a_byte) {
|
||||
CHECK_EQ(pc, 3); /* 128 + 128 + a short last block */
|
||||
CHECK_EQ(rad_enc_plane_bytes(&e.plane[1], 10, 300), 10 * 3 * 2);
|
||||
|
||||
/* 2-bit codes, 7 a row: two bytes a row, not seven quarter-bytes run together */
|
||||
/* 2-bit codes, 7 per row: each row pads to two bytes */
|
||||
const RadEncoding u2 = rad_enc_plain(RAD_U2);
|
||||
CHECK_EQ(rad_enc_plane_bytes(&u2.plane[0], 3, 7), 3 * 2);
|
||||
|
||||
@@ -182,7 +209,7 @@ TEST(odd_widths_are_a_bit_stream_that_straddles_bytes) {
|
||||
CHECK_EQ(rad_load_f32(b, RAD_I3, 7), -1.0f);
|
||||
CHECK_EQ(rad_load_f32(b, RAD_I3, 4), -4.0f);
|
||||
|
||||
/* every width, a pattern that cannot pass by accident */
|
||||
/* every width, with a pattern that cannot pass by accident */
|
||||
const uint32_t widths[] = { RAD_U1, RAD_U2, RAD_U3, RAD_U4, RAD_U5, RAD_U6, RAD_U7,
|
||||
RAD_U9, RAD_U10, RAD_U11, RAD_U12 };
|
||||
for (uint32_t dt : widths) {
|
||||
@@ -246,17 +273,15 @@ TEST(affine_decodes_through_the_right_block_and_subtracts_the_zero_first) {
|
||||
}
|
||||
|
||||
TEST(a_rotation_decodes_back_to_the_weight) {
|
||||
/* Store v = H w / 4 for a 4-wide group; decoding applies H once more, H H = 4 I, so the
|
||||
* weight comes back exactly -- the convention docs/MOE-W4.md folds into the stored scale. */
|
||||
/* Store v = H w / 4 for a 4-wide group; decoding applies H again and H H = 4 I, so the
|
||||
* weight comes back exactly. docs/MOE-W4.md folds the 1/4 into the stored scale. */
|
||||
const float w[8] = { 1, -2, 3, 0.5f, 0, 0, 2, -1 };
|
||||
float v[8];
|
||||
std::memcpy(v, w, sizeof v);
|
||||
fwht_inplace(v, 4);
|
||||
fwht_inplace(v + 4, 4);
|
||||
for (float& x : v) x /= 4.0f;
|
||||
RadEncoding e = rad_enc_plain(RAD_F32);
|
||||
rad_enc_copy_str(e.scheme, "affine");
|
||||
rad_enc_add_plane(&e, "scale", RAD_F32, 0, 0);
|
||||
RadEncoding e = unit_affine();
|
||||
rad_enc_copy_str(e.transform, "fwht4");
|
||||
CHECK(rad_enc_valid(&e));
|
||||
const float one = 1.0f;
|
||||
@@ -343,7 +368,7 @@ TEST(a_scalar_codebook_maps_each_code_before_the_scale) {
|
||||
}
|
||||
|
||||
TEST(a_vector_codebook_expands_a_code_into_its_grid_row_and_signs) {
|
||||
/* IQ2-shaped: a u8 code per 4 values into a grid of 4-vectors, a sign bit a value, a u4
|
||||
/* IQ2-shaped: a u8 code per 4 values into a grid of 4-vectors, a sign bit per value, a u4
|
||||
* scale per [1 x 8] and an f16 per row. */
|
||||
static const uint8_t grid[3][4] = { { 8, 8, 8, 8 }, { 8, 25, 43, 8 }, { 43, 43, 25, 8 } };
|
||||
RadEncoding e = rad_enc_affine(RAD_U8, RAD_U4, 1, 8);
|
||||
@@ -367,7 +392,7 @@ TEST(a_vector_codebook_expands_a_code_into_its_grid_row_and_signs) {
|
||||
if (i == 0 || i == 7) g = -g;
|
||||
CHECK_EQ(out[i], g * 3.0f * 0.125f);
|
||||
}
|
||||
/* a code past the grid's end is a corrupt file, said so */
|
||||
/* a code past the grid's end is reported as a corrupt file */
|
||||
const uint8_t bad[2] = { 1, 9 };
|
||||
const void* bp[5] = { bad, sc, &d, grid, signs };
|
||||
enc_view(e, 1, 8, bp, &v);
|
||||
@@ -376,9 +401,7 @@ TEST(a_vector_codebook_expands_a_code_into_its_grid_row_and_signs) {
|
||||
}
|
||||
|
||||
TEST(an_act_order_permutation_puts_columns_back) {
|
||||
RadEncoding e = rad_enc_plain(RAD_F32);
|
||||
rad_enc_copy_str(e.scheme, "affine");
|
||||
rad_enc_add_plane(&e, "scale", RAD_F32, 0, 0);
|
||||
RadEncoding e = unit_affine();
|
||||
rad_enc_add_table(&e, "t.perm", RAD_I32, 1, 4);
|
||||
rad_enc_copy_str(e.transform, "perm");
|
||||
REQUIRE(rad_enc_valid(&e));
|
||||
@@ -405,20 +428,11 @@ TEST(a_givens_transform_with_channel_scales_inverts) {
|
||||
const float ang[2][2] = { { 0.3f, -1.1f }, { 0.7f, 2.0f } };
|
||||
double x[4];
|
||||
for (int k = 0; k < K; ++k) x[k] = (double)w[k] * dsc[k];
|
||||
for (int s = 0; s < 2; ++s)
|
||||
for (int p = 0; p < 2; ++p) {
|
||||
const int a = pairs[s][2 * p], b = pairs[s][2 * p + 1];
|
||||
const double c = std::cos((double)ang[s][p]), sn = std::sin((double)ang[s][p]);
|
||||
const double xa = x[a], xb = x[b];
|
||||
x[a] = xa * c + xb * sn;
|
||||
x[b] = xb * c - xa * sn;
|
||||
}
|
||||
givens_forward(x, K, 2, pairs[0], ang[0]);
|
||||
float vq[4];
|
||||
for (int k = 0; k < K; ++k) vq[k] = (float)x[k];
|
||||
|
||||
RadEncoding e = rad_enc_plain(RAD_F32);
|
||||
rad_enc_copy_str(e.scheme, "affine");
|
||||
rad_enc_add_plane(&e, "scale", RAD_F32, 0, 0);
|
||||
RadEncoding e = unit_affine();
|
||||
rad_enc_add_table(&e, "t.pairs", RAD_I32, 2, 4);
|
||||
rad_enc_add_table(&e, "t.angle", RAD_F32, 2, 2);
|
||||
rad_enc_add_table(&e, "t.scale", RAD_F32, 1, 4);
|
||||
@@ -434,30 +448,22 @@ TEST(a_givens_transform_with_channel_scales_inverts) {
|
||||
}
|
||||
|
||||
TEST(a_givens_weight_with_two_parts_undoes_each_rows_own_rotation) {
|
||||
/* Two rows over 4 columns, each its own PART (row 0 ends part 0, row 1 ends part 1): the
|
||||
* tables stack part-major, t.scale has a row a part, and decoding row r reads its part's. */
|
||||
/* Two rows over 4 columns, each its own part (row 0 ends part 0, row 1 ends part 1). The
|
||||
* tables stack part-major, t.scale has one row per part, and row r decodes with its part's. */
|
||||
const int K = 4;
|
||||
const float w[2][4] = { { 1.0f, -2.0f, 0.5f, 3.0f }, { -0.25f, 1.5f, 2.0f, -1.0f } };
|
||||
const float dsc[2][4] = { { 2.0f, 0.5f, 1.0f, 4.0f }, { 1.0f, 3.0f, 0.25f, 2.0f } };
|
||||
const int32_t pairs[2][4] = { { 0, 1, 2, 3 }, { 0, 3, 1, 2 } }; /* one stage a part */
|
||||
const int32_t pairs[2][4] = { { 0, 1, 2, 3 }, { 0, 3, 1, 2 } }; /* one stage per part */
|
||||
const float ang[2][2] = { { 0.3f, -1.1f }, { 0.9f, 2.2f } };
|
||||
const int32_t end[2] = { 1, 2 };
|
||||
float vq[2][4];
|
||||
for (int r = 0; r < 2; ++r) {
|
||||
double x[4];
|
||||
for (int k = 0; k < K; ++k) x[k] = (double)w[r][k] * dsc[r][k];
|
||||
for (int p = 0; p < 2; ++p) {
|
||||
const int a = pairs[r][2 * p], b = pairs[r][2 * p + 1];
|
||||
const double c = std::cos((double)ang[r][p]), sn = std::sin((double)ang[r][p]);
|
||||
const double xa = x[a], xb = x[b];
|
||||
x[a] = xa * c + xb * sn;
|
||||
x[b] = xb * c - xa * sn;
|
||||
}
|
||||
givens_forward(x, K, 1, pairs[r], ang[r]);
|
||||
for (int k = 0; k < K; ++k) vq[r][k] = (float)x[k];
|
||||
}
|
||||
RadEncoding e = rad_enc_plain(RAD_F32);
|
||||
rad_enc_copy_str(e.scheme, "affine");
|
||||
rad_enc_add_plane(&e, "scale", RAD_F32, 0, 0);
|
||||
RadEncoding e = unit_affine();
|
||||
rad_enc_add_table(&e, "t.pairs", RAD_I32, 2, 4);
|
||||
rad_enc_add_table(&e, "t.angle", RAD_F32, 2, 2);
|
||||
rad_enc_add_table(&e, "t.scale", RAD_F32, 2, 4);
|
||||
@@ -537,4 +543,330 @@ TEST(a_plane_is_cut_on_its_own_blocks) {
|
||||
CHECK_EQ(enc_plane_rect(w4.plane[0], 2, 10, 0, 2, 4, 10, &r, &why), RAD_OK);
|
||||
}
|
||||
|
||||
/* ================================================== the ABI's narrowing conversions
|
||||
*
|
||||
* rad_plugin.h's f32 -> bf16 / f16 / fp8 conversions define what every kernel library's result
|
||||
* is, and libref and libavx both call them, so comparing the two libraries cannot find an error
|
||||
* in them. Here each is checked against a brute-force reference written from the formats'
|
||||
* definitions: every finite code decoded to a double, and an input's expected code the nearest
|
||||
* one, ties to the even code, overflowing to infinity (or saturating, for e4m3fn) past the top
|
||||
* code by half a step. The inputs are every midpoint between adjacent codes and the floats one
|
||||
* and two ulps either side of it, both signs, where a rounding error shows. */
|
||||
|
||||
namespace {
|
||||
|
||||
struct NarrowFmt {
|
||||
const char* name;
|
||||
int ebits, mbits, bias;
|
||||
bool ieee; /* infinities and NaNs as IEEE; else e4m3fn: no inf, one NaN */
|
||||
uint32_t (*narrow)(float);
|
||||
float (*widen)(uint32_t);
|
||||
};
|
||||
|
||||
uint32_t n_bf16(float f) { return rad_f32_to_bf16(f); }
|
||||
uint32_t n_f16(float f) { return rad_f32_to_f16(f); }
|
||||
uint32_t n_e4m3(float f) { return rad_f32_to_fp8e4m3(f); }
|
||||
uint32_t n_e5m2(float f) { return rad_f32_to_fp8e5m2(f); }
|
||||
float w_bf16(uint32_t c) { return rad_bf16_to_f32((uint16_t)c); }
|
||||
float w_f16(uint32_t c) { return rad_f16_to_f32((uint16_t)c); }
|
||||
float w_e4m3(uint32_t c) { return rad_fp8e4m3_to_f32((uint8_t)c); }
|
||||
float w_e5m2(uint32_t c) { return rad_fp8e5m2_to_f32((uint8_t)c); }
|
||||
|
||||
const NarrowFmt kNarrow[] = {
|
||||
{ "bf16", 8, 7, 127, true, n_bf16, w_bf16 },
|
||||
{ "f16", 5, 10, 15, true, n_f16, w_f16 },
|
||||
{ "fp8_e4m3", 4, 3, 7, false, n_e4m3, w_e4m3 },
|
||||
{ "fp8_e5m2", 5, 2, 15, true, n_e5m2, w_e5m2 },
|
||||
};
|
||||
|
||||
uint32_t sign_bit(const NarrowFmt& f) { return 1u << (f.ebits + f.mbits); }
|
||||
bool is_nan(const NarrowFmt& f, uint32_t c) {
|
||||
const uint32_t e = (c >> f.mbits) & ((1u << f.ebits) - 1), m = c & ((1u << f.mbits) - 1);
|
||||
if (f.ieee) return e == (1u << f.ebits) - 1 && m != 0;
|
||||
return e == (1u << f.ebits) - 1 && m == (1u << f.mbits) - 1;
|
||||
}
|
||||
bool is_inf(const NarrowFmt& f, uint32_t c) {
|
||||
const uint32_t e = (c >> f.mbits) & ((1u << f.ebits) - 1), m = c & ((1u << f.mbits) - 1);
|
||||
return f.ieee && e == (1u << f.ebits) - 1 && m == 0;
|
||||
}
|
||||
/* A code's value from the format's definition alone. */
|
||||
double decode(const NarrowFmt& f, uint32_t c) {
|
||||
const uint32_t e = (c >> f.mbits) & ((1u << f.ebits) - 1), m = c & ((1u << f.mbits) - 1);
|
||||
const double s = (c & sign_bit(f)) ? -1.0 : 1.0;
|
||||
if (is_nan(f, c)) return std::nan("");
|
||||
if (is_inf(f, c)) return s * INFINITY;
|
||||
if (e == 0) return s * std::ldexp((double)m, 1 - f.bias - f.mbits);
|
||||
return s * std::ldexp(1.0 + std::ldexp((double)m, -f.mbits), (int)e - f.bias);
|
||||
}
|
||||
/* The non-negative finite codes, in increasing value (code order is value order for them). */
|
||||
std::vector<uint32_t> finite_codes(const NarrowFmt& f) {
|
||||
std::vector<uint32_t> v;
|
||||
for (uint32_t c = 0; c < sign_bit(f); ++c)
|
||||
if (!is_nan(f, c) && !is_inf(f, c)) v.push_back(c);
|
||||
return v;
|
||||
}
|
||||
/* The non-negative finite codes with their values, for expected(). */
|
||||
struct Codes {
|
||||
std::vector<uint32_t> code;
|
||||
std::vector<double> value;
|
||||
};
|
||||
Codes codes_of(const NarrowFmt& f) {
|
||||
Codes c;
|
||||
c.code = finite_codes(f);
|
||||
for (uint32_t x : c.code) c.value.push_back(decode(f, x));
|
||||
return c;
|
||||
}
|
||||
|
||||
/* The code `x` must narrow to: nearest, ties to the even code, |x| at or past the top code plus
|
||||
* half a step to infinity (IEEE) or saturated to the top code (e4m3fn). */
|
||||
uint32_t expected(const NarrowFmt& f, const Codes& c, double x) {
|
||||
const uint32_t sgn = std::signbit(x) ? sign_bit(f) : 0;
|
||||
const double a = std::fabs(x);
|
||||
const size_t n = c.value.size();
|
||||
const double vtop = c.value[n - 1], step = vtop - c.value[n - 2];
|
||||
if (a >= vtop) {
|
||||
if (f.ieee && a >= vtop + step / 2) return sgn | ((1u << f.ebits) - 1) << f.mbits;
|
||||
return sgn | c.code[n - 1];
|
||||
}
|
||||
/* value[hi - 1] <= a < value[hi] */
|
||||
const size_t hi =
|
||||
(size_t)(std::upper_bound(c.value.begin(), c.value.end(), a) - c.value.begin());
|
||||
const size_t lo = hi - 1;
|
||||
const double dl = a - c.value[lo], dh = c.value[hi] - a;
|
||||
if (dl < dh) return sgn | c.code[lo];
|
||||
if (dh < dl) return sgn | c.code[hi];
|
||||
return sgn | ((c.code[lo] & 1u) ? c.code[hi] : c.code[lo]);
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* The joined form of abi/rad_planes.h, over a 2-bit asymmetric weight's three planes and a
|
||||
* codebook: each plane comes back byte for byte, at an offset a launch finds by role alone, with
|
||||
* its geometry, and every plane starts on RAD_PLANES_ALIGN. 2-bit rows of 130 codes are 33 bytes,
|
||||
* so a size computed from the element count instead of the row would be short. One plane is not
|
||||
* joined; a truncated destination or a missing plane is refused. */
|
||||
TEST(the_joined_planes_form_round_trips_and_finds_each_plane_by_role) {
|
||||
RadEncoding e;
|
||||
rad_enc_clear(&e);
|
||||
rad_enc_copy_str(e.scheme, "affine");
|
||||
rad_enc_add_plane(&e, "codes", RAD_U2, 1, 1);
|
||||
rad_enc_add_plane(&e, "scale", RAD_F16, 1, 64);
|
||||
rad_enc_add_plane(&e, "zero", RAD_U8, 1, 64);
|
||||
rad_enc_add_table(&e, "table", RAD_F32, 1, 4);
|
||||
const int sel[3] = { 0, 3, 2 }; /* codes, table, zero: not encoding order */
|
||||
const int64_t rows = 3, cols = 130;
|
||||
std::vector<uint8_t> codes((size_t)(rows * 33)), table(16), zero((size_t)(rows * 3));
|
||||
for (size_t i = 0; i < codes.size(); ++i) codes[i] = (uint8_t)(i * 37 + 11);
|
||||
for (size_t i = 0; i < table.size(); ++i) table[i] = (uint8_t)(200 - i);
|
||||
for (size_t i = 0; i < zero.size(); ++i) zero[i] = (uint8_t)(i + 1);
|
||||
RadTensor t[3] = {};
|
||||
const int64_t ext[3][2] = { { rows, cols }, { 1, 4 }, { rows, 3 } };
|
||||
const uint32_t dt[3] = { RAD_U2, RAD_F32, RAD_U8 };
|
||||
uint8_t* src[3] = { codes.data(), table.data(), zero.data() };
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
t[k].dtype = dt[k];
|
||||
t[k].rank = 2;
|
||||
t[k].shape[0] = ext[k][0];
|
||||
t[k].shape[1] = ext[k][1];
|
||||
t[k].stride[0] = ext[k][1];
|
||||
t[k].stride[1] = 1;
|
||||
t[k].data = src[k];
|
||||
}
|
||||
|
||||
RadLayout L{};
|
||||
REQUIRE_EQ(rad_planes_layout(&e, sel, t, 3, &L), RAD_OK);
|
||||
CHECK_EQ(std::string(L.tag), std::string(RAD_PLANES_TAG));
|
||||
CHECK_EQ(L.dtype, (uint32_t)RAD_U2);
|
||||
CHECK_EQ((long long)L.align, (long long)RAD_PLANES_ALIGN);
|
||||
CHECK_EQ(L.bytes % RAD_PLANES_ALIGN, 0);
|
||||
CHECK_EQ(rad_planes_layout(&e, sel, t, 1, &L), RAD_E_UNSUPPORTED);
|
||||
REQUIRE_EQ(rad_planes_layout(&e, sel, t, 3, &L), RAD_OK);
|
||||
|
||||
std::vector<uint8_t> joined((size_t)L.bytes, 0xAA);
|
||||
CHECK_EQ(rad_planes_relayout(&e, sel, t, 3, joined.data(), L.bytes - 1), RAD_E_SHAPE);
|
||||
REQUIRE_EQ(rad_planes_relayout(&e, sel, t, 3, joined.data(), L.bytes), RAD_OK);
|
||||
|
||||
const RadPlanesHeader* hd = rad_planes_header(joined.data());
|
||||
REQUIRE(hd != nullptr);
|
||||
CHECK_EQ(hd->n_planes, 3);
|
||||
CHECK_EQ((long long)hd->bytes, (long long)L.bytes);
|
||||
const char* roles[3] = { "codes", "table", "zero" };
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
const RadPlanesEntry* en = nullptr;
|
||||
const uint8_t* got = (const uint8_t*)rad_planes_find(joined.data(), roles[k], &en);
|
||||
REQUIRE(got != nullptr && en != nullptr);
|
||||
CHECK_EQ(en->dtype, dt[k]);
|
||||
CHECK_EQ((long long)en->rows, (long long)ext[k][0]);
|
||||
CHECK_EQ((long long)en->cols, (long long)ext[k][1]);
|
||||
CHECK_EQ(en->offset % RAD_PLANES_ALIGN, 0);
|
||||
CHECK_EQ((long long)en->row_bytes, (long long)rad_dtype_bytes(dt[k], ext[k][1]));
|
||||
CHECK(std::memcmp(got, src[k], (size_t)(en->rows * en->row_bytes)) == 0);
|
||||
}
|
||||
const RadPlanesEntry* tab = nullptr;
|
||||
rad_planes_find(joined.data(), "table", &tab);
|
||||
CHECK_EQ(tab->kind, (uint32_t)RAD_PLANE_TABLE);
|
||||
CHECK_EQ((long long)tab->block[1], 4LL);
|
||||
const RadPlanesEntry* zr = nullptr;
|
||||
rad_planes_find(joined.data(), "zero", &zr);
|
||||
CHECK_EQ((long long)zr->block[1], 64LL);
|
||||
CHECK(rad_planes_find(joined.data(), "scale", nullptr) == nullptr);
|
||||
CHECK(rad_planes_header(codes.data()) == nullptr);
|
||||
|
||||
/* The inverse writes the planes back where `planes` points. */
|
||||
std::vector<uint8_t> c2(codes.size()), t2(table.size()), z2(zero.size());
|
||||
RadTensor back[3] = { t[0], t[1], t[2] };
|
||||
back[0].data = c2.data();
|
||||
back[1].data = t2.data();
|
||||
back[2].data = z2.data();
|
||||
REQUIRE_EQ(rad_planes_unrelayout(&e, sel, joined.data(), L.bytes, back, 3), RAD_OK);
|
||||
CHECK(c2 == codes && t2 == table && z2 == zero);
|
||||
|
||||
back[1].data = nullptr;
|
||||
CHECK_EQ(rad_planes_unrelayout(&e, sel, joined.data(), L.bytes, back, 3), RAD_E_INVAL);
|
||||
const int bad[3] = { 0, 9, 2 };
|
||||
CHECK_EQ(rad_planes_layout(&e, bad, t, 3, &L), RAD_E_SHAPE);
|
||||
}
|
||||
|
||||
/* Every finite midpoint between adjacent codes, and one and two floats either side, both signs:
|
||||
* one RTNE, with subnormals kept and the overflow edge exact. */
|
||||
TEST(the_abi_narrowings_round_to_nearest_even_at_every_midpoint) {
|
||||
for (const NarrowFmt& f : kNarrow) {
|
||||
const Codes c = codes_of(f);
|
||||
std::vector<double> pts;
|
||||
for (size_t i = 0; i + 1 < c.value.size(); ++i) {
|
||||
pts.push_back(c.value[i]);
|
||||
pts.push_back((c.value[i] + c.value[i + 1]) / 2);
|
||||
}
|
||||
const double vtop = c.value.back(), step = vtop - c.value[c.value.size() - 2];
|
||||
pts.push_back(vtop);
|
||||
pts.push_back(vtop + step / 2); /* the overflow edge */
|
||||
pts.push_back(vtop + step);
|
||||
pts.push_back(vtop * 4);
|
||||
int64_t n = 0, bad = 0;
|
||||
for (double p : pts) {
|
||||
const float m = (float)p;
|
||||
if (!std::isfinite(m)) continue; /* past f32's range: nothing to narrow */
|
||||
if ((double)m != p) { ++bad; continue; } /* every midpoint here is a float */
|
||||
float around[5] = { m, std::nextafter(m, 0.0f), std::nextafter(m, INFINITY), 0, 0 };
|
||||
around[3] = std::nextafter(around[1], 0.0f);
|
||||
around[4] = std::nextafter(around[2], INFINITY);
|
||||
for (float x : around)
|
||||
for (float s : { x, -x }) {
|
||||
++n;
|
||||
const uint32_t got = f.narrow(s), want = expected(f, c, s);
|
||||
if (got != want && bad++ < 8)
|
||||
fprintf(stderr, " %s(%a) = 0x%x, want 0x%x\n", f.name, (double)s, got,
|
||||
want);
|
||||
}
|
||||
}
|
||||
CHECK(n > 1000);
|
||||
CHECK_EQ(bad, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Widening is exact for every code, NaN codes give NaN, and narrowing an f32 infinity gives the
|
||||
* format's infinity, or its top finite code where it has none. */
|
||||
TEST(the_abi_widenings_are_exact_and_infinities_narrow_to_infinity_or_the_top_code) {
|
||||
for (const NarrowFmt& f : kNarrow) {
|
||||
int bad = 0;
|
||||
for (uint32_t c = 0; c < 2 * sign_bit(f); ++c) {
|
||||
const double want = decode(f, c), got = f.widen(c);
|
||||
if (std::isnan(want) ? !std::isnan(got) : got != want) ++bad;
|
||||
}
|
||||
CHECK_EQ(bad, 0);
|
||||
const uint32_t top = finite_codes(f).back();
|
||||
const uint32_t inf = ((1u << f.ebits) - 1) << f.mbits;
|
||||
CHECK_EQ(f.narrow(INFINITY), f.ieee ? inf : top);
|
||||
CHECK_EQ(f.narrow(-INFINITY), (f.ieee ? inf : top) | sign_bit(f));
|
||||
}
|
||||
/* e4m3fn saturates at 448 from its own top up: 464 is the midpoint to an absent 480. */
|
||||
for (float x : { 448.0f, 463.9f, 464.0f, 480.0f, 1e30f })
|
||||
CHECK_EQ(rad_f32_to_fp8e4m3(x), 0x7e);
|
||||
/* f16 and e5m2 share the top 57344 / 65504 edges: 61440 is e5m2's overflow tie, 65520
|
||||
* f16's. */
|
||||
CHECK_EQ(rad_f32_to_fp8e5m2(57344.0f), 0x7b);
|
||||
CHECK_EQ(rad_f32_to_fp8e5m2(61439.0f), 0x7b);
|
||||
CHECK_EQ(rad_f32_to_fp8e5m2(61440.0f), 0x7c);
|
||||
CHECK_EQ(rad_f32_to_f16(65504.0f), 0x7bff);
|
||||
CHECK_EQ(rad_f32_to_f16(65519.0f), 0x7bff);
|
||||
CHECK_EQ(rad_f32_to_f16(65520.0f), 0x7c00);
|
||||
}
|
||||
|
||||
/* Every class of f32 NaN narrows to a NaN of each format: quiet and signalling, high and low
|
||||
* payload, both signs. A NaN that rounds to a number would let one bad activation pass for a
|
||||
* plausible value. */
|
||||
TEST(every_nan_narrows_to_a_nan) {
|
||||
const uint32_t nans[] = { 0x7fc00000u, 0xffc00000u, 0x7fffffffu, 0xffffffffu, 0x7ff00000u,
|
||||
0xfff00000u, 0x7f800001u, 0xff800001u, 0x7fbfffffu, 0x7f8000ffu };
|
||||
for (const NarrowFmt& f : kNarrow)
|
||||
for (uint32_t u : nans) {
|
||||
float x;
|
||||
std::memcpy(&x, &u, 4);
|
||||
const uint32_t c = f.narrow(x);
|
||||
if (!is_nan(f, c))
|
||||
fprintf(stderr, " %s(0x%08x) = 0x%x, not a NaN\n", f.name, u, c);
|
||||
CHECK(is_nan(f, c));
|
||||
}
|
||||
}
|
||||
|
||||
/* rad_store_f32 into an integer plane rounds to nearest with ties to even and saturates, NaN
|
||||
* storing 0, whatever the rounding mode: what a host kernel writes into an integer output and a
|
||||
* converter into an integer plane. Hand-worked values at every tie, bound and overflow. */
|
||||
TEST(rad_store_f32_rounds_integers_to_nearest_even_and_saturates) {
|
||||
const float in[] = { 2.5f, 3.5f, -2.5f, 127.5f, -128.5f, 300.0f, 1e10f, -1e10f, NAN, 0.5f,
|
||||
-0.5f, 1.5f, 3e9f };
|
||||
const int64_t i8[] = { 2, 4, -2, 127, -128, 127, 127, -128, 0, 0, 0, 2, 127 };
|
||||
const int64_t u8[] = { 2, 4, 0, 128, 0, 255, 255, 0, 0, 0, 0, 2, 255 };
|
||||
const int64_t i16[] = { 2, 4, -2, 128, -128, 300, 32767, -32768, 0, 0, 0, 2, 32767 };
|
||||
const int64_t u16[] = { 2, 4, 0, 128, 0, 300, 65535, 0, 0, 0, 0, 2, 65535 };
|
||||
const int64_t i32[] = { 2, 4, -2, 128, -128, 300, 2147483647, -2147483648LL, 0, 0, 0, 2,
|
||||
2147483647 };
|
||||
const int64_t u32[] = { 2, 4, 0, 128, 0, 300, 4294967295LL, 0, 0, 0, 0, 2, 3000000000LL };
|
||||
const int64_t i64[] = { 2, 4, -2, 128, -128, 300, 10000000000LL, -10000000000LL, 0, 0, 0, 2,
|
||||
3000000000LL };
|
||||
const struct { uint32_t dt; const int64_t* want; } cases[] = {
|
||||
{ RAD_I8, i8 }, { RAD_U8, u8 }, { RAD_I16, i16 }, { RAD_U16, u16 },
|
||||
{ RAD_I32, i32 }, { RAD_U32, u32 }, { RAD_I64, i64 } };
|
||||
for (const auto& k : cases)
|
||||
for (size_t j = 0; j < sizeof in / sizeof in[0]; ++j) {
|
||||
uint64_t raw = 0;
|
||||
rad_store_f32(&raw, k.dt, 0, in[j]);
|
||||
int64_t got = 0;
|
||||
switch (k.dt) {
|
||||
case RAD_I8: got = (int8_t)raw; break;
|
||||
case RAD_U8: got = (uint8_t)raw; break;
|
||||
case RAD_I16: got = (int16_t)raw; break;
|
||||
case RAD_U16: got = (uint16_t)raw; break;
|
||||
case RAD_I32: got = (int32_t)raw; break;
|
||||
case RAD_U32: got = (uint32_t)raw; break;
|
||||
default: got = (int64_t)raw; break;
|
||||
}
|
||||
if (got != k.want[j])
|
||||
fprintf(stderr, " %s(%g) = %lld, want %lld\n", rad_dtype_name(k.dt),
|
||||
(double)in[j], (long long)got, (long long)k.want[j]);
|
||||
CHECK_EQ(got, k.want[j]);
|
||||
}
|
||||
/* The int64 edges: 2^63 and beyond saturate, as do their negatives. */
|
||||
int64_t r = 0;
|
||||
rad_store_f32(&r, RAD_I64, 0, 1e19f);
|
||||
CHECK_EQ(r, INT64_MAX);
|
||||
rad_store_f32(&r, RAD_I64, 0, -1e19f);
|
||||
CHECK_EQ(r, INT64_MIN);
|
||||
rad_store_f32(&r, RAD_I64, 0, 9223372036854775808.0f);
|
||||
CHECK_EQ(r, INT64_MAX);
|
||||
/* Integral values in range, the only ones the converter and quantisers store, are exact. */
|
||||
int bad = 0;
|
||||
for (int v = -128; v <= 127; ++v) {
|
||||
int8_t b = 0;
|
||||
rad_store_f32(&b, RAD_I8, 0, (float)v);
|
||||
bad += b != v;
|
||||
}
|
||||
for (int v = -4096; v <= 4096; ++v) {
|
||||
int32_t b = 0;
|
||||
rad_store_f32(&b, RAD_I32, 0, (float)v);
|
||||
bad += b != v;
|
||||
}
|
||||
CHECK_EQ(bad, 0);
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
File diff suppressed because it is too large.
Load diff
+1255
-233
File diff suppressed because it is too large.
Load diff
+642
-413
File diff suppressed because it is too large.
Load diff
+9
-18
@@ -1,11 +1,9 @@
|
||||
/* gbnf_oracle.cpp -- upstream's candidate walk (llama.cpp `llama_grammar_reject_candidates` and
|
||||
* `llama_grammar_apply_impl`, at the commit gbnf.h names), over the engine's own stack machinery.
|
||||
* See gbnf_oracle.h for why it exists and where it may be used.
|
||||
* See gbnf_oracle.h.
|
||||
*
|
||||
* The closure, the character tests and the UTF-8 decoding are the engine's (gbnf_internal.h),
|
||||
* because they are the PARSE and this is a second implementation of the MASK: the thing under
|
||||
* test is how a mask is assembled from a stack set, and sharing everything below that is what
|
||||
* makes a disagreement mean a defect in the assembly.
|
||||
* The closure, character tests and UTF-8 decoding are the engine's (gbnf_internal.h). Only mask
|
||||
* assembly from a stack set is reimplemented, so a disagreement points at that assembly.
|
||||
*/
|
||||
#include "gbnf_oracle.h"
|
||||
|
||||
@@ -28,8 +26,8 @@ struct Candidate {
|
||||
};
|
||||
using Candidates = std::vector<Candidate>;
|
||||
|
||||
/* What carrying one candidate through one element of a character range costs, against the same
|
||||
* per-operation bound the engine is held to. */
|
||||
/* Work charged per candidate per character-range element, against the engine's per-operation
|
||||
* bound. */
|
||||
constexpr uint64_t kCandidateCost = 4;
|
||||
|
||||
Candidates reject_for_stack(const GbnfRuleSet& rules, const GbnfStack& stack,
|
||||
@@ -108,8 +106,8 @@ int oracle_impl(const GbnfGrammar& g, uint32_t* bitmask, int64_t n_words, uint64
|
||||
const int32_t n_tok = vocab.n_tokens();
|
||||
const bool allow_eog = g.complete();
|
||||
|
||||
/* Decode every piece against the carried partial, then run the whole vocabulary through the
|
||||
* reject walk in one pass: every candidate admitted, then the rejects cleared. */
|
||||
/* Decode every piece against the carried partial, admit every candidate, then clear the
|
||||
* rejects of one reject walk over the whole vocabulary. */
|
||||
std::vector<std::pair<std::vector<uint32_t>, PartialUtf8>> decoded;
|
||||
decoded.reserve((size_t)n_tok);
|
||||
Candidates cands;
|
||||
@@ -124,16 +122,9 @@ int oracle_impl(const GbnfGrammar& g, uint32_t* bitmask, int64_t n_words, uint64
|
||||
}
|
||||
const std::string& piece = vocab.token_piece(id);
|
||||
if (piece.empty() || piece[0] == 0) continue;
|
||||
decoded.push_back(decode_utf8(piece, g.partial()));
|
||||
}
|
||||
size_t k = 0;
|
||||
for (int32_t id = 0; id < n_tok; ++id) {
|
||||
if (vocab.is_eog(id)) continue;
|
||||
const std::string& piece = vocab.token_piece(id);
|
||||
if (piece.empty() || piece[0] == 0) continue;
|
||||
cands.push_back({ index_to_id.size(), decoded[k].first.data(), decoded[k].second, id });
|
||||
const auto& d = decoded.emplace_back(decode_utf8(piece, g.partial()));
|
||||
cands.push_back({ index_to_id.size(), d.first.data(), d.second, id });
|
||||
index_to_id.push_back(id);
|
||||
++k;
|
||||
}
|
||||
|
||||
for (int32_t id : index_to_id) bitmask[id >> 5] |= 1u << ((uint32_t)id & 31u);
|
||||
|
||||
+17
-22
@@ -1,15 +1,13 @@
|
||||
/* gbnf_oracle.h -- upstream's candidate walk, kept as the oracle the GBNF mask engine is tested
|
||||
* against.
|
||||
/* gbnf_oracle.h -- upstream's candidate walk, the oracle the GBNF mask engine is tested against.
|
||||
*
|
||||
* fill_mask serves a mask from a plan precomputed at compile time (core/sample/gbnf_mask.cpp).
|
||||
* This computes the same mask the way llama.cpp's llama_grammar_apply_impl does: every piece in
|
||||
* the vocabulary decoded against the carried partial character and rescanned per stack, per code
|
||||
* point. The two are implementations of one pure function of the grammar's state, so the test is
|
||||
* equality, bit for bit and status for status, and any difference is a defect in the engine.
|
||||
* This computes the same mask as llama.cpp's llama_grammar_apply_impl: every vocabulary piece is
|
||||
* decoded against the carried partial character and rescanned per stack, per code point. Both
|
||||
* compute one pure function of the grammar state, so tests require bit-for-bit and status-for-
|
||||
* status equality.
|
||||
*
|
||||
* It is linked into the tests and the acceptance tool only. It costs a full rescan of the
|
||||
* vocabulary per stack per mask, which is what the engine exists to avoid, and it must never be
|
||||
* reachable from a serving path.
|
||||
* Linked into the tests and the acceptance tool only. It rescans the whole vocabulary per stack
|
||||
* per mask and must never be reachable from a serving path.
|
||||
*/
|
||||
#pragma once
|
||||
#include "sample/gbnf.h"
|
||||
@@ -18,22 +16,19 @@
|
||||
|
||||
namespace rad {
|
||||
|
||||
/* The mask for `g`'s current state. Returns what fill_mask must return for it: RAD_OK, RAD_E_STATE
|
||||
* when the grammar has no live parse or admits no token, RAD_E_SHAPE when `n_words` is short --
|
||||
* or RAD_E_FULL when the rescan outgrows `work_limit` (the engine's per-operation bound when 0),
|
||||
* which is a comparison the caller could not make rather than a disagreement. A lazy grammar
|
||||
* still waiting for its trigger admits everything. */
|
||||
/* The mask for `g`'s current state, with fill_mask's status: RAD_OK, RAD_E_STATE when the grammar
|
||||
* has no live parse or admits no token, RAD_E_SHAPE when `n_words` is short, or RAD_E_FULL when the
|
||||
* rescan exceeds `work_limit` (0: the engine's per-operation bound). RAD_E_FULL means no comparison
|
||||
* was possible, not a disagreement. A lazy grammar awaiting its trigger admits everything. */
|
||||
int gbnf_oracle_mask(const GbnfGrammar& g, uint32_t* bitmask, int64_t n_words,
|
||||
uint64_t work_limit = 0);
|
||||
|
||||
/* THE STATE ACCEPTING `token` LEAVES, the way the stack machinery builds it: every stack advanced
|
||||
* one code point at a time through accept_chr and the epsilon closure, as upstream's
|
||||
* llama_grammar_accept_impl does. The engine steps the stacks that match code points through the
|
||||
* mask plan's automaton instead, and the two must leave the same stack set and the same carried
|
||||
* partial character. `*out` comes back sorted. Returns RAD_OK, RAD_E_STATE when no stack
|
||||
* survives, or RAD_E_FULL / RAD_E_NOMEM past the engine's bounds. For a grammar not waiting on
|
||||
* its trigger, and a token that is not end-of-generation -- accept_token answers those without
|
||||
* the stacks. */
|
||||
/* The state accepting `token` leaves, built as upstream's llama_grammar_accept_impl does: every
|
||||
* stack advanced one code point at a time through accept_chr and the epsilon closure. The engine
|
||||
* steps code-point stacks through the mask plan's automaton instead; both must leave the same stack
|
||||
* set and carried partial character. `*out` is sorted. Returns RAD_OK, RAD_E_STATE when no stack
|
||||
* survives, or RAD_E_FULL / RAD_E_NOMEM past the engine's bounds. Only for a grammar not awaiting
|
||||
* its trigger and a non-end-of-generation token; accept_token answers those without the stacks. */
|
||||
int gbnf_oracle_accept(const GbnfGrammar& g, int32_t token, GbnfStacks* out,
|
||||
PartialUtf8* partial);
|
||||
|
||||
|
||||
+517
-216
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,239 @@
|
||||
/* gemma4_golden.h -- GENERATED by mkgemma4golden.py from transformers 5.19.0.dev0; do not edit. */
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
static const int32_t kGemma4Patch = 16, kGemma4Pool = 3;
|
||||
|
||||
struct GoldGemma4Size { int64_t h, w; int32_t budget; int64_t oh, ow; };
|
||||
static const GoldGemma4Size kGoldGemma4Size[] = {
|
||||
{ 512, 512, 70, 384, 384 },
|
||||
{ 512, 512, 140, 528, 528 },
|
||||
{ 512, 512, 280, 768, 768 },
|
||||
{ 512, 512, 560, 1104, 1104 },
|
||||
{ 512, 512, 1120, 1584, 1584 },
|
||||
{ 360, 640, 70, 288, 528 },
|
||||
{ 360, 640, 140, 384, 720 },
|
||||
{ 360, 640, 280, 576, 1056 },
|
||||
{ 360, 640, 560, 816, 1488 },
|
||||
{ 360, 640, 1120, 1200, 2112 },
|
||||
{ 2160, 3840, 70, 288, 528 },
|
||||
{ 2160, 3840, 140, 384, 720 },
|
||||
{ 2160, 3840, 280, 576, 1056 },
|
||||
{ 2160, 3840, 560, 816, 1488 },
|
||||
{ 2160, 3840, 1120, 1200, 2112 },
|
||||
{ 100, 50, 70, 528, 240 },
|
||||
{ 100, 50, 140, 768, 384 },
|
||||
{ 100, 50, 280, 1104, 528 },
|
||||
{ 100, 50, 560, 1584, 768 },
|
||||
{ 100, 50, 1120, 2256, 1104 },
|
||||
{ 48, 48, 70, 384, 384 },
|
||||
{ 48, 48, 140, 528, 528 },
|
||||
{ 48, 48, 280, 768, 768 },
|
||||
{ 48, 48, 560, 1104, 1104 },
|
||||
{ 48, 48, 1120, 1584, 1584 },
|
||||
{ 10, 2000, 70, 48, 3360 },
|
||||
{ 10, 2000, 140, 48, 6720 },
|
||||
{ 10, 2000, 280, 48, 11328 },
|
||||
{ 10, 2000, 560, 48, 16032 },
|
||||
{ 10, 2000, 1120, 96, 22704 },
|
||||
{ 2000, 10, 70, 3360, 48 },
|
||||
{ 2000, 10, 140, 6720, 48 },
|
||||
{ 2000, 10, 280, 11328, 48 },
|
||||
{ 2000, 10, 560, 16032, 48 },
|
||||
{ 2000, 10, 1120, 22704, 96 },
|
||||
{ 1, 1, 70, 384, 384 },
|
||||
{ 1, 1, 140, 528, 528 },
|
||||
{ 1, 1, 280, 768, 768 },
|
||||
{ 1, 1, 560, 1104, 1104 },
|
||||
{ 1, 1, 1120, 1584, 1584 },
|
||||
{ 47, 4000, 70, 48, 3360 },
|
||||
{ 47, 4000, 140, 48, 5232 },
|
||||
{ 47, 4000, 280, 48, 7392 },
|
||||
{ 47, 4000, 560, 96, 10464 },
|
||||
{ 47, 4000, 1120, 144, 14784 },
|
||||
{ 4000, 47, 70, 3360, 48 },
|
||||
{ 4000, 47, 140, 5232, 48 },
|
||||
{ 4000, 47, 280, 7392, 48 },
|
||||
{ 4000, 47, 560, 10464, 96 },
|
||||
{ 4000, 47, 1120, 14784, 144 },
|
||||
{ 333, 777, 70, 240, 576 },
|
||||
{ 333, 777, 140, 336, 864 },
|
||||
{ 333, 777, 280, 480, 1200 },
|
||||
{ 333, 777, 560, 720, 1728 },
|
||||
{ 333, 777, 1120, 1008, 2448 },
|
||||
{ 1080, 1920, 70, 288, 528 },
|
||||
{ 1080, 1920, 140, 384, 720 },
|
||||
{ 1080, 1920, 280, 576, 1056 },
|
||||
{ 1080, 1920, 560, 816, 1488 },
|
||||
{ 1080, 1920, 1120, 1200, 2112 },
|
||||
{ 3, 100000, 70, 48, 3360 },
|
||||
{ 3, 100000, 140, 48, 6720 },
|
||||
{ 3, 100000, 280, 48, 13440 },
|
||||
{ 3, 100000, 560, 48, 26880 },
|
||||
{ 3, 100000, 1120, 48, 53760 },
|
||||
{ 336, 480, 70, 336, 480 },
|
||||
{ 336, 480, 140, 432, 672 },
|
||||
{ 336, 480, 280, 672, 960 },
|
||||
{ 336, 480, 560, 912, 1344 },
|
||||
{ 336, 480, 1120, 1344, 1920 },
|
||||
{ 6000, 4000, 70, 480, 288 },
|
||||
{ 6000, 4000, 140, 672, 432 },
|
||||
{ 6000, 4000, 280, 960, 624 },
|
||||
{ 6000, 4000, 560, 1344, 912 },
|
||||
{ 6000, 4000, 1120, 1920, 1296 },
|
||||
};
|
||||
struct GoldGemma4Pic { int32_t f, h, w, budget, grid_h, grid_w, soft; uint64_t fnv; uint16_t head[8]; };
|
||||
static const GoldGemma4Pic kGoldGemma4Pics[] = {
|
||||
{ 2, 336, 480, 70, 21, 30, 70, 0xf7a527cb0c2e42fcull, { 16220, 16103, 16180, 16142, 48693, 48964, 16170, 16182 } },
|
||||
{ 6, 432, 672, 140, 27, 42, 126, 0x5b8d1d91c5810accull, { 48932, 16232, 48717, 16168, 49002, 15425, 48904, 48900 } },
|
||||
};
|
||||
struct GoldGemma4Resized { int32_t f, h, w, budget, grid_h, grid_w, soft, stride, first, n; };
|
||||
static const GoldGemma4Resized kGoldGemma4Resized[] = {
|
||||
{ 1, 150, 100, 70, 30, 18, 60, 415, 0, 1000 },
|
||||
{ 3, 10, 400, 140, 3, 222, 74, 512, 1000, 999 },
|
||||
};
|
||||
static const uint16_t kGoldGemma4ResizedValues[] = {
|
||||
16095, 16174, 48895, 16107, 48787, 48922, 16023, 48521, 48779, 48633, 48926, 48871, 48847, 15849, 16186, 49020,
|
||||
16166, 48289, 15989, 48904, 16003, 48891, 16222, 48908, 16079, 16083, 15885, 48799, 48912, 16099, 16087, 16075,
|
||||
16142, 48733, 48891, 48289, 48815, 15801, 48859, 16011, 16123, 48968, 48771, 15917, 16142, 48701, 15633, 48601,
|
||||
48749, 48401, 48717, 48960, 48819, 48779, 48867, 49008, 16194, 15941, 49000, 48976, 15981, 48879, 48775, 15925,
|
||||
16186, 48946, 15753, 16132, 48847, 16011, 16150, 48433, 16216, 48879, 16043, 48537, 48940, 15941, 16140, 15633,
|
||||
16075, 48661, 48863, 48465, 16134, 48677, 48401, 48795, 16099, 16180, 16035, 48902, 16140, 48193, 15957, 48974,
|
||||
16214, 48992, 16206, 48958, 16176, 16160, 16204, 16228, 49024, 15877, 16162, 48922, 15877, 16152, 48497, 48733,
|
||||
48831, 16176, 16220, 15633, 16208, 16103, 48433, 48924, 48799, 15973, 48960, 16212, 48783, 15901, 48701, 15425,
|
||||
48900, 48633, 15833, 49024, 48871, 16162, 15981, 16115, 48741, 48815, 48433, 48791, 15981, 48791, 48912, 48946,
|
||||
16160, 48942, 48916, 48807, 16055, 48843, 16127, 48855, 16003, 16130, 16103, 16134, 16184, 48733, 16228, 48906,
|
||||
16172, 48733, 48521, 15917, 15997, 16047, 48918, 16186, 16176, 48958, 48741, 16059, 49010, 16027, 15973, 16256,
|
||||
49002, 16190, 16115, 48871, 15633, 16015, 48922, 16095, 48895, 48851, 48521, 48936, 16166, 15909, 16047, 48000,
|
||||
16182, 48910, 16170, 48992, 16228, 48879, 48645, 48725, 16023, 16103, 48895, 48898, 48749, 48891, 16142, 15973,
|
||||
16148, 48401, 16087, 15909, 16043, 48791, 48779, 48815, 48465, 15849, 15901, 16047, 49010, 15949, 16051, 15989,
|
||||
16075, 48353, 15941, 15785, 48693, 48795, 16023, 48585, 48783, 16158, 48771, 15917, 48000, 48879, 48771, 15769,
|
||||
48831, 48815, 16031, 15521, 48669, 48942, 15925, 16146, 48741, 16051, 16252, 16206, 48765, 48954, 49018, 15801,
|
||||
48827, 16242, 48970, 16039, 48986, 48779, 15753, 49010, 48617, 15917, 16079, 16047, 48847, 16184, 15233, 48839,
|
||||
16027, 48914, 48851, 48895, 16170, 16170, 48685, 16027, 16148, 49000, 48934, 15817, 48677, 48879, 16011, 48433,
|
||||
48879, 16027, 48749, 48851, 48895, 48661, 48912, 48994, 15941, 16091, 48617, 48920, 16119, 16091, 48733, 16127,
|
||||
48521, 48497, 16043, 16142, 15585, 15801, 15909, 16208, 48827, 48617, 48851, 15877, 15753, 48653, 16134, 16007,
|
||||
16184, 16180, 48771, 15901, 49012, 48601, 16194, 16087, 16043, 48811, 48779, 48791, 48749, 48902, 16224, 15997,
|
||||
48401, 48401, 16047, 15949, 48653, 16232, 48799, 48757, 15965, 15697, 48537, 49004, 48787, 48843, 16152, 48795,
|
||||
16142, 48815, 48717, 16226, 48990, 48553, 16190, 16156, 16256, 48633, 48883, 48980, 16148, 48717, 48803, 15997,
|
||||
16071, 48733, 48000, 48986, 48827, 48851, 16130, 16035, 48936, 16210, 48926, 15909, 48867, 48653, 15849, 16063,
|
||||
16087, 16160, 16144, 49016, 16055, 15877, 48783, 16115, 48855, 16180, 16204, 48465, 48765, 15877, 48859, 16011,
|
||||
48717, 48839, 48918, 15877, 16095, 48902, 16103, 48839, 15769, 48819, 16119, 48891, 16091, 48964, 48990, 48950,
|
||||
48807, 48966, 16154, 48908, 48783, 48823, 15885, 16228, 16031, 15817, 16115, 16132, 16240, 48741, 48725, 48811,
|
||||
48289, 48521, 15817, 15965, 16075, 16011, 48966, 49004, 48928, 48289, 48922, 48839, 49002, 48928, 48693, 16015,
|
||||
16216, 48952, 16007, 48940, 16115, 48968, 16190, 16003, 16123, 48661, 15665, 15909, 48725, 48661, 16194, 48725,
|
||||
16168, 48994, 16160, 16170, 16180, 15877, 48944, 48701, 48000, 16059, 48863, 16115, 48779, 48867, 49012, 48771,
|
||||
48795, 49018, 16184, 48887, 16210, 16242, 48972, 16142, 48891, 48992, 48962, 15917, 15585, 48912, 16194, 15729,
|
||||
16051, 15941, 48960, 16095, 48982, 48823, 48831, 15769, 16091, 16202, 48765, 15965, 16075, 15941, 16051, 48741,
|
||||
16162, 48843, 15925, 48908, 48497, 48904, 16136, 16115, 16119, 16196, 15817, 16083, 48879, 48633, 15981, 15885,
|
||||
48827, 48733, 48537, 48932, 16170, 48831, 16174, 48811, 48685, 15933, 16154, 15877, 48741, 15865, 16103, 16091,
|
||||
48585, 48843, 15521, 16099, 15965, 16063, 48553, 48701, 15933, 16083, 48749, 48922, 15233, 15233, 48994, 48914,
|
||||
16176, 15865, 48645, 48928, 48811, 48918, 48900, 15729, 15785, 48000, 48974, 48653, 48831, 48757, 15941, 16216,
|
||||
15893, 48839, 48912, 16099, 15909, 48795, 16240, 48902, 48783, 16115, 48863, 15833, 16242, 16182, 48795, 15785,
|
||||
48353, 48749, 48863, 16244, 15917, 48898, 15877, 16091, 48839, 15585, 48000, 48934, 16208, 16063, 16176, 16256,
|
||||
16087, 15981, 16150, 16091, 48537, 48521, 15817, 48803, 16011, 48669, 16031, 48954, 16134, 15801, 48946, 16087,
|
||||
16180, 16256, 15877, 16087, 48775, 16208, 16039, 15633, 15817, 48803, 48433, 48783, 48895, 16136, 16071, 16210,
|
||||
48807, 48601, 48912, 48569, 48934, 16154, 16015, 48964, 48757, 16220, 48677, 16031, 48569, 15965, 16039, 48497,
|
||||
15425, 48771, 15981, 48783, 48771, 48553, 48883, 16142, 16230, 48831, 16242, 48353, 15633, 48521, 48433, 48902,
|
||||
15965, 16162, 16119, 16119, 15521, 16222, 15233, 16134, 16132, 16071, 16202, 48725, 48986, 48353, 16200, 48569,
|
||||
48895, 15893, 48537, 48942, 16130, 15865, 15933, 48353, 48871, 16051, 16176, 16007, 15785, 48863, 15925, 48940,
|
||||
15697, 48908, 48875, 15949, 16071, 16123, 16132, 16150, 15909, 16166, 15833, 48779, 16164, 16031, 16132, 48920,
|
||||
48875, 48803, 16208, 15989, 16035, 48433, 48771, 15729, 16019, 48823, 48617, 48912, 15965, 16254, 48984, 48980,
|
||||
48920, 49024, 48585, 15917, 16123, 48779, 48653, 48749, 16015, 48289, 48791, 48839, 15949, 48827, 16156, 15925,
|
||||
48000, 48930, 16079, 16142, 48926, 16027, 48653, 16196, 15989, 16063, 48633, 16256, 48871, 16220, 48875, 48749,
|
||||
48863, 48709, 49010, 16047, 16003, 48994, 16079, 48823, 48924, 16254, 48906, 48783, 15925, 48891, 16160, 16136,
|
||||
15917, 48433, 48883, 48914, 48000, 15521, 48791, 16059, 48709, 15425, 16178, 16047, 48701, 15973, 16003, 15925,
|
||||
16172, 16188, 16136, 16023, 16248, 48353, 48902, 48946, 16190, 16023, 48968, 15885, 16216, 48839, 48353, 15877,
|
||||
48645, 49014, 16039, 15769, 16079, 48779, 15753, 16099, 15941, 16003, 16083, 16140, 16071, 48771, 16250, 48831,
|
||||
16023, 48353, 48867, 15925, 48795, 49002, 15957, 48757, 16176, 48765, 16011, 16150, 16051, 16178, 48633, 16180,
|
||||
16111, 48000, 16055, 16156, 48855, 48944, 48811, 48765, 48803, 48617, 15785, 48803, 48193, 15981, 48952, 48465,
|
||||
15753, 48709, 15865, 48685, 48948, 15729, 16079, 16208, 16140, 15833, 16011, 48958, 16127, 48433, 48900, 16142,
|
||||
15665, 16043, 15521, 16127, 15933, 48765, 16119, 16039, 48914, 48497, 15973, 16256, 16095, 48954, 15785, 48867,
|
||||
16148, 16003, 48569, 15981, 48948, 48685, 48601, 48891, 16184, 48725, 16252, 48633, 48791, 48709, 48867, 48791,
|
||||
48787, 15901, 15633, 16059, 16154, 16063, 16039, 48433, 48771, 15521, 16095, 48940, 16176, 48521, 16166, 16208,
|
||||
48815, 48000, 49016, 48685, 48537, 48827, 16186, 16132, 48996, 48954, 48779, 48741, 16079, 48839, 48906, 16075,
|
||||
16067, 16007, 48922, 48749, 48978, 15965, 48799, 16176, 15941, 48725, 15425, 48617, 16196, 16091, 16095, 15973,
|
||||
48795, 48859, 48912, 16138, 16178, 15425, 48859, 48863, 16194, 48908, 48863, 48984, 48954, 48601, 48839, 15949,
|
||||
48693, 15949, 15729, 48908, 48952, 16248, 48725, 16156, 16188, 48521, 16047, 16059, 16047, 16180, 48733, 15585,
|
||||
16160, 16035, 48779, 16172, 15965, 48401, 48960, 48401, 49024, 48791, 16011, 16250, 48677, 48289, 16208, 49024,
|
||||
48835, 15697, 48433, 16172, 16083, 16136, 48891, 16178, 48910, 15233, 48855, 48835, 15585, 16256, 16208, 48944,
|
||||
48725, 48497, 48952, 49000, 48193, 16174, 16256, 16142, 48938, 48465, 16099, 15877, 16160, 15801, 48863, 16003,
|
||||
48851, 48847, 48827, 48497, 16027, 48887, 48749, 15949, 48569, 16111, 16150, 15849, 16144, 16166, 49024, 48863,
|
||||
48968, 16007, 16127, 15909, 16178, 48653, 16220, 16035, 48757, 15997, 48537, 48978, 16015, 16079, 48775, 48819,
|
||||
16140, 48827, 15901, 16047, 48936, 48765, 16127, 16071, 16115, 49024, 16035, 16043, 48617, 15989, 48863, 16196,
|
||||
16206, 48871, 48831, 16148, 48601, 16047, 48795, 16095, 16180, 48765, 16023, 16172, 15697, 48912, 49024, 48920,
|
||||
48553, 16236, 16059, 48859, 16248, 15801, 48585, 48601, 16043, 48871, 16256, 16015, 48807, 16250, 48807, 48958,
|
||||
16111, 48465, 48958, 48898, 48585, 15893, 15633, 48765, 16063, 48895, 48717, 16023, 48289, 48733, 48617, 15941,
|
||||
15425, 48569, 16160, 15965, 15849, 16140, 48811, 48819, 16142, 48401, 48980, 48835, 15925, 48709, 16156, 15521,
|
||||
48926, 48908, 48916, 48952, 48982, 15425, 16039, 16192, 48685, 16176, 16144, 48920, 48771, 15909, 48787, 16039,
|
||||
15957, 48633, 48859, 48958, 48916, 15973, 15729, 48771, 48998, 48996, 15925, 16003, 48497, 16051, 16140, 15893,
|
||||
48895, 48497, 49024, 16031, 15933, 48847, 16186, 48717, 16003, 15817, 15901, 16083, 49024, 15877, 16182, 48353,
|
||||
48831, 49024, 16059, 15989, 15941, 16202, 15989, 48938, 16019, 15925, 16095, 49020, 48749, 48787, 16019, 15885,
|
||||
16220, 48895, 48401, 48193, 48827, 15925, 48795, 48779, 48757, 16156, 49014, 16228, 15585, 16198, 48934, 16170,
|
||||
48537, 48521, 48569, 48900, 48922, 48924, 48585, 48879, 15957, 16234, 48569, 48898, 48871, 15909, 48353, 48645,
|
||||
15997, 48677, 16063, 48823, 15949, 48779, 48807, 16152, 48783, 16148, 15925, 48585, 48765, 16198, 16123, 48803,
|
||||
48677, 48847, 48974, 16186, 15917, 48918, 16202, 48791, 48954, 15909, 48994, 15697, 16234, 48988, 48741, 16256,
|
||||
15521, 16107, 16130, 48859, 16031, 16011, 15521, 15989, 48677, 48617, 48926, 16212, 48585, 16142, 48779, 15933,
|
||||
16214, 48653, 15633, 48807, 48910, 16043, 16142, 15817, 48193, 15425, 16099, 15941, 48867, 16256, 48948, 48815,
|
||||
48948, 15817, 48725, 16256, 16015, 16051, 16130, 48942, 48823, 49024, 16047, 16027, 48653, 16132, 15769, 48771,
|
||||
16035, 16083, 16222, 48775, 16043, 15585, 48741, 16103, 16164, 16136, 48944, 16218, 16204, 49014, 48787, 16043,
|
||||
16252, 48954, 48871, 16095, 16115, 16047, 16019, 16238, 16256, 48908, 15769, 15785, 16130, 15849, 48757, 48775,
|
||||
16019, 16152, 48916, 48851, 16188, 16119, 16148, 48661, 48465, 16204, 16186, 48867, 15801, 15941, 16214, 48904,
|
||||
16154, 48912, 48569, 48803, 16119, 48956, 16228, 16119, 48795, 48701, 48855, 48839, 16196, 16222, 16256, 48465,
|
||||
48904, 16055, 48779, 16142, 16196, 48922, 16031, 16212, 16206, 16039, 16174, 16071, 48749, 16226, 16172, 48733,
|
||||
48835, 49014, 16208, 16174, 48553, 48847, 48970, 16152, 48653, 16178, 16140, 48521, 16210, 16047, 48916, 48940,
|
||||
48685, 48988, 16254, 48883, 48904, 15901, 16123, 16252, 48725, 48867, 48898, 16148, 48867, 48992, 16172, 48537,
|
||||
48956, 16162, 48617, 48633, 48851, 48898, 48835, 48992, 16027, 16127, 16200, 16007, 16242, 16059, 48918, 15885,
|
||||
48839, 16218, 15877, 15893, 48936, 48497, 16039, 48902, 48978, 16188, 48289, 15965, 48799, 16087, 16119, 15981,
|
||||
15785, 48709, 48497, 48930, 48661, 16091, 16031, 48964, 15885, 48787, 48633, 16079, 48970, 48585, 48193, 48741,
|
||||
15633, 48795, 48859, 48904, 16119, 48765, 48741, 48924, 16063, 15925, 48932, 48353, 16039, 48982, 16099, 48717,
|
||||
16003, 16156, 16200, 48749, 48891, 16160, 16182, 48910, 48521, 48819, 15785, 48902, 48952, 48645, 16051, 48855,
|
||||
48601, 16111, 16194, 16111, 48904, 48942, 16007, 48851, 48932, 48942, 16210, 48958, 16091, 48867, 48940, 48823,
|
||||
48000, 48811, 48871, 49024, 48289, 48815, 15989, 15801, 15833, 48775, 16071, 15785, 48193, 16198, 48693, 16051,
|
||||
48827, 48855, 48661, 48585, 16075, 48898, 48401, 16144, 15893, 16003, 48553, 16168, 15425, 48912, 48867, 48601,
|
||||
48898, 48725, 49016, 48936, 48823, 48902, 16007, 16019, 48775, 48908, 16099, 48653, 49024, 15233, 48733, 15957,
|
||||
15665, 48928, 48811, 16119, 48601, 48948, 48553, 48936, 48661, 48757, 48537, 15981, 48978, 48908, 16162, 48948,
|
||||
16244, 15965, 48601, 16242, 15801, 15753, 48585, 48898, 48815, 48978, 15925, 15893, 15885, 16200, 48902, 48775,
|
||||
48831, 16134, 16186, 48978, 48677, 15957, 48685, 16206, 48920, 48807, 48906, 48908, 48952, 15769, 15521, 15585,
|
||||
16170, 49002, 48940, 16075, 16234, 48819, 16115, 16055, 48948, 48803, 48831, 48653, 48986, 48898, 16230, 49024,
|
||||
48795, 48783, 15769, 48936, 48922, 16160, 48976, 15665, 16170, 48653, 48950, 48867, 49010, 16142, 16103, 48859,
|
||||
16166, 16192, 48795, 15925, 49016, 15917, 48940, 16003, 48912, 15817, 48823, 48902, 15425, 48585, 48807, 16144,
|
||||
48843, 48771, 48831, 15633, 16079, 15833, 48765, 48193, 48863, 16075, 16107, 48693, 15957, 16015, 48811, 16115,
|
||||
48653, 48916, 16214, 16107, 16150, 48677, 48928, 15817, 48952, 48843, 48685, 48601, 16039, 48968, 16047, 48891,
|
||||
15925, 48918, 48765, 48891, 16103, 15885, 16134, 48289, 16142, 48795, 48815, 16182, 48717, 15801, 48653, 15901,
|
||||
16158, 48725, 48932, 48986, 16099, 16202, 16051, 48757, 48839, 48553, 48871, 16226, 15633, 16047, 16027, 48823,
|
||||
15893, 48701, 48855, 48932, 16127, 15425, 16003, 48895, 15925, 48924, 48930, 48906, 16164, 15801, 48353, 48980,
|
||||
48733, 16206, 16136, 16132, 48954, 48521, 16087, 16011, 16007, 16156, 48934, 48819, 16154, 48749, 15769, 48799,
|
||||
48843, 16107, 48693, 16178, 16119, 48855, 16031, 48940, 16067, 48289, 48779, 16182, 16228, 16055, 16027, 15785,
|
||||
48401, 48823, 48433, 48827, 15941, 15585, 16164, 16119, 15965, 48193, 16224, 16178, 15729, 15973, 48617, 15633,
|
||||
48585, 48553, 48353, 15941, 48815, 48835, 15729, 16011, 16103, 48871, 48353, 15893, 15965, 48891, 16099, 16164,
|
||||
48741, 15697, 48902, 16059, 15849, 48669, 16007, 48940, 15729, 16059, 16192, 15989, 16027, 16107, 48855, 48433,
|
||||
48863, 15865, 49006, 48669, 16043, 48585, 48962, 15997, 16079, 48900, 48875, 16099, 48617, 16154, 15697, 48693,
|
||||
15769, 48946, 16146, 48569, 15233, 49004, 16087, 48871, 48940, 15785, 16212, 15729, 48733, 48497, 15633, 16023,
|
||||
48895, 16148, 48827, 48823, 15521, 48353, 16220, 15697, 16059, 48920, 48920, 16170, 16111, 48914, 15941, 16246,
|
||||
16146, 15925, 48976, 15425, 48887, 48922, 16095, 16011, 48902, 16146, 48289, 48633, 16063, 15973, 16079, 16039,
|
||||
16115, 48289, 48910, 16130, 16079, 16091, 15425, 16063, 15521, 48839, 48807, 48851, 15893, 48958, 16150, 16178,
|
||||
15769, 48765, 48910, 16192, 15801, 48906, 15901, 48433, 15957, 48815, 16146, 16138, 48962, 16127, 15833, 16063,
|
||||
48976, 16111, 48940, 16136, 15753, 16123, 48930, 16071, 48928, 16156, 48617, 16127, 16035, 48569, 15729, 49012,
|
||||
48669, 16115, 48900, 16007, 48942, 48916, 15665, 15957, 16196, 48585, 48795, 48795, 48910, 48928, 48843, 48908,
|
||||
16071, 48900, 48693, 16162, 16087, 48693, 15925, 48950, 48952, 16216, 16152, 48855, 15585, 48537, 16162, 15933,
|
||||
48926, 15933, 16248, 15949, 48783, 48950, 15877, 48553, 48938, 15909, 48521, 48954, 15729, 48775, 16019,
|
||||
};
|
||||
static const int32_t kGoldGemma4ClipFrames[] = { 4, 5, 6 };
|
||||
static const int32_t kGoldGemma4ClipH = 336, kGoldGemma4ClipW = 432, kGoldGemma4ClipGridH = 21, kGoldGemma4ClipGridW = 27, kGoldGemma4ClipSoft = 63;
|
||||
static const uint64_t kGoldGemma4ClipFnv = 0x7184c13d69271d48ull;
|
||||
static const int64_t kGoldGemma4SampleIdx[] = { 0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 0, 30, 60, 0, 299, 629, 959, 1258, 1588, 1918, 2217, 2547, 2877, 3206, 3506, 3836, 4165, 4465, 4795, 5124, 5454, 5754, 6083, 6413, 6713, 7042, 7372, 7702, 8001, 8331, 8661, 8961, 9290, 9620, 9950, 0, 0, 0, 216, 456, 672, 912, 1152, 1368, 1608, 1848, 2064, 2304, 2544, 2760, 3000, 3240, 3456, 3696, 3912, 4152, 4392, 4608, 4848, 5088, 5304, 5544, 5784, 6000, 6240, 6480, 6696, 6936, 7176, 0, 60, 120, 180, 0, 100, 200, 325, 425, 525, 650, 750, 850, 975, 0, 90, 210, 330, 420, 540, 660, 0, 119, 239, 383, 503, 647, 767, 911, 1030, 1174, 1294, 1438, 1558, 1702, 1822, 1966, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120 };
|
||||
struct GoldGemma4Sample { int64_t total; double fps; int32_t max_frames, first, n; };
|
||||
static const GoldGemma4Sample kGoldGemma4Sample[] = {
|
||||
{ 300, 30.0, 32, 0, 10 },
|
||||
{ 90, 30.0, 32, 10, 3 },
|
||||
{ 10000, 29.97, 32, 13, 32 },
|
||||
{ 5, 25.0, 32, 45, 1 },
|
||||
{ 1, 30.0, 32, 46, 1 },
|
||||
{ 7200, 24.0, 32, 47, 32 },
|
||||
{ 240, 60.0, 4, 79, 4 },
|
||||
{ 1000, 25.0, 10, 83, 10 },
|
||||
{ 700, 30.0, 7, 93, 7 },
|
||||
{ 2001, 23.976, 16, 100, 16 },
|
||||
{ 130, 10.0, 12, 116, 12 },
|
||||
};
|
||||
+41
-31
@@ -1,20 +1,20 @@
|
||||
/* gen_config_test.cpp -- the sampling a checkpoint states for itself.
|
||||
*
|
||||
* WHAT THIS IS HOLDING DOWN. SamplingParams' defaults are an untruncated sampler, and a model
|
||||
* tuned against a truncated tail served that way draws, now and then, a token from far down its
|
||||
* distribution. End-of-turn is one of those tokens, so the symptom is not prose that reads badly
|
||||
* -- it is a reply that ends early, which from outside the server is indistinguishable from a
|
||||
* dropped request. Nothing about a wrong sampler default announces itself, which is exactly why
|
||||
* the reading of it is a component with a test rather than a helper inside the engine.
|
||||
* SamplingParams' defaults are an untruncated sampler. A model tuned with a truncated tail and
|
||||
* served that way occasionally draws a token from far down its distribution; end-of-turn is one
|
||||
* such token, so the symptom is a reply that ends early and looks like a dropped request. A wrong
|
||||
* default is silent, hence a tested component.
|
||||
*
|
||||
* No model and no container: the three sources are a string, a file and a key lookup, and all
|
||||
* three are reachable directly.
|
||||
* No model and no container: the three sources (a string, a file and a key lookup) are reached
|
||||
* directly.
|
||||
*/
|
||||
#include "rad_test.h"
|
||||
|
||||
#include "gen_config.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
@@ -22,8 +22,8 @@ using namespace rad;
|
||||
|
||||
namespace {
|
||||
|
||||
/* The container's metadata table as gen_sampling_from_kv sees it: bare field names, and every
|
||||
* value a string, which is how rad-convert writes free-form metadata. */
|
||||
/* The container's metadata table as gen_sampling_from_kv sees it: bare field names and string
|
||||
* values, as rad-convert writes free-form metadata. */
|
||||
std::function<const char*(const char*)> kv_of(const std::map<std::string, std::string>& m) {
|
||||
return [&m](const char* k) -> const char* {
|
||||
auto it = m.find(k);
|
||||
@@ -32,7 +32,7 @@ std::function<const char*(const char*)> kv_of(const std::map<std::string, std::s
|
||||
}
|
||||
|
||||
std::string write_temp(const char* name, const std::string& body) {
|
||||
std::string path = std::string("/tmp/radiance_gen_config_test_") + name + ".json";
|
||||
const std::string path = radtest::tmp_path(std::string(name) + ".json");
|
||||
FILE* f = std::fopen(path.c_str(), "w");
|
||||
if (!f) return std::string();
|
||||
std::fwrite(body.data(), 1, body.size(), f);
|
||||
@@ -40,7 +40,7 @@ std::string write_temp(const char* name, const std::string& body) {
|
||||
return path;
|
||||
}
|
||||
|
||||
/* Qwen3.8-Flash-Next's, verbatim -- the shape this was built for. */
|
||||
/* Qwen3.8-Flash-Next's generation_config.json, verbatim. */
|
||||
const char* const kQwenGenConfig = R"({
|
||||
"bos_token_id": 248044,
|
||||
"do_sample": true,
|
||||
@@ -59,20 +59,19 @@ TEST(gen_config_reads_a_real_generation_config) {
|
||||
CHECK_NEAR(g.temp, 1.0f, 1e-6);
|
||||
CHECK_EQ(g.top_k, 20);
|
||||
CHECK_NEAR(g.top_p, 0.95f, 1e-6);
|
||||
CHECK_NEAR(g.min_p, -1.0f, 1e-6); /* the file does not say, so nothing is claimed */
|
||||
CHECK_NEAR(g.min_p, -1.0f, 1e-6); /* not in the file, so not claimed */
|
||||
|
||||
/* Overlaid on the built-in defaults it truncates the tail, which is the whole point: the
|
||||
* untruncated sampler is what lets an early end-of-turn be drawn at all. */
|
||||
/* Overlaid on the built-in defaults, it truncates the tail. */
|
||||
const SamplingParams sp = g.onto(SamplingParams{});
|
||||
CHECK_NEAR(sp.temp, 1.0f, 1e-6);
|
||||
CHECK_EQ(sp.top_k, 20);
|
||||
CHECK_NEAR(sp.top_p, 0.95f, 1e-6);
|
||||
CHECK_NEAR(sp.min_p, 0.0f, 1e-6); /* untouched, so still the struct's own */
|
||||
CHECK_NEAR(sp.min_p, 0.0f, 1e-6); /* untouched: the struct's default */
|
||||
CHECK(!sp.greedy());
|
||||
}
|
||||
|
||||
/* A FIELD A SOURCE DID NOT STATE MUST NOT BE CLAIMED, or the sources cannot stack: a sidecar that
|
||||
* sets only top_k would otherwise wipe the temperature underneath it. */
|
||||
/* A field a source did not state is not claimed, so sources stack: a sidecar that sets only
|
||||
* top_k keeps the temperature underneath it. */
|
||||
TEST(gen_config_claims_only_what_a_source_states) {
|
||||
GenSampling g;
|
||||
CHECK(gen_sampling_parse(R"({"top_k": 40})", "test", &g));
|
||||
@@ -99,10 +98,10 @@ TEST(gen_config_reads_do_sample_false_as_greedy) {
|
||||
CHECK(gen_sampling_parse(R"({"do_sample": false, "temperature": 0.7, "top_k": 20})",
|
||||
"test", &g));
|
||||
CHECK_NEAR(g.temp, 0.0f, 1e-6);
|
||||
CHECK_EQ(g.top_k, -1); /* not taken: greedy does not have one */
|
||||
CHECK_EQ(g.top_k, -1); /* not claimed under greedy */
|
||||
CHECK(g.onto(SamplingParams{}).greedy());
|
||||
|
||||
/* do_sample true is the ordinary case and says nothing by itself. */
|
||||
/* do_sample true claims nothing by itself. */
|
||||
GenSampling t;
|
||||
CHECK(gen_sampling_parse(R"({"do_sample": true, "temperature": 0.7})", "test", &t));
|
||||
CHECK_NEAR(t.temp, 0.7f, 1e-6);
|
||||
@@ -115,12 +114,25 @@ TEST(gen_config_translates_top_k_minus_one_to_off) {
|
||||
CHECK_EQ(g.top_k, 0);
|
||||
}
|
||||
|
||||
/* A VALUE OUT OF RANGE IS DROPPED, NOT REFUSED, and it drops alone: these arrive with the model,
|
||||
* and one implausible entry is not a reason to serve the rest wrongly or not at all. */
|
||||
/* The startup line names what top_k 0 does: the sampler draws from its 1024 most likely
|
||||
* candidates, which is neither "off" nor the whole vocabulary. */
|
||||
TEST(the_sampling_line_says_what_top_k_zero_samples_from) {
|
||||
SamplingParams sp;
|
||||
sp.top_k = 0;
|
||||
const std::string zero = GenSampling::describe(sp);
|
||||
CHECK(has(zero, "top_k 0 (the 1024 most likely tokens"));
|
||||
CHECK(!has(zero, "(off)"));
|
||||
sp.top_k = 20;
|
||||
const std::string twenty = GenSampling::describe(sp);
|
||||
CHECK(has(twenty, "top_k 20, top_p"));
|
||||
}
|
||||
|
||||
/* An out-of-range value is dropped on its own, not refused: the config ships with the model,
|
||||
* and one implausible entry should not discard the rest. */
|
||||
TEST(gen_config_drops_an_out_of_range_field_and_keeps_the_rest) {
|
||||
GenSampling g;
|
||||
CHECK(gen_sampling_parse(R"({"temperature": 9.0, "top_p": 0.95, "top_k": 20})", "test", &g));
|
||||
CHECK(g.temp < 0.0f); /* 9.0 is not a temperature; nothing was claimed */
|
||||
CHECK(g.temp < 0.0f); /* 9.0 is out of range, so not claimed */
|
||||
CHECK_NEAR(g.top_p, 0.95f, 1e-6);
|
||||
CHECK_EQ(g.top_k, 20);
|
||||
|
||||
@@ -140,9 +152,8 @@ TEST(gen_config_survives_text_that_is_not_a_config) {
|
||||
CHECK(!g.any());
|
||||
}
|
||||
|
||||
/* The container's copy and the original file must resolve to the same sampler: rad-convert
|
||||
* flattens every value to a string, and two readings of one schema is how the two come to
|
||||
* disagree about a checkpoint. */
|
||||
/* The container's copy, where rad-convert flattened every value to a string, and the original
|
||||
* file resolve to the same sampler. */
|
||||
TEST(gen_config_reads_the_container_table_as_the_file) {
|
||||
GenSampling from_file;
|
||||
CHECK(gen_sampling_parse(kQwenGenConfig, "test", &from_file));
|
||||
@@ -177,17 +188,16 @@ TEST(gen_config_reads_a_file_and_treats_absence_as_silence) {
|
||||
GenSampling g;
|
||||
CHECK(gen_sampling_from_file(path, /*required=*/false, &g));
|
||||
CHECK_EQ(g.top_k, 20);
|
||||
std::remove(path.c_str());
|
||||
|
||||
/* A checkpoint that ships no generation config is served from whatever lies underneath, not
|
||||
* refused -- so a missing file takes nothing and reports nothing taken. */
|
||||
/* A checkpoint without a generation config is served from the layers underneath, not
|
||||
* refused: a missing file claims nothing and returns false. */
|
||||
GenSampling missing;
|
||||
CHECK(!gen_sampling_from_file("/nonexistent/generation_config.json", false, &missing));
|
||||
CHECK(!missing.any());
|
||||
}
|
||||
|
||||
/* The sidecar is the container's path with its extension replaced, and the extension is the LAST
|
||||
* dot in the basename -- a directory with a dot in its name must not eat it. */
|
||||
/* The sidecar is the container's path with its extension replaced. The extension starts at the
|
||||
* last dot in the basename, so a dot in a directory name is not one. */
|
||||
TEST(gen_config_derives_the_sidecar_path) {
|
||||
CHECK_EQ(gen_sidecar_path("/m/q38-flashnext-unc-w4-mtp.rad"),
|
||||
std::string("/m/q38-flashnext-unc-w4-mtp.generation.json"));
|
||||
|
||||
@@ -0,0 +1,330 @@
|
||||
/* gen_test.cpp -- the image generator's request side (core/gen/gen.h) and its pass driver's
|
||||
* admission (core/gen/driver.h), against sched_fakes.h's KV manager and device layer.
|
||||
*/
|
||||
#include "sched_fakes.h"
|
||||
|
||||
using namespace sched_fake;
|
||||
|
||||
#include "gen/driver.h"
|
||||
#include "gen/gen.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace rad;
|
||||
|
||||
namespace {
|
||||
|
||||
RadGeneratorDecl decl_base() {
|
||||
RadGeneratorDecl d{};
|
||||
d.name = "test";
|
||||
d.layout = RAD_GEN_LAYOUT_JOINT_GRID;
|
||||
d.latent_scale = 16;
|
||||
d.size_multiple = 32;
|
||||
d.pixel_channels = 4;
|
||||
d.slot_rows = 4;
|
||||
d.max_tokens = 1024;
|
||||
d.max_refs = 2;
|
||||
d.ref_area = 256 * 256;
|
||||
d.default_steps = 4;
|
||||
d.shift = 1.0;
|
||||
d.max_lanes = 4;
|
||||
return d;
|
||||
}
|
||||
|
||||
/* The schedule diffusers' FlowMatchEulerDiscreteScheduler.set_timesteps gives, in double:
|
||||
* linspace(1, 1/n, n), shifted (exp(mu) / (exp(mu) + 1/t - 1) dynamically, s*t / (1 + (s-1)*t)
|
||||
* statically), stretched so the last sigma is the terminal, then a closing 0. */
|
||||
std::vector<double> diffusers_sigmas(const RadGeneratorDecl& d, int n, int64_t tokens) {
|
||||
std::vector<double> s;
|
||||
for (int i = 0; i < n; ++i) s.push_back(n == 1 ? 1.0 : 1.0 + (1.0 / n - 1.0) * i / (n - 1));
|
||||
if (d.dyn_shift) {
|
||||
const double m = (d.max_shift - d.base_shift) / (double)(d.max_seq - d.base_seq);
|
||||
const double mu = (double)tokens * m + d.base_shift - m * (double)d.base_seq;
|
||||
const double e = d.shift_exp ? std::exp(mu) : mu;
|
||||
for (double& t : s) t = e / (e + (1.0 / t - 1.0));
|
||||
} else {
|
||||
for (double& t : s) t = d.shift * t / (1.0 + (d.shift - 1.0) * t);
|
||||
}
|
||||
if (d.shift_terminal > 0) {
|
||||
const double scale = (1.0 - s.back()) / (1.0 - d.shift_terminal);
|
||||
for (double& t : s) t = 1.0 - (1.0 - t) / scale;
|
||||
}
|
||||
s.push_back(0.0);
|
||||
return s;
|
||||
}
|
||||
|
||||
bool close_to(const std::vector<float>& got, const std::vector<double>& want, double tol) {
|
||||
if (got.size() != want.size()) return false;
|
||||
for (size_t i = 0; i < got.size(); ++i)
|
||||
if (std::fabs((double)got[i] - want[i]) > tol) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
/* ================================================================== the schedule */
|
||||
/* The sigmas follow diffusers' FlowMatchEuler for both shifts, the exponential and linear
|
||||
* dynamic forms and the terminal stretch, and end in 0. A wrong sigma degrades every image with
|
||||
* no error anywhere. */
|
||||
TEST(the_schedule_is_diffusers_flow_match_euler) {
|
||||
RadGeneratorDecl d = decl_base();
|
||||
d.dyn_shift = 1; d.shift_exp = 1;
|
||||
d.base_shift = 0.5; d.max_shift = 0.9; d.base_seq = 256; d.max_seq = 8192;
|
||||
d.shift_terminal = 0.02;
|
||||
for (int n : { 1, 4, 30 })
|
||||
for (int64_t tokens : { (int64_t)256, (int64_t)1024, (int64_t)4096 }) {
|
||||
const std::vector<float> s = gen::schedule(d, {}, n, tokens);
|
||||
CHECK(close_to(s, diffusers_sigmas(d, n, tokens), 2e-6));
|
||||
CHECK_EQ(s.back(), 0.0f);
|
||||
if (n > 1) CHECK_NEAR(s[(size_t)n - 1], 0.02, 2e-6); /* the terminal */
|
||||
}
|
||||
d.shift_exp = 0;
|
||||
CHECK(close_to(gen::schedule(d, {}, 6, 2048), diffusers_sigmas(d, 6, 2048), 2e-6));
|
||||
d.dyn_shift = 0; d.shift_terminal = 0; d.shift = 3.0;
|
||||
CHECK(close_to(gen::schedule(d, {}, 5, 999), diffusers_sigmas(d, 5, 999), 2e-6));
|
||||
/* 0 steps is the model's default. */
|
||||
CHECK_EQ(gen::schedule(d, {}, 0, 64).size(), (size_t)d.default_steps + 1);
|
||||
}
|
||||
|
||||
/* A fixed schedule is taken as declared (with shift 1), then closed with 0. */
|
||||
TEST(a_fixed_schedule_is_used_as_declared) {
|
||||
RadGeneratorDecl d = decl_base();
|
||||
const std::vector<float> s = gen::schedule(d, { 0.9, 0.5, 0.125 }, 10, 64);
|
||||
REQUIRE_EQ(s.size(), (size_t)4);
|
||||
CHECK_EQ(s[0], 0.9f); CHECK_EQ(s[1], 0.5f); CHECK_EQ(s[2], 0.125f); CHECK_EQ(s[3], 0.0f);
|
||||
}
|
||||
|
||||
/* ================================================================== the sequence */
|
||||
/* An h x w image at frame `pos`: every row at that frame, height and width centred on zero. */
|
||||
TEST(image_rotary_positions_centre_the_grid_on_its_frame) {
|
||||
int32_t p[3 * 12];
|
||||
gen::image_rope(7, 3, 4, p, 12);
|
||||
for (int r = 0; r < 3; ++r)
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
const int k = r * 4 + c;
|
||||
CHECK_EQ(p[k], 7);
|
||||
CHECK_EQ(p[12 + k], r - 2);
|
||||
CHECK_EQ(p[24 + k], c - 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* The generator's sequence: the prompt past its fixed prefix, text rows at consecutive rotary
|
||||
* positions, each picture's slots replaced by its latent rows on a grid at one frame, and a
|
||||
* segment per run (bidirectional for a picture). Refused, by name, when a picture sits in the
|
||||
* prefix or its slots do not tile its latent grid. */
|
||||
TEST(the_generators_sequence_lays_out_text_and_pictures) {
|
||||
gen::Branch b;
|
||||
b.tokens = { 90, 91, 92, 3, 4, 500, 500, 7, 8 };
|
||||
b.n_drop = 3;
|
||||
b.media = std::make_shared<mm::PromptMedia>();
|
||||
mm::RopeLayout::Run run;
|
||||
run.tok = 5; run.n = 2; run.item = 0;
|
||||
b.media->rope.runs.push_back(run);
|
||||
gen::Layout L;
|
||||
std::string why;
|
||||
REQUIRE_EQ(gen::build_layout(b, /*slot_rows=*/2, { { 2, 2 } }, &L, &why), (int)RAD_OK);
|
||||
REQUIRE_EQ(L.rows, (int64_t)8);
|
||||
const std::vector<int32_t> src = { 3, 4, -1, -2, -3, -4, 7, 8 };
|
||||
CHECK(L.src == src);
|
||||
const int32_t t[8] = { 0, 1, 2, 2, 2, 2, 4, 5 };
|
||||
const int32_t h[8] = { 0, 1, -1, -1, 0, 0, 4, 5 };
|
||||
const int32_t w[8] = { 0, 1, -1, 0, -1, 0, 4, 5 };
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
CHECK_EQ(L.rope[(size_t)i], t[i]);
|
||||
CHECK_EQ(L.rope[(size_t)(8 + i)], h[i]);
|
||||
CHECK_EQ(L.rope[(size_t)(16 + i)], w[i]);
|
||||
}
|
||||
CHECK(L.seg == std::vector<int32_t>({ 0, 2, 6, 8 }));
|
||||
CHECK(L.bidi == std::vector<int32_t>({ 0, 1, 0 }));
|
||||
CHECK_EQ(L.next_pos, 6);
|
||||
|
||||
CHECK_EQ(gen::build_layout(b, 2, { { 3, 2 } }, &L, &why), (int)RAD_E_INVAL);
|
||||
CHECK(has(why, "do not tile"));
|
||||
CHECK_EQ(gen::build_layout(b, 2, {}, &L, &why), (int)RAD_E_INVAL);
|
||||
CHECK(has(why, "were encoded for it"));
|
||||
b.media->rope.runs[0].tok = 2;
|
||||
CHECK_EQ(gen::build_layout(b, 2, { { 2, 2 } }, &L, &why), (int)RAD_E_INVAL);
|
||||
CHECK(has(why, "inside the prompt's fixed prefix"));
|
||||
b.media.reset();
|
||||
b.n_drop = 9;
|
||||
CHECK_EQ(gen::build_layout(b, 2, {}, &L, &why), (int)RAD_E_INVAL);
|
||||
CHECK(has(why, "no longer than its fixed prefix"));
|
||||
}
|
||||
|
||||
/* ================================================================== the ticket */
|
||||
/* Images pushed before the end are all delivered, the first finish wins, and an empty ticket
|
||||
* that has not ended times out rather than reporting the end. */
|
||||
TEST(a_ticket_delivers_every_image_before_its_end) {
|
||||
gen::Ticket t;
|
||||
gen::Image im;
|
||||
bool timed_out = false;
|
||||
CHECK(!t.next(&im, 0, &timed_out));
|
||||
CHECK(timed_out);
|
||||
gen::Image a; a.index = 0;
|
||||
gen::Image b; b.index = 1;
|
||||
t.push(std::move(a));
|
||||
t.push(std::move(b));
|
||||
t.finish(RAD_OK);
|
||||
t.finish(RAD_E_STATE, "late");
|
||||
CHECK(!t.finished());
|
||||
CHECK(t.next(&im, 0, &timed_out) && im.index == 0);
|
||||
CHECK(t.next(&im, 0, &timed_out) && im.index == 1);
|
||||
CHECK(!t.next(&im, 0, &timed_out));
|
||||
CHECK(!timed_out);
|
||||
CHECK(t.finished());
|
||||
CHECK_EQ(t.status(), (int)RAD_OK);
|
||||
}
|
||||
|
||||
/* ================================================================== the driver */
|
||||
namespace {
|
||||
struct GenFixture {
|
||||
Program prog;
|
||||
FakeKV kv;
|
||||
gen::Driver drv;
|
||||
void build(int64_t max_tok = 2048, int64_t kv_blocks = 4096) {
|
||||
prog.generator = decl_base();
|
||||
prog.ctx.max_tok = max_tok;
|
||||
prog.ctx.max_seqs = 8;
|
||||
prog.kv_groups.emplace_back();
|
||||
KVGroupInfo g;
|
||||
g.name = "cond";
|
||||
g.decl.kind = RAD_KV_FULL;
|
||||
g.block_size = 16;
|
||||
prog.kv_groups.push_back(g);
|
||||
kv.setup(prog.kv_groups, 1 << 20, kv_blocks, 4);
|
||||
}
|
||||
int start() { return drv.init(prog, &kv, { gen::Driver::RankIO{} }); }
|
||||
std::unique_ptr<gen::Request> req(int w, int h, int n = 1) {
|
||||
auto r = std::make_unique<gen::Request>();
|
||||
r->width = w;
|
||||
r->height = h;
|
||||
r->n = n;
|
||||
r->pos.tokens = { 1, 2, 3, 4 };
|
||||
r->ticket = std::make_shared<gen::Ticket>();
|
||||
return r;
|
||||
}
|
||||
};
|
||||
} /* namespace */
|
||||
|
||||
/* A request that can never run is refused at submission, naming the field: the size multiple,
|
||||
* the largest image, the rows a step with guidance would need, n, the picture count, the prompt's
|
||||
* length, the partial image count and an inpainting mask of the wrong size. */
|
||||
TEST(the_generator_refuses_a_request_that_can_never_run_by_field) {
|
||||
GenFixture f;
|
||||
f.build(/*max_tok=*/1500);
|
||||
CHECK_OK(f.start());
|
||||
std::string why;
|
||||
auto refused = [&](std::unique_ptr<gen::Request> r, const char* says) {
|
||||
why.clear();
|
||||
CHECK_EQ(f.drv.submit(std::move(r), &why), (int)RAD_E_INVAL);
|
||||
const bool named = has(why, says);
|
||||
CHECK(named);
|
||||
if (!named) std::fprintf(stderr, " refusal said: %s\n", why.c_str());
|
||||
};
|
||||
refused(f.req(100, 64), "whole multiples of 32");
|
||||
refused(f.req(1024, 1024), "the largest this model makes is 1024 latent tokens");
|
||||
auto g = f.req(512, 512);
|
||||
g->has_neg = true;
|
||||
g->neg.tokens = { 1 };
|
||||
refused(std::move(g), "with guidance needs 2048 rows");
|
||||
refused(f.req(64, 64, 0), "n must be 1..4");
|
||||
refused(f.req(64, 64, 5), "n must be 1..4");
|
||||
auto refs = f.req(64, 64);
|
||||
refs->refs.resize(3);
|
||||
refused(std::move(refs), "at most 2 pictures");
|
||||
auto longp = f.req(64, 64);
|
||||
longp->pos.tokens.assign(1501, 7);
|
||||
refused(std::move(longp), "the prompt is 1501 tokens");
|
||||
auto prev = f.req(64, 64);
|
||||
prev->previews = 4;
|
||||
refused(std::move(prev), "partial_images must be 0..3");
|
||||
auto inp = f.req(64, 64);
|
||||
inp->inpaint = true;
|
||||
inp->inp_src.w = 64; inp->inp_src.h = 64;
|
||||
inp->inp_mask.assign(3, 1.0f);
|
||||
refused(std::move(inp), "the mask's picture is not at the size being made");
|
||||
CHECK_OK(f.drv.submit(f.req(512, 512), &why));
|
||||
CHECK_EQ(f.drv.queued(), (int64_t)1);
|
||||
}
|
||||
|
||||
/* A request's passes in order: its conditioning, then denoise steps over both images at once, a
|
||||
* preview of each image at the step its partial image falls on (decoded before the next step
|
||||
* overwrites the preview latent), then each final image, which ends the ticket and frees the
|
||||
* lanes for the next request. Image i carries seed + i. */
|
||||
TEST(a_request_runs_its_conditioning_its_steps_its_previews_and_its_images_in_order) {
|
||||
GenFixture f;
|
||||
f.build();
|
||||
CHECK_OK(f.start());
|
||||
std::string why;
|
||||
auto r = f.req(64, 64, 2);
|
||||
r->previews = 1;
|
||||
r->steps = 4;
|
||||
r->seed = 100;
|
||||
auto t = r->ticket;
|
||||
CHECK_OK(f.drv.submit(std::move(r), &why));
|
||||
std::string kinds;
|
||||
std::vector<gen::Image> got;
|
||||
for (int i = 0; i < 20 && !t->finished(); ++i) {
|
||||
const RadBatch* b = f.drv.next(i);
|
||||
REQUIRE(b != nullptr);
|
||||
kinds += b->gen == RAD_GEN_PASS_COND ? 'C' : b->gen == RAD_GEN_PASS_DENOISE ? 'S'
|
||||
: b->gen == RAD_GEN_PASS_DECODE ? 'D' : '?';
|
||||
CHECK_OK(f.drv.done());
|
||||
gen::Image im;
|
||||
bool to = false;
|
||||
while (t->next(&im, 0, &to)) got.push_back(std::move(im));
|
||||
}
|
||||
CHECK_EQ(kinds, std::string("CSSDDSSDD"));
|
||||
REQUIRE_EQ(got.size(), (size_t)4);
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
CHECK(got[(size_t)i].preview);
|
||||
CHECK_EQ(got[(size_t)i].index, i);
|
||||
CHECK(!got[(size_t)(2 + i)].preview);
|
||||
CHECK_EQ(got[(size_t)(2 + i)].index, i);
|
||||
CHECK_EQ(got[(size_t)(2 + i)].seed, (uint64_t)(100 + i));
|
||||
}
|
||||
CHECK_EQ(t->status(), (int)RAD_OK);
|
||||
/* Every lane is free again: a request for all four images is admitted at once. */
|
||||
CHECK_OK(f.drv.submit(f.req(64, 64, 4), &why));
|
||||
const RadBatch* b = f.drv.next(20);
|
||||
CHECK(b != nullptr && b->gen == RAD_GEN_PASS_COND);
|
||||
CHECK_EQ(f.drv.running(), (int64_t)1);
|
||||
CHECK_EQ(f.drv.queued(), (int64_t)0);
|
||||
}
|
||||
|
||||
/* Admission is in order: a request that cannot get lanes for every image blocks the requests
|
||||
* behind it, even one that would fit, so a large request is not starved by small ones. A
|
||||
* shutdown answers every ticket, queued or running, with the status that stopped the engine. */
|
||||
TEST(the_generator_admits_in_order_and_shutdown_answers_every_ticket) {
|
||||
GenFixture f;
|
||||
f.build();
|
||||
CHECK_OK(f.start());
|
||||
std::string why;
|
||||
auto a = f.req(64, 64, 3), b = f.req(64, 64, 2), c = f.req(64, 64, 1);
|
||||
auto ta = a->ticket, tb = b->ticket, tc = c->ticket;
|
||||
CHECK_OK(f.drv.submit(std::move(a), &why));
|
||||
CHECK_OK(f.drv.submit(std::move(b), &why));
|
||||
CHECK_OK(f.drv.submit(std::move(c), &why));
|
||||
const RadBatch* p = f.drv.next(0); /* A's conditioning */
|
||||
CHECK(p != nullptr);
|
||||
CHECK_EQ(f.drv.running(), (int64_t)1); /* A holds 3 of 4 lanes */
|
||||
CHECK_EQ(f.drv.queued(), (int64_t)2); /* B needs 2; C, behind it, waits too */
|
||||
CHECK_EQ(ta->steps, (int32_t)4); /* the default schedule */
|
||||
CHECK_EQ(ta->out_tokens, (int64_t)(4 * 4 * 3)); /* 64x64 at scale 16, three images */
|
||||
|
||||
f.drv.shutdown("the engine stopped", RAD_E_UNSUPPORTED);
|
||||
for (const auto& t : { ta, tb, tc }) {
|
||||
gen::Image im;
|
||||
bool to = false;
|
||||
CHECK(!t->next(&im, 0, &to));
|
||||
CHECK(t->finished());
|
||||
CHECK_EQ(t->status(), (int)RAD_E_UNSUPPORTED);
|
||||
CHECK_EQ(t->why(), std::string("the engine stopped"));
|
||||
}
|
||||
CHECK_EQ(f.drv.submit(f.req(64, 64), &why), (int)RAD_E_UNSUPPORTED);
|
||||
CHECK(f.drv.next(1) == nullptr);
|
||||
}
|
||||
|
||||
RAD_TEST_MAIN()
|
||||
Loaded 100 of 739 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user