sycl: no short first prompt chunk while part of the experts is in the host mirror; setup asks a 24 GB+ card for 4096-token chunks
Every prompt chunk streams the experts the VRAM cache does not hold, over PCIe, and a 4K prompt touches nearly all 512 experts of a layer. The short first chunk (STRATA_PREFILL_FIRST, 256 tokens, there to start the GPU while PLE rows are read) therefore cost a whole extra pass of that stream whenever the cache holds only part of the model. Its default is now 256 only when the cache holds every expert, else 0 (an explicit STRATA_PREFILL_FIRST still decides). Arc Pro B70 32 GB, IQ3_S (11.5k of 24.6k experts in VRAM, the rest in the pinned mirror at 13 GB/s), a 4,095-token prompt, MTP on, interleaved runs, medians of 3: 2048-token chunks 618 -> 730 tok/s, 4096-token chunks 784 -> 980. sycl/setup_intel.py now writes --prefill 4096 for a card with 24 GB or more (it costs ~700 expert cache slots, about 3% of decode on the 200-token story).
This commit is contained in:
1 parent
78f6174474
commit
6fd12038b1
4 files changed
+103
-6
No files matched your search
@@ -0,0 +1,44 @@
|
||||
// gemm_launch: what does one expert-sized FP16 GEMM (oneMKL, half in, float out) cost back to back, by row count?
|
||||
// The prompt path issues one gate/up and one down GEMM per routed expert (~25k experts per 4K prompt on the 48 layers); if the
|
||||
// per-call time barely moves with the rows, the path is bound by launches, not by the XMX units.
|
||||
// gemm_launch [calls=2000]
|
||||
#include <sycl/sycl.hpp>
|
||||
#include <oneapi/mkl.hpp>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const int calls = argc > 1 ? std::atoi(argv[1]) : 2000;
|
||||
sycl::queue q{sycl::gpu_selector_v, sycl::property::queue::in_order{}};
|
||||
const int64_t N = 2560;
|
||||
struct Shape { const char* name; int64_t n, k; };
|
||||
const Shape shapes[] = {{"gate/up 1280x2560", 1280, N}, {"down 2560x640", N, 640}};
|
||||
const int64_t Ts[] = {8, 32, 80, 160, 320, 640, 1280};
|
||||
const int64_t maxT = 1280;
|
||||
using half = sycl::half;
|
||||
half* X = sycl::malloc_device<half>(maxT * N, q);
|
||||
half* W = sycl::malloc_device<half>(N * 1280 * 4, q);
|
||||
float* Y = sycl::malloc_device<float>(maxT * N, q);
|
||||
q.memset(X, 0, maxT * N * sizeof(half));
|
||||
q.memset(W, 0, N * 1280 * 4 * sizeof(half));
|
||||
q.wait();
|
||||
for (const Shape& s : shapes) {
|
||||
for (int64_t T : Ts) {
|
||||
auto run = [&](int n) {
|
||||
for (int i = 0; i < n; ++i)
|
||||
oneapi::mkl::blas::column_major::gemm(q, oneapi::mkl::transpose::trans, oneapi::mkl::transpose::nontrans, s.n, T, s.k, 1.0f,
|
||||
W, s.k, X, s.k, 0.0f, Y, s.n);
|
||||
q.wait();
|
||||
};
|
||||
run(50);
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
run(calls);
|
||||
const double us = std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - t0).count() / calls;
|
||||
const double gflop = 2.0 * (double) s.n * (double) T * (double) s.k * 1e-9;
|
||||
std::printf("%-20s T=%5lld: %7.1f us/call (%6.1f TFLOP/s)\n", s.name, (long long) T, us, gflop / us * 1e-3 * 1e3 / 1e3);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// launch_cost: host time per submission on an in-order queue (empty-ish kernel), with and without queue profiling, and with
|
||||
// an event per submission. If the prompt path's ~6 submissions per expert cost this much each, the 25k experts of a 4K
|
||||
// prompt are launch-bound.
|
||||
#include <sycl/sycl.hpp>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
template <class F>
|
||||
static double per_call_us(sycl::queue& q, int n, F&& f) {
|
||||
for (int i = 0; i < 100; ++i) f(i);
|
||||
q.wait();
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
for (int i = 0; i < n; ++i) f(i);
|
||||
const double submit_us = std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - t0).count() / n;
|
||||
q.wait();
|
||||
const double total_us = std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - t0).count() / n;
|
||||
std::printf(" host submit %.2f us/call, until done %.2f us/call\n", submit_us, total_us);
|
||||
return submit_us;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const int n = argc > 1 ? std::atoi(argv[1]) : 20000;
|
||||
for (int prof = 0; prof < 2; ++prof) {
|
||||
sycl::queue q = prof ? sycl::queue{sycl::gpu_selector_v, {sycl::property::queue::in_order(), sycl::property::queue::enable_profiling()}}
|
||||
: sycl::queue{sycl::gpu_selector_v, {sycl::property::queue::in_order()}};
|
||||
float* d = sycl::malloc_device<float>(1 << 20, q);
|
||||
std::printf("queue profiling %s\n", prof ? "on" : "off");
|
||||
std::printf(" tiny kernel, 1 work-group:\n");
|
||||
per_call_us(q, n, [&](int) { q.parallel_for(sycl::nd_range<1>(256, 256), [=](sycl::nd_item<1> it) { d[it.get_global_id(0)] = 1.f; }); });
|
||||
std::printf(" kernel of 4096 work-groups (1M items):\n");
|
||||
per_call_us(q, n / 4, [&](int) { q.parallel_for(sycl::nd_range<1>(1 << 20, 256), [=](sycl::nd_item<1> it) { d[it.get_global_id(0)] += 1.f; }); });
|
||||
std::printf(" tiny kernel, event kept:\n");
|
||||
sycl::event e;
|
||||
per_call_us(q, n, [&](int) { e = q.parallel_for(sycl::nd_range<1>(256, 256), [=](sycl::nd_item<1> it) { d[it.get_global_id(0)] = 1.f; }); });
|
||||
std::printf(" submit_barrier(event) + tiny kernel:\n");
|
||||
per_call_us(q, n, [&](int) {
|
||||
q.ext_oneapi_submit_barrier({e});
|
||||
e = q.parallel_for(sycl::nd_range<1>(256, 256), [=](sycl::nd_item<1> it) { d[it.get_global_id(0)] = 1.f; });
|
||||
});
|
||||
sycl::free(d, q);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+7
-5
@@ -115,7 +115,7 @@ def drop(args, name, value=False):
|
||||
del args[i:i + 1 + int(value)]
|
||||
|
||||
|
||||
def to_sycl(cfg: dict, exe: Path, ram: float, keep: dict) -> dict:
|
||||
def to_sycl(cfg: dict, exe: Path, ram: float, keep: dict, vram_gb: float = 0.0) -> dict:
|
||||
"""setup's config (written for its HIP path) -> the SYCL port's: the container's paths, experts streamed from the
|
||||
GGUF into VRAM (every expert must fit, so the VRAM reserve is the smallest that leaves the KV and the prompt
|
||||
buffers room - docs/INTEL.md), KV streaming from 64K up when the RAM holds the KV (the B70 at 256K decodes at
|
||||
@@ -137,9 +137,11 @@ def to_sycl(cfg: dict, exe: Path, ram: float, keep: dict) -> dict:
|
||||
S.ok(f"KV streaming on: the context's KV cache lives in RAM ({kv_ram:.1f} GB), every expert stays in VRAM")
|
||||
drop(args, "--vram-reserve-mib", True)
|
||||
args += ["--stream-experts", "--vram-reserve-mib", "1024" if ctx <= 32768 else "2048"]
|
||||
if ctx > 32768: # long contexts: 4096-token chunks keep the prompt buffers small
|
||||
drop(args, "--prefill", True)
|
||||
args += ["--prefill", "4096"]
|
||||
if ctx > 32768 or vram_gb >= 24: # long contexts: 4096-token chunks keep the prompt buffers small; a
|
||||
drop(args, "--prefill", True) # 24 GB+ card with part of the experts in the RAM mirror streams those
|
||||
args += ["--prefill", "4096"] # over PCIe once per chunk, so fewer, bigger chunks read the prompt
|
||||
# faster (Arc Pro B70, IQ3_S, a 4,095-token prompt: 2,048-token
|
||||
# chunks 618 tok/s, 4,096: 1,002; docs/INTEL.md); it costs ~700 cache slots
|
||||
out = {k: v for k, v in cfg.items() if k not in ("lib_dirs", "env", "vision", "gpus")}
|
||||
out.update({"backend": "sycl", "exe": str(SYCL_WRAPPER), "args": args, "sycl_root": str(MOUNT)})
|
||||
env = {}
|
||||
@@ -207,7 +209,7 @@ def install(argv) -> None:
|
||||
|
||||
def write_run_script(model, cfg_path, port, open_browser=True): # setup.write_run_script's signature (#870)
|
||||
cfg = json.loads(Path(cfg_path).read_text(encoding="utf-8"))
|
||||
cfg = to_sycl(cfg, exe, real_ram, keep.get(Path(cfg_path).name, {}))
|
||||
cfg = to_sycl(cfg, exe, real_ram, keep.get(Path(cfg_path).name, {}), intel[0]["vram_gb"])
|
||||
Path(cfg_path).write_text(json.dumps(cfg, indent=1), encoding="utf-8")
|
||||
script = write(model, cfg_path, port, open_browser)
|
||||
script.write_text(script.read_text().replace(str(ROOT / "serve" / "server.py"), str(SERVER)))
|
||||
|
||||
@@ -2156,7 +2156,13 @@ bool Prefill::run_impl(const int64_t *tokens, int64_t n, int64_t pos0,
|
||||
// SYCL port: a short first chunk so the GPU starts while the rest of the prompt's PLE rows are still being read
|
||||
// (27k random 4 KB reads per 2k tokens, 330 ms at the drive's ~85k IOPS, otherwise all before the first kernel).
|
||||
// STRATA_PREFILL_FIRST=<tokens> (0: off), default 256 when the prompt is longer than twice that.
|
||||
static const int64_t first_chunk = [] { const char* v = std::getenv("STRATA_PREFILL_FIRST"); return v ? std::atoll(v) : 256; }();
|
||||
// Every chunk streams the experts the cache does not hold (a 4K prompt touches nearly all 512 per layer), over PCIe: with
|
||||
// part of the model in the host mirror a short first chunk costs a whole extra pass of that stream (an Arc Pro B70 on
|
||||
// IQ3_S: a 4,095-token prompt 784 -> 1,002 tok/s without it). So the default is 256 only when the cache holds every
|
||||
// expert; STRATA_PREFILL_FIRST=<tokens> decides explicitly.
|
||||
const bool all_cached = m.cache != nullptr && m.g != nullptr && m.cache->slots() >= m.g->n_layers * m.g->n_expert;
|
||||
static const char* const first_env = std::getenv("STRATA_PREFILL_FIRST");
|
||||
const int64_t first_chunk = first_env ? std::atoll(first_env) : (all_cached ? 256 : 0);
|
||||
auto chunk_len = [&](int64_t c0) {
|
||||
if (c0 == 0 && first_chunk > 0 && first_chunk < m.T && n > 2 * first_chunk) return first_chunk;
|
||||
return std::min(m.T, n - c0);
|
||||
|
||||
Reference in new issue
Block a user