mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 00:08:52 +00:00
ling32 --mtp-auto: tier B also needs at least 4500 experts on the card (pool slots + card prefix); STRATA_L32_MTP_AUTO_MIN_CARD is the test hook
A verify batch of 2 tokens needs the experts of both tokens and consecutive tokens share only about 19 % of their expert uses, so with an LRU pool the misses of a 2-row verify are 2.0x those of one row (cache simulation on 2810 real decode tokens, L32-MID2): 1.8 tokens per verify then run at 0.90x on a link-bound card. Measured: RTX 5090 (PCIe 5.0, 5466 slots) +4..11 %; RTX 5070 Ti 16 GB (PCIe 5.0, 2413 slots) -0.7 %, 12 GB emulation (1485 slots) -2.4 %; RTX 4090 and 3090 (PCIe 4.0, about 4000 slots): forced MTP never gains (K=1: 1.83 tokens per verify at 48.0 tok/s against 49.0 plain; the adaptive controller runs plain). No measurement between 2413 and 5466 slots on a fast link: 4500 (22 % of the 20480 routed experts) is the conservative side of the cut. mtp_auto_pays takes the card expert count (-1: unknown, rule unchanged); tier A and unified memory ignore it. Tests: ling32_tier_planner_test table, ling32_mtp_auto_regress (pool cut off / small pool legs); z440 CTest 19/19 apart from this leg's first version (the fixture's pool holds many fixture experts: the leg moves the cut by hand).
This commit is contained in:
1 parent
e43485cb73
commit
875d0ec86a
5 files changed
+63
-11
No files matched your search
@@ -290,11 +290,17 @@ inline TierPlan plan_tier(const TierHardware& hw, const TierRequestOpts& rq, con
|
||||
// The tiers decode at the host-to-device link's speed (about 0.3 GB of expert slabs per token): a verify of several rows touches more distinct experts, so the drafter only wins when the link has the room, i.e.
|
||||
// on a PCIe 5.0 x16 class card (45-50 GB/s practical); with everything resident (tier A) and on unified memory there is no link to wait for. Tier C reads the SSD: never.
|
||||
constexpr double kMtpAutoMinLinkGbps = 32.0; // between PCIe 4.0 x16 (24.4 GB/s measured) and PCIe 5.0 x16 (45+ GB/s)
|
||||
inline bool mtp_auto_pays(TierMode mode, bool unified, double h2d_gbps, std::string* why = nullptr) {
|
||||
// Tier B also needs a big enough card pool: a verify batch of 2 tokens needs the experts of both tokens and consecutive tokens share only about 19 % of their expert uses, so with an LRU pool the misses of a
|
||||
// 2-row verify are 2.0x those of one row (cache simulation on 2810 real decode tokens, L32-MID2): 1.8 tokens per verify then run at 0.90x on a link-bound card. MTP only pays when the GPU, not the link, limits
|
||||
// the step, i.e. from a hit rate of about 90 %. Measured: RTX 5090 (PCIe 5.0, 5466 slots) +4..11 %; RTX 5070 Ti (PCIe 5.0, 2413 slots) -0.7 %, 12 GB emulation (1485 slots) -2.4 %; RTX 4090 / 3090 (PCIe 4.0,
|
||||
// about 4000 slots) never. No point between 2413 and 5466 slots on a fast link: 4500 (22 % of the 20480 routed experts) is the conservative side of the cut.
|
||||
constexpr int kMtpAutoMinCardExperts = 4500;
|
||||
inline bool mtp_auto_pays(TierMode mode, bool unified, double h2d_gbps, std::string* why = nullptr, int card_experts = -1, int min_card_experts = kMtpAutoMinCardExperts) {
|
||||
auto say = [&](const char* s) { if (why) *why = s; };
|
||||
if (unified) { say("unified memory: no link to wait for"); return true; }
|
||||
if (mode == TierMode::A) { say("all experts resident: no link to wait for"); return true; }
|
||||
if (mode == TierMode::C) { say("the SSD tier is slower than any drafter gain"); return false; }
|
||||
if (h2d_gbps >= kMtpAutoMinLinkGbps && card_experts >= 0 && card_experts < min_card_experts) { say("tier B with fewer than 4500 experts on the card: a 2-token verify misses twice as much as one token"); return false; }
|
||||
if (h2d_gbps >= kMtpAutoMinLinkGbps) { say("the host-to-device link has room (>= 32 GB/s)"); return true; }
|
||||
if (h2d_gbps <= 0.0) { say("the host-to-device link could not be measured"); return false; }
|
||||
say("tier B over a link below 32 GB/s: the controller never finds a gain");
|
||||
|
||||
@@ -770,7 +770,9 @@ int cmd_run(const RunOpts& o_in) {
|
||||
if (o.mtp_auto && !o.mtp_file.empty()) { // --mtp-auto: the sidecar only where it pays (tier A, unified memory, tier B over a fast link)
|
||||
std::string why;
|
||||
if (tiered) h2d_gbps = measure_h2d_gbps(o.device);
|
||||
const bool pays = mtp_auto_pays(tiered ? plan.mode : TierMode::A, integrated, h2d_gbps, &why);
|
||||
int min_card = kMtpAutoMinCardExperts;
|
||||
if (const char* ev = std::getenv("STRATA_L32_MTP_AUTO_MIN_CARD")) if (ev[0]) min_card = std::atoi(ev); // test hook: the pool-size cut by hand (0: off; ling32_mtp_auto_regress)
|
||||
const bool pays = mtp_auto_pays(tiered ? plan.mode : TierMode::A, integrated, h2d_gbps, &why, tiered ? plan.dyn_slots + plan.vram_ranks * 40 : -1, min_card); // 40 routed layers
|
||||
if (tiered) std::printf("tier store: host-to-device link moved %.1f GB/s (pinned 256 MiB copies, median of 3)\n", h2d_gbps);
|
||||
std::printf("MTP sidecar (--mtp-auto): %s: %s\n", pays ? "loaded" : "not loaded (--mtp FILE forces it)", why.c_str());
|
||||
if (!pays) {
|
||||
|
||||
@@ -20,12 +20,15 @@ import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def run(exe, wide, jobs, out, extra, link=None):
|
||||
def run(exe, wide, jobs, out, extra, link=None, min_card=None):
|
||||
os.makedirs(out, exist_ok=True)
|
||||
env = dict(os.environ)
|
||||
env.pop("STRATA_L32_H2D_GBPS", None)
|
||||
env.pop("STRATA_L32_MTP_AUTO_MIN_CARD", None)
|
||||
if link is not None:
|
||||
env["STRATA_L32_H2D_GBPS"] = str(link)
|
||||
if min_card is not None:
|
||||
env["STRATA_L32_MTP_AUTO_MIN_CARD"] = str(min_card)
|
||||
cmd = [exe, "--model", wide, "--genjobs", jobs, "--out", out, "--ctx", "400", "--no-selfcheck", "--chunk", "64", "--stop", "999999"] + extra
|
||||
p = subprocess.run(cmd, capture_output=True, text=True, errors="replace", env=env)
|
||||
txt = p.stdout + p.stderr
|
||||
@@ -49,13 +52,15 @@ def main():
|
||||
# name, extra args, link, expected 'MTP sidecar (--mtp-auto): ' text, whether speculation runs
|
||||
("plain tier B", tier_b, None, None, False),
|
||||
("auto, tier B, link 24.4", tier_b + ["--mtp-auto", mtp] + spec, 24.4, "not loaded", False),
|
||||
("auto, tier B, link 46", tier_b + ["--mtp-auto", mtp] + spec, 46.0, "loaded", True),
|
||||
("auto, tier B, link 46, pool cut off", tier_b + ["--mtp-auto", mtp] + spec, 46.0, "loaded", True, 0),
|
||||
("auto, tier B, link 46, small pool", tier_b + ["--mtp-auto", mtp] + spec, 46.0, "not loaded", False, 1000000), # the fixture's pool is tiny in bytes but holds many fixture experts: the cut is moved above them
|
||||
("forced, tier B, link 24.4", tier_b + ["--mtp", mtp] + spec, 24.4, None, True),
|
||||
("auto, tier A", ["--mtp-auto", mtp] + spec, None, "loaded", True),
|
||||
]
|
||||
ref = None
|
||||
for i, (name, extra, link, want, spec_on) in enumerate(legs):
|
||||
got, txt, err = run(exe, wide, jobs, os.path.join(work, "leg%d" % i), extra, link)
|
||||
for i, leg in enumerate(legs):
|
||||
name, extra, link, want, spec_on = leg[:5]
|
||||
got, txt, err = run(exe, wide, jobs, os.path.join(work, "leg%d" % i), extra, link, leg[5] if len(leg) > 5 else None)
|
||||
if got is None:
|
||||
print("FAIL: %s: %s" % (name, err))
|
||||
return 1
|
||||
|
||||
@@ -184,6 +184,12 @@ int main(int argc, char** argv) {
|
||||
CHECK(mtp_auto_pays(TierMode::B, true, 0.0)); // unified memory (Mac, Spark, Strix): pays
|
||||
CHECK(mtp_auto_pays(TierMode::B, false, 46.0, &why)); // RTX 5090, PCIe 5.0 x16: +11 % decode
|
||||
CHECK(mtp_auto_pays(TierMode::B, false, 32.0)); // the threshold itself
|
||||
CHECK(mtp_auto_pays(TierMode::B, false, 46.0, &why, 5466)); // RTX 5090: 5466 slots
|
||||
CHECK(!mtp_auto_pays(TierMode::B, false, 39.0, &why, 2413) && !why.empty()); // RTX 5070 Ti 16 GB on PCIe 5.0: 2413 slots, -0.7 %
|
||||
CHECK(!mtp_auto_pays(TierMode::B, false, 46.0, &why, 1485)); // 12 GB emulation: -2.4 %
|
||||
CHECK(mtp_auto_pays(TierMode::B, false, 46.0, &why, kMtpAutoMinCardExperts)); // the cut itself
|
||||
CHECK(mtp_auto_pays(TierMode::B, true, 0.0, &why, 100)); // unified memory ignores the pool size
|
||||
CHECK(mtp_auto_pays(TierMode::A, false, 0.0, &why, 100)); // tier A: everything is resident
|
||||
CHECK(!mtp_auto_pays(TierMode::B, false, 24.4, &why) && !why.empty()); // RTX 3090 / 4090, PCIe 4.0 x16: 1.00 tokens per verify
|
||||
CHECK(!mtp_auto_pays(TierMode::B, false, 12.0)); // PCIe 3.0 x16 / 4.0 x8 (5060 Ti, 5080 16 GB): -3 %
|
||||
CHECK(!mtp_auto_pays(TierMode::B, false, 0.0, &why) && !why.empty()); // link not measured: not loaded (--mtp forces it)
|
||||
|
||||
@@ -32343,7 +32343,7 @@
|
||||
"reads": [
|
||||
{
|
||||
"file": "engine/src/ling32/ling32_main.cpp",
|
||||
"line": 1180,
|
||||
"line": 1182,
|
||||
"backend": "cuda-hip",
|
||||
"fn": "getenv"
|
||||
}
|
||||
@@ -32673,7 +32673,7 @@
|
||||
"reads": [
|
||||
{
|
||||
"file": "engine/src/ling32/ling32_main.cpp",
|
||||
"line": 1730,
|
||||
"line": 1732,
|
||||
"backend": "cuda-hip",
|
||||
"fn": "getenv"
|
||||
}
|
||||
@@ -32698,6 +32698,39 @@
|
||||
"retire_after": "",
|
||||
"retired_in": ""
|
||||
},
|
||||
{
|
||||
"name": "STRATA_L32_MTP_AUTO_MIN_CARD",
|
||||
"backends": [
|
||||
"cuda-hip"
|
||||
],
|
||||
"reads": [
|
||||
{
|
||||
"file": "engine/src/ling32/ling32_main.cpp",
|
||||
"line": 774,
|
||||
"backend": "cuda-hip",
|
||||
"fn": "getenv"
|
||||
}
|
||||
],
|
||||
"parse": "int",
|
||||
"default_state": null,
|
||||
"code_default": "-1",
|
||||
"engine_sets": [],
|
||||
"engine_defaults": [],
|
||||
"launch_files": [],
|
||||
"launch_sets": [],
|
||||
"launch_reads": [],
|
||||
"doc_mentions": [],
|
||||
"first_commit": null,
|
||||
"first_date": null,
|
||||
"since": null,
|
||||
"last_commit": null,
|
||||
"last_date": null,
|
||||
"status": "research",
|
||||
"owner": "L32",
|
||||
"note": "test hook: replaces the card-expert count (pool slots + card prefix) below which --mtp-auto leaves the sidecar out in tier B (default 4500; 0: off; ling32_mtp_auto_regress)",
|
||||
"retire_after": "",
|
||||
"retired_in": ""
|
||||
},
|
||||
{
|
||||
"name": "STRATA_L32_MTP_FLOOR",
|
||||
"backends": [
|
||||
@@ -32844,7 +32877,7 @@
|
||||
},
|
||||
{
|
||||
"file": "engine/src/ling32/ling32_main.cpp",
|
||||
"line": 807,
|
||||
"line": 809,
|
||||
"backend": "cuda-hip",
|
||||
"fn": "getenv"
|
||||
}
|
||||
@@ -33576,7 +33609,7 @@
|
||||
"reads": [
|
||||
{
|
||||
"file": "engine/src/ling32/ling32_main.cpp",
|
||||
"line": 875,
|
||||
"line": 877,
|
||||
"backend": "cuda-hip",
|
||||
"fn": "getenv"
|
||||
}
|
||||
@@ -33708,7 +33741,7 @@
|
||||
"reads": [
|
||||
{
|
||||
"file": "engine/src/ling32/ling32_main.cpp",
|
||||
"line": 866,
|
||||
"line": 868,
|
||||
"backend": "cuda-hip",
|
||||
"fn": "getenv"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user