APR port, stage 3: Hadamard-folded experts on the CPU path

- hadamard.{hpp,cpp}: hadamard.txt parser, process-wide spec, in-place
  signs + normalized FWHT per block.
- expert_layout_load reads native_experts.txt v5 + hadamard.txt and sets
  NativeFmt::{had_block, had_gu, had_d, gu_signs, d_signs}; inconsistent
  packs are refused.
- native_quant_act / native_quant_h rotate before quantizing, which covers
  every CPU consumer (expert_source's doorbell copy, the pool's h).
- generate.cpp refuses Hadamard packs until the GPU paths rotate too.
- native_hadamard_test: Strata's CPU expert vs the fork's ggml graph
  (ggml_mul(signs) + llama_mul_mat_hadamard + ggml_mul_mat): bit-identical
  on real Gyro-S (TQK6/TQK7) and Gyro-M (TQ2_T) experts, also through
  ExpertPool::run_split_multi_native; synthetic Q8_0 reproduces the
  unrotated float expert to 1.2%.

Built with -DSTRATA_GGML_DIR=<agention llama.cpp> (ggml-cpu supplies the
trellis vec_dot kernels).

Ported from agentionai/Strata rc2 1587897 (rc2 = 9ff02c9), author Laurent Zuijdwijk.
This commit is contained in:
Laurent Zuijdwijk authored and Niko1221 committed 2026-10-15 21:28:58 +02:00
1 parent 89febede8b
commit f47b0385f3
9 files changed
+560 -4

No files matched your search

+9
View File
@@ -43,6 +43,7 @@
#include "strata/kernels/cpu/pool.hpp"
#include "strata/platform/aux_cpus.hpp"
#include "strata/kernels/cpu/expert_layout.hpp"
#include "strata/kernels/cpu/hadamard.hpp"
#include "strata/kernels/ngram.hpp"
#include "strata/kernels/iq_kernels.hpp"
#include "strata/kernels/s2_expert_grouped.hpp"
@@ -3015,6 +3016,14 @@ int main(int argc, char** argv) {
(void) strata::prefill::mmq::supported(f.d_type);
#endif
}
// APR (prism.hadamard) packs: the CPU pool rotates the expert activations (native_quant_act / _h), the GPU
// expert kernels, the remote GPUs and the prompt path do not yet. Refused here
// rather than run with unrotated activations, which would produce plausible-looking garbage.
if (strata::kernels::cpu::hadamard_spec().any()) {
std::fprintf(stderr, "strata generate: this pack's experts are Hadamard-folded (hadamard.txt, an APR "
"model); the GPU expert paths cannot apply the activation rotation yet\n");
return 1;
}
}
const bool native_pack = strata::kernels::cpu::expert_layout().native;
// STRATA_MMQ_DIRECT: the room each sized expert slot keeps after its blob (0 unless it is on: the slot costs and