SYCL: data/expert-profile-sycl.bin, the experts' ranking for a card on xe, built with make_profile_mix.py from the routing of 45 varied prompts and eight document summaries; setup_intel writes it instead of the shipped profile there (i915 keeps the shipped one). B70: +5..64% decode (mean +21%) on 12 unseen prompts, the same tokens. The copy-engine queue is Battlemage-only by default (it hung the A750's prompt)

This commit is contained in:
Niko1221 committed 2026-10-11 08:25:30 +02:00
1 parent 218df14283
commit 8cb26e6095
6 files changed
+85 -1

No files matched your search

Binary file not shown.
+2 -1
View File
@@ -11,7 +11,8 @@
// sycl::make_queue<ext_oneapi_level_zero>, so everything built on SYCL queues (memcpy, events, ext_oneapi_submit_barrier
// across queues) keeps working, only the engine changes. It returns nullptr (the caller keeps an ordinary in-order queue)
// when the backend is not Level Zero, the device has no copy-only group, the loader or the call fails, or
// STRATA_COPY_ENGINE=0. Same bytes, same kernels: the tokens do not change.
// STRATA_COPY_ENGINE=0 (default: on for a Battlemage card, which is where it was measured; =1 forces it on any Level Zero
// device, =0 off). Same bytes, same kernels: the tokens do not change.
#pragma once
#include <sycl/sycl.hpp>
+11
View File
@@ -121,6 +121,7 @@ def drop(args, name, value=False):
del args[i:i + 1 + int(value)]
SYCL_PROFILE = "expert-profile-sycl.bin" # data/: the xe cards' expert ranking (to_sycl)
SMALL_CARD_GB = 12.0 # under this the engine's own advice is --vram-reserve-mib 300 (a 1024 MiB reserve leaves an
# 8 GB card no room for even one expert slot) and the English draft vocabulary
SMALL_RESERVE_MIB = 300
@@ -149,6 +150,16 @@ def to_sycl(cfg: dict, exe: Path, ram: float, keep: dict, vram_gb: float = 0.0,
for f in ("--resident-experts", "--mmap-experts"): # setup's low-RAM mode is the CUDA engine's
drop(args, f)
drop(args, "--kv-resident", True) # decided below on the real RAM
if driver != "i915" and "--expert-profile" in args and (ROOT / "data" / SYCL_PROFILE).is_file():
# 0.1.43: a card on xe runs every expert on the GPU (the ones the cache does not hold are read from the pinned mirror
# by the same kernels), so WHICH experts the cache holds changes speed and no token: data/expert-profile-sycl.bin
# ranks them from the routing of 45 varied prompts (chat, code, maths, six languages) and eight document summaries,
# where the shipped profile holds 60% of a chat prompt's experts and 85% of a summary's (B70: +9..25% decode on prompts left
# out of it, same tokens). Another profile the user chose is kept; i915 keeps the shipped one (there the CPU
# computes the misses, so the residency moves roundings).
i = args.index("--expert-profile") + 1
if args[i].replace("\\", "/").rsplit("/", 1)[-1] == "expert-profile.bin":
args[i] = args[i][:-len("expert-profile.bin")] + SYCL_PROFILE
for f in ("--pack", "--native", "--ple-gguf", "--expert-profile", "--mtp", "--control-vector-scaled"):
if f in args:
v = args[args.index(f) + 1]
+8
View File
@@ -1,5 +1,6 @@
// src/core/copy_queue.cpp - see include/strata/copy_queue.hpp.
#include "strata/copy_queue.hpp"
#include "strata/sycl_queue.hpp"
#include <dpct/dpct.hpp>
#include <sycl/ext/oneapi/backend/level_zero.hpp>
@@ -84,6 +85,13 @@ sycl::queue* make_copy_engine_queue(const char* what) {
try {
if (dev.get_backend() != sycl::backend::ext_oneapi_level_zero) return nullptr;
// Battlemage only unless STRATA_COPY_ENGINE=1: on an Arc A750 (i915, JIT) the prompt path hung with it once the stager's
// completion flag became a copy-engine memcpy (4K and 600-token prompts, 10+ minutes, GPU not hung), and the measured gain
// there was 1.4% (a prompt there is compute bound).
{
const char* force = std::getenv("STRATA_COPY_ENGINE");
if (!(force && force[0] == '1') && strata::intel_gpu_gen(dev) != strata::IntelGpuGen::Battlemage) return nullptr;
}
// The legacy Level Zero adapter already puts memcpy on the copy engine (and its kernel launches are slower); only
// the v2 adapter needs this. SYCL_UR_USE_LEVEL_ZERO_V2=0 selects the legacy one.
const char* v2 = std::getenv("SYCL_UR_USE_LEVEL_ZERO_V2");
+53
View File
@@ -0,0 +1,53 @@
"""Tests for tools/make_profile_mix.py, without a model: synthetic routing traces.
python -m unittest tools.test_make_profile_mix
"""
from __future__ import annotations
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "tools"))
import make_profile as MP # noqa: E402
from test_make_profile import write_trace # noqa: E402
NE = 4
def run(args):
r = subprocess.run([sys.executable, str(ROOT / "tools" / "make_profile_mix.py")] + args, capture_output=True, text=True)
assert r.returncode == 0, r.stderr
return r.stdout
class MixProfile(unittest.TestCase):
def test_a_long_trace_does_not_outvote_a_short_one(self):
with tempfile.TemporaryDirectory() as d:
long_t, short_t, out = Path(d, "long"), Path(d, "short"), Path(d, "p.bin")
# the long trace uses pair (0, 1) 1000 times and (0, 2) 100 times; the short one uses (0, 3) 5 times
write_trace(long_t, [(0, [1] * 10)] * 100 + [(0, [2] * 10)] * 10)
write_trace(short_t, [(0, [3] * 5)])
run([str(long_t), str(short_t), "--out", str(out), "--n-expert", str(NE)])
ranked = MP.read_profile(out, NE)
# as distributions: (0,1) 0.909, (0,2) 0.091 in the long one; (0,3) 1.0 in the short one -> (0,3) first
self.assertEqual(ranked[:3], [(0, 3), (0, 1), (0, 2)])
self.assertEqual(len(ranked), MP.N_LAYER * NE) # every pair, once
self.assertEqual(len(set(ranked)), len(ranked))
def test_weights(self):
with tempfile.TemporaryDirectory() as d:
a, b, out = Path(d, "a"), Path(d, "b"), Path(d, "p.bin")
write_trace(a, [(1, [0] * 4)])
write_trace(b, [(1, [2] * 4)])
run([f"{a}:1", f"{b}:3", "--out", str(out), "--n-expert", str(NE)])
self.assertEqual(MP.read_profile(out, NE)[:2], [(1, 2), (1, 0)])
run([f"{a}:3", f"{b}:1", "--out", str(out), "--n-expert", str(NE)])
self.assertEqual(MP.read_profile(out, NE)[:2], [(1, 0), (1, 2)])
if __name__ == "__main__":
unittest.main()
+11
View File
@@ -179,6 +179,17 @@ class ToSycl(unittest.TestCase):
self.assertEqual(c["args"][c["args"].index("--vram-reserve-mib") + 1], "1024")
self.assertNotIn("STRATA_VERIFY_NO_HOST", c.get("env", {}))
def test_xe_ranks_the_experts_with_the_sycl_profile_and_i915_keeps_the_shipped_one(self):
m = self.mod()
shipped = str(m.MOUNT / "data" / "expert-profile.bin")
other = str(m.MOUNT / "mine" / "learned.bin")
c = m.to_sycl(self.cfg(m, ["--expert-profile", shipped]), m.ROOT / "build-sycl-aot" / "strata", 64.0, {}, 32.0, "xe")
self.assertTrue(c["args"][c["args"].index("--expert-profile") + 1].endswith("expert-profile-sycl.bin"))
c = m.to_sycl(self.cfg(m, ["--expert-profile", other]), m.ROOT / "build-sycl-aot" / "strata", 64.0, {}, 32.0, "xe")
self.assertTrue(c["args"][c["args"].index("--expert-profile") + 1].endswith("learned.bin")) # the user's own file stays
c = m.to_sycl(self.cfg(m, ["--expert-profile", shipped]), m.ROOT / "build-sycl" / "strata", 64.0, {}, 8.0, "i915")
self.assertTrue(c["args"][c["args"].index("--expert-profile") + 1].endswith("expert-profile.bin")) # the CPU computes the misses there
def test_an_explicit_reserve_is_kept_on_both_drivers(self):
m = self.mod()
for vram, drv in ((32.0, "xe"), (8.0, "i915")):