STRATA_HC_REQ8: hyper-connection projections requantized to int8 + fp32 scale per 32 at load

The rebased #704 under the name asked for there (upstream's STRATA_HC_Q8 now
reads the GGUF's Q8_0 bytes, a different thing).  Opt-in.  The four BF16 hc_*
projections per layer (1,200 MiB) are skipped by the loader and uploaded as
int8 codes with one fp32 scale per 32 values (675 MiB); the freed VRAM goes to
the expert cache.

- Q8 is a template parameter of the down/up kernels (single- and multi-token):
  the BF16 instantiations compile exactly as before, the launch sites pick the
  Q8 ones when w_down / w_up carry scales.  The inject rows stay BF16.
- The staged / v3 / upmix / PF_HCDOWN / gfx906 split paths read BF16 rows and
  are skipped for it; the prompt path expands the codes into a bf16 scratch for
  its GEMM.
- The loader seeks with 64-bit offsets.
- A layer split keeps BF16 with a warning instead of exiting.
This commit is contained in:
Benjamin Larsson authored and Niko1221 committed 2026-10-14 07:11:52 +02:00
1 parent 653f011360
commit 2f44bf51dd
8 files changed
+267 -39

No files matched your search

+15
View File
@@ -3110,6 +3110,15 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: layer split: CUDA0 loads the dense weights of layers 0-%lld only\n",
(long long) split_at[0] - 1);
}
// STRATA_HC_REQ8=1 (opt-in, changes the output): the hyper-connection projections are not loaded as BF16;
// load_hc_q8 below requantizes them to int8 + an fp32 scale per 32 values (~0.56x the bytes), and the freed VRAM
// goes to the expert cache like any other. (Upstream's STRATA_HC_Q8 is a different thing: the GGUF's Q8_0 bytes.)
const bool hc_req8_env = std::getenv("STRATA_HC_REQ8") != nullptr && std::atoi(std::getenv("STRATA_HC_REQ8")) != 0;
if (hc_req8_env && multi_gpu)
std::fprintf(stderr, "strata generate: WARNING: STRATA_HC_REQ8 does not support a layer split yet - the BF16 "
"projections are used\n");
const bool hc_q8 = hc_req8_env && !multi_gpu;
if (hc_q8) strata::core::WeightTable::hc_q8_names(g.n_layers, skip);
uint64_t pool_bytes = 0;
if (!strata::core::WeightTable::pool_bytes(o.pack, pool_bytes, err, skip.empty() ? nullptr : &skip)) {
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
@@ -3159,6 +3168,12 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
return 1;
}
if (hc_q8) {
uint64_t qb = 0;
if (!wt.load_hc_q8(o.pack, qb, err)) { std::fprintf(stderr, "strata generate: %s\n", err.c_str()); return 1; }
std::fprintf(stderr, "strata generate: STRATA_HC_REQ8: hyper-connection projections as int8 + fp32/32 scales, "
"%llu MiB\n", (unsigned long long) (qb >> 20));
}
std::fprintf(stderr, "strata generate: %llu MiB of weights loaded from %s in %.1f s (%zu canonical tensors "
"skipped: served natively)\n",
(unsigned long long) (pool_bytes >> 20), o.pack.c_str(), load_s(), skip.size());