[PR #500] [CLOSED] perf(cpu-pool): eliminate host serialization barrier for intermediate activation quantization with adaptive threshold #2667

Closed
opened 2026-11-04 02:02:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/500
Author: @praveshkhatana
Created: 10/2/2026
Status: ❌ Closed

Base: main ← Head: feat/parallel-intermediate-quant


📝 Commits (10+)

  • cc97fcd setup: AMD layer splits with --gpus (every chosen card a supported AMD arch; the engine compiled for each)
  • e9e2ba3 pinned (#243 follow-up): the shared-memory-budget cap on the sliced pin is opt-in (STRATA_ARENA_PIN_GIB=auto) - by default the arena pins as in 0.1.30; on this 64 GB PC the cap pinned 26 instead of 30 GiB and cost ~20% prompt speed and 2-4% IQ3_S decode
  • cacffa9 CS-T speed: the file tier fetched in parallel, PCIe planning without file reads, a partial pin of the RAM tier, bit-exact AVX2 multi-token kernels for Q4_K / Q5_1 / Q8_0 experts, decode-only tier stats
  • a348c7a Merge branch 'f-131-srv' into r131-q4
  • b93a00c Merge branch 'f-q4-on242' into r131-q4
  • 8f5148c CS-T: the partial pin at most 24 GiB (STRATA_PARTIAL_PIN_GIB), the Q4_K/Q5_1/Q8_0 multi-token kernels from two tokens on
  • 5ffda19 CS-T: the GGUF-in-place prefetch asks Windows for all of a layer's missed slices at once (PrefetchVirtualMemory)
  • ed6c124 #253: the 8 GiB arena pin cap only under WDDM; STRATA_ARENA_PIN_GIB; the split's prompt chunk steps down
  • 450149d --split-skip-if-fits (opt-in): an auto split runs on the main card alone when it holds every profiled expert + KV
  • 6926e0b Merge branch 'f-131-amd' into r131-amd

📊 Changes

2 files changed (+22 additions, -2 deletions)

View changed files

📝 include/strata/kernels/cpu/pool.hpp (+2 -0)
📝 src/kernels/cpu/pool.cpp (+20 -2)

📄 Description

Summary

In multi-token speculative verification passes (run_split_multi and run_split_multi_native), between phase 5 (gate/up projections) and phase 6 (down projections), intermediate activations ff[t] are quantized (act_quant_any / native_quant_h into a2 or hq).

Previously, this intermediate activation quantization was executed sequentially on the host thread in a nested loop while all worker threads sat idle in a barrier:

for (int e = 0; e < nb; ++e)
    for (int t = 0; t < mjobs_[e].nt; ++t)
        native_quant_h(f, split_multi_[e].ff[t], split_multi_[e].hq[t]);

This PR removes the host serialization barrier and introduces pooled parallel quantization protected by an adaptive threshold:

  1. Mode 7 in ExpertPool::drain: Executes intermediate activation quantization tasks in parallel across pool workers using lock-free task claiming.
  2. Adaptive Threshold (quant_threshold_ = std::max(8, n_workers)):
    • For standard generation and small verification windows (\le \text{threshold}), quantization executes sequentially on the host thread with zero worker wake / spin-barrier overhead (matching upstream baseline).
    • Under heavy speculative bursts (> \text{threshold}), quantization tasks dispatch across idle pool workers via run_phase(7).
    • Configurable at runtime via STRATA_POOL_QUANT_THRESH (e.g. set to 0 to force parallel).

Scope & Micro-Benchmarking Clarification

Internal engine timers (pool multi ... gate/up / quantize / down ms/round, profiled via STRATA_VERIFY_PROFILE=1) show that sequential intermediate quantization takes ~0.007 to 0.13 ms per round (<0.5% of round time on modern AVX2/AVX-512 CPUs).

This PR is therefore designed as a thread-pipeline hygiene improvement to eliminate the host wait during speculative bursts, rather than a macro tok/s booster. It guarantees zero regression on low-fanout verification passes via the adaptive threshold while cleanly utilizing available worker threads during multi-token bursts.


Numerical Parity & Correctness

All bitwise parity tests pass with zero discrepancies:

  • iq_multi_parity: PASSED
  • mmvq_multi_parity: PASSED
  • quantize_act_parity: PASSED
  • s2_expert_grouped_parity: PASSED
  • native_expert_parity: PASSED

Bit-for-bit identical outputs: intermediate quantizations write to independent, disjoint thread buffers (split_multi_[e].a2[t] / split_multi_[e].hq[t]), ensuring zero race conditions.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/500 **Author:** [@praveshkhatana](https://github.com/praveshkhatana) **Created:** 10/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/parallel-intermediate-quant` --- ### 📝 Commits (10+) - [`cc97fcd`](https://github.com/Niko1221/Strata/commit/cc97fcde526e1b2d4cbee39ba21e54a0ef7505b1) setup: AMD layer splits with --gpus (every chosen card a supported AMD arch; the engine compiled for each) - [`e9e2ba3`](https://github.com/Niko1221/Strata/commit/e9e2ba31abdc211a618b5faf7226732d40bbcf2b) pinned (#243 follow-up): the shared-memory-budget cap on the sliced pin is opt-in (STRATA_ARENA_PIN_GIB=auto) - by default the arena pins as in 0.1.30; on this 64 GB PC the cap pinned 26 instead of 30 GiB and cost ~20% prompt speed and 2-4% IQ3_S decode - [`cacffa9`](https://github.com/Niko1221/Strata/commit/cacffa95aff016939edd7c15534c0067ec0ee93c) CS-T speed: the file tier fetched in parallel, PCIe planning without file reads, a partial pin of the RAM tier, bit-exact AVX2 multi-token kernels for Q4_K / Q5_1 / Q8_0 experts, decode-only tier stats - [`a348c7a`](https://github.com/Niko1221/Strata/commit/a348c7a4ed64f5f7f24ce3f1cba2d1439f673fed) Merge branch 'f-131-srv' into r131-q4 - [`b93a00c`](https://github.com/Niko1221/Strata/commit/b93a00c65a21fcc5b6431b8091e348d2976259f0) Merge branch 'f-q4-on242' into r131-q4 - [`8f5148c`](https://github.com/Niko1221/Strata/commit/8f5148c14d34c404e8a2d6a45188088714f3c9bb) CS-T: the partial pin at most 24 GiB (STRATA_PARTIAL_PIN_GIB), the Q4_K/Q5_1/Q8_0 multi-token kernels from two tokens on - [`5ffda19`](https://github.com/Niko1221/Strata/commit/5ffda19098202b82943fc80281ce0eb34d8e08a3) CS-T: the GGUF-in-place prefetch asks Windows for all of a layer's missed slices at once (PrefetchVirtualMemory) - [`ed6c124`](https://github.com/Niko1221/Strata/commit/ed6c1244dcd31789007540cb9d8498fbd4134b7f) #253: the 8 GiB arena pin cap only under WDDM; STRATA_ARENA_PIN_GIB; the split's prompt chunk steps down - [`450149d`](https://github.com/Niko1221/Strata/commit/450149d3f248438d8a2526c600b5a75c3dbea6c6) --split-skip-if-fits (opt-in): an auto split runs on the main card alone when it holds every profiled expert + KV - [`6926e0b`](https://github.com/Niko1221/Strata/commit/6926e0b4f4f72cda4f95a0218a89500135af7e4e) Merge branch 'f-131-amd' into r131-amd ### 📊 Changes **2 files changed** (+22 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/kernels/cpu/pool.hpp` (+2 -0) 📝 `src/kernels/cpu/pool.cpp` (+20 -2) </details> ### 📄 Description ### Summary In multi-token speculative verification passes (`run_split_multi` and `run_split_multi_native`), between phase 5 (gate/up projections) and phase 6 (down projections), intermediate activations $ff[t]$ are quantized (`act_quant_any` / `native_quant_h` into $a2$ or $hq$). Previously, this intermediate activation quantization was executed **sequentially on the host thread** in a nested loop while all worker threads sat idle in a barrier: ```cpp for (int e = 0; e < nb; ++e) for (int t = 0; t < mjobs_[e].nt; ++t) native_quant_h(f, split_multi_[e].ff[t], split_multi_[e].hq[t]); ``` This PR removes the host serialization barrier and introduces pooled parallel quantization protected by an adaptive threshold: 1. **Mode 7 in `ExpertPool::drain`**: Executes intermediate activation quantization tasks in parallel across pool workers using lock-free task claiming. 2. **Adaptive Threshold (`quant_threshold_ = std::max(8, n_workers)`)**: - For standard generation and small verification windows ($\le \text{threshold}$), quantization executes sequentially on the host thread with **zero worker wake / spin-barrier overhead** (matching upstream baseline). - Under heavy speculative bursts ($> \text{threshold}$), quantization tasks dispatch across idle pool workers via `run_phase(7)`. - Configurable at runtime via `STRATA_POOL_QUANT_THRESH` (e.g. set to `0` to force parallel). --- ### Scope & Micro-Benchmarking Clarification Internal engine timers (`pool multi ... gate/up / quantize / down ms/round`, profiled via `STRATA_VERIFY_PROFILE=1`) show that sequential intermediate quantization takes ~0.007 to 0.13 ms per round (<0.5% of round time on modern AVX2/AVX-512 CPUs). This PR is therefore designed as a **thread-pipeline hygiene improvement** to eliminate the host wait during speculative bursts, rather than a macro tok/s booster. It guarantees zero regression on low-fanout verification passes via the adaptive threshold while cleanly utilizing available worker threads during multi-token bursts. --- ### Numerical Parity & Correctness All bitwise parity tests pass with zero discrepancies: - `iq_multi_parity`: **PASSED** - `mmvq_multi_parity`: **PASSED** - `quantize_act_parity`: **PASSED** - `s2_expert_grouped_parity`: **PASSED** - `native_expert_parity`: **PASSED** Bit-for-bit identical outputs: intermediate quantizations write to independent, disjoint thread buffers (`split_multi_[e].a2[t]` / `split_multi_[e].hq[t]`), ensuring zero race conditions. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:02:14 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2667
No description provided.