Files
Strata/tests/prefill/qsa_two_pass_status_test.cpp
T
bitaccesscomau 386f9959f1 Exact two-pass QSA prompt selection (opt-in STRATA_SELECT_TWO_PASS=1)
Prompt-path block scores in single-pass TF32 with a per-block error bound,
3xTF32 rescoring only near each query's top-k cut-off, so qsa_block_topk
returns the same cells in the same order, ties included. Off unless the
variable is set; says once where it cannot run (HIP, Metal, SYCL, layer-major
path). Adds qsa_two_pass_test, qsa_two_pass_status_test and the GPU parity
test qsa_two_pass_parity.

Ported from PR 4119 (bitaccesscomau); the log line of the per-prompt counters
is shortened without dropping a field.

l620 (sm_120, IQ3_S), greedy ids identical off vs on in every pair:
prompt 128K +1.65% (n=12), 256K +4.10% (n=8), 32K -0.14% (noise).

(cherry picked from commit bbf7c55f1351d913233250fe7869642f7c2b98a1)
2026-11-06 15:47:43 +01:00

81 lines
3.5 KiB
C++

// STRATA_SELECT_TWO_PASS's request and its line where the two-pass scorer cannot run (qsa_two_pass_status.hpp).
// GPU-free: the parse, quiet when unset or supported, one line per process where unsupported.
#include "strata/kernels/qsa_two_pass_status.hpp"
#include <cstdio>
#include <cstdlib>
#include <string>
namespace tp = strata::kernels::two_pass;
static void check(bool ok, const char* why) {
if (!ok) {
std::fprintf(stderr, "FAIL: %s\n", why);
std::exit(1);
}
}
static std::string output(FILE* log) {
check(std::fflush(log) == 0 && std::fseek(log, 0, SEEK_SET) == 0, "rewind the log");
std::string text;
char buf[512];
while (const size_t n = std::fread(buf, 1, sizeof(buf), log)) text.append(buf, n);
check(!std::ferror(log), "read the log");
return text;
}
static std::string line(const char* where) {
return std::string("strata: STRATA_SELECT_TWO_PASS=1 is not used on ") + where +
": the two-pass scorer runs only in the CUDA prompt path's tensor-core selection (sm_80+); the selection is "
"unchanged\n";
}
int main(int argc, char** argv) {
check(argc == 2, "pass a scratch log path (no GPU or model needed)");
FILE* log = std::fopen(argv[1], "w+");
check(log != nullptr, "open the log");
// exactly "1" is on, as the scorer parsed it before; unset or anything else is off and prints nothing anywhere
check(tp::requested_from("1"), "1: on");
const char* off[] = {nullptr, "", "0", "01", "1x", "true", "1 ", "2"};
for (const char* flag : off) {
check(!tp::requested_from(flag), "not exactly 1: off");
tp::RequestStatus status(flag);
check(!status.requested(), "not requested");
check(!status.on("HIP", log), "off stays off where unsupported");
check(!status.on(nullptr, log), "off stays off where supported");
}
check(output(log).empty(), "no line without the switch");
// a supported path returns the request and prints nothing (the engine's per-segment line reports what ran)
tp::RequestStatus cuda("1");
check(cuda.on(nullptr, log) && cuda.on(nullptr, log), "supported: on");
check(output(log).empty(), "supported: no line");
// each unsupported path the engine names: off, one line, never repeated
const char* where[] = {"HIP", "Metal", "SYCL", "this CUDA card or with STRATA_QSA_WARP",
"the layer-major prompt path"};
std::string expected;
for (const char* w : where) {
tp::RequestStatus status("1");
check(!status.on(w, log), "unsupported: off");
expected += line(w);
check(output(log) == expected, "unsupported: one line naming the path");
check(!status.on(w, log) && !status.on(w, log), "unsupported again: off");
check(output(log) == expected, "unsupported: the line is printed once");
}
// a layer split can mix cards: a supported query neither uses up the line nor is turned off by an unsupported one
tp::RequestStatus mixed("1");
check(mixed.on(nullptr, log), "supported card first");
check(!mixed.on("this CUDA card or with STRATA_QSA_WARP", log), "then an unsupported card");
check(mixed.on(nullptr, log), "the supported card stays on");
expected += line("this CUDA card or with STRATA_QSA_WARP");
check(output(log) == expected, "the unsupported card's line once");
check(std::fclose(log) == 0, "close the log");
check(std::remove(argv[1]) == 0, "remove the log");
std::puts("qsa_two_pass_status_test: OK");
return 0;
}