Inkling CUDA hybrid: the cold-expert lane probe runs three times and keeps the exact lane unless the CPU lane is clearly faster; STRATA_INK_LANE_PROBE_OLD=1 brings the old rule back

The launch probe times the CPU lane and the card's copy-in (exact) lane and keeps the faster one. The old rule kept the CPU lane unless the copy-in lane was 10 % faster (t_card < 0.9 * t_cpu), from one
probe per lane. On the owner's RTX 5070 12 GB (Windows, SQ-10, drafter off, the published 0.2.24 packages) a quiet PC measured CPU 9.0 to 9.5 ms and copy-in 8.6 to 8.8 ms (ratio 0.95): the old rule kept the CPU
lane and every start decoded 65-68 tok/s and 34.5 on a 4K document where the copy-in lane gives 73 and 56.4 (+11 to +64 %); with a busier PC the same card measured 12.0 against 8.6 and chose the copy-in lane,
so two starts can land on different sides of the threshold (that is the only reading of the 9 to 12 % cuda12 / cuda13 gap of NUMBERS-0224 that the data allows: the packages themselves are equal in every forced lane).

- strata/core/ink_cold_lane.hpp: ink_probe_median and ink_cold_lane_exact (the exact lane unless the CPU lane is clearly (10 %) faster: t_cpu < 0.9 * t_card; ties go to the exact lane); unit test
  ink_cold_lane_test (in CMake, no GPU).
- ink_runner.cuh pick_cold_lane: three probes per lane, alternating, the median of each (about 1 s more at start); "(median of 3)" in the line. STRATA_INK_LANE_PROBE_OLD=1: the old rule (one probe per lane).
  Register entry (rollback) and the SETTINGS.md row; docs/INKLING_KV.md (the earlier commit) says what it does.

Gates (decode tok/s prose / chat / code / doc4k, ABAB, 3 rounds, SQ-10 for the 5070, ctx 8192, drafter off):
- owner RTX 5070 (MSVC + CUDA 13.0, sandboxed jobq): new rule picked the copy-in lane in all 3 starts (CPU 9.0-9.2 against copy 8.7): 65.4 -> 73.x / 67.2 -> 73.5 / 68.5 -> 72.9 / 34.4 -> 56.0 against the old rule
  (old exe, same host): chat +9 %, code +6 %, doc4k +63 %; STRATA_INK_LANE_PROBE_OLD=1 on the new exe reproduces the old numbers (65.4 / 67.0 / 68.5 / 34.4).
- z440 RTX A4000, SQ-15 made hybrid with a VRAM ballast (1,977 experts on the card, 1,095 in RAM): CPU lane 31.9 ms against copy-in 42.7: the CPU lane under both rules, identical decode (34.2 / 36.2 / 34.9 / 31.4
  against 34.2 / 36.3 / 34.8 / 31.2): the rule changes nothing where the CPU lane is clearly faster. (Without the ballast SQ-15 fits the A4000 whole: no cold expert, no probe.)
- HIP and SYCL have no such probe (cuda/ink_runner.cuh only): no R9700 / A750 gate applies.
Tests: ink_cold_lane_test and ink_sm120_table_test pass, settings register check passes, MSVC + CUDA 13.0 sm_120 build OK.
This commit is contained in:
Niko1221 committed 2026-12-02 18:35:17 +01:00
1 parent c18992382f
commit 580852d82f
6 files changed
+130 -9

No files matched your search

+2 -1
View File
@@ -470,7 +470,7 @@ Off unless you set them. The last column says where each one is described.
| `STRATA_WATCHDOG_S` | text | NVIDIA and AMD, Intel Arc | [DETAILS.md](DETAILS.md) |
| `STRATA_WDDM_BUDGET` | number | AMD, Intel Arc | [AMD_HIP.md](AMD_HIP.md) |
## Switches that go back to earlier behaviour (142)
## Switches that go back to earlier behaviour (143)
These behaviours are on by default. Setting the switch returns the earlier behaviour; the notes in the register say which
version made it the default.
@@ -522,6 +522,7 @@ version made it the default.
| `STRATA_INK_IQ_TC_MASK` | number | NVIDIA and AMD | v0.2.23 | - |
| `STRATA_INK_KEEP_MAPPED_PAGES` | on / off | NVIDIA and AMD | v0.2.21 | - |
| `STRATA_INK_KV_VMM` | on / off | NVIDIA and AMD | - | [INKLING_KV.md](INKLING_KV.md) |
| `STRATA_INK_LANE_PROBE_OLD` | on / off | NVIDIA and AMD | - | [INKLING_KV.md](INKLING_KV.md) |
| `STRATA_INK_MOE_V1` | on / off | NVIDIA and AMD | v0.2.21 | - |
| `STRATA_INK_NO_CAND` | on / off | NVIDIA and AMD | v0.2.21 | - |
| `STRATA_INK_OOM_RETRY` | number | NVIDIA and AMD | v0.2.21 | - |
+3
View File
@@ -324,6 +324,9 @@ if(STRATA_BUILD_TESTS)
target_include_directories(ink_batch_budget_test PRIVATE src/inkling2)
add_test(NAME ink_batch_budget_test COMMAND ink_batch_budget_test)
# #6770 / #6755: when strata-inkling's CUDA global K/V may grow in VRAM (net growth, not the whole new K/V; no GPU)
add_executable(ink_cold_lane_test tests/core/ink_cold_lane_test.cpp)
target_include_directories(ink_cold_lane_test PRIVATE include)
add_test(NAME ink_cold_lane_test COMMAND ink_cold_lane_test)
add_executable(ink_kv_grow_test tests/core/ink_kv_grow_test.cpp)
target_include_directories(ink_kv_grow_test PRIVATE include)
add_test(NAME ink_kv_grow_test COMMAND ink_kv_grow_test)
@@ -0,0 +1,33 @@
// strata-inkling CUDA, hybrid placement: which lane computes the cold experts (the ones that are not on the card), decided by a short probe at the start.
//
// STRATA_INK_EXACT unset: the same few decode steps are timed with the CPU lane and with the card's own copy-in lane (the "exact" lane: the same bits as an all-resident run), once
// per lane, and the faster one is kept. The probe is noisy (the PC's own load moves the CPU lane's time by 10 to 30 %) and the old rule kept the CPU lane unless the copy-in lane was
// clearly (10 %) faster: on an RTX 5070 12 GB (Windows, SQ-10, drafter off, the published 0.2.24 packages) the probe measured the CPU lane at 9.0 to 9.5 ms and the copy-in lane at
// 8.6 ms (ratio 0.95), the old rule kept the CPU lane, and every start decoded 65-68 tok/s and 34.5 on a 4K document where the copy-in lane gives 73 and 56.4 (+11 to +64 %); with a
// busier PC the same card measured 12 against 8.6 and chose the copy-in lane. The rule below runs the probe three times, alternating the lanes (the median of each lane), and keeps the
// exact lane unless the CPU lane is clearly (10 %) faster; a tie goes to the exact lane.
//
// STRATA_INK_LANE_PROBE_OLD=1 brings the old rule back (one probe per lane, the CPU lane unless the copy-in lane is 10 % faster).
#pragma once
#include <algorithm>
#include <vector>
namespace strata::core {
/// The median of the timed probes of one lane (the middle one of an odd count, the mean of the two middle ones of an even count); 0 for no probe.
inline double ink_probe_median(std::vector<double> v) {
if (v.empty()) return 0.0;
std::sort(v.begin(), v.end());
const size_t n = v.size();
return (n % 2) ? v[n / 2] : 0.5 * (v[n / 2 - 1] + v[n / 2]);
}
/// true: the cold experts are copied into the card and computed by its kernels (the exact lane); false: computed on the CPU where they are.
/// `t_cpu`, `t_card`: the probe's time per token with each lane. `old_rule`: STRATA_INK_LANE_PROBE_OLD=1.
inline bool ink_cold_lane_exact(double t_cpu, double t_card, bool old_rule) {
if (old_rule) return t_card < 0.9 * t_cpu;
return !(t_cpu < 0.9 * t_card);
}
} // namespace strata::core
+17 -8
View File
@@ -24,6 +24,7 @@
#include "ink_head_screen.cuh" // PERF-STEP: INT8-screened exact top-128 of the head (STRATA_INK_HEAD_SCREEN)
#include "strata/artifact/strata_reader.hpp"
#include "strata/core/ink_cold_lane.hpp"
#include "strata/core/ink_kv_grow.hpp"
#include "strata/core/ink_kv_reserve.hpp"
#include "strata/core/vmm.hpp"
@@ -6786,9 +6787,10 @@ struct InkCudaRunner {
}
// Launch probe for the cold-expert lane (STRATA_INK_EXACT unset): the same short run of decode steps is timed with the CPU lane and with
// the card's own copy-in lane (exact), on the placement the loaders made (the tier is paused and learns nothing), and the faster one is kept:
// the CPU lane unless the card's copy is clearly (10%) faster, because a CPU lane is the default of this engine and the probe is noisy.
// Runs once after the runner exists, before any request; a slot is reset when a request takes it, so the probe leaves no state behind.
// the card's own copy-in lane (exact), on the placement the loaders made (the tier is paused and learns nothing). The probe is run three times, alternating the lanes, and the median of
// each lane is compared (strata/core/ink_cold_lane.hpp): the exact (copy-in) lane unless the CPU lane is clearly (10%) faster, a tie going to the exact lane. The old rule (one probe per
// lane, the CPU lane unless the copy-in lane was 10% faster) kept the CPU lane on a quiet RTX 5070 at a ratio of 0.95 and decoded 11 to 64% slower than the copy-in lane;
// STRATA_INK_LANE_PROBE_OLD=1 brings it back. Runs once after the runner exists, before any request; a slot is reset when a request takes it, so the probe leaves no state behind.
void pick_cold_lane() {
auto& h = m.hybrid;
if (h.lane_pref != 0 || !h.active || m.n_host_experts == 0) return; // forced lane, or nothing is cold
@@ -6816,10 +6818,17 @@ struct InkCudaRunner {
return ms[ms.size() / 2];
};
h.probing = true;
const double t_cpu = run_lane(false);
const double t_card = run_lane(true);
const char* old_env = std::getenv("STRATA_INK_LANE_PROBE_OLD");
const bool old_rule = old_env && old_env[0] == '1';
std::vector<double> v_cpu, v_card;
for (int rep = 0; rep < (old_rule ? 1 : 3); ++rep) {
v_cpu.push_back(run_lane(false));
v_card.push_back(run_lane(true));
}
h.probing = false;
const bool exact = t_card < 0.9 * t_cpu;
const double t_cpu = strata::core::ink_probe_median(v_cpu);
const double t_card = strata::core::ink_probe_median(v_card);
const bool exact = strata::core::ink_cold_lane_exact(t_cpu, t_card, old_rule);
h.set_lane(exact);
if (ink_rtx5060ti_cfg(m.primary_gpu).compact_hybrid && !exact && t_cpu > 0.0 && t_card > 0.0 && h.dec_share_user < 0.0) {
// COMPACT_HYBRID row: the split of the batched cold experts comes from this box's own two lane times (see auto_pcie_share)
@@ -6836,8 +6845,8 @@ struct InkCudaRunner {
std::fill(h.h_use_batch.begin(), h.h_use_batch.end(), 0.0f); // the eager copy lane counted its routing here
if (h.d_trace_n) { INK_CK(cudaMemsetAsync(h.d_trace_n, 0, 4, st)); h.trace_flushed = 0; }
INK_CK(cudaStreamSynchronize(st));
std::fprintf(stderr, "[InkHybrid] cold experts: launch probe (%d decode steps each): CPU lane %.1f ms/token, copy into the card %.1f ms/token -> %s%s\n",
kTimed, t_cpu, t_card, exact ? "copied into the card and computed by its kernels (identical answers wherever an expert lives)"
std::fprintf(stderr, "[InkHybrid] cold experts: launch probe (%d decode steps each, median of %d): CPU lane %.1f ms/token, copy into the card %.1f ms/token -> %s%s\n",
kTimed, (int)v_cpu.size(), t_cpu, t_card, exact ? "copied into the card and computed by its kernels (identical answers wherever an expert lives)"
: "computed on the CPU where they are (the answer can differ from an all-resident run in rounding)",
" (STRATA_INK_EXACT=1 or 0 forces a lane)");
}
+40
View File
@@ -0,0 +1,40 @@
// ink_cold_lane.hpp: the probe's median and the lane rule (no GPU).
#include "strata/core/ink_cold_lane.hpp"
#include <cstdio>
using namespace strata::core;
static int failed = 0;
#define CHECK(c) do { if (!(c)) { std::fprintf(stderr, "ink_cold_lane_test: FAILED line %d: %s\n", __LINE__, #c); ++failed; } } while (0)
int main() {
// the median
CHECK(ink_probe_median({}) == 0.0);
CHECK(ink_probe_median({8.6}) == 8.6);
CHECK(ink_probe_median({9.5, 9.0, 12.4}) == 9.5); // an outlier does not move it
CHECK(ink_probe_median({3.0, 1.0}) == 2.0);
CHECK(ink_probe_median({5.0, 1.0, 3.0, 2.0}) == 2.5);
// the quiet RTX 5070 of the published packages: CPU lane 9.1 ms, copy-in lane 8.6 ms (ratio 0.945): the exact lane now (the old rule kept the CPU lane and lost 11 to 64 %)
CHECK(ink_cold_lane_exact(9.1, 8.6, false));
CHECK(!ink_cold_lane_exact(9.1, 8.6, true));
// a busy PC: CPU lane 12.1 ms, copy-in 8.6: the exact lane under both rules
CHECK(ink_cold_lane_exact(12.1, 8.6, false));
CHECK(ink_cold_lane_exact(12.1, 8.6, true));
// the CPU lane clearly faster (more than 10 %): the CPU lane under both rules
CHECK(!ink_cold_lane_exact(7.0, 8.6, false));
CHECK(!ink_cold_lane_exact(7.0, 8.6, true));
// a tie goes to the exact lane (the old rule kept the CPU lane)
CHECK(ink_cold_lane_exact(8.6, 8.6, false));
CHECK(!ink_cold_lane_exact(8.6, 8.6, true));
// the CPU lane 5 % faster: not clearly, so the exact lane (the new rule's hysteresis is on the CPU side)
CHECK(ink_cold_lane_exact(8.17, 8.6, false));
// exactly 10 % faster is not "clearly": the boundary stays with the exact lane
CHECK(ink_cold_lane_exact(0.9 * 8.6, 8.6, false));
CHECK(!ink_cold_lane_exact(0.89 * 8.6, 8.6, false));
if (failed) { std::fprintf(stderr, "ink_cold_lane_test: %d failure(s)\n", failed); return 1; }
std::printf("ink_cold_lane_test: ok\n");
return 0;
}
+35
View File
@@ -23524,6 +23524,41 @@
"retire_after": "",
"retired_in": ""
},
{
"name": "STRATA_INK_LANE_PROBE_OLD",
"backends": [
"cuda-hip"
],
"reads": [
{
"file": "engine/src/inkling2/cuda/ink_runner.cuh",
"line": 6821,
"backend": "cuda-hip",
"fn": "getenv"
}
],
"parse": "flag",
"default_state": "off",
"code_default": null,
"engine_sets": [],
"engine_defaults": [],
"launch_files": [],
"launch_sets": [],
"launch_reads": [],
"doc_mentions": [
"docs/INKLING_KV.md:73"
],
"first_commit": "",
"first_date": "2026-12-02",
"since": null,
"last_commit": "",
"last_date": "2026-12-02",
"status": "rollback",
"owner": "inkling2/cuda",
"note": "Rollback (0.2.25): =1 brings back the old cold-expert lane rule of the launch probe (one probe per lane, the CPU lane unless the copy-in lane is 10% faster). The default now runs the probe three times, alternating the lanes, and keeps the median of each: the exact (copy-in) lane unless the CPU lane is clearly (10%) faster, a tie going to the exact lane. A quiet RTX 5070 12 GB measured CPU 9.0-9.2 ms against copy-in 8.7 and the old rule kept the slower CPU lane (decode 65-68 tok/s and 34 on a 4K document against 73 and 56 with the copy-in lane). STRATA_INK_EXACT=1 or 0 still forces a lane.",
"retire_after": "",
"retired_in": ""
},
{
"name": "STRATA_INK_M1_DNPF",
"backends": [