[Engine] SYCL: a pipelined window never self-commits, so --pipeline-windows 2 is token-exact

Problem: `--pipeline-windows 2` (the two-card window overlap) ran but produced different tokens from
`--pipeline-windows 1`.  Ten rounds of switches, splits and modes narrowed it to the two alternating verifiers, and a
state dump (STRATA_PIPELINE_DUMP: a hash of the first stage's GDN recurrence and conv history after every window)
found the moment: identical after the prompt, different after the first decode window.

Root cause: the serial path lets a one-token window advance the GDN state inside the window and skips the commit
graph for it (`record_window` + `commit`).  That is safe there because a serial window never runs before its
predecessor's verdict.  A *pipelined* window may: stage 0 runs window K+1 speculatively while window K's verdict is
still open, so a self-commit lands on state that is not final yet - and the first decode window of every request is a
single token.

Fix: a per-verifier switch (`set_self_commit_off`) that the pipelined verifiers set.  With it `record_window` does not
self-commit and `pl_commit_async` always queues the commit graph - the configuration that already measured
token-identical (`STRATA_ONE_TOKEN_COMMIT=0`) but kept a global switch.

Result on 2x Arc Pro B65, Qwen3.8-Flash-Next IQ3_S, same build, back to back:

| case | pw 1 | pw 2 | tokens |
| --- | ---: | ---: | --- |
| short prompt, 256 tokens, spec 4 | 56.3 / 56.1 tok/s | **59.6 / 61.4** | identical |
| 4K context, 128 tokens | 55.6 | **60.3** | identical |
| `--spec 2 --spec-min-p 0`, 64 tokens | 49.2 / 50.3 | **59.6 / 63.2** | identical |
| 512 tokens, one run | - | **60.6** | - |
| prefill 4,106 tokens | 1,244.8 / 1,242.0 | 1,253.8 / 1,251.3 | identical |
| prefill 16,380 tokens | 1,548.1 | 1,561.1 | - |

So decode gains 7-9% at the default window and 21-26% at two-token windows, and the prompt path is unchanged or
marginally faster.

Validation: tokens identical in all four decode cases above (`scripts/compare_tokens.py`); the serial path's tokens are
unchanged against the pre-change reference.  The state dump still reads one window behind in the pipelined arm (an
ordering artifact of where it copies), so the token comparisons are the evidence, not the dump.
Not run: CUDA/HIP (the files are the port's own), a 32K-context prompt, an overnight soak.

Limits: `--pipeline-windows 2` stays opt-in.  It costs 278 MiB of card 0's expert cache (the second verifier and the
GDN snapshots) and its gain depends on the window size, so the default remains `--pipeline-windows 1`.
This commit is contained in:
Niko1221 committed 2026-10-29 12:45:35 +01:00
1 parent 7356aa1404
commit bf8d88b9dd
3 files changed
+63 -21

No files matched your search

+6
View File
@@ -205,6 +205,11 @@ public:
/// expert evicted on the host (the pool then computes it on the CPU) before the device table follows. Also turns
/// the device-planned layers (E-6) off. Before `init`.
void set_always_publish(bool on) { always_publish_ = on; }
/// The pipelined windows never let a one-token window advance the state itself: its graph may run *speculatively*
/// (ahead of the previous window's verdict), so a self-commit would land before the state it must build on is
/// final. With this set, record_window does not self-commit and pl_commit_async always queues the commit graph -
/// the configuration that measures token-identical to the serial path. Before `capture_all`.
void set_self_commit_off(bool on) { self_commit_off_ = on; }
dpct::queue_ptr stream() const { return cs_; }
int device() const { return device_; }
/// Capture every window size and the commit graph now (a capture syncs the stream: never with a window in flight).
@@ -267,6 +272,7 @@ private:
// batch windows (see init_slots)
std::vector<SessionState*> slots_;
bool batch_rec_ = false; ///< record_window is capturing a batch window
bool self_commit_off_ = false; ///< set_self_commit_off: the pipelined windows commit through the graph
int row_base_ = 0; ///< ... its hand-off rows start here (a pipeline group's own rows)
int brow_[8] = {}; ///< ... and row t is slot brow_[t]
bool last_batch_ = false; ///< the last run was a batch window (set_plan_slot: one group)
+4 -3
View File
@@ -841,7 +841,8 @@ bool Verifier::record_window(int T, dpct::queue_ptr cs, std::string &err) {
const bool ple_on = ss.ple.ready() && ple_stage();
auto Rt = [&](int t) { return R_ + (size_t) t * HC * N; };
const int G = (split_ && T >= 2 && !batch_rec_) ? 2 : 1; // a batch window is one group
const bool self_commit = T == 1 && !batch_rec_ && !g_qfuse() && one_token_self_commit(); // see Verifier::commit
const bool self_commit = T == 1 && !batch_rec_ && !g_qfuse() && one_token_self_commit() &&
!self_commit_off_; // see Verifier::commit
static const bool dec_batch = [] { const char* v = std::getenv("STRATA_DEC_BATCH"); return v == nullptr || std::atoi(v) != 0; }();
// SYCL port, STRATA_VERIFY_EAGER=1: the window runs on the queue instead of as a graph, and each stage stamp is
// a host-side wait + clock (there is no %globaltimer here), so the existing stage profiler reports ms per stage.
@@ -2693,7 +2694,7 @@ bool Verifier::commit(int n_keep, std::string &err) try {
h_commit_[0] = n_keep;
h_commit_[1] = n_keep - 1;
for (int t = 0; t < max_t_; ++t) h_commit_[2 + t] = t < n_keep ? (int32_t) (last_pos0_ + t) : -1;
if (last_t_ == 1 && one_token_self_commit()) {
if (last_t_ == 1 && one_token_self_commit() && !self_commit_off_) {
// a one-token window has advanced the state itself (record_window): no commit graph
} else {
std::atomic_thread_fence(std::memory_order_seq_cst);
@@ -4009,7 +4010,7 @@ bool Verifier::pl_commit_async(int n_keep, std::string &err) try {
// single-token window; the first decode window is always one token, so the two paths' GDN states were
// equal after the prompt and different after that window (STRATA_PIPELINE_DUMP), and the tokens diverged
// at the fourth. With this skip the pipelined windows are token-identical to the serial path.
if (last_t_ == 1 && one_token_self_commit()) {
if (last_t_ == 1 && one_token_self_commit() && !self_commit_off_) {
h_commit_[0] = n_keep;
h_commit_[1] = n_keep - 1;
for (int t = 0; t < max_t_; ++t) h_commit_[2 + t] = t < n_keep ? (int32_t) (last_pos0_ + t) : -1;
+53 -18
View File
@@ -7279,10 +7279,14 @@ int main(int argc, char **argv) try {
for (strata::core::Verifier* v : {&ver, &ver_b}) {
v->set_stream(pl_stream[0]);
v->set_always_publish(true);
v->set_self_commit_off(true); // a pipelined window may run speculatively: never let it
// advance the state itself, the commit graph always does
}
for (strata::core::Verifier* v : {&stages[0]->ver, &stages[0]->ver_b}) {
v->set_stream(pl_stream[1]);
v->set_always_publish(true);
v->set_self_commit_off(true); // a pipelined window may run speculatively: never let it
// advance the state itself, the commit graph always does
}
}
if (n_stages > 1) {
@@ -11551,17 +11555,33 @@ int main(int argc, char **argv) try {
const size_t n = (size_t) ss.gdn_alloc * (size_t) gdn_floats;
std::vector<float> h(n);
(void) DPCT_CHECK_ERROR(s0->memcpy(h.data(), ss.gdn_state, n * sizeof(float)).wait());
uint64_t hs = 1469598103934665603ull;
double sum = 0.0;
for (size_t i = 0; i < n; ++i) {
uint64_t b = 0;
std::memcpy(&b, &h[i], sizeof(float));
hs = (hs ^ b) * 1099511628211ull;
sum += (double) h[i];
// the recurrence state and the conv history hashed apart: a wrong row shows which half it is
const size_t n_rec = (size_t) g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size;
const size_t n_cnv = (size_t) g.ssm_conv_channels * (g.ssm_d_conv - 1);
double rec_sum = 0.0, cnv_sum = 0.0;
uint64_t rec_hash = 1469598103934665603ull, cnv_hash = 1469598103934665603ull;
for (int64_t l = 0; l < ss.gdn_alloc; ++l) {
const size_t base = (size_t) l * (size_t) gdn_floats;
uint64_t rh = 1469598103934665603ull, ch = 1469598103934665603ull;
for (size_t i = 0; i < n_rec; ++i) {
uint64_t b = 0;
std::memcpy(&b, &h[base + i], sizeof(float));
rh = (rh ^ b) * 1099511628211ull;
rec_sum += (double) h[base + i];
}
for (size_t i = 0; i < n_cnv; ++i) {
uint64_t b = 0;
std::memcpy(&b, &h[base + n_rec + i], sizeof(float));
ch = (ch ^ b) * 1099511628211ull;
cnv_sum += (double) h[base + n_rec + i];
}
rec_hash = (rec_hash ^ rh) * 1099511628211ull;
cnv_hash = (cnv_hash ^ ch) * 1099511628211ull;
}
if (std::FILE* df = std::fopen(pl_dump, "a")) {
std::fprintf(df, "pos %lld windows %lld gdn %zu sum %.9g hash %016llx\n", (long long) p,
(long long) dec_windows, n, sum, (unsigned long long) hs);
std::fprintf(df, "pos %lld windows %lld rec %.9g %016llx cnv %.9g %016llx\n", (long long) p,
(long long) dec_windows, rec_sum, (unsigned long long) rec_hash, cnv_sum,
(unsigned long long) cnv_hash);
std::fclose(df);
}
}
@@ -11781,17 +11801,32 @@ int main(int argc, char **argv) try {
const size_t n = (size_t) ss.gdn_alloc * (size_t) gf;
std::vector<float> h(n);
(void) DPCT_CHECK_ERROR(ver.stream()->memcpy(h.data(), ss.gdn_state, n * sizeof(float)).wait());
uint64_t hs = 1469598103934665603ull;
double sum = 0.0;
for (size_t i = 0; i < n; ++i) {
uint64_t bb = 0;
std::memcpy(&bb, &h[i], sizeof(float));
hs = (hs ^ bb) * 1099511628211ull;
sum += (double) h[i];
const size_t n_rec = (size_t) g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size;
const size_t n_cnv = (size_t) g.ssm_conv_channels * (g.ssm_d_conv - 1);
double rec_sum = 0.0, cnv_sum = 0.0;
uint64_t rec_hash = 1469598103934665603ull, cnv_hash = 1469598103934665603ull;
for (int64_t l = 0; l < ss.gdn_alloc; ++l) {
const size_t base = (size_t) l * (size_t) gf;
uint64_t rh = 1469598103934665603ull, ch = 1469598103934665603ull;
for (size_t i = 0; i < n_rec; ++i) {
uint64_t bb = 0;
std::memcpy(&bb, &h[base + i], sizeof(float));
rh = (rh ^ bb) * 1099511628211ull;
rec_sum += (double) h[base + i];
}
for (size_t i = 0; i < n_cnv; ++i) {
uint64_t bb = 0;
std::memcpy(&bb, &h[base + n_rec + i], sizeof(float));
ch = (ch ^ bb) * 1099511628211ull;
cnv_sum += (double) h[base + n_rec + i];
}
rec_hash = (rec_hash ^ rh) * 1099511628211ull;
cnv_hash = (cnv_hash ^ ch) * 1099511628211ull;
}
if (std::FILE* df = std::fopen(sd, "a")) {
std::fprintf(df, "pos %lld serial gdn %zu sum %.9g hash %016llx\n", (long long) (p + a + 1), n,
sum, (unsigned long long) hs);
std::fprintf(df, "pos %lld serial rec %.9g %016llx cnv %.9g %016llx\n", (long long) (p + a + 1),
rec_sum, (unsigned long long) rec_hash, cnv_sum,
(unsigned long long) cnv_hash);
std::fclose(df);
}
}