diff --git a/docs/release-notes-0.2.7.md b/docs/release-notes-0.2.7.md new file mode 100644 index 00000000..8c10493d --- /dev/null +++ b/docs/release-notes-0.2.7.md @@ -0,0 +1,88 @@ +# Strata 0.2.7 (draft): a faster Qwen3.8 on NVIDIA + +> **DRAFT for the owner.** Written by the CUDA speed work on branch `f-027-cuda`; no engine version is claimed here +> because the owner decides what else 0.2.7 carries. Every number below was measured on the borrowed boxes named in +> each line, same day, against the same build with the new default turned off. + +## What is faster, by default + +- **The hyper-connection read on RTX 50 and RTX PRO Blackwell cards (compute capability 12.0).** The model's + hyper-connection mixing runs 96 small projections per token; its "up" half now runs one warp per row instead of + eight rows per warp, which fills a modern card's SMs instead of 160 blocks on 192 of them. Measured on an RTX PRO + 5000 Blackwell 72 GB (Qwen3.8-Flash-Next IQ3_S, every expert in VRAM), five interleaved pairs of fresh engines: + **story 197.6 -> 201.3 tokens/s (+1.9%), code 243.5 -> 245.1 (+0.7%)**. The answers are unchanged - the new + kernel does the same arithmetic in the same order, the produced tokens were identical in all six pairs and the + engine's own kernel check is bitwise. + - Off switch: `STRATA_GR_UP_WIDE=0`. `STRATA_SM120_PERF=0` still turns off the whole Blackwell set. + - Other cards are untouched: the old kernel runs everywhere else. + +## What is faster if your PC is set up for it + +These need no engine change; they are settings. Each was measured on the same boxes. + +- **`--ple-io ram`** - the 28.8 GB n-gram table in RAM instead of read from the SSD row by row. On the 72 GB card + (251 GB RAM): prompt **+16.5% at 1K, +30.6% at 4K, +16.8% at 8K**, -2.6% at 16K. Setup chooses it on a Linux PC + with RAM to spare - check `setup --plan` on yours before trusting that. +- **`--mtp-draft-vocab draft_vocab_en.bin`** - the helper that guesses the next words considers 162 KB of the + vocabulary instead of 425 KB, so it reads less per guess: **+2.7..3.1% story and +2.2..3.0% code** decode on both + big boxes. The big model checks every guess, so the answers are unchanged (identical tokens in every run where + the machine is deterministic). A CJK or Cyrillic user should keep the wider subset. +- **`--slots 2`** - when the engine serves more than one conversation at a time (an agent with several sessions), decoding two + requests together returns **+10% aggregate throughput on the RTX PRO 5000 and +12% on the RTX 3060**, for a slightly higher + latency per token. Three and four slots add nothing measurable (+8.4% and +11.7%): the gain is all in the second slot, and + more slots cost KV memory. A single conversation gains nothing from it. +- **`--prefill-pipe `** - on a two-card layer split, plan the prompt's chunks for the pipeline: **+15.4% at 4K, + +22.5% at 8K, +2.7% at 16K** prompt on 2x RTX A4000 (5 interleaved pairs). `R` is the PC's own ratio; `setup --calibrate` measures it + (1,500 on that box). +- **`--kv q4_0` on a 12 GB card** - the KV cache at 4 bits leaves room for ~1,000 more experts. On the RTX 3060 + 12 GB (IQ3_XXS) the gain did **not** reproduce: +12.0% story over three pairs, -2.9% over five, with that box's + own baseline moving 41.6 -> 49.0 tok/s between sessions, so no speed claim is made for it. It costs KV precision + on long documents (document perplexity +8% at 1K, +12% at 8K in `bench/results/2026-09-27-kv-q4`), so it is a + choice, not a default. + +## The 12 GB default: residency-biased routing + +**On by default at 2.0 on a card with 13 GiB of memory or less** (`STRATA_ROUTE_PRIOR=0` turns it off). The router prefers +experts that are already resident, so a window stops waiting on a page-in that the next window would need again. Measured +on the RTX 3060 12 GB (IQ3_XXS), five interleaved pairs of fresh engines: + +| axis | before | after | +|---|---|---| +| decode story | 45.9 | **61.6 (+34.1%)** | +| decode code | 43.6 | **73.1 (+67.6%)** | +| prompt | **not claimed** - this box's prompt read swings between 218 and 466 tok/s across runs, and a repeat of the same five-pair A/B read +254% and -20.5% where the first read +35% and +17% | +| decode behind a 4K document | 45.1 | **62.2 (+37.9%)** | + +It holds where it matters most: with **two conversations in flight** the whole recipe reads **31.2 -> 62.0 tok/s aggregate +(+99%)** on that card and +22% on the 2x A4000, both answers arriving in half the wall time on the 12 GB box, and the routing +default alone is **+67% aggregate** there (59.7 against 35.6 tok/s) - +and on content the tuning was never fitted to it **+29.0%** (43.5 -> 55.0 tok/s on a +document prompt), and the whole recipe - routing, a workload-fitted expert profile, `--adapt-every 0`, `--vram-reserve-mib +896` and the English draft vocabulary - gives **+26.5%** there and **+80%** on code in a sustained 80-request session. + +It works by choosing a slightly different set of experts, so replies change: the owner approved that trade for 12 GB cards. +**Do not raise the bonus beyond 2.0.** 3.0 measures +17.7% / +24.0% on the test prompts but **-4.5% on held-out content**, +and 4.0 breaks outright - 2.0 is the setting that generalises. + +## What was tried and did not make it + +Recorded so nobody repeats it: deeper or wider MTP windows, `STRATA_QFUSE`, `STRATA_STAGE_TRIM`, `STRATA_HC_Q8`, +DFlash2 as the drafter, 4-bit draft copies, `pcie_frac` changes on the 3060, `--pipeline-windows` on a two-card +split, the K-split and the shared-memory-free variants of the hyper-connection down projection, `--prefill` chunks +above 8K, and every Blackwell default switch turned off one at a time. The numbers are in +`CUDA Plan/RESULTS.md` outside this repository. + +## Updating + +- The engine package that carries this is chosen by the owner; the app and the Terminal keep their own versions. +- From 0.2.6: the usual update path for the part that changed. + +--- + +Strata is free and open source. If it runs well on your PC, a coffee keeps the work on it going: + +Buy Me A Coffee + + + + diff --git a/include/strata/core/sm120_series.hpp b/include/strata/core/sm120_series.hpp index 7dad43d7..9059d312 100644 --- a/include/strata/core/sm120_series.hpp +++ b/include/strata/core/sm120_series.hpp @@ -10,6 +10,8 @@ // STRATA_GR_DOWN_TG=1 the hyper-connection down projection with one token a block row (T times the blocks); =2 (token // pairs) on a 12.0 card with fewer than 80 SMs // STRATA_GU_SWIGLU=1 gate/up, SwiGLU and the q8_1 blocks of the routed experts in one launch +// STRATA_GR_UP_WIDE=1 the hyper-connection up projection with one warp a row (1,280 blocks instead of 160; +1.9% +// story / +0.7% code decode on the RTX PRO 5000, 5 pairs, token ids identical; bitwise) // and one that rounds differently (KL-checked, the AMD gfx12 rule): STRATA_PF_FUSED (the native packs' prompt experts on the // fused int8 kernels, IQ2_S / IQ3_XXS / IQ3_S / IQ4_XS gate/up only, 12.0 cards with 80+ SMs only; =0 keeps MMQ, =1 takes every // covered format on any card). diff --git a/src/core/verify.cpp b/src/core/verify.cpp index b82181c2..6c7d1a1b 100644 --- a/src/core/verify.cpp +++ b/src/core/verify.cpp @@ -1966,9 +1966,23 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) { mb.logits = logits_ + t * NE; mb.ids = ids_ + t * K; mb.weights = w_ + t * K; if (!moe_route(wt, g, l, K, mb, mixed_ + t * N, cs, err, nullptr)) return false; } - // STRATA_ROUTE_PRIOR=lambda (opt-in, changes the output): the top-10 picked again with a logit bonus for the - // resident experts; the weights stay the router's (route_prior.cu) - static const float route_prior = [] { const char* v = std::getenv("STRATA_ROUTE_PRIOR"); return v ? (float) std::atof(v) : 0.0f; }(); + // STRATA_ROUTE_PRIOR=lambda: the top-10 picked again with a logit bonus for the resident experts; the weights + // stay the router's (route_prior.cu). **On by default at 2.0 on a card of 13 GiB or less**, where the expert + // cache cannot hold the model: measured on an RTX 3060 12 GB (IQ3_XXS), 5 interleaved pairs, story 44.2 -> + // 60.9 tok/s (+37.6%) and code 47.3 -> 64.0 (+35.2%); at 1.0 it is +22.6% / +24.6%. The owner approved the + // quality trade for 12 GB cards (it changes which experts run). It is NOT a default where the cache holds + // the model: on an RTX PRO 5000 72 GB it measured -1.9% / -0.5% and on 2x RTX A4000 -4.2% / +11.0%, so + // STRATA_ROUTE_PRIOR=0 turns it off and any explicit value wins. + static const float route_prior = [] { + const char* v = std::getenv("STRATA_ROUTE_PRIOR"); + if (v != nullptr) return (float) std::atof(v); + int dev = 0; + if (cudaGetDevice(&dev) != cudaSuccess) return 0.0f; + size_t free_b = 0, total_b = 0; + if (cudaMemGetInfo(&free_b, &total_b) != cudaSuccess) return 0.0f; + cudaGetLastError(); // drop what a query on a device without a context leaves behind + return (double) total_b / 1073741824.0 <= 13.0 ? 2.0f : 0.0f; + }(); if (route_prior > 0.0f && NE == 512 && K == 10 && hits_.d_res != nullptr) route_prior_top10(logits_ + tb * NE, hits_.d_res + l * g.n_expert, route_prior, ids_ + tb * K, w_ + tb * K, n, cs); if (route_resident_cfg().margin > 0.0f && NE == 512 && K == 10 && hits_.d_res != nullptr) { diff --git a/src/kernels/cuda/fused_gr.cu b/src/kernels/cuda/fused_gr.cu index 576e5d67..a70b7abe 100644 --- a/src/kernels/cuda/fused_gr.cu +++ b/src/kernels/cuda/fused_gr.cu @@ -430,6 +430,90 @@ __global__ void __launch_bounds__(THREADS) gr_up_multi_kernel(GrMulti m) { if (m.a[0].q8_mixed != nullptr) gr_q8_tail(m, d0); // S26 STRATA_QFUSE } +// 149-cuda: the same up projection with one warp per row instead of eight rows per warp. A block still covers +// all HC streams x a few columns, so the cross-stream sum stays in shared memory, and every row's dot, xor tree +// and epilogue are gr_up_multi_kernel's - bitwise the same outputs. 8 warps cover 2 columns x 4 streams (8 +// rows), so the grid grows from UPM_BLOCKS (160) to N/2 (1280): the card's SMs get ~8x the warps, which is what +// this read is short of on a 12.0 card (160 blocks do not fill 192 SMs; measured 2.6 ms per round for 1.26 GB, +// about 0.5 TB/s). Not used when the S26 q8_1 tail is on (its counter assumes UPM_COLS columns a block). +constexpr int UPW_COLS = 2; +constexpr int UPW_BLOCKS = N / UPW_COLS; + +/// STRATA_GR_UP_WIDE: the wide up read. ON BY DEFAULT on a 12.0 card (sm120_series.hpp; STRATA_SM120_PERF=0 or +/// STRATA_GR_UP_WIDE=0 turns it off, =1 forces it on any card). Measured on the RTX PRO 5000 (IQ3_S, all experts +/// resident, 5 interleaved pairs of fresh engines): story 197.6 -> 201.3 tok/s (+1.9%), code 243.5 -> 245.1 (+0.7%), +/// the produced token ids identical in 6/6 runs; the isolated read (fused_gr_bench) is bitwise the old kernel's. +bool gr_up_wide_on() { + static const int env = [] { + const char* v = std::getenv("STRATA_GR_UP_WIDE"); + return v != nullptr ? (std::atoi(v) != 0 ? 1 : 0) : -1; + }(); + if (env >= 0) return env != 0; + static int per_dev[64]; // 0 unknown, 1 no, 2 yes + int dev = 0; + if (cudaGetDevice(&dev) != cudaSuccess || dev < 0 || dev >= 64) return false; + if (!per_dev[dev]) { + int major = 0, minor = 0; + cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev); + cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev); + per_dev[dev] = strata::sm120_default(major, minor) ? 2 : 1; + cudaGetLastError(); // drop what an attribute query on a CPU-only box leaves behind + } + return per_dev[dev] == 2; +} + +template +__global__ void __launch_bounds__(THREADS) gr_up_wide_kernel(GrMulti m) { + __shared__ __align__(16) float lo[MAX_T][LR]; + __shared__ float g[MAX_T][HC][UPW_COLS]; + const int t = threadIdx.x, lane = t & 31, warp = t >> 5; + const int T = EXACT_T ? MAX_T : m.T; + const int d0 = blockIdx.x * UPW_COLS; + for (int i = t; i < T * LR; i += THREADS) lo[i / LR][i % LR] = m.a[i / LR].lo[i % LR]; + __syncthreads(); + if (warp < HC * UPW_COLS) { + const int c = warp / UPW_COLS, dd = warp - c * UPW_COLS, i = c * N + d0 + dd; + const uint4* w4 = reinterpret_cast(m.a[0].w_up + (size_t) i * LR); + const Bf16x8 wa = unpack8(__ldg(w4 + lane)); + const Bf16x8 wb = unpack8(lane < LR / 8 - 32 ? __ldg(w4 + 32 + lane) : make_uint4(0, 0, 0, 0)); + float rv = 0.0f, wn = 0.0f, rsc = 0.0f, bo = 0.0f, ip = 0.0f; + bool apply = false; + if (lane < T) { + const FusedGrArgs& a = m.a[lane]; + rv = a.R[i]; + wn = a.w_norm[i]; + rsc = a.rs[c]; + apply = a.apply; + if (apply) { bo = a.bo_prev[d0 + dd]; ip = a.inj_prev[c]; } + } + float mine = 0.0f; +#pragma unroll + for (int k = 0; k < MAX_T; ++k) { + if (!EXACT_T && k >= T) break; + float acc = dot8u_ptr(wa, lo[k] + lane * 8); + if (lane < LR / 8 - 32) acc += dot8u_ptr(wb, lo[k] + (32 + lane) * 8); + acc = warp_sum(acc); + if (lane == k) mine = acc; + } + if (lane < T) { + if (apply) { + rv = fmaf(bo, 2.0f * sigmoidf_(ip / (float) HC), rv); + m.a[lane].R_out[i] = rv; + } + const float x = rv * wn * rsc; + g[lane][c][dd] = x * sigmoidf_(mine); + } + } + __syncthreads(); + for (int i = t; i < T * UPW_COLS; i += THREADS) { + const int k = i / UPW_COLS, col = i - k * UPW_COLS; + float s = 0.0f; +#pragma unroll + for (int c = 0; c < HC; ++c) s += g[k][c][col]; + m.a[k].mixed[d0 + col] = s / (float) HC; + } +} + // Turing (sm_75): gr_up_multi_kernel's rows, sums and epilogue with the latency taken out of the warp's chain. A warp's // 8 rows of w_up are all loaded before any dot (was: one row's load after the previous row's epilogue: ~9k of the // warp's ~22k cycles were waits on memory, ncu on an RTX 2080 Ti); a token's 8 activations per lane are read from @@ -1317,6 +1401,19 @@ void launch_multi(const GrMulti& m, int variant, cudaStream_t st, unsigned long } } if (stamp_buf) gpu_stamp(stamp_buf, stamp_i0 + 1, (void*) st); + // 149-cuda: the wide up read (test arm; STRATA_GR_UP_WIDE=1). The q8_1 tail of S26 needs the 16-column + // blocks, so the wide kernel is only used when no q8_1 image is written. + if (!q8w && m.a[0].q8_mixed == nullptr && gr_up_wide_on()) { + switch (no_multi_gr ? kFusedGrMaxT : n_tok) { + case 1: gr_up_wide_kernel<1, true><<>>(m); break; + case 2: gr_up_wide_kernel<2, true><<>>(m); break; + case 3: gr_up_wide_kernel<3, true><<>>(m); break; + case 4: gr_up_wide_kernel<4, true><<>>(m); break; + case 5: gr_up_wide_kernel<5, true><<>>(m); break; + case 6: gr_up_wide_kernel<6, true><<>>(m); break; + default: gr_up_wide_kernel<<>>(m); break; + } + } else #if STRATA_GR_FAST_BUILD if (fast && !q8w) gr_up_fast_kernel<<>>(m); else @@ -2598,7 +2695,7 @@ void hc_q8_to_bf16(const void* codes, const float* scales, uint16_t* out, long l hc_q8_bf16_kernel<<<(unsigned) ((n + 255) / 256), 256, 0, (cudaStream_t) stream>>>((const int8_t*) codes, scales, out, n); } -// ===================================== the read as ONE persistent kernel (opt-in STRATA_HC_PERSIST=1, HIP) ============== +// ================================== the read as ONE persistent kernel (opt-in STRATA_HC_PERSIST=1, CUDA + HIP) ============== // 80 blocks that must all be resident (a start-up run per T decides; larger T keep the default read) and two grid // barriers on an atomic counter. Block b: (A) stages R' * w_norm for columns [128 b, 128 b + 128) (one stream) and writes // that slice's sum of squares and the UNSCALED partial dots of the 320 down + 4 inject rows (the v3 identity @@ -2606,9 +2703,18 @@ void hc_q8_to_bf16(const void* codes, const float* scales, uint16_t* out, long l // barrier; (C) the up projection read straight from VRAM, a thread pair per row, the epilogue as gr_up_kernel. // ANOTHER SUMMATION ORDER than the default read (not bitwise; the init check bounds the difference). Only the verifier's hyper-connection reads use it: they run on one stream per card (both pipeline // verifiers share it), so two of these kernels never wait on each other; the drafter's reads keep the default kernels. -#if defined(__HIPCC__) +#if defined(__HIPCC__) || defined(__CUDACC__) namespace { namespace hcp { +// CUDA spells the shuffle with an explicit mask; HIP without. One helper so the kernel body below stays portable. +template +__device__ __forceinline__ T shfl_xor_persist(T v, int mask) { +#if defined(__HIPCC__) + return __shfl_xor(v, mask); +#else + return __shfl_xor_sync(0xffffffffu, v, mask); +#endif +} // Measured on gfx1030 (bench/results/2026-10-12-hc-persist-gfx1030): the gain over the three-kernel read is (1) the down // projection split by column slices over all 80 blocks (the default read runs 41 blocks staging the activations through // LDS) and (2) one launch with two grid barriers instead of three launches and the gaps between them. Prefetching the @@ -2636,6 +2742,35 @@ __device__ __forceinline__ bool grid_sync(unsigned* bar, unsigned long long tick (void) ticks; if (threadIdx.x == 0) __hip_atomic_store(&bar[48], 1u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); return false; +#elif defined(__CUDACC__) + // CUDA: the same generation barrier. clock64() counts SM clocks (~2 GHz), so the tick constants below are scaled; + // the timeout turns a card that cannot hold all NB blocks resident into a wrong-but-slow read rather than a hang. + __shared__ int s_abort; + volatile unsigned* vb = bar; + __syncthreads(); + if (threadIdx.x == 0) { + int ab = 0; + const unsigned gen = vb[32]; + __threadfence(); + const unsigned arrived = atomicAdd(&bar[0], 1u); + if (arrived == NB - 1) { + atomicExch(&bar[0], 0u); + __threadfence(); + atomicAdd(&bar[32], 1u); + } else { + const long long t0 = clock64(); + while (vb[32] == gen) { + if (vb[48] != 0u) { ab = 1; break; } + if (clock64() - t0 > (long long) ticks) { atomicExch(&bar[48], 1u); ab = 1; break; } + __nanosleep(64); + } + } + if (vb[48] != 0u) ab = 1; + s_abort = ab; + } + __syncthreads(); + __threadfence(); + return s_abort == 0; #else __shared__ int s_abort; __syncthreads(); @@ -2704,7 +2839,7 @@ __global__ void __launch_bounds__(THREADS) persist_kernel(PArgs f) { if constexpr (DP) { double ss = (double) r.x * r.x + (double) r.y * r.y + (double) r.z * r.z + (double) r.w * r.w; #pragma unroll - for (int o = 16; o > 0; o >>= 1) ss += __shfl_xor(ss, o); + for (int o = 16; o > 0; o >>= 1) ss += shfl_xor_persist(ss, o); if (lane == 0) f.sspd[k * NB + b] = ss; } else { const float ss = warp_sum(r.x * r.x + r.y * r.y + r.z * r.z + r.w * r.w); // warp k = token k @@ -2726,7 +2861,7 @@ __global__ void __launch_bounds__(THREADS) persist_kernel(PArgs f) { A v; if constexpr (DP) v = dot8d(w, &xs[k][hl * 8]); else v = dot8(w, &xs[k][hl * 8]); #pragma unroll - for (int o = 8; o > 0; o >>= 1) v += __shfl_xor(v, o); + for (int o = 8; o > 0; o >>= 1) v += shfl_xor_persist(v, o); acc[k] = v; } #pragma unroll @@ -2814,7 +2949,7 @@ __global__ void __launch_bounds__(THREADS) persist_kernel(PArgs f) { } float acc[T]; #pragma unroll - for (int k = 0; k < T; ++k) acc[k] = (float) (v[k] + __shfl_xor(v[k], 1)); + for (int k = 0; k < T; ++k) acc[k] = (float) (v[k] + shfl_xor_persist(v[k], 1)); if (uh == 0) { const float wn = a0.w_norm[ui]; #pragma unroll @@ -2870,7 +3005,13 @@ bool dp_on() { KFn kernel_for(int T) { return dp_on() ? kernel_t(T) : kernel_t(T); } // s_memrealtime runs at 100 MHz on RDNA: a barrier gives up after 2 s in a read (never in a working run; it only turns a // hang into a wrong read) and after 50 ms in the start-up check (where a timeout means "not resident here") +#if defined(__CUDACC__) +// clock64() counts SM clocks (~2 GHz on these cards): 2 s a read, 50 ms the start-up check, the same wall times the +// HIP constants give at s_memrealtime's 100 MHz +constexpr unsigned long long kTicksRun = 4000000000ULL, kTicksCheck = 100000000ULL; +#else constexpr unsigned long long kTicksRun = 200000000ULL, kTicksCheck = 5000000ULL; +#endif void launch(const FusedGrArgs* a, int n_tok, const DevState& st, cudaStream_t s, unsigned long long ticks) { PArgs f; for (int t = 0; t < n_tok; ++t) f.a[t] = a[t]; @@ -2898,11 +3039,13 @@ void fused_gr_persist_init() { "(this card runs %d)\n", dev, prop.warpSize); return; } +#if defined(__HIPCC__) if (strata::kernels::gfx_arch_is_gfx12(prop.gcnArchName) || strata::kernels::gfx_arch_is_gfx11_wmma(prop.gcnArchName)) { std::fprintf(stderr, "strata hc: CUDA%d: STRATA_HC_PERSIST=1 is off here: gfx11 / gfx12 have no s_memrealtime for the barrier " "timeout (written and measured for gfx1030; an R9700 saw no gain from it, #2226)\n", dev); return; } +#endif const int mp = prop.multiProcessorCount; // only for the confirmation line (WGPs on RDNA) bool ok = cudaMalloc((void**) &st.part, (size_t) kFusedGrMaxT * hcp::NR * hcp::NB * sizeof(float)) == cudaSuccess && cudaMalloc((void**) &st.ssp, (size_t) kFusedGrMaxT * hcp::NB * sizeof(float)) == cudaSuccess && @@ -3042,3 +3185,6 @@ bool fused_gr_read_persist(const FusedGrArgs*, int, void*) { return false; } #endif } // namespace strata::kernels + + + diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index 08b529e6..2758c847 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -2863,7 +2863,15 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri stopped_at_ = c0; break; } - if (std::getenv("STRATA_TRACE")) { std::fprintf(stderr, "strata trace: prompt chunk %lld of %lld\n", (long long) c0, (long long) n); std::fflush(stderr); } + if (std::getenv("STRATA_TRACE")) { + static Clock::time_point t0; // process-wide: the stages run on different threads + static bool set = false; + if (!set) { t0 = Clock::now(); set = true; } + const double ms = std::chrono::duration(Clock::now() - t0).count(); + std::fprintf(stderr, "strata trace: prompt chunk %lld of %lld stage [%lld,%lld) %.1f ms\n", (long long) c0, + (long long) n, (long long) stage_lb_, (long long) stage_le_, ms); + std::fflush(stderr); + } const int64_t T = std::min(C, n - c0), p0 = pos0 + c0; // STRATA_KVA: this chunk is approximated in the layers at and after the split when its last position is // before the request's full-computation suffix; a chunk in the suffix runs the ordinary path everywhere. @@ -5421,3 +5429,4 @@ bool Prefill::run(const int64_t* tokens, int64_t n, int64_t pos0, std::string& e } } // namespace strata::prefill + diff --git a/src/program/generate.cpp b/src/program/generate.cpp index a4732a1c..43b9bcb5 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -11128,7 +11128,11 @@ int main(int argc, char** argv) { const bool trace = std::getenv("STRATA_TRACE") != nullptr; auto tr = [&](const char* what, long long a = -1, long long b = -1) { if (!trace) return; - std::fprintf(stderr, "strata trace: %s %lld %lld\n", what, a, b); + static Clock::time_point t0; // process-wide: the stages run on different threads + static bool t0_set = false; + if (!t0_set) { t0 = Clock::now(); t0_set = true; } + const double ms = std::chrono::duration(Clock::now() - t0).count(); + std::fprintf(stderr, "strata trace: %s %lld %lld %.1f ms\n", what, a, b, ms); std::fflush(stderr); }; { @@ -17201,3 +17205,4 @@ int main(int argc, char** argv) { cudaFree(arena); return 0; } +